Enumerating domains in Prolog's clpfd -
i'm exploring dependent structures of constraints one:
assign(x,y) :- x in 1..5, ((x mod 2 #= 1) #=> y in 2..3), ((x mod 2 #= 0) #=> y #= 5).
what i'm looking representation of x
's , y
's domains sparse possible - in case along lines of x in {1,3,5} , y in {2,3} or x in {2,4} , y = 5
.
one way of doing detect variables on left side of #=>
, enumerate values , collect , merge them together, ?- assign(x, y), findall(x-d, (indomain(x),fd_dom(y,d)), c), stuff c
, maybe there more efficient way?
i've encountered error trying label([x,y])
: arguments not sufficiently instantiated goes away when add constraint on y
's domain.
when should expect error occur? feel have poor understanding of clpfd's mechanisms , limitations, there resources learn from? know basics of constraint programming, arc consistency etc.
to keep clpfd enumeration predicates (like indomain/1
, label/1
, labeling/2
, etc.) ever throwing instantiation errors, ensure all variables have been assigned finite domain before enumeration predicates executed.
so how directly translating wrote code?
assign(x,y) :- x in 1\/3\/5, y in 2..3. % x in {1,3,5} , y in {2,3} assign(x,y) :- x in 2..4, y in 5. % or x in {2,4} , y = 5
a simple query (with swi-prolog):
?- assign(x,y), labeling([],[x,y]). x = 1, y = 2 ; x = 1, y = 3 ; x = 3, y = 2 ; x = 3, y = 3 ; x = 5, y = 2 ; x = 5, y = 3 ; x = 2, y = 5 ; x = 3, y = 5 ; x = 4, y = 5.
Comments
Post a Comment