Skip to content

Commit

Permalink
fix(interpreted functions): cleaned code from most prints and temp co…
Browse files Browse the repository at this point in the history
…mments
  • Loading branch information
Samuel Gobbi committed Nov 12, 2024
1 parent 1800320 commit a42c46e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def _compile(
new_fluents: dict = {}
if_known: dict = {}
for ifun_exp, val in self._interpreted_functions_values.items():
# this does not add the functions we have not found with the validator yet
ifun = ifun_exp.interpreted_function()
if ifun not in if_known:
if_known[ifun] = []
Expand Down Expand Up @@ -280,10 +279,6 @@ def _compile(

else:

# if effect assigns value to an unknown fluent, put tracker back to known state
# TODO - fix cascade effect that might lead to incorrect results
# cascade effect is preset not only here

effs.append((time, ef))
if ef.fluent.fluent() in assignment_tracking_fluents.keys():
# if the fluent is one of the changing ones
Expand Down
4 changes: 2 additions & 2 deletions unified_planning/engines/interpreted_functions_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ def _attempt_to_solve(
def _refine(self, problem, validation_result):
newProb = None
if validation_result.calculated_interpreted_functions is None:
print("no updates available, the problem has no solution")
pass

Check warning on line 218 in unified_planning/engines/interpreted_functions_planner.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/interpreted_functions_planner.py#L218

Added line #L218 was not covered by tests
elif len(validation_result.calculated_interpreted_functions) == 0:
print("no updates available, the problem has no solution")
pass

Check warning on line 220 in unified_planning/engines/interpreted_functions_planner.py

View check run for this annotation

Codecov / codecov/patch

unified_planning/engines/interpreted_functions_planner.py#L220

Added line #L220 was not covered by tests
else:
for k in validation_result.calculated_interpreted_functions:
self.add_knowledge(k, validation_result.calculated_interpreted_functions[k])
Expand Down
31 changes: 5 additions & 26 deletions unified_planning/test/test_interpreted_functions_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ def test_interpreted_functions_in_preconditions_planner_always_impossible(self):
with OneshotPlanner(
name="interpreted_functions_planning[opt-pddl-planner]"
) as planner:
planner._skip_checks = True # enhsp does not like bounded fluents but it does not make any difference here
planner.skip_checks = True # enhsp does not like bounded fluents but it does not make any difference here
result = planner.solve(problem)
print(result)
print(result.plan)

self.assertFalse(result.status in up.engines.results.POSITIVE_OUTCOMES)

Expand All @@ -65,11 +63,9 @@ def test_interpreted_functions_planner_int_assignment(self):
with OneshotPlanner(
name="interpreted_functions_planning[opt-pddl-planner]"
) as planner:
planner._skip_checks = True # -----------------------------
planner.skip_checks = True # enhsp does not like bounded fluents but it does not make any difference here

result = planner.solve(problem)
print(result)
print(result.plan)

self.assertTrue(result.status in up.engines.results.POSITIVE_OUTCOMES)

Expand All @@ -80,12 +76,8 @@ def test_interpreted_functions_in_preconditions(self):
with OneshotPlanner(
name="interpreted_functions_planning[opt-pddl-planner]"
) as planner:
planner._skip_checks = True
planner.skip_checks = True # enhsp does not like bounded fluents but it does not make any difference here
result = planner.solve(problem)
print(result)
print(result.plan)
print("increase val -> action if in condition ")
print("is a valid solution")
self.assertEqual(len(result.plan.actions), 2)
self.assertEqual(result.plan.actions[0].action, problem.actions[0])
self.assertEqual(result.plan.actions[1].action, problem.actions[1])
Expand All @@ -101,11 +93,8 @@ def test_interpreted_functions_in_preconditions_planner_complex(self):
with OneshotPlanner(
name="interpreted_functions_planning[opt-pddl-planner]"
) as planner:
planner._skip_checks = True # -----------------------------
planner.skip_checks = True # enhsp does not like bounded fluents but it does not make any difference here
result = planner.solve(problem)
print(result)
print("known valid plan:")
print(testproblem.valid_plans[0])
self.assertTrue(result.status in up.engines.results.POSITIVE_OUTCOMES)
self.assertEqual(
len(result.plan.actions), len(testproblem.valid_plans[0].actions)
Expand All @@ -126,11 +115,8 @@ def test_interpreted_functions_reals(self):
with OneshotPlanner(
name="interpreted_functions_planning[opt-pddl-planner]"
) as planner:
planner._skip_checks = True # -----------------------------
planner.skip_checks = True # enhsp does not like bounded fluents but it does not make any difference here
result = planner.solve(problem)
print(result)
print("known valid plan:")
print(testproblem.valid_plans[0])
self.assertTrue(result.status in up.engines.results.POSITIVE_OUTCOMES)
self.assertEqual(
len(result.plan.actions), len(testproblem.valid_plans[0].actions)
Expand All @@ -142,22 +128,15 @@ def test_interpreted_functions_in_durations_planner(self):
problem = testproblem.problem

with OneshotPlanner(name="interpreted_functions_planning[tamer]") as planner:
# print("now attempting to solve")
planner.skipChecks = True
result = planner.solve(problem)
print(result)

self.assertTrue(result.status in up.engines.results.POSITIVE_OUTCOMES)
self.assertEqual(len(result.plan._actions), 2)
print(result.plan)
print(testproblem.valid_plans[0])
i = 0
while i < len(testproblem.valid_plans[0].timed_actions):
j = 0
while j < 3:
# the result tuple has 3 values: start time, action, duration
print(result.plan.timed_actions[i][j])
print(testproblem.valid_plans[0].timed_actions[i][j])
if j != 1:
self.assertEqual(
result.plan.timed_actions[i][j],
Expand Down
12 changes: 0 additions & 12 deletions unified_planning/test/test_interpreted_functions_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ def test_interpreted_functions_in_preconditions_remover_simple(self):
problem, CompilationKind.INTERPRETED_FUNCTIONS_REMOVING
)
compiled_problem = ifr.problem
# print(problem)
# print(problem.kind)
# print(compiled_problem)
# print(compiled_problem.kind)

self.assertTrue(problem.kind.has_interpreted_functions_in_conditions())
self.assertFalse(problem.kind.has_simple_numeric_planning())
Expand All @@ -99,10 +95,6 @@ def test_interpreted_functions_in_preconditions_remover_always_impossible(self):
problem, CompilationKind.INTERPRETED_FUNCTIONS_REMOVING
)
compiled_problem = ifr.problem
# print(problem)
# print(problem.kind)
# print(compiled_problem)
# print(compiled_problem.kind)
self.assertTrue(problem.kind.has_interpreted_functions_in_conditions())
self.assertFalse(problem.kind.has_simple_numeric_planning())
self.assertFalse(
Expand All @@ -120,10 +112,6 @@ def test_interpreted_functions_in_durative_conditions_remover(self):
problem, CompilationKind.INTERPRETED_FUNCTIONS_REMOVING
)
compiled_problem = ifr.problem
# print(problem)
# print(problem.kind)
# print(compiled_problem)
# print(compiled_problem.kind)
self.assertTrue(problem.kind.has_interpreted_functions_in_conditions())
self.assertFalse(
compiled_problem.kind.has_interpreted_functions_in_conditions()
Expand Down
2 changes: 0 additions & 2 deletions unified_planning/test/test_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,6 @@ def test_interpreted_functions_simple(self):

def test_interpreted_functions_complex(self):
problem = self.problems["go_home_with_rain_and_interpreted_functions"].problem
print(problem)
print(problem.kind)
self.assertTrue(problem.kind.has_interpreted_functions_in_durations())
self.assertTrue(problem.kind.has_interpreted_functions_in_boolean_assignments())
problem = self.problems["IF_in_conditions_complex_1"].problem
Expand Down

0 comments on commit a42c46e

Please sign in to comment.