bug-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in gprolog under MacOS X (fd solver?)


From: Jérôme Cornet
Subject: Bug in gprolog under MacOS X (fd solver?)
Date: Wed, 21 Dec 2005 22:47:04 -0000

Hello,

consider the simple sudoku solver at the end of the mail. When
executing the following query:

sudoku(8,_,_,_,_,_,_,_,3,
     _,_,_,7,_,_,_,_,_,
     _,_,2,_,_,4,1,8,9,
     _,_,8,_,_,_,_,_,_,
     7,_,9,6,_,1,8,_,2,
     _,_,_,_,_,_,3,_,_,
     6,5,1,3,_,_,7,_,_,
     _,_,_,_,_,2,_,_,_,
     2,_,_,_,_,_,_,_,1).

on gprolog 1.2.16 and 1.2.19 under Linux
(for instance Linux buet 2.4.32-686 #2 SMP Sat Nov 19 17:27:19 CET 2005 i686 GNU/Linux)

we get the following answer:

-------------------------
| 8 4 5 | 2 1 9 | 6 7 3 |
| 9 1 6 | 7 8 3 | 2 4 5 |
| 3 7 2 | 5 6 4 | 1 8 9 |
-------------------------
| 5 2 8 | 9 3 7 | 4 1 6 |
| 7 3 9 | 6 4 1 | 8 5 2 |
| 1 6 4 | 8 2 5 | 3 9 7 |
-------------------------
| 6 5 1 | 3 9 8 | 7 2 4 |
| 4 9 3 | 1 7 2 | 5 6 8 |
| 2 8 7 | 4 5 6 | 9 3 1 |
-------------------------

which is correct.

Now, when executing the same query on the same program
running on gprolog compiled for MacOS X/Darwin, we get this answer:

-------------------------
| 8 4 5 | 2 1 9 | 6 7 3 |
| 9 9 6 | 7 8 3 | 2 4 5 |
| 3 7 2 | 5 6 4 | 1 8 9 |
-------------------------
| 5 2 8 | 9 3 5 | 4 1 7 |
| 7 3 9 | 6 4 1 | 8 5 2 |
| 5 1 4 | 8 2 7 | 3 9 6 |
-------------------------
| 6 5 1 | 3 9 8 | 7 2 4 |
| 4 9 3 | 1 7 2 | 5 6 8 |
| 2 8 7 | 4 5 6 | 9 3 1 |
-------------------------

which violate trivially sudoku's constraints and
above all produce multiple answer where only
one is possible.

The faulty behavior has been tested and reproduced
under both versions 1.2.16 and 1.2.19 under MacOS X 10.4
(Darwin thot-2.local 8.3.0 Darwin Kernel Version 8.3.0: Mon Oct 3 20:04:04 PDT 2005; root:xnu-792.6.22.obj~2/RELEASE_PPC Power Macintosh powerpc)

with gprolog compiled with gcc 3.3 (same version of gcc for linux tests).

The bug seems to affect sudoku's program using fd constraints (this
is not the only program exhibiting faulty behavior under MacOS X;
basically the same kind of program here:

http://lists.gnu.org/archive/html/users-prolog/2004-12/msg00009.html

produce the same results).

Do you have any idea of what is going wrong?

Jérôme Cornet


% Sudoku
%
% (pour GNU Prolog)
%
% par Jerome Cornet
%
% (c) Copyright 2005 Jerome Cornet

% --------------------------------------
% partie non portable

valide(X) :- fd_domain(X, 1, 9).

tousdifferents(L) :- fd_all_different(L).

%---------------------------------------
% Affichage

afficheligne(X1, X2, X3, X4, X5, X6, X7, X8, X9) :-
  write('| '),
write(X1), write(' '), write(X2), write(' '), write(X3), write(' | '), write(X4), write(' '), write(X5), write(' '), write(X6), write(' | '), write(X7), write(' '), write(X8), write(' '), write(X9), write(' |'), nl.

