From 5593774da9e677ef714ee0d2d38e9e9559cb168a Mon Sep 17 00:00:00 2001 From: Alelafar Date: Mon, 5 Feb 2024 14:54:10 +0100 Subject: [PATCH] Fixed bug dumping conditional_effects --- unified_planning/io/pddl_reader.py | 76 ++++++++++++++++++++++++++++++ unified_planning/io/pddl_writer.py | 4 +- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/unified_planning/io/pddl_reader.py b/unified_planning/io/pddl_reader.py index 037dab815..20b99766e 100644 --- a/unified_planning/io/pddl_reader.py +++ b/unified_planning/io/pddl_reader.py @@ -952,6 +952,82 @@ def _add_timed_effects( if op == "and": for i in range(1, len(eff)): to_add.append((eff[i], forall_variables)) + elif op == "when": + if ( + len(eff) == 3 + and eff[1][0].value == "at" + and eff[1][1].value == "start" + ): + cond = self._parse_exp( + problem, + act, + types_map, + forall_variables, + eff[1][2], + complete_str, + ) + if len(eff[2]) == 3 and not "#t" in eff[2] and "start" in eff[2]: + self._add_effect( + problem, + act, + types_map, + eff[2][2], + complete_str, + cond, + timing=up.model.StartTiming(), + forall_variables=forall_variables, + ) + elif "#t" in eff[2]: + self._add_effect( + problem, + act, + types_map, + eff[2], + complete_str, + timing=up.model.timing.ClosedTimeInterval( + up.model.timing.StartTiming(), + up.model.timing.EndTiming(), + ), + forall_variables=forall_variables, + ) + else: + raise UPUnsupportedProblemTypeError( + "Conditional effects with different timing are not supported." + ) + + elif ( + len(eff) == 3 + and eff[1][0].value == "at" + and eff[1][1].value == "end" + ): + cond = self._parse_exp( + problem, + act, + types_map, + forall_variables, + eff[1][2], + complete_str, + ) + if len(eff[2]) == 3 and "end" in eff[2]: + self._add_effect( + problem, + act, + types_map, + eff[2][2], + complete_str, + cond, + timing=up.model.EndTiming(), + forall_variables=forall_variables, + ) + else: + raise UPUnsupportedProblemTypeError( + "Conditional effects with different timing are not supported." + ) + + else: + raise UPUnsupportedProblemTypeError( + "Conditional durative effects syntax is not correct." + ) elif len(eff) == 3 and op == "at" and eff[1].value == "start": self._add_effect( problem, diff --git a/unified_planning/io/pddl_writer.py b/unified_planning/io/pddl_writer.py index 999261bed..a02e5b06a 100644 --- a/unified_planning/io/pddl_writer.py +++ b/unified_planning/io/pddl_writer.py @@ -1127,7 +1127,7 @@ def _write_effect( or effect.is_continuous_decrease() ): out.write(")") - out.write(f" not {converter.convert(effect.fluent)}))") + out.write(f" (not {converter.convert(effect.fluent)}))") if timing is not None: if timing.is_from_start(): out.write(f" (at start") @@ -1135,7 +1135,7 @@ def _write_effect( out.write(f" (at end") if negative_cond.is_true(): out.write(f" {converter.convert(effect.fluent)}") - if timing is not None and not negative_cond.is_true(): + if timing is not None: out.write(")") if effect.is_forall(): out.write(")")