FAQ Database Discussion Community


Constraint not propagated upon instantiation of list members

parsing,prolog,clpfd
I am building a parser and generator for dates and times. In an ordinary programming language these would be written separately. In Prolog+CLP(FD) I can write 1 predicate that does both :-) In my use case it often makes sense to parse a number of digits and convert the to...

Not sufficiently instantiated for maplist(all_distinct, list)

prolog,swi-prolog,clpfd,declarative-programming
I'm not able to run this code, what exactly do I have to say about the list to allow maplist/2 to run all_distinct/1? Solution = [A, B, C, D, E, F, G, H, I], Solution ins 1..9, maplist(all_distinct, Solution). I get ERROR: Arguments are not sufficiently instantiated. I understand that...

Prolog constraint

prolog,constraints,clpfd
I have 3 Constraints for a List: list ins 1..9 all_different(list) lists in the list --> I get some lists from the list. every list from the list has to fulfill the constraint to be gapless. for example: List1 = [1,3,2,4]; List2=[3,2,1]; List3= [5,7,6] WRONG: List4=[1,4,3] 1 Question: You have...

Use reified constraints to make 3 numbers consecutive

prolog,constraints,clpfd
Here's an outline of my SWI-Prolog program: :- use_module(library(clpfd)). consec1(L) :- L=[L1,L2,L3,L4,L5,L6,L7,L8,L9], L ins 1..9, ..., abs(L5-L4)#=1, all_different(L), labeling([],L) abs(L5-L4)#=1 makes L5 and L4 next to each other. If I wanted to make three numbers next to each other e.g. L3, L4 and L5, how could I use reified constraints...

Logic Programming

prolog,clpfd
Time 5, 3, 8, 2, 7, 3, 9, 3, 3, 5, 7 You have to schedule players (which uses Time) to three different showers. Get the best solution. So far, my solution is: use_module(library(clpfd)). shower(S, E, D, Done) :- D = [5, 3, 8, 2, 7, 3, 9, 3, 3,...