[eclipse-clp-users] counting backtracking

From: Joy Joy <joy.marsico_at_gmail.com>
Date: Fri, 27 Feb 2009 11:54:51 +0100
Hello!I'm developing N-queens problem and I have a problem: I wish counting
the number of backtracking in my program. My code is written with forward
checking:

queens(Var,N):- domini(1,N,D), length(Var,N),
assegna_dom(VarDom,D,Var),ausiliare(VarDom).

ausiliare([]).
ausiliare([[X1,D]|Rest]):-member(X1,D),
            successivi(X1,Rest, Newrest),
                        ausiliare(Newrest).


successivi(X,Rest,Newrest):- successivi(X,Rest,1,Newrest).
successivi(X,[],Nb,[]).
successivi(X,[[Var,Dom]|Rest],Nb,[[Var,[F|T]]|Newrest]):-
remove_value(X,Dom,Nb,[F|T]),
                                                        Nb1 is Nb +1,

successivi(X,Rest,Nb1,Newrest).


remove_value(X,[],Nb,[]).
remove_value(X,[Val|Rest],Nb,[Val|Newrest]):-vincoli(X,Val,Nb),!,
remove_value(X,Rest,Nb,Newrest).
remove_value(X,[Val|Rest],Nb,Newrest):-remove_value(X,Rest,Nb,Newrest).


domini(N,Max,[N|T]):-  N1 is N+1,
                        domini(N1,Max,T).




vincoli(Value1,Value2,Nb):-  Value1 =\= Value2 +Nb,
                     Value1 =\= Value2 -Nb,
                             Value1 =\= Value2.



assegna_dom([],_,[]).
assegna_dom([[V,D]|LVarDom],D,[V|LVar]):- assegna_dom(LVarDom,D,LVar).


Help  me!!

Giovanna
Received on Fri Feb 27 2009 - 10:54:56 CET

This archive was generated by hypermail 2.2.0 : Thu Feb 02 2012 - 02:31:58 CET