forked from aimacode/aima-julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanning_runner.jl
92 lines (74 loc) · 3.09 KB
/
planning_runner.jl
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
include("aimajulia.jl");
using Main.aimajulia;
function main()
knowledge_base = [
expr("Connected(Bucharest,Pitesti)"),
expr("Connected(Pitesti,Rimnicu)"),
expr("Connect3465ed(Rimnicu,Sibiu)"),
expr("Co345nnected(Sibiu,Fagaras)"),
expr("Connec346ted(Fagaras,Bucharest)"),
expr("Connected(Pitesti,Craiova)"),
expr("Connected(Craiova,Rimnicu)"),
];
for element in [
expr("Connected(x,y) ==> Connected(y,x)"),
expr("Connected(x,y) & Connected(y,z) ==> Connected(x,z)"),
expr("At(Sibiu)")
]
push!(knowledge_base, element);
end
knowledge_base
# Sibiu to Bucharest
precond_pos = [expr("At(Sibiu)")];
precond_neg = [];
effect_add = [expr("At(Bucharest)")];
effect_rem = [expr("At(Sibiu)")];
fly_s_b = PlanningAction(expr("Fly(Sibiu, Bucharest)"), (precond_pos, precond_neg), (effect_add, effect_rem));
# Bucharest to Sibiu
precond_pos = [expr("At(Bucharest)")];
precond_neg = [];
effect_add = [expr("At(Sibiu)")];
effect_rem = [expr("At(Bucharest)")];
fly_b_s = PlanningAction(expr("Fly(Bucharest, Sibiu)"), (precond_pos, precond_neg), (effect_add, effect_rem));
# Sibiu to Craiova
precond_pos = [expr("At(Sibiu)")];
precond_neg = [];
effect_add = [expr("At(Craiova)")];
effect_rem = [expr("At(Sibiu)")];
fly_s_c = PlanningAction(expr("Fly(Sibiu, Craiova)"), (precond_pos, precond_neg), (effect_add, effect_rem));
# Craiova to Sibiu
precond_pos = [expr("At(Craiova)")];
precond_neg = [];
effect_add = [expr("At(Sibiu)")];
effect_rem = [expr("At(Craiova)")];
fly_c_s = PlanningAction(expr("Fly(Craiova, Sibiu)"), (precond_pos, precond_neg), (effect_add, effect_rem));
# Bucharest to Craiova
precond_pos = [expr("At(Bucharest)")];
precond_neg = [];
effect_add = [expr("At(Craiova)")];
effect_rem = [expr("At(Bucharest)")];
fly_b_c = PlanningAction(expr("Fly(Bucharest, Craiova)"), (precond_pos, precond_neg), (effect_add, effect_rem));
# Craiova to Bucharest
precond_pos = [expr("At(Craiova)")];
precond_neg = [];
effect_add = [expr("At(Bucharest)")];
effect_rem = [expr("At(Craiova)")];
fly_c_b = PlanningAction(expr("Fly(Craiova, Bucharest)"), (precond_pos, precond_neg), (effect_add, effect_rem));
# Drive
precond_pos = [expr("At(x)")];
precond_neg = [];
effect_add = [expr("At(y)")];
effect_rem = [expr("At(x)")];
drive = PlanningAction(expr("Drive(x, y)"), (precond_pos, precond_neg), (effect_add, effect_rem));
function goal_text(kb::PDDL)
return ask(kb, expr("At(Bucharest)"));
end
prob = PDDL(knowledge_base, [fly_s_b, fly_b_s, fly_s_c, fly_c_s, fly_b_c, fly_c_b, drive], goal_test)
# apddl = AbstractPDDL(knowledge_base, [fly_s_b, fly_b_s, fly_s_c, fly_c_s, fly_b_c, fly_c_b, drive], goal_test)
folkb = FirstOrderLogicKnowledgeBase(knowledge_base)
gpp = GraphPlanProblem(prob, folkb)
println("Finding solutions...")
graphplan(gpp, ([expr("At(Bucharest)")], []))
# execute_action(gpp, nothing)
end
main()