Skip to content

Commit 45cd121

Browse files
authored
Merge pull request #165 from AI-Planning/fix-151
Add test on parsing domain `social-planning` (fix #151)
2 parents a870bcf + 4e9ce2f commit 45cd121

5 files changed

Lines changed: 198 additions & 1 deletion

File tree

pddl/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from pddl.logic.functions import FunctionExpression, Metric, NumericFunction
4141
from pddl.logic.predicates import DerivedPredicate, Predicate
4242
from pddl.logic.terms import Constant
43+
from pddl.parser.symbols import Symbols
4344
from pddl.requirements import Requirements
4445

4546

@@ -174,7 +175,9 @@ def __str__(self) -> str:
174175
"",
175176
self.derived_predicates,
176177
"",
177-
to_string=lambda obj: str(obj) + "\n",
178+
to_string=lambda obj: f"({Symbols.DERIVED.value} "
179+
f"{print_predicates_with_types([obj.predicate])} "
180+
f"{obj.condition})\n",
178181
)
179182
body += sort_and_print_collection(
180183
"",

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"miner",
5959
"rovers-numeric-automatic",
6060
"rovers_fond",
61+
"social-planning",
6162
"sokoban-sequential-optimal",
6263
"spiky-tireworld",
6364
"storage",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
(define (domain social-planning)
2+
(:requirements :adl :derived-predicates :typing)
3+
(:types
4+
locatable place - object
5+
character item - locatable
6+
)
7+
(:predicates (alive ?c - character) (alone-at ?c - character ?p - place) (at ?l - locatable ?p - place) (believes-loves ?a - character ?c - character ?d - character) (can-see ?c - character ?l - locatable) (dead ?c - character) (friend-of ?a - character ?b - character) (gift ?from - character ?to - character ?i - item) (has ?c - character ?i - item) (is-curious ?c - character) (is-evil ?c - character) (is-greedy ?c - character) (is-jealous ?c - character) (is-lustful ?c - character) (is-obedient ?c - character) (is-pursuing ?c - character) (is-suspicious ?c - character) (is-vain ?c - character) (is-wrathful ?c - character) (killed ?a - character ?c - character) (loves ?c - character ?d - character) (main-character ?c - character) (man ?c - character) (married ?a - character ?b - character) (motive-for-at ?a - character ?l - locatable ?p - place) (motive-for-dead ?a - character ?c - character) (motive-for-has ?a - character ?c - character ?i - item) (precious ?i - item) (reason-to-believe-loves ?a - character ?c - character ?d - character) (reason-to-love ?a - character ?c - character) (requested-at ?a - character ?c - character ?p - place) (requested-has ?a - character ?c - character ?i - item) (woman ?c - character))
8+
(:derived (alone-at ?c - character ?p - place) (forall (?d - character) (or (not (at ?d ?p)) (= ?d ?c))))
9+
(:derived (can-see ?c - character ?l - locatable) (exists (?p - place) (and (at ?c ?p) (at ?l ?p))))
10+
(:derived (motive-for-at ?a - character ?a1 - character ?p - place) (and (is-curious ?a) (exists (?f - character) (and (friend-of ?a ?f) (requested-at ?f ?a ?p)))))
11+
(:derived (motive-for-at ?a - character ?a1 - character ?p - place) (exists (?c - character) (and (motive-for-dead ?a ?c) (at ?c ?p))))
12+
(:derived (motive-for-at ?a - character ?a1 - character ?p - place) (exists (?i - item ?c - character) (and (motive-for-has ?a ?c ?i) (has ?a ?i) (at ?c ?p))))
13+
(:derived (motive-for-at ?a - character ?a1 - character ?p - place) (exists (?i - item) (and (motive-for-has ?a ?a ?i) (at ?i ?p))))
14+
(:derived (motive-for-at ?a - character ?c - character ?p - place) (exists (?q - place ?i - item) (and (motive-for-has ?a ?a ?i) (at ?i ?q) (at ?c ?q))))
15+
(:derived (motive-for-dead ?a - character ?c - character) (and (is-jealous ?a) (not (= ?c ?a)) (exists (?d - character) (and (married ?a ?c) (believes-loves ?a ?c ?d)))))
16+
(:derived (motive-for-dead ?a - character ?c - character) (and (is-wrathful ?a) (not (= ?c ?a)) (exists (?d - character) (and (loves ?a ?d) (killed ?c ?d)))))
17+
(:derived (motive-for-dead ?a - character ?d - character) (and (is-jealous ?a) (not (= ?d ?a)) (exists (?c - character) (and (married ?a ?c) (believes-loves ?a ?c ?d)))))
18+
(:derived (motive-for-has ?a - character ?a1 - character ?i - item) (and (is-greedy ?a) (precious ?i) (can-see ?a ?i)))
19+
(:derived (motive-for-has ?a - character ?a1 - character ?i - item) (exists (?c - character) (motive-for-has ?a ?c ?i)))
20+
(:derived (motive-for-has ?a - character ?c - character ?i - item) (and (is-obedient ?a) (loves ?a ?c) (requested-has ?c ?c ?i)))
21+
(:derived (motive-for-has ?a - character ?c - character ?i - item) (and (is-pursuing ?a) (loves ?a ?c) (precious ?i)))
22+
(:derived (reason-to-believe-loves ?a - character ?c - character ?d - character) (and (is-suspicious ?a) (not (= ?c ?d)) (not (= ?a ?c)) (not (= ?a ?d)) (exists (?i - item) (and (gift ?a ?c ?i) (has ?d ?i) (can-see ?a ?d)))))
23+
(:derived (reason-to-love ?a - character ?c - character) (and (man ?a) (is-lustful ?a) (woman ?c) (can-see ?a ?c) (exists (?i - item) (and (has ?c ?i) (precious ?i)))))
24+
(:derived (reason-to-love ?a - character ?c - character) (and (woman ?a) (is-vain ?a) (man ?c) (exists (?i - item) (and (gift ?c ?a ?i) (precious ?i)))))
25+
(:action adopt-belief-loves
26+
:parameters (?a - character ?c - character ?d - character)
27+
:precondition (and (reason-to-believe-loves ?a ?c ?d) (alive ?a) (alive ?c))
28+
:effect (believes-loves ?a ?c ?d)
29+
)
30+
(:action drop
31+
:parameters (?a - character ?i - item ?p - place)
32+
:precondition (and (or (main-character ?a) (motive-for-at ?a ?i ?p)) (alive ?a) (has ?a ?i) (at ?a ?p))
33+
:effect (and (not (has ?a ?i)) (at ?i ?p))
34+
)
35+
(:action fall-in-love
36+
:parameters (?a - character ?c - character)
37+
:precondition (and (reason-to-love ?a ?c) (not (= ?a ?c)) (alive ?a) (alive ?c))
38+
:effect (loves ?a ?c)
39+
)
40+
(:action give
41+
:parameters (?a - character ?c - character ?i - item ?p - place)
42+
:precondition (and (or (main-character ?a) (motive-for-has ?a ?c ?i)) (alive ?a) (alive ?c) (has ?a ?i) (at ?a ?p) (at ?c ?p))
43+
:effect (and (not (has ?a ?i)) (has ?c ?i) (gift ?a ?c ?i))
44+
)
45+
(:action goto
46+
:parameters (?a - character ?p - place ?from - place)
47+
:precondition (and (or (main-character ?a) (motive-for-at ?a ?a ?p)) (alive ?a) (at ?a ?from) (not (= ?p ?from)))
48+
:effect (and (not (at ?a ?from)) (at ?a ?p))
49+
)
50+
(:action kill
51+
:parameters (?a - character ?c - character ?p - place)
52+
:precondition (and (motive-for-dead ?a ?c) (alive ?a) (alive ?c) (at ?a ?p) (at ?c ?p))
53+
:effect (and (not (alive ?c)) (dead ?c) (killed ?a ?c))
54+
)
55+
(:action request-at
56+
:parameters (?a - character ?c - character ?p - place)
57+
:precondition (and (or (main-character ?a) (motive-for-at ?a ?c ?p)) (alive ?a) (alive ?c))
58+
:effect (requested-at ?a ?c ?p)
59+
)
60+
(:action request-has
61+
:parameters (?a - character ?c - character ?i - item)
62+
:precondition (and (or (main-character ?a) (motive-for-has ?a ?c ?i)) (alive ?a) (alive ?c))
63+
:effect (requested-has ?a ?c ?i)
64+
)
65+
(:action take
66+
:parameters (?a - character ?i - item ?p - place)
67+
:precondition (and (or (main-character ?a) (motive-for-has ?a ?a ?i)) (alive ?a) (at ?i ?p) (at ?a ?p) (alone-at ?a ?p))
68+
:effect (and (not (at ?i ?p)) (has ?a ?i))
69+
)
70+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
;; An instance of the social planning domain, based on Iago's problem:
3+
;; How to make Othello kill Desdemona?
4+
5+
(define (problem Iago-1)
6+
(:domain social-planning)
7+
8+
(:objects
9+
Iago Othello Emilia Desdemona Cassio - character
10+
handkerchief - item
11+
garden bedroom residence palace - place
12+
)
13+
14+
(:init
15+
(man Iago)
16+
(man Othello)
17+
(woman Emilia)
18+
(woman Desdemona)
19+
(man Cassio)
20+
(married Iago Emilia)
21+
(married Emilia Iago)
22+
(married Othello Desdemona)
23+
(married Desdemona Othello)
24+
(friend-of Cassio Iago)
25+
(friend-of Othello Iago)
26+
(friend-of Desdemona Emilia)
27+
(precious handkerchief)
28+
(loves Emilia Iago)
29+
(loves Othello Desdemona)
30+
(loves Desdemona Othello)
31+
(is-curious Othello)
32+
(is-jealous Othello)
33+
(is-suspicious Othello)
34+
(is-wrathful Othello)
35+
(is-curious Cassio)
36+
(is-greedy Cassio)
37+
(is-lustful Cassio)
38+
(is-wrathful Cassio)
39+
(is-obedient Emilia)
40+
(is-vain Emilia)
41+
(is-curious Desdemona)
42+
(is-obedient Desdemona)
43+
(is-evil Iago) ;; MUHAHAHAHA!!
44+
(main-character Iago)
45+
(alive Iago)
46+
(alive Othello)
47+
(alive Emilia)
48+
(alive Desdemona)
49+
(alive Cassio)
50+
(at Iago garden)
51+
(at Othello palace)
52+
(at Desdemona bedroom)
53+
(at Emilia garden)
54+
(at Cassio residence)
55+
(at handkerchief bedroom)
56+
(gift Othello Desdemona handkerchief)
57+
)
58+
59+
(:goal (killed Othello Desdemona))
60+
61+
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
;; An instance of the social planning domain, based on Iago's problem:
3+
;; How to make Othello kill Desdemona and then die?
4+
5+
(define (problem Iago-2)
6+
(:domain social-planning)
7+
8+
(:objects
9+
Iago Othello Emilia Desdemona Cassio - character
10+
handkerchief - item
11+
garden bedroom residence palace - place
12+
)
13+
14+
(:init
15+
(man Iago)
16+
(man Othello)
17+
(woman Emilia)
18+
(woman Desdemona)
19+
(man Cassio)
20+
(married Iago Emilia)
21+
(married Emilia Iago)
22+
(married Othello Desdemona)
23+
(married Desdemona Othello)
24+
(friend-of Cassio Iago)
25+
(friend-of Othello Iago)
26+
(friend-of Desdemona Emilia)
27+
(precious handkerchief)
28+
(loves Emilia Iago)
29+
(loves Othello Desdemona)
30+
(loves Desdemona Othello)
31+
(is-curious Othello)
32+
(is-jealous Othello)
33+
(is-suspicious Othello)
34+
(is-wrathful Othello)
35+
(is-curious Cassio)
36+
(is-greedy Cassio)
37+
(is-lustful Cassio)
38+
(is-wrathful Cassio)
39+
(is-obedient Emilia)
40+
(is-vain Emilia)
41+
(is-curious Desdemona)
42+
(is-obedient Desdemona)
43+
(is-evil Iago) ;; MUHAHAHAHA!!
44+
(main-character Iago)
45+
(alive Iago)
46+
(alive Othello)
47+
(alive Emilia)
48+
(alive Desdemona)
49+
(alive Cassio)
50+
(at Iago garden)
51+
(at Othello palace)
52+
(at Desdemona bedroom)
53+
(at Emilia garden)
54+
(at Cassio residence)
55+
(at handkerchief bedroom)
56+
(gift Othello Desdemona handkerchief)
57+
)
58+
59+
(:goal (and (killed Othello Desdemona)
60+
(dead Othello)))
61+
62+
)

0 commit comments

Comments
 (0)