Skip to content

Commit

Permalink
add consistency check on actions costs and total-cost
Browse files Browse the repository at this point in the history
  • Loading branch information
francescofuggitti committed Oct 9, 2023
1 parent 3e9f10e commit bbcf49c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pddl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
from pddl.action import Action
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.exceptions import PDDLValidationError
from pddl.helpers.base import assert_, check, ensure, ensure_set
from pddl.logic.base import And, Formula, is_literal
from pddl.logic.functions import Function, Metric
from pddl.logic.functions import Function, Metric, TotalCost
from pddl.logic.predicates import DerivedPredicate, Predicate
from pddl.logic.terms import Constant
from pddl.requirements import Requirements
from pddl.requirements import Requirements, _extend_domain_requirements


class Domain:
Expand Down Expand Up @@ -75,12 +76,13 @@ def __init__(

def _check_consistency(self) -> None:
"""Check consistency of a domain instance object."""
checker = TypeChecker(self._types, self.requirements)
checker.check_type(self._constants)
checker.check_type(self._predicates)
checker.check_type(self._actions)
type_checker = TypeChecker(self._types, self.requirements)
type_checker.check_type(self._constants)
type_checker.check_type(self._predicates)
type_checker.check_type(self._actions)
_check_types_in_has_terms_objects(self._actions, self._types.all_types) # type: ignore
self._check_types_in_derived_predicates()
self._check_action_costs_requirement()

def _check_types_in_derived_predicates(self) -> None:
"""Check types in derived predicates."""
Expand All @@ -91,6 +93,15 @@ def _check_types_in_derived_predicates(self) -> None:
)
_check_types_in_has_terms_objects(dp_list, self._types.all_types)

def _check_action_costs_requirement(self) -> None:
"""Check that the action-costs requirement is specified."""
if not (
Requirements.ACTION_COSTS in _extend_domain_requirements(self._requirements)
) and any(isinstance(f, TotalCost) for f in self._functions):
raise PDDLValidationError(
f"action costs requirement is not specified, but the total-cost function is specified."
)

@property
def name(self) -> name_type:
"""Get the name."""
Expand Down

0 comments on commit bbcf49c

Please sign in to comment.