Skip to content

Commit

Permalink
Added support to TILs in the PDDLWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
alvalentini committed Dec 6, 2023
1 parent 435072c commit 02ab2fd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
50 changes: 33 additions & 17 deletions unified_planning/io/pddl_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,12 +375,10 @@ def __init__(
def _write_domain(self, out: IO[str]):
if self.problem_kind.has_intermediate_conditions_and_effects():
raise UPProblemDefinitionError(
"PDDL2.1 does not support ICE.\nICE are Intermediate Conditions and Effects therefore when an Effect (or Condition) are not at StartTIming(0) or EndTIming(0)."
)
if self.problem_kind.has_timed_effects() or self.problem_kind.has_timed_goals():
raise UPProblemDefinitionError(
"PDDL2.1 does not support timed effects or timed goals."
"PDDL does not support ICE.\nICE are Intermediate Conditions and Effects therefore when an Effect (or Condition) are not at StartTIming(0) or EndTIming(0)."
)
if self.problem_kind.has_timed_goals():
raise UPProblemDefinitionError("PDDL does not support timed goals.")
obe = ObjectsExtractor()
out.write("(define ")
if self.problem.name is None:
Expand Down Expand Up @@ -428,6 +426,8 @@ def _write_domain(self, out: IO[str]):
or self.problem_kind.has_plan_length()
):
out.write(" :action-costs")
if self.problem_kind.has_timed_effects():
out.write(" :timed-initial-literals")
out.write(")\n")

if self.problem_kind.has_hierarchical_typing():
Expand Down Expand Up @@ -686,7 +686,20 @@ def _write_problem(self, out: IO[str]):
else:
out.write(f" (= {converter.convert(f)} {converter.convert(v)})")
if self.problem.kind.has_actions_cost() or self.problem.kind.has_plan_length():
out.write(f" (= (total-cost) 0)")
out.write(" (= (total-cost) 0)")
for tm, le in self.problem.timed_effects.items():
for e in le:
out.write(f" (at {tm.delay}")
_write_effect(
e,
None,
out,
converter,
self.rewrite_bool_assignments,
self._get_mangled_name,
True,
)
out.write(")")
out.write(")\n")
goals_str: List[str] = []
for g in (c.simplify() for c in self.problem.goals):
Expand Down Expand Up @@ -985,6 +998,7 @@ def _write_effect(
],
str,
],
initial: bool = False,
):
simplified_cond = effect.condition.simplify()
# check for non-constant-bool-assignment
Expand Down Expand Up @@ -1061,22 +1075,24 @@ def _write_effect(
if not simplified_cond.is_true():
out.write(f" (when {converter.convert(effect.condition)}")
simplified_value = effect.value.simplify()
fluent = converter.convert(effect.fluent)
if simplified_value.is_true():
out.write(f" {converter.convert(effect.fluent)}")
out.write(f" {fluent}")
elif simplified_value.is_false():
out.write(f" (not {converter.convert(effect.fluent)})")
out.write(f" (not {fluent})")
elif initial:
value = converter.convert(simplified_value)
if effect.is_increase():
value = f"(+ {fluent} {value})"
elif effect.is_decrease():
value = f"(- {fluent} {value})"
out.write(f" (= {fluent} {value})")
elif effect.is_increase():
out.write(
f" (increase {converter.convert(effect.fluent)} {converter.convert(simplified_value)})"
)
out.write(f" (increase {fluent} {converter.convert(simplified_value)})")
elif effect.is_decrease():
out.write(
f" (decrease {converter.convert(effect.fluent)} {converter.convert(simplified_value)})"
)
out.write(f" (decrease {fluent} {converter.convert(simplified_value)})")
else:
out.write(
f" (assign {converter.convert(effect.fluent)} {converter.convert(simplified_value)})"
)
out.write(f" (assign {fluent} {converter.convert(simplified_value)})")
if not simplified_cond.is_true():
out.write(")")
if timing is not None:
Expand Down
1 change: 0 additions & 1 deletion unified_planning/test/test_pddl_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ def test_examples_io(self):
kind.has_intermediate_conditions_and_effects()
or kind.has_object_fluents()
or kind.has_oversubscription()
or kind.has_timed_effects()
or kind.has_timed_goals()
or kind.has_bool_fluent_parameters()
or kind.has_bounded_int_fluent_parameters()
Expand Down

0 comments on commit 02ab2fd

Please sign in to comment.