1#script (lua) 2 3require("clingo") 4 5Propagator = { } 6Propagator.__index = Propagator 7 8function Propagator.new() 9 local self = setmetatable({}, Propagator) 10 self.lits = {} 11 return self 12end 13 14function Propagator:init(init) 15 for atom in init.symbolic_atoms:by_signature("p", 1) do 16 local sym = atom.symbol 17 self.lits[#self.lits+1] = init:solver_literal(atom.literal) 18 end 19 print(init.check_mode, clingo.PropagatorCheckMode.Total) 20 assert(init.check_mode == clingo.PropagatorCheckMode.Total) 21 assert(init.check_mode ~= clingo.PropagatorCheckMode.Fixpoint) 22 assert(init.check_mode ~= clingo.PropagatorCheckMode.Off) 23 init.check_mode = clingo.PropagatorCheckMode.Fixpoint 24 assert(init.check_mode == clingo.PropagatorCheckMode.Fixpoint) 25end 26 27function Propagator:check(ctl) 28 -- assert(not ctl.assignment.is_total) 29 for _, lit in ipairs(self.lits) do 30 if ctl.assignment:value(lit) == nil then 31 ctl:add_clause{{lit}} 32 break 33 end 34 end 35end 36 37function main(prg) 38 local p = Propagator.new() 39 prg:register_propagator(p) 40 prg:ground({{"base", {}}}) 41 prg:solve() 42end 43 44#end. 45 46{ p(1..10) }. 47