Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding continuous effects to durative actions #563

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
58885fd
added new problem_kind and is_continuous_increase/decrease
Alelafar Jan 19, 2024
dae296b
added as comments some intentions and tried to add the add_continuous…
Alelafar Jan 19, 2024
6639460
added continuous effects in DurativeAction and deleted from TimedCond…
Alelafar Jan 22, 2024
29af286
changed #-= but still to discuss and change for increase
Alelafar Jan 22, 2024
6be93f4
started modifications in problem.kind but doesn't work
Alelafar Jan 22, 2024
b2426b6
added local test
Alelafar Jan 22, 2024
b309210
added increase/decrease continuous_effects but not requirement contin…
Alelafar Jan 23, 2024
92f1776
made some adjustements
Alelafar Jan 23, 2024
49c31f3
starting some local testing
Alelafar Jan 23, 2024
56fed1c
made some adjustements
Alelafar Jan 23, 2024
4f2ab6e
made some adjustments to new functions for continuous change
Alelafar Jan 23, 2024
c24353e
local test files
Alelafar Jan 23, 2024
4804f30
made some adjustements. Now should work print(problem), pddl_writer a…
Alelafar Jan 24, 2024
0523353
local testing
Alelafar Jan 24, 2024
fcdd869
new file for testing
Alelafar Jan 24, 2024
9c9a1d1
made some modifications in order to let PDDL domain and problem more …
Alelafar Jan 26, 2024
61e35d7
made some modifications. And local testing
Alelafar Jan 26, 2024
dd94a9d
made some modifications. And modified tests for PDDL_writer_io
Alelafar Jan 29, 2024
3c53eff
Made some modifications to adapt for new pddl_writer
Alelafar Jan 31, 2024
18e46db
Made few updates
Alelafar Jan 31, 2024
f15a2d2
Update pddl_reader in order to read continuous change in durative act…
Alelafar Jan 31, 2024
5fe8a28
deleted local test files
Alelafar Jan 31, 2024
d4e5108
updates
Alelafar Jan 31, 2024
bf7326c
fixed mypy errors
Alelafar Jan 31, 2024
4d262f8
fixed bug
Alelafar Jan 31, 2024
5b96152
Fixed bug dumping conditional_effects
Alelafar Feb 2, 2024
651edcc
Fixed bug dumping conditional_effects
Alelafar Feb 2, 2024
b1f9b9b
Fixed bug dumping conditional_effects
Alelafar Feb 5, 2024
81f3420
Added new problem_kind 'Non_Linear_Continuous_Effect'
Alelafar Feb 7, 2024
5212971
Fixed bug mypy
Alelafar Feb 7, 2024
fd9db33
updates for non_linear_continuous_effects and tests
Alelafar Feb 8, 2024
fcaf7f9
fixed some bugs
Alelafar Feb 9, 2024
b77d1eb
fixed some problems
Alelafar Feb 12, 2024
2720bcd
updates some functions added loop on continuous_effects
Alelafar Feb 16, 2024
42f6844
update time_triggered_plan and test
Alelafar Feb 19, 2024
31dca0a
fixed formatting
Alelafar Mar 14, 2024
e3813bf
fixed a bug in pddl_reader
Alelafar Apr 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/problem_representation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ Problem Kinds
* -
- DECREASE_EFFECTS
- At least one effect uses the numeric decrement operator.
* -
- INCREASE_CONTINUOUS_EFFECTS
- At least one effect uses the continuous numeric increment operator.
* -
- DECREASE_CONTINUOUS_EFFECTS
- At least one effect uses the continuous numeric decrement operator.
* -
- NON_LINEAR_CONTINUOUS_EFFECTS
- At least one continuous effect is described by a differential equation that depends on a continuous variable.
* -
- STATIC_FLUENTS_IN_BOOLEAN_ASSIGNMENTS
- At least one effect uses a static fluent in the expression of a boolean assignment.
Expand Down
266 changes: 242 additions & 24 deletions unified_planning/io/pddl_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
if len(self.value) == 1 and isinstance(self.value[0], str):
self.value = self.value[0]

