Skip to content

Commit

Permalink
fix(interpreted functions): fixed typing and unused checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Gobbi committed Sep 16, 2024
1 parent b094f8c commit 1e9a3ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
36 changes: 19 additions & 17 deletions unified_planning/model/mixins/interpreted_functions_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
self._add_user_type_method = add_user_type_method
self._has_name_method = has_name_method
self._interpreted_functions: List[
"up.model.interpreted_funciton.InterpretedFunction"
"up.model.interpreted_function.InterpretedFunction"
] = []
self._interpreted_functions_defaults: Dict[
"up.model.interpreted_function.InterpretedFunction", "up.model.fnode.FNode"
Expand All @@ -64,7 +64,9 @@ def interpreted_functions(
"""Returns the `interpreted_functions` currently in the `problem`."""
return self._interpreted_functions

def interpreted_function(self, name: str) -> "up.model.fluent.Fluent":
def interpreted_function(
self, name: str
) -> "up.model.interpreted_function.InterpretedFunction":
"""
Returns the `interpreted_function` with the given name.
Expand Down Expand Up @@ -148,20 +150,20 @@ def add_interpreted_function( ###### adding from name does not work yet
else:
warn(msg)
self._interpreted_functions.append(interpreted_function)
if not default_initial_value is None:
(v_exp,) = self.environment.expression_manager.auto_promote(
default_initial_value
)
self._interpreted_functions_defaults[interpreted_function] = v_exp
elif interpreted_function.type in self._initial_defaults:
self._interpreted_functions_defaults[
interpreted_function
] = self._initial_defaults[interpreted_function.type]
if interpreted_function.type.is_user_type():
self._add_user_type_method(interpreted_function.type)
for param in interpreted_function.signature:
if param.type.is_user_type():
self._add_user_type_method(param.type)
# if not default_initial_value is None:
# (v_exp,) = self.environment.expression_manager.auto_promote(
# default_initial_value
# )
# self._interpreted_functions_defaults[interpreted_function] = v_exp
# elif interpreted_function.type in self._initial_defaults:
# self._interpreted_functions_defaults[
# interpreted_function
# ] = self._initial_defaults[interpreted_function.type]
# if interpreted_function.type.is_user_type():
# self._add_user_type_method(interpreted_function.type)
# for param in interpreted_function.signature:
# if param.type.is_user_type():
# self._add_user_type_method(param.type)

return interpreted_function

Expand Down Expand Up @@ -195,7 +197,7 @@ def __eq__(self, oth):
return True

def __hash__(self):
return sum(map(hash, self._fluents))
return sum(map(hash, self._interpreted_functions))

def _clone_to(self, other: "InterpretedFunctionsSetMixin"):
other._interpreted_functions = self._interpreted_functions.copy()
Expand Down
3 changes: 3 additions & 0 deletions unified_planning/model/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ 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

0 comments on commit 1e9a3ff

Please sign in to comment.