diff --git a/unified_planning/io/pddl_reader.py b/unified_planning/io/pddl_reader.py index 5e75ede5b..70554cac4 100644 --- a/unified_planning/io/pddl_reader.py +++ b/unified_planning/io/pddl_reader.py @@ -655,7 +655,7 @@ def _add_effect( if isinstance(act, up.model.Process): eff1 = (eff[0], eff[1].simplify()) - act.add_continuous_increase(*eff1) + act.add_increase_continuous_effect(*eff1) else: act.add_increase_effect(*eff if timing is None else (timing, *eff)) # type: ignore elif op == "decrease": @@ -670,7 +670,7 @@ def _add_effect( ) if isinstance(act, up.model.Process): eff1 = (eff[0], eff[1].simplify()) - act.add_continuous_decrease(*eff1) + act.add_decrease_continuous_effect(*eff1) else: act.add_decrease_effect(*eff if timing is None else (timing, *eff)) # type: ignore elif op == "forall": diff --git a/unified_planning/io/pddl_writer.py b/unified_planning/io/pddl_writer.py index bc29d514f..2a9d4380a 100644 --- a/unified_planning/io/pddl_writer.py +++ b/unified_planning/io/pddl_writer.py @@ -1240,8 +1240,10 @@ def _write_derivative( out.write(f" (increase {fluent} (* #t {converter.convert(simplified_value)} ))") elif effect.is_decrease(): out.write(f" (decrease {fluent} (* #t {converter.convert(simplified_value)} ))") - elif effect.is_continuous_increase() or effect.is_continuous_decrease(): + elif effect.is_increase_continuous_effect(): out.write(f" (increase {fluent} (* #t {converter.convert(simplified_value)} ))") + elif effect.is_decrease_continuous_effect(): + out.write(f" (decrease {fluent} (* #t {converter.convert(simplified_value)} ))") else: raise UPProblemDefinitionError( "Derivative can only be expressed as increase, decrease in processes", diff --git a/unified_planning/model/effect.py b/unified_planning/model/effect.py index 236d50f72..ba9413858 100644 --- a/unified_planning/model/effect.py +++ b/unified_planning/model/effect.py @@ -38,15 +38,15 @@ class EffectKind(Enum): `ASSIGN` => `if C then F <= V` `INCREASE` => `if C then F <= F + V` `DECREASE` => `if C then F <= F - V` - `CONTINUOUS_INCREASE` => `dF/dt <= V` - `CONTINUOUS_DECREASE` => `dF/dt <= -V` + `INCREASE_CONTINUOUS_EFFECT` => `dF/dt <= V` + `DECREASE_CONTINUOUS_EFFECT` => `dF/dt <= -V` """ ASSIGN = auto() INCREASE = auto() DECREASE = auto() - CONTINUOUS_INCREASE = auto() - CONTINUOUS_DECREASE = auto() + INCREASE_CONTINUOUS_EFFECT = auto() + DECREASE_CONTINUOUS_EFFECT = auto() class Effect: @@ -113,7 +113,9 @@ def __repr__(self) -> str: s.append(f"forall {', '.join(str(v) for v in self._forall)}") if self.is_conditional(): s.append(f"if {str(self._condition)} then") - if not (self.is_continuous_increase() or self.is_continuous_decrease()): + if not ( + self.is_increase_continuous_effect() or self.is_decrease_continuous_effect() + ): s.append(f"{str(self._fluent)}") if self.is_assignment(): s.append(":=") @@ -121,8 +123,10 @@ def __repr__(self) -> str: s.append("+=") elif self.is_decrease(): s.append("-=") - elif self.is_continuous_increase() or self.is_continuous_decrease(): + elif self.is_increase_continuous_effect(): s.append(f"d{str(self._fluent)}/dt =") + elif self.is_decrease_continuous_effect(): + s.append(f"d{str(self._fluent)}/dt = -") s.append(f"{str(self._value)}") return " ".join(s) @@ -252,13 +256,13 @@ def is_decrease(self) -> bool: """Returns `True` if the :func:`kind ` of this `Effect` is a `decrease`, `False` otherwise.""" return self._kind == EffectKind.DECREASE - def is_continuous_increase(self) -> bool: + def is_increase_continuous_effect(self) -> bool: """Returns `True` if the :func:`kind ` of this `Effect` is a `continuous increase`, `False` otherwise.""" - return self._kind == EffectKind.CONTINUOUS_INCREASE + return self._kind == EffectKind.INCREASE_CONTINUOUS_EFFECT - def is_continuous_decrease(self) -> bool: + def is_decrease_continuous_effect(self) -> bool: """Returns `True` if the :func:`kind ` of this `Effect` is a `continuous decrease`, `False` otherwise.""" - return self._kind == EffectKind.CONTINUOUS_DECREASE + return self._kind == EffectKind.DECREASE_CONTINUOUS_EFFECT class SimulatedEffect: diff --git a/unified_planning/model/natural_transition.py b/unified_planning/model/natural_transition.py index 4305e6834..768b69a8d 100644 --- a/unified_planning/model/natural_transition.py +++ b/unified_planning/model/natural_transition.py @@ -161,28 +161,21 @@ def _add_continuous_effect( ) if not fluent_exp.type.is_int_type() and not fluent_exp.type.is_real_type(): raise UPTypeError("Derivative can be created only on numeric types!") - if not negative: - self._add_effect_instance( - up.model.effect.Effect( - fluent_exp, - value_exp, - condition_exp, - kind=up.model.effect.EffectKind.CONTINUOUS_INCREASE, - forall=tuple(), - ) - ) - else: - self._add_effect_instance( - up.model.effect.Effect( - fluent_exp, - value_exp, - condition_exp, - kind=up.model.effect.EffectKind.CONTINUOUS_DECREASE, - forall=tuple(), - ) + e_kind = up.model.effect.EffectKind.INCREASE_CONTINUOUS_EFFECT + + if negative: + e_kind = up.model.effect.EffectKind.DECREASE_CONTINUOUS_EFFECT + self._add_effect_instance( + up.model.effect.Effect( + fluent_exp, + value_exp, + condition_exp, + kind=e_kind, + forall=tuple(), ) + ) - def add_continuous_increase( + def add_increase_continuous_effect( self, fluent: Union["up.model.fnode.FNode", "up.model.fluent.Fluent"], value: "up.model.expression.Expression", @@ -196,7 +189,7 @@ def add_continuous_increase( """ self._add_continuous_effect(fluent, value, False) - def add_continuous_decrease( + def add_decrease_continuous_effect( self, fluent: Union["up.model.fnode.FNode", "up.model.fluent.Fluent"], value: "up.model.expression.Expression", diff --git a/unified_planning/model/problem.py b/unified_planning/model/problem.py index eff08b858..b8fb24b40 100644 --- a/unified_planning/model/problem.py +++ b/unified_planning/model/problem.py @@ -888,9 +888,9 @@ def update_problem_kind_effect( 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") - elif e.is_continuous_increase(): + elif e.is_increase_continuous_effect(): self.kind.unset_problem_type("SIMPLE_NUMERIC_PLANNING") - elif e.is_continuous_decrease(): + elif e.is_decrease_continuous_effect(): self.kind.unset_problem_type("SIMPLE_NUMERIC_PLANNING") def update_problem_kind_expression( diff --git a/unified_planning/test/examples/processes.py b/unified_planning/test/examples/processes.py index cd0f4fd9e..36d69f36e 100644 --- a/unified_planning/test/examples/processes.py +++ b/unified_planning/test/examples/processes.py @@ -19,7 +19,7 @@ def get_example_problems(): b = Process("moving") b.add_precondition(on) - b.add_continuous_increase(d, 1) + b.add_increase_continuous_effect(d, 1) problem = Problem("1d_Movement") problem.add_fluent(on) @@ -54,11 +54,11 @@ def get_example_problems(): water_heating = Process("water_heating") water_heating.add_precondition(And(boiler_on, LE(temperature, 100))) - water_heating.add_continuous_increase(temperature, 1) + water_heating.add_increase_continuous_effect(temperature, 1) water_boiling = Process("water_boiling") water_boiling.add_precondition(And(boiler_on, GE(temperature, 100))) - water_boiling.add_continuous_decrease(water_level, 1) + water_boiling.add_decrease_continuous_effect(water_level, 1) open_chimney_vent_auto = Event("open_chimney_vent_auto") open_chimney_vent_auto.add_precondition( diff --git a/unified_planning/test/test_model.py b/unified_planning/test/test_model.py index 2c63e9f6e..b1fb8467f 100644 --- a/unified_planning/test/test_model.py +++ b/unified_planning/test/test_model.py @@ -126,12 +126,12 @@ def test_process(self): x = Fluent("x", IntType()) move = Process("moving", car=Vehicle) move.add_precondition(a) - move.add_continuous_increase(x, 1) + move.add_increase_continuous_effect(x, 1) e = Effect( FluentExp(x), Int(1), TRUE(), - unified_planning.model.EffectKind.CONTINUOUS_INCREASE, + unified_planning.model.EffectKind.INCREASE_CONTINUOUS_EFFECT, ) self.assertEqual(move.effects[0], e) self.assertEqual(move.name, "moving") diff --git a/unified_planning/test/test_pddl_io.py b/unified_planning/test/test_pddl_io.py index 71fe65539..034b22617 100644 --- a/unified_planning/test/test_pddl_io.py +++ b/unified_planning/test/test_pddl_io.py @@ -451,8 +451,8 @@ def test_non_linear_car(self): if isinstance(ele, Process): for e in ele.effects: self.assertTrue( - (e.kind == EffectKind.CONTINUOUS_INCREASE) - or (e.kind == EffectKind.CONTINUOUS_DECREASE) + (e.kind == EffectKind.INCREASE_CONTINUOUS_EFFECT) + or (e.kind == EffectKind.DECREASE_CONTINUOUS_EFFECT) ) if ele.name == "drag_ahead": found_drag_ahead = True