Skip to content

Commit

Permalink
feature(interpreted functions): IF remover compiler now splits one la…
Browse files Browse the repository at this point in the history
…yer of ands in preconditions for instantaneous actions
  • Loading branch information
Samuel Gobbi committed Sep 23, 2024
1 parent 24349b6 commit 1532690
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class InterpretedFunctionsRemover(

def __init__(self):
engines.engine.Engine.__init__(self)
self.operators_extractor: up.model.walkers.OperatorsExtractor = (

Check warning on line 69 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L68-L69

Added lines #L68 - L69 were not covered by tests
up.model.walkers.OperatorsExtractor()
)
CompilerMixin.__init__(self, CompilationKind.INTERPRETED_FUNCTIONS_REMOVING)

Check warning on line 72 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L72

Added line #L72 was not covered by tests

@property
Expand Down Expand Up @@ -144,6 +147,21 @@ def supports(problem_kind):
def supports_compilation(compilation_kind: CompilationKind) -> bool:
return compilation_kind == CompilationKind.INTERPRETED_FUNCTIONS_REMOVING

def _fix_precondition(self, a):
# simplified_precondition = simplifier.simplify(p)
# precondition_operators = operators_extractor.get(simplified_precondition)
# operators_extractor: up.model.walkers.OperatorsExtractor = (
# up.model.walkers.OperatorsExtractor()
# )
templist = []
if a.is_and():
for sub in a.args:
templist.append(sub)

Check warning on line 159 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L156-L159

Added lines #L156 - L159 were not covered by tests
else:
templist.append(a)

Check warning on line 161 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L161

Added line #L161 was not covered by tests
# print (templist)
return templist

Check warning on line 163 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L163

Added line #L163 was not covered by tests

@staticmethod
def resulting_problem_kind(
problem_kind: ProblemKind, compilation_kind: Optional[CompilationKind] = None
Expand Down Expand Up @@ -181,10 +199,10 @@ def _compile(

new_to_old: Dict[Action, Optional[Action]] = {}

Check warning on line 200 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L200

Added line #L200 was not covered by tests
# name_action_map: Dict[str, Union[InstantaneousAction, DurativeAction]] = {}
operators_extractor: up.model.walkers.OperatorsExtractor = (
up.model.walkers.OperatorsExtractor()
)

# operators_extractor: up.model.walkers.OperatorsExtractor = (
# up.model.walkers.OperatorsExtractor()
# )
new_problem = problem.clone()
new_problem.name = f"{self.name}_{problem.name}"
new_problem.clear_actions()

Check warning on line 208 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L206-L208

Added lines #L206 - L208 were not covered by tests
Expand All @@ -194,10 +212,16 @@ def _compile(
no_IF_action = a.clone()
no_IF_action.name = get_fresh_name(new_problem, a.name)
no_IF_action.clear_preconditions()
fixed_preconditions = []
for p in a.preconditions:
# simplified_precondition = simplifier.simplify(p)
# precondition_operators = operators_extractor.get(simplified_precondition)
precondition_operators = operators_extractor.get(p)
templist = self._fix_precondition(p)
fixed_preconditions.extend(templist)

Check warning on line 218 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L210-L218

Added lines #L210 - L218 were not covered by tests
# print ("\n\n fixed preconds \n\n")
# print (fixed_preconditions)
# print (a.preconditions)
for p in fixed_preconditions:
precondition_operators = self.operators_extractor.get(p)

Check warning on line 223 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L222-L223

Added lines #L222 - L223 were not covered by tests

if not (

Check warning on line 225 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L225

Added line #L225 was not covered by tests
OperatorKind.INTERPRETED_FUNCTION_EXP in precondition_operators
):
Expand All @@ -211,7 +235,7 @@ def _compile(
for c in cl:

Check warning on line 235 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L228-L235

Added lines #L228 - L235 were not covered by tests
# simplified_precondition = simplifier.simplify(p)
# precondition_operators = operators_extractor.get(simplified_precondition)
precondition_operators = operators_extractor.get(p)
precondition_operators = self.operators_extractor.get(p)
if not (

Check warning on line 239 in unified_planning/engines/compilers/interpreted_functions_remover.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/compilers/interpreted_functions_remover.py#L238-L239

Added lines #L238 - L239 were not covered by tests
OperatorKind.INTERPRETED_FUNCTION_EXP
in precondition_operators
Expand Down

0 comments on commit 1532690

Please sign in to comment.