affichelignehorizontale :- write('-------------------------'), nl.

affichesudoku(A1, A2, A3, A4, A5, A6, A7, A8, A9,
              B1, B2, B3, B4, B5, B6, B7, B8, B9,
              C1, C2, C3, C4, C5, C6, C7, C8, C9,
              D1, D2, D3, D4, D5, D6, D7, D8, D9,
              E1, E2, E3, E4, E5, E6, E7, E8, E9,
              F1, F2, F3, F4, F5, F6, F7, F8, F9,
              G1, G2, G3, G4, G5, G6, G7, G8, G9,
              H1, H2, H3, H4, H5, H6, H7, H8, H9,
              I1, I2, I3, I4, I5, I6, I7, I8, I9) :-

   nl,
   affichelignehorizontale,
   afficheligne(A1, A2, A3, A4, A5, A6, A7, A8, A9),
   afficheligne(B1, B2, B3, B4, B5, B6, B7, B8, B9),
   afficheligne(C1, C2, C3, C4, C5, C6, C7, C8, C9),
   affichelignehorizontale,
   afficheligne(D1, D2, D3, D4, D5, D6, D7, D8, D9),
   afficheligne(E1, E2, E3, E4, E5, E6, E7, E8, E9),
   afficheligne(F1, F2, F3, F4, F5, F6, F7, F8, F9),
   affichelignehorizontale,
   afficheligne(G1, G2, G3, G4, G5, G6, G7, G8, G9),
   afficheligne(H1, H2, H3, H4, H5, H6, H7, H8, H9),
   afficheligne(I1, I2, I3, I4, I5, I6, I7, I8, I9),
   affichelignehorizontale.

%---------------------------------------

