This is a really neat and simple way of showing progress in a tree search. I'm sure someone has thought of it before... ?- queens_array(20, Q). 1 2 3 4 5 6 7 8 9 10 11 12 11 .. 12 10 .. 12 13 14 11 .. 14 10 .. 14 9 .. 14 15 10 .. 15 9 .. 15 16 13 .. 16 11 .. 16 10 .. 16 9 .. 16 8 .. 16 7 .. 16 17 18 19 20 Q = [](1, 3, 5, 2, 4, 13, 15, 12, 18, 20, 17, 9, 16, 19, 8, 10, 7, 14, 6, 11) Yes (1.25s cpu, solution 1, maybe more) ? % Simple search depth display, demonstrated on queens :- lib(ic). queens_array(N, Board) :- dim(Board, [N]), Board[1..N] :: 1..N, ( for(I,1,N), param(Board,N) do ( for(J,I+1,N), param(Board,I) do Board[I] #\= Board[J], Board[I] #\= Board[J]+J-I, Board[I] #\= Board[J]+I-J ) ), init_depth(Shelf), ( foreacharg(Q,Board,Depth), param(Shelf) do report_depth(Shelf, Depth), indomain(Q) ). init_depth(Shelf) :- shelf_create(1..0, Shelf). report_depth(Shelf, Depth) :- shelf_get(Shelf, 0, Min..Max), ( Depth > Max -> shelf_set(Shelf, 0, Depth..Depth), writeln(Depth) ; Depth < Min -> shelf_set(Shelf, 1, Depth), writeln(Depth..Max) ; true ). -- JoachimReceived on Fri Jul 16 2010 - 11:53:07 CEST
This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET