Skip to content

Commit

Permalink
Fixed bug dumping conditional_effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Alelafar committed Feb 5, 2024
1 parent 203facb commit 5593774
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
76 changes: 76 additions & 0 deletions unified_planning/io/pddl_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions unified_planning/io/pddl_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1127,15 +1127,15 @@ 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")
else:
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(")")
Expand Down

0 comments on commit 5593774

Please sign in to comment.