Skip to content

Commit

Permalink
feature(interpreted functions): added check for interpreted functions…
Browse files Browse the repository at this point in the history
… in durations in _KindFactory
  • Loading branch information
Samuel Gobbi committed Sep 13, 2024
1 parent 88f5198 commit 7cc2f4d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
30 changes: 13 additions & 17 deletions unified_planning/model/interpreted_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,26 @@ def __init__(
self._signature.append(

Check warning on line 52 in unified_planning/model/interpreted_function.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/model/interpreted_function.py#L46-L52

Added lines #L46 - L52 were not covered by tests
up.model.parameter.Parameter(param_name, param_type, self._env)
)
elif isinstance(_signature, List):
assert all(
p.environment == self._env for p in _signature
), "one of the parameters does not belong to the same environment of the interpreted function"
self._signature = _signature[:]
else:
raise NotImplementedError

Check warning on line 56 in unified_planning/model/interpreted_function.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/model/interpreted_function.py#L56

Added line #L56 was not covered by tests
else:
for param_name, param_type in kwargs.items():
self._signature.append(

Check warning on line 59 in unified_planning/model/interpreted_function.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/model/interpreted_function.py#L58-L59

Added lines #L58 - L59 were not covered by tests
up.model.parameter.Parameter(param_name, param_type, self._env)
)
for param in self._signature:
pt = param.type
if pt.is_real_type() or (
pt.is_int_type()
and (
cast(_IntType, pt).lower_bound is None
or cast(_IntType, pt).upper_bound is None
)
):
raise UPTypeError(
f"Parameter {param} of interpreted function {name} has type {pt}; interpreted function parameters must be int|real|bool|userType." # this should probably be different
)

# for param in self._signature:
# pt = param.type
# if pt.is_real_type() or (
# pt.is_int_type()
# and (
# cast(_IntType, pt).lower_bound is None
# or cast(_IntType, pt).upper_bound is None
# )
# ):
# raise UPTypeError(
# f"Parameter {param} of interpreted function {name} has type {pt}; interpreted function parameters must be int|real|bool|userType." # this should probably be different
# )

def __repr__(self) -> str:
sign = ""
Expand Down
5 changes: 5 additions & 0 deletions unified_planning/model/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,9 @@ 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 @@ -979,6 +982,8 @@ 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")

Check warning on line 986 in unified_planning/model/problem.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/model/problem.py#L986

Added line #L986 was not covered by tests

def update_action_timed_condition(
self, span: "up.model.TimeInterval", cond: "up.model.FNode"
Expand Down

0 comments on commit 7cc2f4d

Please sign in to comment.