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!! GiovannaReceived on Wed Feb 25 2009 - 23:28:02 CET
This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:21 CEST