Skip to content

Commit

Permalink
Merge pull request #591 from aiplan4eu/Fix_dumping_pddl_cond_effects_…
Browse files Browse the repository at this point in the history
…durative_actions

Fix dumping pddl cond effects durative actions
  • Loading branch information
alvalentini committed Apr 12, 2024
2 parents f85d022 + 08e5ffc commit 1a540af
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ jobs:

with:
python-version: "3.10"

secrets: inherit
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
python-version: ${{matrix.python-version}}

secrets: inherit

deploy:
needs: [test]
uses: ./.github/workflows/deploy.yml
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
python-version:
required: true
type: string
secrets:
CODECOV_TOKEN:
required: true

env:
up_tamer_commit: "631dfd43a56e7c2dda44fe273ec6f5492e99cfe1"
Expand Down Expand Up @@ -218,8 +221,8 @@ jobs:
run: bash run_tests.sh

- name: "Upload coverage to Codecov"
if: ${{ github.repository == 'aiplan4eu/unified-planning' }}
uses: codecov/codecov-action@v1
if: ${{ github.repository == 'aiplan4eu/unified-planning' && inputs.python-version == '3.10' }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
Expand Down
63 changes: 62 additions & 1 deletion unified_planning/io/pddl_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,67 @@ 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 eff[2][1].value == "start":
self._add_effect(
problem,
act,
types_map,
eff[2][2],
complete_str,
cond,
timing=up.model.StartTiming(),
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 eff[2][1].value == "end":
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 Expand Up @@ -802,7 +863,7 @@ def _add_timed_effects(
complete_str
)
raise SyntaxError(
f"Not able to handle: {eff}, from line: {start_line}, col {start_col} to line: {end_line}, col {end_col}"
f"Not able to handle: {eff.value}, from line: {start_line}, col {start_col} to line: {end_line}, col {end_col}"
)

def _parse_subtask(
Expand Down
43 changes: 33 additions & 10 deletions unified_planning/io/pddl_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,35 +1098,50 @@ def _write_effect(
positive_cond = (simplified_cond & effect.value).simplify()
if not positive_cond.is_false():
out.write(forall_str)
if not positive_cond.is_true():
out.write(" (when ")
if timing is not None:
if timing.is_from_start():
out.write(f" (at start")
else:
out.write(f" (at end")
out.write(f"{converter.convert(positive_cond)}")
if timing is not None:
out.write(")")
out.write(f" {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 positive_cond.is_true():
out.write(f" {converter.convert(effect.fluent)}")
else:
out.write(
f" (when {converter.convert(positive_cond)} {converter.convert(effect.fluent)})"
)
if timing is not None:
out.write(")")
if effect.is_forall():
out.write(")")
negative_cond = (simplified_cond & effect.value.Not()).simplify()
if not negative_cond.is_false():
out.write(forall_str)
if not negative_cond.is_true():
out.write(" (when")
if timing is not None:
if timing.is_from_start():
out.write(f" (at start")
else:
out.write(f" (at end")
out.write(f" (at start")
out.write(f" {converter.convert(negative_cond)}")
if timing is not None:
out.write(")")
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)}")
else:
out.write(
f" (when {converter.convert(negative_cond)} (not {converter.convert(effect.fluent)}))"
)
if timing is not None:
out.write(")")
if effect.is_forall():
Expand All @@ -1136,13 +1151,21 @@ def _write_effect(
if simplified_cond.is_false():
return
out.write(forall_str)
if not simplified_cond.is_true():
out.write(f" (when")
if timing is not None:
if timing.is_from_start():
out.write(f" (at start")
else:
out.write(f" (at end")
out.write(f" {converter.convert(effect.condition)}")
if timing is not None:
out.write(")")
if timing is not None:
if timing.is_from_start():
out.write(f" (at start")
else:
out.write(f" (at end")
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():
Expand Down

0 comments on commit 1a540af

Please sign in to comment.