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

Add internal time info #55

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
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
20 changes: 14 additions & 6 deletions up_tamer/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


import sys
import time
import warnings
import unified_planning as up
import pytamer # type: ignore
Expand Down Expand Up @@ -157,8 +158,11 @@ def _validate(self, problem: 'up.model.AbstractProblem', plan: 'up.plans.Plan')
epsilon = plan.extract_epsilon(problem)
if epsilon is not None:
pytamer.tamer_env_set_string_option(self._env, "plan-epsilon", str(epsilon))
start = time.time()
value = pytamer.tamer_ttplan_validate(tproblem, tplan) == 1
return ValidationResult(ValidationResultStatus.VALID if value else ValidationResultStatus.INVALID, self.name, [])
solving_time = time.time() - start
return ValidationResult(ValidationResultStatus.VALID if value else ValidationResultStatus.INVALID,
self.name, [], metrics={"engine_internal_time": str(solving_time)})

def _solve(self, problem: 'up.model.AbstractProblem',
heuristic: Optional[Callable[["up.model.state.State"], Optional[float]]] = None,
Expand Down Expand Up @@ -200,18 +204,20 @@ def fun(ts: pytamer.tamer_classical_state,
pytamer.tamer_env_set_string_option(self._env, "plan-epsilon", str(problem.epsilon))
else:
pytamer.tamer_env_set_string_option(self._env, "plan-epsilon", "0.01")
start = time.time()
ttplan = pytamer.tamer_do_ftp_planning(tproblem, heuristic_fun)
solving_time = time.time() - start
if pytamer.tamer_ttplan_is_error(ttplan) == 1:
ttplan = None
else:
if self._heuristic is not None:
pytamer.tamer_env_set_string_option(self._env, 'tsimple-heuristic', self._heuristic)
else:
pytamer.tamer_env_set_string_option(self._env, 'tsimple-heuristic', "hadd")
ttplan = self._solve_classical_problem(tproblem, heuristic_fun)
ttplan, solving_time = self._solve_classical_problem(tproblem, heuristic_fun)
plan = self._to_up_plan(problem, ttplan)
status = PlanGenerationResultStatus.UNSOLVABLE_INCOMPLETELY if plan is None else PlanGenerationResultStatus.SOLVED_SATISFICING
return up.engines.PlanGenerationResult(status, plan, self.name)
return up.engines.PlanGenerationResult(status, plan, self.name, metrics={"engine_internal_time": str(solving_time)})

def _convert_type(self, typename: 'up.model.Type',
user_types_map: Dict['up.model.Type', pytamer.tamer_type]) -> pytamer.tamer_type:
Expand Down Expand Up @@ -512,12 +518,14 @@ def _to_up_plan(self, problem: 'up.model.Problem',
return up.plans.SequentialPlan([a[1] for a in actions], problem.environment)

def _solve_classical_problem(self, tproblem: pytamer.tamer_problem,
heuristic_fun) -> Optional[pytamer.tamer_ttplan]:
heuristic_fun) -> Tuple[Optional[pytamer.tamer_ttplan], float]:
start = time.time()
potplan = pytamer.tamer_do_tsimple_planning(tproblem, heuristic_fun)
solving_time = time.time() - start
if pytamer.tamer_potplan_is_error(potplan) == 1:
return None
return None, solving_time
ttplan = pytamer.tamer_ttplan_from_potplan(potplan)
return ttplan
return ttplan, solving_time

def _convert_plan(self, tproblem: pytamer.tamer_problem, plan: 'up.plans.Plan') -> pytamer.tamer_ttplan:
actions_map = {}
Expand Down