Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor touchup to preconditions and fix for minus. #104

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pddl/parser/domain.lark
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,16 @@ constant: NAME
| GREATER_EQUAL_OP
| LESSER_EQUAL_OP

?binary_op: multi_op
| MINUS
?binary_op: MINUS
| DIVIDE

?multi_op: TIMES
| PLUS

f_exp: NUMBER
| LPAR binary_op f_exp f_exp RPAR
| LPAR multi_op f_exp f_exp+ RPAR
| LPAR MINUS f_exp RPAR
| LPAR multi_op f_exp+ RPAR
| LPAR MINUS f_exp+ RPAR
| f_head

f_head: NAME
Expand Down
7 changes: 6 additions & 1 deletion pddl/parser/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,12 @@ def f_exp(self, args):
return args[0]
op = None
if args[1] == Symbols.MINUS.value:
op = Minus
if len(args[2:-1]) == 1:
return Times(NumericValue(-1), args[2])
elif len(args[2:-1]) == 2:
op = Minus
else:
raise PDDLParsingError(f"MINUS symbol used with {len(args[2:-1])} args")
if args[1] == Symbols.PLUS.value:
op = Plus
if args[1] == Symbols.TIMES.value:
Expand Down
60 changes: 60 additions & 0 deletions tests/test_parser/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,63 @@ def test_check_action_costs_requirement_with_total_cost() -> None:
match=r"action costs requirement is not specified, but the total-cost function is specified.",
):
DomainParser()(domain_str)


def test_minus_in_precondition() -> None:
"""Check minus in precondition."""
domain_str = dedent(
"""
(define (domain cant-subtract-in-precondition)
(:requirements :strips :typing :numeric-fluents)

(:types
agent - object
)

(:functions
(x ?l - agent)
)

(:action move-south
:parameters (?ag - agent)
:precondition (and
(< (- (x ?ag) 1) 1)
(< (- (x ?ag)) 1)
)
:effect (and (decrease (x ?ag) 1))
)
)
"""
)
DomainParser()(domain_str)


def test_multi_minus_in_precondition() -> None:
"""Check minus in precondition."""
domain_str = dedent(
"""
(define (domain cant-subtract-in-precondition)
(:requirements :strips :typing :numeric-fluents)

(:types
agent - object
)

(:functions
(x ?l - agent)
)

(:action move-south
:parameters (?ag - agent)
:precondition (and
(< (- (x ?ag) 1 3) 1)
)
:effect (and (decrease (x ?ag) 1))
)
)
"""
)
try:
DomainParser()(domain_str)
except Exception as e:
assert "MINUS symbol used with 3 args" in str(e)
Loading