From 2c7e25a1edb50d25fc114cbc3cbf846380f9c625 Mon Sep 17 00:00:00 2001 From: Alessandro Valentini Date: Tue, 7 Nov 2023 15:52:40 +0100 Subject: [PATCH] Added internal time info --- up_tamer/engine.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/up_tamer/engine.py b/up_tamer/engine.py index 43eaa8f..e4d7b82 100644 --- a/up_tamer/engine.py +++ b/up_tamer/engine.py @@ -14,6 +14,7 @@ import sys +import time import warnings import unified_planning as up import pytamer # type: ignore @@ -157,8 +158,10 @@ 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, [], extra_engine_info={"internal_time": str(solving_time)}) def _solve(self, problem: 'up.model.AbstractProblem', heuristic: Optional[Callable[["up.model.state.State"], Optional[float]]] = None, @@ -200,7 +203,9 @@ 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: @@ -208,10 +213,10 @@ def fun(ts: pytamer.tamer_classical_state, 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, extra_engine_info={"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: @@ -512,12 +517,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], str]: + 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 = {}