Skip to content

Commit

Permalink
update code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
francescofuggitti committed Jun 21, 2023
1 parent 496a254 commit eac7882
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 40 deletions.
16 changes: 1 addition & 15 deletions pddl/_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@
from pddl.exceptions import PDDLValidationError
from pddl.helpers.base import check, ensure, ensure_set, find_cycle
from pddl.logic import Predicate
from pddl.logic.base import (
BinaryOp,
FalseFormula,
QuantifiedCondition,
TrueFormula,
UnaryOp,
)
from pddl.logic.base import BinaryOp, QuantifiedCondition, UnaryOp
from pddl.logic.effects import AndEffect, Forall, When
from pddl.logic.predicates import DerivedPredicate, EqualTo
from pddl.logic.terms import Term
Expand Down Expand Up @@ -261,14 +255,6 @@ def _(self, formula: BinaryOp) -> None:
"""Check types annotations of a PDDL binary operator."""
self.check_type(formula.operands)

@check_type.register
def _(self, formula: TrueFormula) -> None:
"""Check types annotations of a PDDL true formula."""

@check_type.register
def _(self, formula: FalseFormula) -> None:
"""Check types annotations of a PDDL false formula."""

@check_type.register
def _(self, formula: QuantifiedCondition) -> None:
"""Check types annotations of a PDDL quantified condition."""
Expand Down
4 changes: 2 additions & 2 deletions pddl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from pddl.custom_types import name as name_type
from pddl.custom_types import namelike, parse_name, to_names, to_types # noqa: F401
from pddl.helpers.base import assert_, check, ensure, ensure_set
from pddl.logic.base import Formula, TrueFormula, is_literal
from pddl.logic.base import And, Formula, is_literal
from pddl.logic.predicates import DerivedPredicate, Predicate
from pddl.logic.terms import Constant
from pddl.requirements import Requirements
Expand Down Expand Up @@ -172,7 +172,7 @@ def __init__(
] = self._parse_requirements(domain, requirements)
self._objects: AbstractSet[Constant] = ensure_set(objects)
self._init: AbstractSet[Formula] = ensure_set(init)
self._goal: Formula = ensure(goal, TrueFormula())
self._goal: Formula = ensure(goal, And())
validate(
all(map(is_literal, self.init)),
"Not all formulas of initial condition are literals!",
Expand Down
7 changes: 1 addition & 6 deletions pddl/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from pddl.core import Domain, Problem
from pddl.custom_types import name
from pddl.logic.base import TRUE
from pddl.logic.terms import Constant


Expand Down Expand Up @@ -153,11 +152,7 @@ def problem_to_string(problem: Problem) -> str:
body += _sort_and_print_collection(
"(:init ", problem.init, ")\n", is_mandatory=True
)
body += (
f"{'(:goal ' + str(problem.goal) + ')'}\n"
if problem.goal != TRUE
else "(:goal (and))\n"
)
body += f"{'(:goal ' + str(problem.goal) + ')'}\n"
result = result + "\n" + indent(body, indentation) + "\n)"
result = _remove_empty_lines(result)
return result
15 changes: 3 additions & 12 deletions pddl/parser/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@
from pddl.custom_types import name
from pddl.exceptions import PDDLMissingRequirementError, PDDLParsingError
from pddl.helpers.base import assert_
from pddl.logic.base import (
And,
ExistsCondition,
FalseFormula,
ForallCondition,
Imply,
Not,
OneOf,
Or,
)
from pddl.logic.base import And, ExistsCondition, ForallCondition, Imply, Not, OneOf, Or
from pddl.logic.effects import AndEffect, Forall, When
from pddl.logic.predicates import DerivedPredicate, EqualTo, Predicate
from pddl.logic.terms import Constant, Variable
Expand Down Expand Up @@ -138,7 +129,7 @@ def action_parameters(self, args):
def emptyor_pregd(self, args):
"""Process the 'emptyor_pregd' rule."""
if len(args) == 2:
return FalseFormula()
return Or()
else:
assert_(len(args) == 1)
return args[0]
Expand Down Expand Up @@ -217,7 +208,7 @@ def gd(self, args):
def emptyor_effect(self, args):
"""Process the 'emptyor_effect' rule."""
if len(args) == 2:
return FalseFormula()
return Or()
else:
return args[0]

Expand Down
4 changes: 2 additions & 2 deletions tests/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pddl.core import Domain
from pddl.exceptions import PDDLValidationError
from pddl.logic import Constant, Variable
from pddl.logic.base import Not, TrueFormula
from pddl.logic.base import And, Not
from pddl.logic.helpers import constants, variables
from pddl.logic.predicates import DerivedPredicate, Predicate
from pddl.parser.symbols import Symbols
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_derived_predicate_type_not_available() -> None:
"""Test that when a type of a term of a derived predicate is not declared we raise error."""
x = Variable("a", type_tags={"t1", "t2"})
p = Predicate("p", x)
dp = DerivedPredicate(p, TrueFormula())
dp = DerivedPredicate(p, And())

my_type = "my_type"
type_set = {my_type: None}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ def test_typed_objects_formatting_in_problem() -> None:
(:requirements :typing)
(:objects a b c - type_1 d e f - type_2 g h i - type_3 j k l)
(:init )
(:goal (and))
(:goal (and ))
)"""
)
4 changes: 2 additions & 2 deletions tests/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pytest

from pddl.core import Domain, Problem
from pddl.logic.base import Not, TrueFormula
from pddl.logic.base import And, Not
from pddl.logic.helpers import constants, variables
from pddl.logic.predicates import Predicate
from tests.conftest import pddl_objects_problems
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_init(self):

def test_goal(self):
"""Test the goal getter."""
assert self.problem.goal == TrueFormula()
assert self.problem.goal == And()


def test_build_simple_problem():
Expand Down

0 comments on commit eac7882

Please sign in to comment.