Re: FD constraints - strange behavior
Daniel Diaz <[email protected]>
| Newsgroups | gmane.comp.gnu.prolog.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, Fred 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). -------------------------------------------------- thank you for report. it is due to how big expressions are split into simpler ones. This is done with new brand intermediate variables whose initial domain is 0..max_int. When 2 of these variables are multiplied (non-linearity) an overflow occurs and resulting in an empty domain (max < min). This is clearly a behavior we don"t want. I add it to my TODO list. A workaround consists in splitting by hand the expression (as you did). 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). Strange, I have no problem with this one ! | ?- fractions1(Ls). Ls = [5,3,4,7,6,8,9,1,2] ? ; Ls = [5,3,4,9,1,2,7,6,8] ? ; Ls = [7,6,8,5,3,4,9,1,2] ? ; Ls = [7,6,8,9,1,2,5,3,4] ? ; Ls = [9,1,2,5,3,4,7,6,8] ? ; Ls = [9,1,2,7,6,8,5,3,4] ? ; (140 ms) no _______________________________________________ Users-prolog mailing list [email protected] http://lists.gnu.org/mailman/listinfo/users-prolog