1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % Author
: Tom Schrijvers
3 % Email
: Tom
.Schrijvers
@cs.kuleuven
.be
4 % Copyright
: K
.U
.Leuven
2004
5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 :- use_module
(binomialheap
).
15 :- use_module
(hprolog
).
18 %% :- use_module
(library
(terms
),[term_variables
/2]).
21 a_star
(DataIn
,FinalData
,ExpandData
,DataOut
) :-
22 a_star_node
(DataIn
,0,InitialNode
),
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
) ->
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
),
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
).