astar(state([Aim|T],G,F),state([Aim|T],G,F),Open):-
Aim=t,true.
astar(X,Y,Open):-
findall(Z,rule(X,Z),L),
enter1(L,Open,[T]),
not(empty(T)),
get_first(state([A|B],G,H),T,T1),
delete(state([A|_ ],_,_),T1,T2),
astar(state([A|B],G,H),state([A|B],G,H),T1).
rule(state([W1|T],G1,H1),state([W2,W1|T],G2,H2)):-
goes(W1,W2,G0),
not(member(W2,[W1|T])),
count_g(G1,G0,G2),
count_h(W2,H2).
enter([ ],X,X):-true.
enter([X|Y],L,L1):-enter(X,L,L2),enter(Y,L2,L1).
enter1(X,[ ],[X]):-true.
enter1(X,[F|T],[X,F|T]):-le(X,F).
enter1(X,[F|T],[F|T1]):-enter1(X,T,T1).
le(state(X,G1,H1),state(Y,G2,H2)):- G1+H1=<G2+H2.
get_first(X,[X|T],T):-true.
delete(_,[ ],[ ]):-true.
delete(X,[X|L],M):-delete(X,L,M).
delete(X,[Y|L1],[Y|L2]):-delete(X,L1,L2).
empty([ ]):-true.
member(X,[X|_]):-true.
member(X,[_|Y]):-member(X,Y).
max(X,X,Y):-X>Y,true.
max(Y,X,Y):-Y>X,true.
count_g(G1,G0,G2):-G2=G1+G0.
goes(s,a,11).
goes(a,b,9).
goes(a,c,6).
goes(a,d,1).
goes(a,t,18).
goes(b,a,1).
goes(c,a,3).
goes(c,b,1).
goes(d,a,6).
goes(d,c,1).
count_h(a,1).
count_h(b,4).
count_h(c,.
count_h(d,14).
count_h(s,20).
count_h(t,0).
/*astar(state([s],0,20),state(Path,G,H),[ ]).*/
/*rule(state([c|[d,s]],11,,state([W,c|[d,s]],G,H)).*/
以上代码运行出了问题,SWI输入astar(state([s],0,20),state(Path,G,H),[ ]).之后没有结果显示,只有false,跪求指导!!谢了!!!
Aim=t,true.
astar(X,Y,Open):-
findall(Z,rule(X,Z),L),
enter1(L,Open,[T]),
not(empty(T)),
get_first(state([A|B],G,H),T,T1),
delete(state([A|_ ],_,_),T1,T2),
astar(state([A|B],G,H),state([A|B],G,H),T1).
rule(state([W1|T],G1,H1),state([W2,W1|T],G2,H2)):-
goes(W1,W2,G0),
not(member(W2,[W1|T])),
count_g(G1,G0,G2),
count_h(W2,H2).
enter([ ],X,X):-true.
enter([X|Y],L,L1):-enter(X,L,L2),enter(Y,L2,L1).
enter1(X,[ ],[X]):-true.
enter1(X,[F|T],[X,F|T]):-le(X,F).
enter1(X,[F|T],[F|T1]):-enter1(X,T,T1).
le(state(X,G1,H1),state(Y,G2,H2)):- G1+H1=<G2+H2.
get_first(X,[X|T],T):-true.
delete(_,[ ],[ ]):-true.
delete(X,[X|L],M):-delete(X,L,M).
delete(X,[Y|L1],[Y|L2]):-delete(X,L1,L2).
empty([ ]):-true.
member(X,[X|_]):-true.
member(X,[_|Y]):-member(X,Y).
max(X,X,Y):-X>Y,true.
max(Y,X,Y):-Y>X,true.
count_g(G1,G0,G2):-G2=G1+G0.
goes(s,a,11).
goes(a,b,9).
goes(a,c,6).
goes(a,d,1).
goes(a,t,18).
goes(b,a,1).
goes(c,a,3).
goes(c,b,1).
goes(d,a,6).
goes(d,c,1).
count_h(a,1).
count_h(b,4).
count_h(c,.
count_h(d,14).
count_h(s,20).
count_h(t,0).
/*astar(state([s],0,20),state(Path,G,H),[ ]).*/
/*rule(state([c|[d,s]],11,,state([W,c|[d,s]],G,H)).*/
以上代码运行出了问题,SWI输入astar(state([s],0,20),state(Path,G,H),[ ]).之后没有结果显示,只有false,跪求指导!!谢了!!!