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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
mod blocksworld {
use pddlp::problem::{self, Fact, Goal, Object};
pub const BLOCKSWORLD: &'static str = "
;; base case
;;
(define (problem blocksworld-01)
(:domain blocksworld)
(:objects b1 b2 - object)
(:init
(arm-empty)
(clear b2)
(on-table b2)
(clear b1)
(on-table b1)
)
(:goal (and
(clear b1)
(on b1 b2)
(on-table b2)
)))";
#[test]
fn parse() {
let problem = problem::parse(BLOCKSWORLD).unwrap();
assert_eq!("blocksworld-01", problem.name.unwrap());
assert_eq!("blocksworld", problem.domain.unwrap());
assert_eq!(
vec![
Object {
name: "b1",
type_name: Some("object")
},
Object {
name: "b2",
type_name: Some("object")
}
],
problem.objects.unwrap()
);
assert_eq!(
vec![
Fact {
predicate: "arm-empty",
objects: vec![]
},
Fact {
predicate: "clear",
objects: vec!["b2"]
},
Fact {
predicate: "on-table",
objects: vec!["b2"]
},
Fact {
predicate: "clear",
objects: vec!["b1"]
},
Fact {
predicate: "on-table",
objects: vec!["b1"]
},
],
problem.init.unwrap()
);
assert_eq!(
Goal::And(vec![
Goal::Fact(Fact {
predicate: "clear",
objects: vec!["b1"]
}),
Goal::Fact(Fact {
predicate: "on",
objects: vec!["b1", "b2"]
}),
Goal::Fact(Fact {
predicate: "on-table",
objects: vec!["b2"]
}),
]),
problem.goal.unwrap()
);
}
}
mod ferry {
use pddlp::problem::{self, Fact, Goal, Object};
pub const BLOCKSWORLD: &'static str = "
;; base case
;;
(define (problem ferry-01)
(:domain ferry)
(:objects
car1 - car
loc1 loc2 - location
)
(:init
(empty-ferry)
(at-ferry loc1)
(at car1 loc1)
)
(:goal (and (at car1 loc2))))";
#[test]
fn parse() {
let problem = problem::parse(BLOCKSWORLD);
assert!(problem.is_ok());
let problem = problem.unwrap();
assert_eq!("ferry-01", problem.name.unwrap());
assert_eq!("ferry", problem.domain.unwrap());
assert_eq!(
vec![
Object {
name: "car1",
type_name: Some("car")
},
Object {
name: "loc1",
type_name: Some("location")
},
Object {
name: "loc2",
type_name: Some("location")
}
],
problem.objects.unwrap()
);
assert_eq!(
vec![
Fact {
predicate: "empty-ferry",
objects: vec![]
},
Fact {
predicate: "at-ferry",
objects: vec!["loc1"]
},
Fact {
predicate: "at",
objects: vec!["car1", "loc1"]
},
],
problem.init.unwrap()
);
assert_eq!(
Goal::And(vec![Goal::Fact(Fact {
predicate: "at",
objects: vec!["car1", "loc2"]
}),]),
problem.goal.unwrap()
);
}
}