Version fonctionnelle
This commit is contained in:
parent
0937e66efb
commit
68f191c7da
1 changed files with 848 additions and 839 deletions
89
TP1.pl
89
TP1.pl
|
@ -45,12 +45,12 @@ Les autres prédicats sont spécifiques au Taquin.
|
||||||
%********************
|
%********************
|
||||||
% format : initial_state(+State) ou State est une matrice (liste de listes)
|
% format : initial_state(+State) ou State est une matrice (liste de listes)
|
||||||
|
|
||||||
|
/*
|
||||||
initial_state([ [b, h, c], % C'EST L'EXEMPLE PRIS EN COURS
|
initial_state([ [b, h, c], % C'EST L'EXEMPLE PRIS EN COURS
|
||||||
[a, f, d], %
|
[a, f, d], %
|
||||||
[g,vide,e] ]). % h1=4, h2=5, f*=5
|
[g,vide,e] ]). % h1=4, h2=5, f*=5
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
% AUTRES EXEMPLES POUR LES TESTS DE A*
|
% AUTRES EXEMPLES POUR LES TESTS DE A*
|
||||||
|
|
||||||
|
@ -59,18 +59,20 @@ initial_state([ [ a, b, c],
|
||||||
[ g, h, d],
|
[ g, h, d],
|
||||||
[vide,f, e] ]). % h2=2, f*=2
|
[vide,f, e] ]). % h2=2, f*=2
|
||||||
|
|
||||||
|
|
||||||
initial_state([ [b, c, d],
|
initial_state([ [b, c, d],
|
||||||
[a,vide,g],
|
[a,vide,g],
|
||||||
[f, h, e] ]). % h2=10 f*=10
|
[f, h, e] ]). % h2=10 f*=10
|
||||||
|
|
||||||
|
|
||||||
initial_state([ [f, g, a],
|
initial_state([ [f, g, a],
|
||||||
[h,vide,b],
|
[h,vide,b],
|
||||||
[d, c, e] ]). % h2=16, f*=20
|
[d, c, e] ]). % h2=16, f*=20
|
||||||
|
*/
|
||||||
initial_state([ [e, f, g],
|
initial_state([ [e, f, g],
|
||||||
[d,vide,h],
|
[d,vide,h],
|
||||||
[c, b, a] ]). % h2=24, f*=30
|
[c, b, a] ]). % h2=24, f*=30
|
||||||
|
/*
|
||||||
initial_state([ [a, b, c],
|
initial_state([ [a, b, c],
|
||||||
[g,vide,d],
|
[g,vide,d],
|
||||||
[h, f, e]]). % etat non connexe avec l'etat final (PAS DE SOLUTION)
|
[h, f, e]]). % etat non connexe avec l'etat final (PAS DE SOLUTION)
|
||||||
|
@ -197,8 +199,8 @@ delete(N,X,[Y|L], [Y|R]) :-
|
||||||
%*************
|
%*************
|
||||||
|
|
||||||
heuristique(U,H) :-
|
heuristique(U,H) :-
|
||||||
heuristique1(U, H). % au debut on utilise l'heuristique 1
|
% heuristique1(U, H). % au debut on utilise l'heuristique 1
|
||||||
% heuristique2(U, H). % ensuite utilisez plutot l'heuristique 2
|
heuristique2(U, H). % ensuite utilisez plutot l'heuristique 2
|
||||||
|
|
||||||
|
|
||||||
%****************
|
%****************
|
||||||
|
@ -634,6 +636,7 @@ avl_test(10, Final) :-
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%*******************************************************************************
|
%*******************************************************************************
|
||||||
% AETOILE
|
% AETOILE
|
||||||
%*******************************************************************************
|
%*******************************************************************************
|
||||||
|
@ -696,17 +699,18 @@ main :-
|
||||||
aetoile(Pf,Pu,Q), !.
|
aetoile(Pf,Pu,Q), !.
|
||||||
|
|
||||||
%*******************************************************************************
|
%*******************************************************************************
|
||||||
aetoile(Pf, Pu, _) :-
|
|
||||||
empty(Pf),
|
|
||||||
empty(Pu),
|
|
||||||
write("PAS de SOLUTION : L’ETAT FINAL N’EST PAS ATTEIGNABLE !").
|
|
||||||
|
|
||||||
aetoile(Pf, _, Qs) :-
|
aetoile(Pf, _, _) :-
|
||||||
|
empty(Pf),
|
||||||
|
writeln("PAS de SOLUTION : L’ETAT FINAL N’EST PAS ATTEIGNABLE !").
|
||||||
|
|
||||||
|
|
||||||
|
aetoile(Pf, Pu, Qs) :-
|
||||||
suppress_min([[_,_,_],Fin],Pf,_Pf_new),
|
suppress_min([[_,_,_],Fin],Pf,_Pf_new),
|
||||||
|
initial_state(Deb),
|
||||||
final_state(Fin),
|
final_state(Fin),
|
||||||
suppress([Fin,[F,H,G],Pere,Action],_Pu,_Pu_new),
|
writeln("Solution trouvée !"),
|
||||||
write("Solution trouvée !"),
|
suppress([Fin,[F,H,G],Pere,Action],Pu,_Pu_new),
|
||||||
writeln(""),
|
|
||||||
affiche_solution([Fin,[F,H,G],Pere,Action], Qs).
|
affiche_solution([Fin,[F,H,G],Pere,Action], Qs).
|
||||||
|
|
||||||
aetoile(Pf, Pu, Qs) :-
|
aetoile(Pf, Pu, Qs) :-
|
||||||
|
@ -719,27 +723,31 @@ aetoile(Pf, Pu, Qs) :-
|
||||||
% INCORRECT
|
% INCORRECT
|
||||||
insert([U,[F,H,G],Pere,Action],Qs,Qs_new),
|
insert([U,[F,H,G],Pere,Action],Qs,Qs_new),
|
||||||
%(Qs) CORRECT
|
%(Qs) CORRECT
|
||||||
|
%print(U),
|
||||||
aetoile(Pf_last,Pu_last,Qs_new).
|
aetoile(Pf_last,Pu_last,Qs_new).
|
||||||
|
|
||||||
|
/*
|
||||||
|
aetoile(Pf, Pu, Q) :-
|
||||||
|
suppress_min([_, U],Pf, PfNext),
|
||||||
|
suppress([U, [F, H, G], Pere, A], Pu, PuNext),
|
||||||
|
expand(U, G, L),
|
||||||
|
loop_successors(L, PfNext, PuNext, Q, PfFinal, PuFinal),
|
||||||
|
insert([U, [F, H, G], Pere, A], Q, QFinal),
|
||||||
|
aetoile(PfFinal, PuFinal, QFinal).
|
||||||
|
*/
|
||||||
|
|
||||||
expand(U,G,L):- findall(U3,(rule(Action,1,U,U2),heuristique(U2,H), F is H+G+1, G2 is G+1, U3 = [U2,[F,H,G2],U,Action]),L).
|
expand(U,G,L):- findall(U3,(rule(Action,1,U,U2),heuristique(U2,H), F is H+G+1, G2 is G+1, U3 = [U2,[F,H,G2],U,Action]),L).
|
||||||
|
|
||||||
/*affiche_soltuion(State,nil) :-
|
|
||||||
State = [U,[_,_,G],_Pere,Action],
|
|
||||||
writeln(""),
|
|
||||||
print(U),
|
|
||||||
writeln(""),
|
|
||||||
write("Cout = "), print(G),
|
|
||||||
writeln(""),
|
|
||||||
write("Action = "), print(Action),
|
|
||||||
writeln("").
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
affiche_solution([Debut,_,nil,nil],_) :-
|
affiche_solution([Debut,_,nil,nil],_) :-
|
||||||
initial_state(Debut),
|
initial_state(Debut),
|
||||||
write("Etat initial : ").
|
writeln("Etat initial : "),
|
||||||
|
writeln(Debut).
|
||||||
|
|
||||||
|
/*
|
||||||
affiche_solution(State,Qs) :-
|
affiche_solution(State,Qs) :-
|
||||||
State = [U,[_,_,G],Pere,Action],
|
State = [U,[_,_,G],Pere,Action],
|
||||||
final_state(U),
|
final_state(U),
|
||||||
|
@ -748,16 +756,16 @@ affiche_solution(State,Qs) :-
|
||||||
writeln(""),
|
writeln(""),
|
||||||
write("Final state : "),
|
write("Final state : "),
|
||||||
print(U).
|
print(U).
|
||||||
|
*/
|
||||||
|
|
||||||
affiche_solution(State,Qs):-
|
affiche_solution(State,Qs):-
|
||||||
State = [U,[_,_,G],Pere,Action],
|
State = [U,[_,_,G],Pere,Action],
|
||||||
suppress([Pere,Cout,Pere1,Action1],Qs, Qs_new),
|
suppress([Pere,Cout,Pere1,Action1],Qs, Qs_new),
|
||||||
affiche_solution([Pere,Cout,Pere1,Action1],Qs_new),
|
affiche_solution([Pere,Cout,Pere1,Action1],Qs_new),
|
||||||
print(U),
|
write("Cout = "), writeln(G),
|
||||||
writeln(""),
|
write("Action = "), writeln(Action),
|
||||||
write("Cout = "), print(G),
|
writeln(U).
|
||||||
writeln(""),
|
|
||||||
write("Action = "), print(Action).
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -768,32 +776,33 @@ loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
||||||
belongs([U,_,_,_],Qs), %S est connu dans Q alors oublier cet état
|
belongs([U,_,_,_],Qs), %S est connu dans Q alors oublier cet état
|
||||||
loop_successors(F,Pf,Pu,Qs,Pf_last,Pu_last).
|
loop_successors(F,Pf,Pu,Qs,Pf_last,Pu_last).
|
||||||
|
|
||||||
|
|
||||||
loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
||||||
D = [U,[Fu,Gu,Hu],Pere,Action],
|
D = [U,[Fu,_Gu,_Hu],_Pere,_Action],
|
||||||
belongs([U,_,_,_],Pu),
|
belongs([U,[FF,_GG,_HH],_Father,_A],Pu),
|
||||||
suppress([U,[FF,GG,HH],Father,A],Pu,Pu_new),
|
FF =< Fu,
|
||||||
suppress([_,U],Pf,Pf_new),
|
loop_successors(F,Pf,Pu,Qs,Pf_last,Pu_last).
|
||||||
FF < Fu,
|
|
||||||
insert([U,[FF,GG,HH],Father,A],Pu_new,Pu_N),
|
|
||||||
insert([[FF,GG,HH],U],Pf_new,Pf_N),
|
|
||||||
loop_successors(F,Pf_N,Pu_N,Qs,Pf_last,Pu_last).
|
|
||||||
|
|
||||||
loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
||||||
D = [U,[Fu,Gu,Hu],Pere,Action],
|
D = [U,[Fu,Gu,Hu],Pere,Action],
|
||||||
belongs([U,_,_,_],Pu),
|
belongs([U,[FF,GG,HH],Father,A],Pu),
|
||||||
|
FF > Fu,
|
||||||
suppress([U,[FF,GG,HH],Father,A],Pu,Pu_new),
|
suppress([U,[FF,GG,HH],Father,A],Pu,Pu_new),
|
||||||
suppress([_,U],Pf,Pf_new),
|
suppress([_,U],Pf,Pf_new),
|
||||||
FF >= Fu,
|
|
||||||
insert([U,[Fu,Gu,Hu],Pere,Action],Pu_new,Pu_N),
|
insert([U,[Fu,Gu,Hu],Pere,Action],Pu_new,Pu_N),
|
||||||
insert([[Fu,Gu,Hu],U],Pf_new,Pf_N),
|
insert([[Fu,Gu,Hu],U],Pf_new,Pf_N),
|
||||||
loop_successors(F,Pf_N,Pu_N,Qs,Pf_last,Pu_last).
|
loop_successors(F,Pf_N,Pu_N,Qs,Pf_last,Pu_last).
|
||||||
|
|
||||||
|
|
||||||
loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
loop_successors([D|F], Pf,Pu,Qs,Pf_last,Pu_last) :-
|
||||||
D = [U,[Fu,Gu,Hu],Pere,Action],
|
D = [U,[Fu,Gu,Hu],Pere,Action],
|
||||||
insert([U,[Fu,Gu,Hu],Pere,Action],Pu,Pu_N),
|
insert([U,[Fu,Gu,Hu],Pere,Action],Pu,Pu_N),
|
||||||
insert([[Fu,Gu,Hu],U],Pf,Pf_N),
|
insert([[Fu,Gu,Hu],U],Pf,Pf_N),
|
||||||
loop_successors(F,Pf_N,Pu_N,Qs,Pf_last,Pu_last).
|
loop_successors(F,Pf_N,Pu_N,Qs,Pf_last,Pu_last).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*loop_successors([D|F], Pf,Pu,Qs) :-
|
/*loop_successors([D|F], Pf,Pu,Qs) :-
|
||||||
D = [U,[Fu,Gu,Hu],Pere,Action],
|
D = [U,[Fu,Gu,Hu],Pere,Action],
|
||||||
belongs([U,_,_,_],Pu) -> %- S est connu dans Pu
|
belongs([U,_,_,_],Pu) -> %- S est connu dans Pu
|
||||||
|
|
Loading…
Reference in a new issue