[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FD constraints - strange behavior
From: |
Fred Bapst |
Subject: |
FD constraints - strange behavior |
Date: |
Tue, 18 Dec 2007 22:24:37 +0100 |
Hello,
Using Gnu-Prolog up to 1.3.0, I'm facing something strange (might be a bug ?)
illustrated in the predicates below. Why on earth doesn't v1(_) find the
solution ? Defining a new variable for the subexpression (C+30) seems to help
Gnu-Prolog...
It could be related to an overflow problem, but It would be surprising : we are
far below max_integer. It does not seem to be related to the "FD sparse
representation" pitfall (setting fd_set_vector_max to a big value has no effect).
Thanks in advance.
-----------
Execution :
-----------
| ?- v1(Res).
no
| ?- v2(Res).
Res = [9,7]
yes
| ?- v3(Res).
Res = [9,7]
yes
-----------
Listing :
-----------
v1(Ls) :-
Ls = [C,G],
fd_domain(C, 8, 9), fd_domain(G, 7, 8),
780 + 52*(C+30) + 12*G*(C+30) #= 156*(C+30),
fd_labelingff(Ls).
v2(Ls) :-
Ls = [C,G],
fd_domain(C, 8, 9), fd_domain(G, 7, 8),
C30#=30+C, % replacing _expression_ in v1
780 + 52*(C30) + 12*G*(C30) #= 156*(C30),
fd_labelingff(Ls).
v3(Ls) :-
Ls = [C,G],
fd_domain(C, 8, 9), fd_domain(G, 7, 8),
C#=9, % adding a constraint to v1
780 + 52*(C+30) + 12*G*(C+30) #= 156*(C+30),
fd_labelingff(Ls).
--------------------------------------------------
By the way, my original code (for a CLP problem taken from a book) showing the
"bug" was :
fractions1(Ls) :-
Ls = [A,B,C,D,E,F,G,H,I],
fd_domain(Ls, 1, 9),
fd_all_different(Ls),
BC #= 10*B+C, EF #= 10*E+F, HI #= 10*H+I,
A*EF*HI + D*BC*HI + G*BC*EF #= BC*EF*HI,
fd_labelingff(Ls).
- FD constraints - strange behavior,
Fred Bapst <=