def __iter__(self):
for i in range(len(self)):
yield self[i]

def __getitem__(self, i):
return CustomParseResults(self.value[i])

Expand All @@ -72,6 +76,20 @@
def col_end(self, complete_str: str) -> int:
return col(self.locn_end, complete_str)

def __contains__(self, string: str):
stack = [self]
while len(stack) > 0:
exp = stack.pop()
if isinstance(exp.value, str):
if exp.value == string:
return True
elif isinstance(exp.value, ParseResults):
for e in exp:
stack.append(e)
else:
raise SyntaxError(f"Not able to handle: {exp}")

Check warning on line 90 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L90

Added line #L90 was not covered by tests
return False


Object = "object"
TypesMap = Dict[str, unified_planning.model.Type]
Expand Down Expand Up @@ -101,7 +119,7 @@
+ ":requirements"
+ OneOrMore(
one_of(
":strips :typing :negative-preconditions :disjunctive-preconditions :equality :existential-preconditions :universal-preconditions :quantified-preconditions :conditional-effects :fluents :numeric-fluents :adl :durative-actions :duration-inequalities :timed-initial-literals :timed-initial-effects :action-costs :hierarchy :method-preconditions :constraints :contingent :preferences"
":strips :typing :negative-preconditions :disjunctive-preconditions :equality :existential-preconditions :universal-preconditions :quantified-preconditions :conditional-effects :fluents :numeric-fluents :adl :durative-actions :duration-inequalities :timed-initial-literals :timed-initial-effects :action-costs :hierarchy :method-preconditions :constraints :contingent :preferences :continuous-effects"
)
)
+ Suppress(")")
Expand Down Expand Up @@ -564,7 +582,9 @@
exp: CustomParseResults,
complete_str: str,
cond: Union[up.model.FNode, bool] = True,
timing: typing.Optional[up.model.Timing] = None,
timing: typing.Optional[
Union[up.model.Timing, up.model.timing.TimeInterval]
] = None,
forall_variables: typing.Optional[Dict[str, up.model.Variable]] = None,
):
if forall_variables is None:
Expand Down Expand Up @@ -610,27 +630,199 @@
)
act.add_effect(*eff if timing is None else (timing, *eff), forall=tuple(forall_variables.values())) # type: ignore
elif op == "increase":
eff = (
self._parse_exp(
problem, act, types_map, forall_variables, exp[1], complete_str
),
self._parse_exp(
problem, act, types_map, forall_variables, exp[2], complete_str
),
cond,
)
act.add_increase_effect(*eff if timing is None else (timing, *eff)) # type: ignore
if "#t" in exp:
if (
len(exp) == 3
and len(exp[2]) == 3
and exp[2][0].value == "*"
and exp[2][1].value == "#t"
):
eff = (
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[2][2],
complete_str,
),
cond,
)
assert isinstance(timing, up.model.TimeInterval)
assert isinstance(act, up.model.DurativeAction)
act.add_increase_continuous_effect(timing, *eff)
elif (

Check warning on line 662 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L662

Added line #L662 was not covered by tests
len(exp) == 3
and len(exp[2]) == 3
and exp[2][0].value == "*"
and exp[2][2].value == "#t"
):
eff_inverted = (

Check warning on line 668 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L668

Added line #L668 was not covered by tests
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[2][1],
complete_str,
),
cond,
)
assert isinstance(timing, up.model.TimeInterval)
assert isinstance(act, up.model.DurativeAction)
act.add_increase_continuous_effect(timing, *eff_inverted)
elif len(exp) == 3 and exp[2].value == "#t":
eff_without = (

Check warning on line 691 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L687-L691

Added lines #L687 - L691 were not covered by tests
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
1,
cond,
)
assert isinstance(timing, up.model.TimeInterval)
assert isinstance(act, up.model.DurativeAction)
act.add_increase_continuous_effect(timing, *eff_without)

Check warning on line 705 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L703-L705

