Skip to content

Commit

Permalink
update time_triggered_plan and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alelafar committed Mar 14, 2024
1 parent fab82a5 commit da58f4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
32 changes: 11 additions & 21 deletions unified_planning/plans/time_triggered_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ def convert_to(
"""
if plan_kind == self._kind:
return self
elif plan_kind == plans.plan.PlanKind.STN_PLAN:
elif (
plan_kind == plans.plan.PlanKind.STN_PLAN
and not problem.kind.has_decrease_continuous_effects()
and not problem.kind.has_increase_continuous_effects()
):
return _convert_to_stn(self, problem)
else:
raise UPUsageError(f"{type(self)} can't be converted to {plan_kind}.")
Expand Down Expand Up @@ -440,24 +444,6 @@ def _get_timepoint_effects(
return timepoint_effects


# def _get_timepoint_continuous_effects(
# action: DurativeAction,
# timing: Fraction,
# start: Fraction,
# duration: Fraction,
# ) -> List[Effect]:
# """
# Returns the List of continuous effects of the given action in the given timing.
# start and duration are the start and duration of the given action
# """
# timepoint_continuous_effects = []
# for c_effects_timing, el in action.continuous_effects.items():
# absolute_effect_time = _absolute_time(c_effects_timing, start, duration)
# if absolute_effect_time == timing:
# timepoint_continuous_effects.extend(el)
# return timepoint_continuous_effects


def _get_timepoint_simulated_effects(
action: DurativeAction,
timing: Fraction,
Expand Down Expand Up @@ -496,7 +482,12 @@ def _extract_action_timings(
timings: Set[Fraction] = set()

absolute_time = lambda timing: _absolute_time(timing, start, duration)
timings.update(map(absolute_time, chain(action.effects, action.simulated_effects)))
timings.update(
map(
absolute_time,
chain(action.effects, action.continuous_effects, action.simulated_effects),
)
)

for interval in action.conditions.keys():
lower_increment: Fraction = epsilon if interval.is_left_open() else Fraction(0)
Expand Down Expand Up @@ -530,7 +521,6 @@ def _extract_instantenous_actions(
inst_action.add_precondition(cond)
for eff in _get_timepoint_effects(action, timing, start, duration):
inst_action._add_effect_instance(eff)
# va aggiunto qualcosa? Come traformo il continuous change in istantenuous action?
sim_eff = _get_timepoint_simulated_effects(action, timing, start, duration)
if sim_eff is not None:
inst_action.set_simulated_effect(sim_eff)
Expand Down
6 changes: 5 additions & 1 deletion unified_planning/test/test_ttp_to_stn.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ def test_all_valid(self):

for name, tc in self.problems.items():
for valid_plan in tc.valid_plans:
if valid_plan.kind == PlanKind.TIME_TRIGGERED_PLAN:
if (
valid_plan.kind == PlanKind.TIME_TRIGGERED_PLAN
and not tc.problem.kind.has_decrease_continuous_effects()
and not tc.problem.kind.has_increase_continuous_effects()
):
stn_plan = valid_plan.convert_to(PlanKind.STN_PLAN, tc.problem)
tt_plan = stn_plan.convert_to(
PlanKind.TIME_TRIGGERED_PLAN, tc.problem
Expand Down

0 comments on commit da58f4c

Please sign in to comment.