missing file
[chr.git] / a_star.pl
blobde40741d7b4be38e0a074cfc0ee74567a91fd189
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Author: Tom Schrijvers
3 % Email: Tom.Schrijvers@cs.kuleuven.be
4 % Copyright: K.U.Leuven 2004
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 :- module(a_star,
8 a_star/4
9 ]).
11 :- use_module(binomialheap).
13 :- use_module(find).
15 :- use_module(hprolog).
17 %% SICStus begin
18 %% :- use_module(library(terms),[term_variables/2]).
19 %% SICStus end
21 a_star(DataIn,FinalData,ExpandData,DataOut) :-
22 a_star_node(DataIn,0,InitialNode),
23 empty_q(NewQueue),
24 insert_q(NewQueue,InitialNode,Queue),
25 a_star_aux(Queue,FinalData,ExpandData,EndNode),
26 a_star_node(DataOut,_,EndNode).
28 a_star_aux(Queue,FinalData,ExpandData,EndNode) :-
29 delete_min_q(Queue,Queue1,Node),
30 ( final_node(FinalData,Node) ->
31 Node = EndNode
33 expand_node(ExpandData,Node,Nodes),
34 insert_list_q(Nodes,Queue1,NQueue),
35 a_star_aux(NQueue,FinalData,ExpandData,EndNode)
38 final_node(D^Call,Node) :-
39 a_star_node(Data,_,Node),
40 term_variables(Call,Vars),
41 chr_delete(Vars,D,DVars),
42 copy_term(D^Call-DVars,Data^NCall-DVars),
43 call(NCall).
45 expand_node(D^Ds^C^Call,Node,Nodes) :-
46 a_star_node(Data,Score,Node),
47 term_variables(Call,Vars),
48 chr_delete(Vars,D,DVars0),
49 chr_delete(DVars0,Ds,DVars1),
50 chr_delete(DVars1,C,DVars),
51 copy_term(D^Ds^C^Call-DVars,Data^EData^Cost^NCall-DVars),
52 term_variables(Node,NVars,DVars),
53 find_with_var_identity(ENode,NVars,(NCall,EScore is Cost + Score,a_star:a_star_node(EData,EScore,ENode)),Nodes).
55 a_star_node(Data,Score,Data-Score).