sudoku(A1, A2, A3, A4, A5, A6, A7, A8, A9,
       B1, B2, B3, B4, B5, B6, B7, B8, B9,
       C1, C2, C3, C4, C5, C6, C7, C8, C9,
       D1, D2, D3, D4, D5, D6, D7, D8, D9,
       E1, E2, E3, E4, E5, E6, E7, E8, E9,
       F1, F2, F3, F4, F5, F6, F7, F8, F9,
       G1, G2, G3, G4, G5, G6, G7, G8, G9,
       H1, H2, H3, H4, H5, H6, H7, H8, H9,
       I1, I2, I3, I4, I5, I6, I7, I8, I9) :-

       % tous les nombres compris entre 1 et 9
       valide(A1), valide(A2), valide(A3),
       valide(A4), valide(A5), valide(A6),
       valide(A7), valide(A8), valide(A9),
       valide(B1), valide(B2), valide(B3),
       valide(B4), valide(B5), valide(B6),
       valide(B7), valide(B8), valide(B9),
       valide(C1), valide(C2), valide(C3),
       valide(C4), valide(C5), valide(C6),
       valide(C7), valide(C8), valide(C9),
       valide(D1), valide(D2), valide(D3),
       valide(D4), valide(D5), valide(D6),
       valide(D7), valide(D8), valide(D9),
       valide(E1), valide(E2), valide(E3),
       valide(E4), valide(E5), valide(E6),
       valide(E7), valide(E8), valide(E9),
       valide(F1), valide(F2), valide(F3),
       valide(F4), valide(F5), valide(F6),
       valide(F7), valide(F8), valide(F9),
       valide(G1), valide(G2), valide(G3),
       valide(G4), valide(G5), valide(G6),
       valide(G7), valide(G8), valide(G9),
       valide(H1), valide(H2), valide(H3),
       valide(H4), valide(H5), valide(H6),
       valide(H7), valide(H8), valide(H9),
       valide(I1), valide(I2), valide(I3),
       valide(I4), valide(I5), valide(I6),
       valide(I7), valide(I8), valide(I9),

       % contraintes sur les lignes
       tousdifferents([A1, A2, A3, A4, A5, A6, A7, A8, A9]),
       tousdifferents([B1, B2, B3, B4, B5, B6, B7, B8, B9]),
       tousdifferents([C1, C2, C3, C4, C5, C6, C7, C8, C9]),
       tousdifferents([D1, D2, D3, D4, D5, D6, D7, D8, D9]),
       tousdifferents([E1, E2, E3, E4, E5, E6, E7, E8, E9]),
       tousdifferents([F1, F2, F3, F4, F5, F6, F7, F8, F9]),
       tousdifferents([G1, G2, G3, G4, G5, G6, G7, G8, G9]),
       tousdifferents([H1, H2, H3, H4, H5, H6, H7, H8, H9]),
       tousdifferents([I1, I2, I3, I4, I5, I6, I7, I8, I9]),

       % contraintes sur les carres 3x3
       tousdifferents([A1, A2, A3, B1, B2, B3, C1, C2, C3]),
       tousdifferents([D1, D2, D3, E1, E2, E3, F1, F2, F3]),
       tousdifferents([G1, G2, G3, H1, H2, H3, I1, I2, I3]),
       tousdifferents([A4, A5, A6, B4, B5, B6, C4, C5, C6]),
       tousdifferents([D4, D5, D6, E4, E5, E6, F4, F5, F6]),
       tousdifferents([G4, G5, G6, H4, H5, H6, I4, I5, I6]),
       tousdifferents([A7, A8, A9, B7, B8, B9, C7, C8, C9]),
       tousdifferents([D7, D8, D9, E7, E8, E9, F7, F8, F9]),
       tousdifferents([G7, G8, G9, H7, H8, H9, I7, I8, I9]),

       % contraintes sur les colonnes
       tousdifferents([A1, B1, C1, D1, E1, F1, G1, H1, I1]),
       tousdifferents([A2, B2, C2, D2, E2, F2, G2, H2, I2]),
       tousdifferents([A3, B3, C3, D3, E3, F3, G3, H3, I3]),
       tousdifferents([A4, B4, C4, D4, E4, F4, G4, H4, I4]),
       tousdifferents([A5, B5, C5, D5, E5, F5, G5, H5, I5]),
       tousdifferents([A6, B6, C6, D6, E6, F6, G6, H6, I6]),
       tousdifferents([A7, B7, C7, D7, E7, F7, G7, H7, I7]),
       tousdifferents([A8, B8, C8, D8, E8, F8, G8, H8, I8]),
       tousdifferents([A9, B9, C9, D9, E9, F9, G9, H9, I9]),

       fd_labelingff([A1, A2, A3, A4, A5, A6, A7, A8, A9,
                      B1, B2, B3, B4, B5, B6, B7, B8, B9,
                      C1, C2, C3, C4, C5, C6, C7, C8, C9,
                      D1, D2, D3, D4, D5, D6, D7, D8, D9,
                      E1, E2, E3, E4, E5, E6, E7, E8, E9,
                      F1, F2, F3, F4, F5, F6, F7, F8, F9,
                      G1, G2, G3, G4, G5, G6, G7, G8, G9,
                      H1, H2, H3, H4, H5, H6, H7, H8, H9,
                      I1, I2, I3, I4, I5, I6, I7, I8, I9]),

       affichesudoku(A1, A2, A3, A4, A5, A6, A7, A8, A9,
                     B1, B2, B3, B4, B5, B6, B7, B8, B9,
                     C1, C2, C3, C4, C5, C6, C7, C8, C9,
                     D1, D2, D3, D4, D5, D6, D7, D8, D9,
                     E1, E2, E3, E4, E5, E6, E7, E8, E9,
                     F1, F2, F3, F4, F5, F6, F7, F8, F9,
                     G1, G2, G3, G4, G5, G6, G7, G8, G9,
                     H1, H2, H3, H4, H5, H6, H7, H8, H9,
                     I1, I2, I3, I4, I5, I6, I7, I8, I9).







reply via email to

[Prev in Thread] Current Thread [Next in Thread]