-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanning.lp
74 lines (57 loc) · 1.8 KB
/
planning.lp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
plan(nil, 0).
plan(seq(Plan, Action), N+1) :- plan(Plan, N), action(Action), N < 3.
% after(Plan, Prop)
after(nil, Prop) :- initially(Prop).
after(seq(Plan, Action), Prop) :-
plan(seq(Plan,Action), _),
possible_after(Plan, Action),
effect(Action, Prop).
after(seq(Plan,Action), Prop) :-
plan(seq(Plan,Action), _),
after(Plan, Prop),
possible_after(Plan, Action),
not deletes(Action, Prop).
%#show after/2.
% possible_after(Plan, Action)
possible_after(Plan, move(C,L))
:- after(Plan, at(C, L')), action(move(C,L)), location(L'), not L = L'.
possible_after(Plan, take(C,I))
:- after(Plan, at(C,L)), after(Plan, at(I,L)).
possible(Plan) :- plan(Plan,_), possible_after(Plan,_).
% effect(Action,Prop)
effect(move(C,L), at(C,L)) :- action(move(C,L)).
effect(take(C,I), has(C,I)) :- action(take(C,I)).
% deletes(Action,Prop)
deletes(move(C,L), at(C,L')) :- action(move(C,L)), location(L'), not L = L'.
deletes(take(C,I), at(I,L)) :- action(take(C,I)), location(L).
% only generate 1 plan
1 { happens(P) : possible(P) } 1.
#show happens/1.
%% Sample domain
character(alice).
character(bob).
item(key).
location(garden).
location(foyer).
% initially(Prop)
initially(at(alice,garden)).
initially(at(bob,foyer)).
initially(at(key,garden)).
action(move(C,L)) :- character(C), location(L).
action(take(C,I)) :- character(C), item(I).
%% This works like a traditional planner
% % goals
% goal(has(bob,key)).
% goal(at(alice,foyer)).
%
% % rule out plans that don't achieve goals
% :- happens(P), goal(G), not after(P, G).
% agents
agent(take(C,I), C) :- action(take(C,I)).
agent(move(C,L), C) :- action(move(C,L)).
% What I want to codify:
% No action Act with agent Ag takes place unless Ag must do Act to
% accomplish their intention
% What I don't know how to say:
% "must do [action] to accomplish [intention]"
%