-
Notifications
You must be signed in to change notification settings - Fork 1
/
briefcase_world.rs
118 lines (106 loc) · 4.52 KB
/
briefcase_world.rs
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
use pddl::{
AtomicFormula, Domain, GoalDefinition, Parser, PreconditionGoalDefinition, PreferenceGD,
Problem, TermLiteral,
};
pub const BRIEFCASE_WORLD: &str = r#"
(define (domain briefcase-world)
(:requirements :strips :equality :typing :conditional-effects)
(:types location physob)
(:constants
B ; the briefcase
P ; the paycheck
D
- physob)
(:predicates (at ?x - physob ?y - location)
(in ?x ?y - physob))
; Move briefcase from one location to another.
(:action mov-B
:parameters (?m ?l - location)
:precondition (and (at B ?m) (not (= ?m ?l)))
:effect (and (at B ?l) (not (at B ?m))
(forall (?z)
(when (and (in ?z) (not (= ?z B)))
(and (at ?z ?l) (not (at ?z ?m)))))) )
; Put the item in the briefcase.
(:action put-in
:parameters (?x - physob ?l - location)
:precondition (not (= ?x B)) ; the item must not be the briefcase itself
:effect (when
(and (at ?x ?l) (at B ?l)) ; briefcase and item are at the same location
(in ?x)) ) ; ... then the item is in the briefcase.
; Take the item out of the briefcase.
(:action take-out
:parameters (?x - physob)
:precondition (not (= ?x B)) ; the item must be the briefcase itself
:effect (not (in ?x)) ) ; the item is not in the briefcase anymore.
)
"#;
pub const BRIEFCASE_WORLD_PROBLEM: &str = r#"
(define (problem get-paid)
(:domain briefcase-world)
(:init
; types: locations
(place home) (place office)
; types: objects
(object p) (object d) (object b)
; setup
(at B home) (at P home) (at D home) (in P))
(:goal (and (at B office) (at D office) (at P home)))
)
"#;
#[test]
fn parse_domain_works() {
let (remainder, domain) = Domain::parse(BRIEFCASE_WORLD).unwrap();
// The input was parsed completely, nothing followed the domain definition.
assert!(remainder.is_empty());
// All elements were parsed.
assert_eq!(domain.name(), "briefcase-world");
assert_eq!(domain.requirements().len(), 4);
assert_eq!(domain.types().len(), 2);
assert_eq!(domain.constants().len(), 3);
assert_eq!(domain.predicates().len(), 2);
assert_eq!(domain.structure().len(), 3);
}
#[test]
fn parse_problem_works() {
let (remainder, problem) = Problem::parse(BRIEFCASE_WORLD_PROBLEM).unwrap();
// The input was parsed completely, nothing followed the problem definition.
assert!(remainder.is_empty(), "{}", remainder);
// All elements were parsed.
assert_eq!(problem.name(), "get-paid");
assert_eq!(problem.domain(), "briefcase-world");
assert!(problem.requirements().is_empty());
assert_eq!(problem.init().len(), 9);
assert_eq!(problem.goals().len(), 3);
let mut atomic_formulas = 0;
for goal in problem.goals().iter() {
match goal {
PreconditionGoalDefinition::Preference(pref) => match pref {
PreferenceGD::Goal(goal) => match goal {
GoalDefinition::AtomicFormula(af) => match af {
AtomicFormula::Predicate(_) => atomic_formulas += 1,
AtomicFormula::Equality(_) => {}
},
GoalDefinition::Literal(literal) => match literal {
TermLiteral::AtomicFormula(_) => {
// The AtomicFormula variant takes precedence over the Literal variant
// because a Literal in the context of a Goal Description can only
// occur with the :negative−preconditions domain requirement.
}
TermLiteral::NotAtomicFormula(_) => {}
},
GoalDefinition::And(_) => {}
GoalDefinition::Or(_) => {}
GoalDefinition::Not(_) => {}
GoalDefinition::Imply(_, _) => {}
GoalDefinition::Exists(_, _) => {}
GoalDefinition::ForAll(_, _) => {}
GoalDefinition::FComp(_) => {}
},
PreferenceGD::Preference(_) => {}
},
PreconditionGoalDefinition::Forall(_, _) => {}
}
}
assert_eq!(atomic_formulas, 3);
}