34
41
42:- module(pddl_valoptic_interface, [
43 optic_workspace/2, 44 optic_requirement/3, 45 optic_init/3, 46 optic_predicate/3, 47 optic_function/3, 48 optic_type/3, 49 optic_object/3, 50 optic_derived/4, 51 optic_axiom/3, 52 optic_action/4, 53 optic_copy_workspace/2, 54 optic_load_pddl_file/2, 55
56 optic_get_plan/3, 57 optic_apply_step/3, 58 ensure_optic/0,
59 optic_debug/1
60
61 ]).
62
63
64optic_copy_workspace(W,NewWorkspace):- optic_missing(optic_copy_workspace(W,NewWorkspace)).
65
66optic_load_pddl_file(W,FileName):- optic_missing(optic_load_pddl_file(W,FileName)).
82optic_workspace(Opr,W):- call_mockup(optic_workspace(Opr,W)).
83
84optic_requirement(Opr,W,Require):- call_mockup(optic_requirement(Opr,W,Require)).
85
86optic_init(Opr,W,Fact):-
87 glean_objs(Opr,W,Fact),
88 call_mockup(optic_init(Opr,W,Fact)).
89
90optic_predicate(Opr,W,Predicate):-
91 glean_types(Opr,W,Predicate),
92 call_mockup(optic_predicate(Opr,W,Predicate)).
93
94optic_function(Opr,W,Function):-
95 glean_types(Opr,W,Function),
96 call_mockup(optic_function(Opr,W,Function)).
97
98optic_type(Opr,W,Type):-
99 glean_types(Opr,W,Type),
100 call_mockup(optic_type(Opr,W,Type)).
101
102optic_object(Opr,W,Object):-
103 glean_types(Opr,W,Object),
104 call_mockup(optic_object(Opr,W,Object)).
105
106optic_derived(Opr,W,Fact,Cond) :- Cond==[], !, optic_init(Opr,W,Fact).
107optic_derived(Opr,W,Fact,Condition) :-
108 call_mockup(optic_derived(Opr,W,Fact,Condition)).
109
110
111optic_axiom(Opr,W,Axiom):- call_mockup(optic_axiom(Opr,W,Axiom)).
112
113optic_action(Opr,W,Action,Info):- check_opr(W,Opr),
114 glean_types(Opr,W,Action),
115 call_mockup(optic_action(Opr,W,Action,Info)).
119optic_get_plan(W,Goal,Plan):-
120 check_workspace(W),
121 ignore(Plan=[s1,s2,s3]),
122 optic_missing(optic_get_plan(W,Goal,Plan)).
125optic_apply_step(W,Step,NewWorkspace):-
126 check_workspace(W),
127 (var(NewWorkspace)->gensym(W,NewWorkspace);true),
128 check_workspace(NewWorkspace),
129 optic_missing(optic_apply_step(W,Step,NewWorkspace)).
130
131
132ensure_optic.
133
134glean_types(Opr,W,Any):- Opr=add,!,
135 check_opr(W,Opr),
136 forall((sub_term(Sub,Any),
137 compound(Sub),member(Sub,[_-Type, Type:_])),
138 optic_type(Opr,W,Type)).
139glean_types(_,_,_).
140
141
142glean_objs(Opr,W,Any):- Opr=add,!,
143 forall((sub_term(Sub,Any),
144 compound(Sub),member(Sub,[Obj-_])),
145 optic_object(Opr,W,Obj)),
146 forall((sub_term(Obj,Any),
147 atom(Obj)),optic_object(Opr,W,Obj)).
148glean_objs(_,_,_).
149
150check_opr(W,add):- check_workspace(W).
151check_opr(W,del):- check_workspace(W).
152check_opr(W,current):- check_workspace(W).
153check_opr(_Workspace,Opr):- throw(opr_missing(Opr)).
154
155:- dynamic(current_workspace/1).
156
157check_workspace(W):- current_workspace(W),!.
158check_workspace(W):- asserta(current_workspace(W)).
159
160call_mockup(Goal):-
161 arg(1,Goal,Opr),
162 arg(2,Goal,W),
163 check_opr(W,Opr),
164 optic_missing(Goal).
165
166optic_debug(Info):- format('~N% ~q.~n',[Info]).
167
168optic_missing(Goal):- !,optic_debug(g(Goal)).
169optic_missing(Goal):- throw(optic_missing(Goal)).
170
171
172