-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* trail access in c/python/lua/c++ APIs * iteration over assignment in c/python/lua/c++ APIs * update travis config for CI tests * rename max_size to size in APIs and remove previous size method (breaks backward compatibility but makes things consistent)
- Loading branch information
Showing
12 changed files
with
796 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#script (lua) | ||
|
||
require("clingo") | ||
|
||
Propagator = { } | ||
Propagator.__index = Propagator | ||
|
||
function Propagator.new() | ||
local self = setmetatable({}, Propagator) | ||
return self | ||
end | ||
|
||
function check_lit(assignment, l) | ||
local trail = assignment.trail | ||
local t = assignment:value(l) | ||
if t ~= nil then | ||
local s = 1 | ||
if not t then | ||
s = -1 | ||
end | ||
local n = 0 | ||
for k in trail:iter() do | ||
if k == s * l then | ||
n = n + 1 | ||
end | ||
end | ||
assert(n == 1) | ||
end | ||
end | ||
|
||
function check_trail(assignment) | ||
local trail = assignment.trail | ||
local n = 0 | ||
for i = 0, assignment.decision_level do | ||
check = false | ||
for j = trail:first(i), trail:last(i) do | ||
check = true | ||
assert(assignment:is_true(trail[j])) | ||
n = n + 1 | ||
end | ||
assert(check) | ||
end | ||
assert(n == #trail) | ||
n = 0 | ||
for l in assignment:iter() do | ||
n = n + 1 | ||
check_lit(assignment, l) | ||
end | ||
assert(n == #assignment) | ||
n = 0 | ||
for i, l in assignment:__pairs() do | ||
n = n + 1 | ||
assert(assignment[i] == l) | ||
end | ||
assert(n == #assignment) | ||
n = 0 | ||
for i, l in assignment:__ipairs() do | ||
n = n + 1 | ||
assert(assignment[i] == l) | ||
end | ||
assert(n == #assignment) | ||
n = 0 | ||
for i, k in trail:__pairs() do | ||
assert(trail[i] == k) | ||
n = n + 1 | ||
end | ||
assert(n == #trail) | ||
n = 0 | ||
for i, k in trail:__ipairs() do | ||
assert(trail[i] == k) | ||
n = n + 1 | ||
end | ||
assert(n == #trail) | ||
end | ||
|
||
|
||
function Propagator:init(init) | ||
check_trail(init.assignment) | ||
|
||
init.check_mode = clingo.PropagatorCheckMode.Fixpoint | ||
end | ||
|
||
function Propagator:check(control) | ||
check_trail(control.assignment) | ||
end | ||
|
||
function main(prg) | ||
local p = Propagator.new() | ||
prg:register_propagator(p) | ||
prg:ground({{"base", {}}}) | ||
prg:solve() | ||
end | ||
|
||
#end. | ||
|
||
{ a; b; c }. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Step: 1 | ||
|
||
a | ||
a b | ||
a b c | ||
a c | ||
b | ||
b c | ||
c | ||
SAT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#script (python) | ||
|
||
import clingo | ||
from itertools import chain | ||
|
||
def check_lit(assignment, l): | ||
trail = assignment.trail | ||
t = assignment.value(l) | ||
if t is not None: | ||
s = 1 | ||
if not t: | ||
s = -1 | ||
n = 0 | ||
for k in trail: | ||
if k == s * l: | ||
n = n + 1 | ||
assert n == 1 | ||
|
||
def check_trail(assignment): | ||
trail = assignment.trail | ||
|
||
n = 0 | ||
for i in range(0, assignment.decision_level + 1): | ||
check = False | ||
for j in range(trail.begin(i), trail.end(i)): | ||
check = True | ||
assert assignment.is_true(trail[j]) | ||
n = n + 1 | ||
assert check | ||
assert n == len(trail) | ||
|
||
n = 0 | ||
for l in assignment: | ||
n = n + 1 | ||
check_lit(assignment, l) | ||
assert n == len(assignment) | ||
|
||
n = 0 | ||
for l in chain(assignment[0::2], assignment[1::2]): | ||
n = n + 1 | ||
assert n == len(assignment) | ||
|
||
n = 0 | ||
for l in chain(trail[0::2], trail[1::2]): | ||
n = n + 1 | ||
assert n == len(trail) | ||
|
||
n = 1 | ||
for l in trail[0:-1]: | ||
n = n + 1 | ||
assert n == len(trail) | ||
|
||
n = 0 | ||
for l in trail[-1:-1-len(trail):-1]: | ||
n = n + 1 | ||
assert n == len(trail) | ||
|
||
n = 0 | ||
for l in chain(trail[-1:-1-len(trail):-2], trail[-2:-1-len(trail):-2]): | ||
n = n + 1 | ||
assert n == len(trail) | ||
|
||
class Propagator: | ||
def init(self, init): | ||
check_trail(init.assignment) | ||
|
||
init.check_mode = clingo.PropagatorCheckMode.Fixpoint | ||
|
||
def check(self, control): | ||
check_trail(control.assignment) | ||
|
||
def main(prg): | ||
prg.register_propagator(Propagator()) | ||
prg.ground([("base", [])]) | ||
prg.solve() | ||
|
||
#end. | ||
|
||
{ a; b; c }. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Step: 1 | ||
|
||
a | ||
a b | ||
a b c | ||
a c | ||
b | ||
b c | ||
c | ||
SAT |
Submodule clasp
updated
4 files
+13 −10 | clasp/clingo.h | |
+1 −1 | libpotassco | |
+13 −2 | src/clingo.cpp | |
+56 −0 | tests/facade_test.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.