Added lines #L703 - L705 were not covered by tests
else:
raise SyntaxError("Continuous change syntax is not correct!")

Check warning on line 707 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L707

Added line #L707 was not covered by tests
else:
eff = (
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[2],
complete_str,
),
cond,
)
act.add_increase_effect(*eff if timing is None else (timing, *eff)) # type: ignore
elif op == "decrease":
eff = (
self._parse_exp(
problem, act, types_map, forall_variables, exp[1], complete_str
),
self._parse_exp(
problem, act, types_map, forall_variables, exp[2], complete_str
),
cond,
)
act.add_decrease_effect(*eff if timing is None else (timing, *eff)) # type: ignore
if "#t" in exp:
if (
len(exp) == 3
and len(exp[2]) == 3
and exp[2][0].value == "*"
and exp[2][1].value == "#t"
):
eff_inverted = (
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[2][2],
complete_str,
),
cond,
)
assert isinstance(timing, up.model.TimeInterval)
assert isinstance(act, up.model.DurativeAction)
act.add_decrease_continuous_effect(timing, *eff_inverted)
elif (

Check warning on line 759 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L759

Added line #L759 was not covered by tests
len(exp) == 3
and len(exp[2]) == 3
and exp[2][0].value == "*"
and exp[2][2].value == "#t"
):
eff = (

Check warning on line 765 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L765

Added line #L765 was not covered by tests
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[2][1],
complete_str,
),
cond,
)
assert isinstance(timing, up.model.TimeInterval)
assert isinstance(act, up.model.DurativeAction)
act.add_decrease_continuous_effect(timing, *eff)
elif len(exp) == 3 and exp[2].value == "#t":
eff_without = (

Check warning on line 788 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L784-L788

Added lines #L784 - L788 were not covered by tests
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
1,
cond,
)
assert isinstance(timing, up.model.TimeInterval)
assert isinstance(act, up.model.DurativeAction)
act.add_decrease_continuous_effect(timing, *eff_without)

Check warning on line 802 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L800-L802

Added lines #L800 - L802 were not covered by tests
else:
raise SyntaxError("Continuous change syntax is not correct!")

Check warning on line 804 in unified_planning/io/pddl_reader.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/io/pddl_reader.py#L804

Added line #L804 was not covered by tests
else:
eff = (
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[1],
complete_str,
),
self._parse_exp(
problem,
act,
types_map,
forall_variables,
exp[2],
complete_str,
),
cond,
)
act.add_decrease_effect(*eff if timing is None else (timing, *eff)) # type: ignore
elif op == "forall":
assert isinstance(exp, CustomParseResults)
if forall_variables:
Expand Down Expand Up @@ -774,7 +966,7 @@
eff[1][2],
complete_str,
)
if len(eff[2]) == 3 and eff[2][1].value == "start":
if len(eff[2]) == 3 and not "#t" in eff[2] and "start" in eff[2]:
self._add_effect(
problem,
act,
Expand All @@ -785,6 +977,20 @@
timing=up.model.StartTiming(),
forall_variables=forall_variables,
)
elif "#t" in eff[2]:
self._add_effect(
problem,
act,
types_map,
eff[2],
complete_str,
cond,
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."
Expand All @@ -802,7 +1008,7 @@
eff[1][2],
complete_str,
)
if len(eff[2]) == 3 and eff[2][1].value == "end":
if len(eff[2]) == 3 and "end" in eff[2]:
self._add_effect(
problem,
act,
Expand Down Expand Up @@ -841,6 +1047,18 @@
timing=up.model.EndTiming(),
forall_variables=forall_variables,
)
elif "#t" in eff:
self._add_effect(
problem,
act,
types_map,
eff,
complete_str,
timing=up.model.timing.ClosedTimeInterval(
up.model.timing.StartTiming(), up.model.timing.EndTiming()
),
forall_variables=forall_variables,
)
elif len(eff) == 3 and op == "forall":
assert isinstance(eff, CustomParseResults)
if forall_variables:
Expand Down
Loading
Loading