-
Notifications
You must be signed in to change notification settings - Fork 0
/
planning_utils.pl
53 lines (42 loc) · 1.49 KB
/
planning_utils.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
:- module(planning_utils, [
read_all_facts/2, safe_bagof/3, state_query_goal_check/3,
skolemize/1, deskolemize/2]
).
:- use_module(state_manipulation, [state_satisfies/2]).
read_all_facts(File, FactList):-
read(File, X) ->
(read(File, FC), FactList= [X|FC]);
(FactList=[]).
safe_bagof(Template, Test, ResultList):-
(bagof(Template, Test, ResultList) ->true ; ResultList=[]).
% Use as meta-call, pass state_query_goal_check(DesiredQuery) as InterestPredicate to the search.
state_query_goal_check(DesiredQuery, State, _ActionPath):-
not(not(state_satisfies(DesiredQuery, State))). % Might have to avoid unification.
% Skolemization, Deskolemization.
skolemize([]):- !.
skolemize([H|T]):-
H =.. [_|ArgList],
skolemize_args(ArgList),
skolemize(T).
skolemize_args([]).
skolemize_args([AH|AT]):-
not(var(AH)), !,
skolemize_args(AT).
skolemize_args([AH|AT]):-
var(AH),
gensym(kgv_, VId),
AH = kg_var(VId, _), % Introduce a new variable as well, so we can easily deskolemize
skolemize_args(AT).
deskolemize([], []) :- !.
deskolemize([H|T], [DH|DT]):-
H =.. [Pred|ArgList],
deskolemize_args(ArgList, DArgList),
DH =.. [Pred|DArgList],
deskolemize(T, DT).
deskolemize_args([], []).
deskolemize_args([AH|AT], [AH|DT]):-
not(AH = kg_var(_,_)), !,
deskolemize_args(AT, DT).
deskolemize_args([AH|AT], [V|DT]):-
AH = kg_var(_,V),% This V
deskolemize_args(AT, DT).