Skip to content

Commit

Permalink
Merge pull request #103 from haz/main
Browse files Browse the repository at this point in the history
Fixing three subtle bugs with numerics in problem files.
  • Loading branch information
haz authored Dec 29, 2023
2 parents 514d568 + 260fe74 commit 7a0132d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pddl/parser/common.lark
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ DECREASE: "decrease"
MAXIMIZE: "maximize"
MINIMIZE: "minimize"
TOTAL_COST: "total-cost"
NUMBER: /[0-9]+(.[0-9]+)*/
NUMBER: /[0-9]+(\.[0-9]+)*/

// available requirements
STRIPS: ":strips"
Expand All @@ -81,4 +81,4 @@ ACTION_COSTS: ":action-costs"
LPAR : "("
RPAR : ")"
TYPE_SEP: "-"
TYPE_NUMBER: "number"
TYPE_NUMBER: "number"
3 changes: 1 addition & 2 deletions pddl/parser/problem.lark
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ basic_function_term: NAME
| LPAR NAME NAME* RPAR

atomic_formula_name: LPAR predicate NAME* RPAR
| LPAR EQUAL_OP NAME NAME RPAR

goal: LPAR GOAL gd_name RPAR

gd_name: atomic_formula_name
| LPAR NOT atomic_formula_name RPAR
| LPAR AND gd_name* RPAR
| LPAR binary_comp f_exp f_exp RPAR
| LPAR binary_comp metric_f_exp metric_f_exp RPAR

metric_spec: LPAR METRIC optimization metric_f_exp RPAR

Expand Down
67 changes: 67 additions & 0 deletions tests/test_parser/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,70 @@ def test_problem_init_predicate_repetition_name_allowed() -> None:
"""
)
ProblemParser()(problem_str)


def test_numeric_comparison_in_goal() -> None:
"""Try to parse a goal with a numeric condition."""
problem_str = dedent(
"""
(define (problem hello-3-times)
(:domain hello-world-functions)
(:init
; if this was undefined, some planners would not assumed `0`
(= (hello_counter jimmy) 0)
)
(:goal
(> 5 3)
)
)
"""
)
ProblemParser()(problem_str)


def test_numeric_function_comparison_in_goal() -> None:
"""Try to parse a goal with a numeric condition and function."""
problem_str = dedent(
"""
(define (problem hello-3-times)
(:domain hello-world-functions)
(:init
; if this was undefined, some planners would not assumed `0`
(= (hello_counter jimmy) 0)
)
(:goal
(>= (hello_counter jimmy) 3)
)
)
"""
)
ProblemParser()(problem_str)


def test_numeric_function_equality_in_goal() -> None:
"""Try to parse a goal with a numeric condition and function."""
problem_str = dedent(
"""
(define (problem hello-3-times)
(:domain hello-world-functions)
(:init
; if this was undefined, some planners would not assumed `0`
(= (hello_counter jimmy) 0)
(= (hello_counter jammy) 0)
)
(:goal
(and
(= 3 (hello_counter jimmy))
(= (hello_counter jammy) 5)
)
)
)
"""
)
ProblemParser()(problem_str)

0 comments on commit 7a0132d

Please sign in to comment.