Skip to content

Commit

Permalink
fix(interpreted functions): functions in conditions should now work
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Sep 16, 2024
1 parent 1d0523c commit aad6735
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 58 deletions.
10 changes: 0 additions & 10 deletions unified_planning/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ def __init__(self):
self._simplifier = unified_planning.model.walkers.Simplifier(self)
self._substituter = unified_planning.model.walkers.Substituter(self)
self._free_vars_extractor = unified_planning.model.walkers.FreeVarsExtractor()
self._interpreted_function_extractor = (
unified_planning.model.walkers.InterpretedFunctionsExtractor()
)
self._names_extractor = unified_planning.model.walkers.NamesExtractor()
self._credits_stream: Optional[IO[str]] = sys.stdout
self._error_used_name: bool = True
Expand Down Expand Up @@ -130,13 +127,6 @@ def free_vars_extractor(self) -> "unified_planning.model.walkers.FreeVarsExtract
"""Returns the environment's `FreeVarsExtractor`."""
return self._free_vars_extractor

@property
def interpreted_function_extractor(
self,
) -> "unified_planning.model.walkers.InterpretedFunctionsExtractor":
"""Returns the environment's `InterpretedFunctionsExtractor`."""
return self._interpreted_function_extractor

@property
def names_extractor(self) -> "unified_planning.model.walkers.NamesExtractor":
"""Returns the environment's `NamesExtractor`."""
Expand Down
4 changes: 0 additions & 4 deletions unified_planning/model/mixins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
from unified_planning.model.mixins.actions_set import ActionsSetMixin
from unified_planning.model.mixins.time_model import TimeModelMixin
from unified_planning.model.mixins.fluents_set import FluentsSetMixin
from unified_planning.model.mixins.interpreted_functions_set import (
InterpretedFunctionsSetMixin,
)
from unified_planning.model.mixins.objects_set import ObjectsSetMixin
from unified_planning.model.mixins.user_types_set import UserTypesSetMixin
from unified_planning.model.mixins.agents_set import AgentsSetMixin
Expand All @@ -29,7 +26,6 @@
"ActionsSetMixin",
"TimeModelMixin",
"FluentsSetMixin",
"InterpretedFunctionsSetMixin",
"ObjectsSetMixin",
"UserTypesSetMixin",
"AgentsSetMixin",
Expand Down
43 changes: 2 additions & 41 deletions unified_planning/model/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
ActionsSetMixin,
TimeModelMixin,
FluentsSetMixin,
InterpretedFunctionsSetMixin,
ObjectsSetMixin,
UserTypesSetMixin,
InitialStateMixin,
Expand Down Expand Up @@ -52,7 +51,6 @@ class Problem( # type: ignore[misc]
UserTypesSetMixin,
TimeModelMixin,
FluentsSetMixin,
InterpretedFunctionsSetMixin,
ActionsSetMixin,
ObjectsSetMixin,
InitialStateMixin,
Expand All @@ -79,9 +77,7 @@ def __init__(
FluentsSetMixin.__init__(
self, self.environment, self._add_user_type, self.has_name, initial_defaults
)
InterpretedFunctionsSetMixin.__init__(
self, self.environment, self._add_user_type, self.has_name, initial_defaults
)

ActionsSetMixin.__init__(
self, self.environment, self._add_user_type, self.has_name
)
Expand Down Expand Up @@ -119,9 +115,6 @@ def __repr__(self) -> str:
s.append("fluents = [\n")
s.extend(map(custom_str, self.fluents))
s.append("]\n\n")
s.append("interpreted functions = [\n")
s.extend(map(custom_str, self.interpreted_functions))
s.append("]\n\n")
s.append("actions = [\n")
s.extend(map(custom_str, self.actions))
s.append("]\n\n")
Expand Down Expand Up @@ -179,8 +172,6 @@ def __eq__(self, oth: object) -> bool:
return False
if not FluentsSetMixin.__eq__(self, oth):
return False
if not InterpretedFunctionsSetMixin.__eq__(self, oth):
return False
if not InitialStateMixin.__eq__(self, oth):
return False
if not MetricsMixin.__eq__(self, oth):
Expand Down Expand Up @@ -215,7 +206,6 @@ def __hash__(self) -> int:
res = hash(self._name)

res += FluentsSetMixin.__hash__(self)
res += InterpretedFunctionsSetMixin.__hash__(self)
res += ObjectsSetMixin.__hash__(self)
res += UserTypesSetMixin.__hash__(self)
res += InitialStateMixin.__hash__(self)
Expand All @@ -242,7 +232,6 @@ def clone(self):
UserTypesSetMixin._clone_to(self, new_p)
ObjectsSetMixin._clone_to(self, new_p)
FluentsSetMixin._clone_to(self, new_p)
InterpretedFunctionsSetMixin._clone_to(self, new_p)
InitialStateMixin._clone_to(self, new_p)
TimeModelMixin._clone_to(self, new_p)

Expand Down Expand Up @@ -720,7 +709,6 @@ def __init__(
):
assert isinstance(pb, MetricsMixin)
assert isinstance(pb, FluentsSetMixin)
# assert isinstance(pb, InterpretedFunctionsSetMixin)#???
assert isinstance(pb, ObjectsSetMixin)
assert isinstance(pb, UserTypesSetMixin)
assert isinstance(pb, TimeModelMixin)
Expand Down Expand Up @@ -792,9 +780,6 @@ def update_problem_kind_effect(
):
value = self.simplifier.simplify(e.value)
fluents_in_value = self.environment.free_vars_extractor.get(value)
interpreted_functions_in_value = (
self.environment.interpreted_function_extractor.get(value)
)
if e.is_conditional():
self.update_problem_kind_expression(e.condition)
self.kind.set_effects_kind("CONDITIONAL_EFFECTS")
Expand Down Expand Up @@ -825,10 +810,6 @@ def update_problem_kind_effect(
self.kind.set_effects_kind("STATIC_FLUENTS_IN_NUMERIC_ASSIGNMENTS")
if any(f not in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("FLUENTS_IN_NUMERIC_ASSIGNMENTS")
if len(interpreted_functions_in_value) != 0:
self.kind.set_effects_kind(
"INTERPRETED_FUNCTIONS_IN_NUMERIC_ASSIGNMENTS"
)
elif e.is_decrease():
self.kind.set_effects_kind("DECREASE_EFFECTS")
# If the value is a number (int or real) and it violates the constraint
Expand All @@ -851,10 +832,6 @@ def update_problem_kind_effect(
self.kind.set_effects_kind("STATIC_FLUENTS_IN_NUMERIC_ASSIGNMENTS")
if any(f not in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("FLUENTS_IN_NUMERIC_ASSIGNMENTS")
if len(interpreted_functions_in_value) != 0:
self.kind.set_effects_kind(
"INTERPRETED_FUNCTIONS_IN_NUMERIC_ASSIGNMENTS"
)
elif e.is_assignment():
value_type = value.type
if (
Expand All @@ -871,28 +848,16 @@ def update_problem_kind_effect(
self.kind.set_effects_kind("STATIC_FLUENTS_IN_NUMERIC_ASSIGNMENTS")
if any(f not in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("FLUENTS_IN_NUMERIC_ASSIGNMENTS")
if len(interpreted_functions_in_value) != 0:
self.kind.set_effects_kind(
"INTERPRETED_FUNCTIONS_IN_NUMERIC_ASSIGNMENTS"
)
elif value.type.is_bool_type():
if any(f in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("STATIC_FLUENTS_IN_BOOLEAN_ASSIGNMENTS")
if any(f not in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("FLUENTS_IN_BOOLEAN_ASSIGNMENTS")
if len(interpreted_functions_in_value) != 0:
self.kind.set_effects_kind(
"INTERPRETED_FUNCTIONS_IN_BOOLEAN_ASSIGNMENTS"
)
elif value.type.is_user_type():
if any(f in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("STATIC_FLUENTS_IN_OBJECT_ASSIGNMENTS")
if any(f not in self.static_fluents for f in fluents_in_value):
self.kind.set_effects_kind("FLUENTS_IN_OBJECT_ASSIGNMENTS")
if len(interpreted_functions_in_value) != 0:
self.kind.set_effects_kind(
"INTERPRETED_FUNCTIONS_IN_OBJECT_ASSIGNMENTS"
)

def update_problem_kind_expression(
self,
Expand Down Expand Up @@ -982,9 +947,7 @@ def update_action_duration(self, duration: "up.model.DurationInterval"):
free_vars = self.environment.free_vars_extractor.get(
lower
) | self.environment.free_vars_extractor.get(upper)
interpreted_functions = self.environment.interpreted_function_extractor.get(
lower
) | self.environment.interpreted_function_extractor.get(upper)

if len(free_vars) > 0:
only_static = True
for fv in free_vars:
Expand All @@ -995,8 +958,6 @@ def update_action_duration(self, duration: "up.model.DurationInterval"):
self.kind.set_expression_duration("STATIC_FLUENTS_IN_DURATIONS")
else:
self.kind.set_expression_duration("FLUENTS_IN_DURATIONS")
if len(interpreted_functions) > 0:
self.kind.set_expression_duration("INTERPRETED_FUNCTIONS_IN_DURATIONS")

def update_action_timed_condition(
self, span: "up.model.TimeInterval", cond: "up.model.FNode"
Expand Down
3 changes: 0 additions & 3 deletions unified_planning/model/walkers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
from unified_planning.model.walkers.substituter import Substituter
from unified_planning.model.walkers.type_checker import TypeChecker
from unified_planning.model.walkers.free_vars import FreeVarsExtractor
from unified_planning.model.walkers.interpreted_functions_extractor import (
InterpretedFunctionsExtractor,
)
from unified_planning.model.walkers.any import AnyChecker, AnyGetter
from unified_planning.model.walkers.usertype_fluents_walker import UsertypeFluentsWalker
from unified_planning.model.walkers.names_extractor import NamesExtractor

0 comments on commit aad6735

Please sign in to comment.