I am writing a Prolog program using clp(fd)
and am having difficultly implementing one of my desired constraints.
The output is a list of integers (the length is dependent on the input to another part of the program), where there are certain pairs of predefined numbers which are mutually exclusive, and one number from each pair must be in the output.
An example:
The output is a list of integers, each between 1 and 10. The output must contain either a 3 or a 4, but not both.
So far I have the below, which constrains it so that 3 and 4 cannot both be in the output, however it does not ensure that one of them is in the output.
mutual2([A], ME1):-
(A in 3 #==> ME1) #/\ (#\ A in 4 #<== ME1).
mutual2([A, B| Tail], ME1):-
(A in 3 #==> ME1) #/\ (#\ A in 4 #<== ME1),
(B in 3 #==> ME1) #/\ (#\ B in 4 #<== ME1),
mutual2([B|Tail], ME1).
EDIT:
So running:
[A,B] ins 2..6, A #< B, mutual2([1,2,B,A,5],M), label([A,B]).
Gives:
A = 2,
B = 3,
M = 1 ;
A = 2,
B = 4,
M = 0 ;
A = 2,
B = 5,
M in 0..1 ;
A = 3,
B = 5,
M = 1 ;
A = 4,
B = 5,
M = 0 ;
But I do not want A=2, B=5, M in 0..1
to be a valid output, as neither A
nor B
are 3 or 4.
ExprA #<==> #\ ExprB
? – ApochromaticA in 3..4
etc – Apochromatic