diff --git a/dependency_repos.repos b/dependency_repos.repos index 689c59ef..4774724f 100644 --- a/dependency_repos.repos +++ b/dependency_repos.repos @@ -15,7 +15,7 @@ repositories: aletheia: type: git url: https://github.com/HanielUlises/del-planner.git - version: 084f28067e40dc17e6da1980d84697cfc463b6b1 + version: 3bae6286b01cfc62116113a424b63a2eea85c1c0 # The EPDDL grounder plansys2_epddl_grounder runs. It is a plain CMake # project rather than a ROS package, so colcon builds it as one and installs # the binary into /bin, which puts `plank` on PATH once the workspace diff --git a/eplansys_docs/concepts/architecture.rst b/eplansys_docs/concepts/architecture.rst index bf126aaf..8e3d7007 100644 --- a/eplansys_docs/concepts/architecture.rst +++ b/eplansys_docs/concepts/architecture.rst @@ -160,6 +160,19 @@ Parameters are declared under the plugin name at configure time - ``3`` - Largest number of actions running at once under ``temporal``. The commutation check enumerates subsets of the running set. + * - ``temporal_estimate`` + - string + - ``admissible`` + - ``admissible``: the least worst-case makespan. ``critical_path``: + deepen with :math:`\max(h_{\mathrm{adm}}, h_{\mathrm{cp}})`, which + weighs each layer of the relaxed closure by its shortest contributing + action; the policy is admissible but not necessarily the shortest. + * - ``temporal_bound_growth`` + - double + - ``1.0`` + - Factor by which the search's time bound grows between iterations. + Optimality does not depend on it; ``1.0`` steps to the next lower + bound. * - ``consistent_beliefs`` - bool - ``true`` diff --git a/plansys2_bringup/params/plansys2_epistemic_params.yaml b/plansys2_bringup/params/plansys2_epistemic_params.yaml index e4872c06..eb31f0c1 100644 --- a/plansys2_bringup/params/plansys2_epistemic_params.yaml +++ b/plansys2_bringup/params/plansys2_epistemic_params.yaml @@ -128,6 +128,13 @@ planner: # commutation check enumerates the subsets of the running set, so it # grows exponentially with this. max_concurrency: 3 + # admissible: the least worst-case makespan. critical_path: a faster, + # satisficing search (relaxed critical path); its policies are valid + # but not necessarily the shortest. + temporal_estimate: "admissible" + # How the search's time bound grows between iterations. Optimality does + # not depend on it; 1.0 steps to the next lower bound. + temporal_bound_growth: 1.0 # The same planning is available from an external Aletheia binary rather # than in process, through plansys2_aletheia_plan_solver. It takes these diff --git a/plansys2_epistemic_planner/CMakeLists.txt b/plansys2_epistemic_planner/CMakeLists.txt index 2ae125ce..af5fe09c 100644 --- a/plansys2_epistemic_planner/CMakeLists.txt +++ b/plansys2_epistemic_planner/CMakeLists.txt @@ -16,7 +16,7 @@ find_package(nlohmann_json 3.10 REQUIRED) # The planning core is Aletheia's, linked as a library rather than copied in, # so the search here and the epistemic_planner binary are one implementation. -find_package(aletheia 0.3 REQUIRED) +find_package(aletheia 0.4 REQUIRED) set(EPISTEMIC_SOURCES src/action_mapping.cpp diff --git a/plansys2_epistemic_planner/include/plansys2_epistemic_planner/epistemic_plan_solver.hpp b/plansys2_epistemic_planner/include/plansys2_epistemic_planner/epistemic_plan_solver.hpp index 23427721..017977e1 100644 --- a/plansys2_epistemic_planner/include/plansys2_epistemic_planner/epistemic_plan_solver.hpp +++ b/plansys2_epistemic_planner/include/plansys2_epistemic_planner/epistemic_plan_solver.hpp @@ -174,6 +174,8 @@ class EpistemicPlanSolver : public PlanSolverBase std::string consistent_beliefs_parameter_name_; std::string temporal_parameter_name_; std::string max_concurrency_parameter_name_; + std::string temporal_estimate_parameter_name_; + std::string temporal_bound_growth_parameter_name_; /// The last goal the epistemic state published, as text. Latched by the /// subscription rather than fetched, so reading it costs nothing and cannot diff --git a/plansys2_epistemic_planner/src/epistemic_plan_solver.cpp b/plansys2_epistemic_planner/src/epistemic_plan_solver.cpp index 3ee7630c..7147deba 100644 --- a/plansys2_epistemic_planner/src/epistemic_plan_solver.cpp +++ b/plansys2_epistemic_planner/src/epistemic_plan_solver.cpp @@ -186,6 +186,8 @@ void EpistemicPlanSolver::configure( consistent_beliefs_parameter_name_ = plugin_name + ".consistent_beliefs"; temporal_parameter_name_ = plugin_name + ".temporal"; max_concurrency_parameter_name_ = plugin_name + ".max_concurrency"; + temporal_estimate_parameter_name_ = plugin_name + ".temporal_estimate"; + temporal_bound_growth_parameter_name_ = plugin_name + ".temporal_bound_growth"; const auto declare = [&](const std::string & name, const std::string & def) { if (!lc_node_->has_parameter(name)) { @@ -220,6 +222,13 @@ void EpistemicPlanSolver::configure( if (!lc_node_->has_parameter(max_concurrency_parameter_name_)) { lc_node_->declare_parameter(max_concurrency_parameter_name_, 3); } + // admissible: the least worst-case makespan. critical_path: deepen with + // max(h_adm, h_cp), an admissible policy found faster on most tasks but not + // necessarily the shortest. + declare(temporal_estimate_parameter_name_, "admissible"); + if (!lc_node_->has_parameter(temporal_bound_growth_parameter_name_)) { + lc_node_->declare_parameter(temporal_bound_growth_parameter_name_, 1.0); + } declare_epddl_parameters(lc_node_, epddl_parameter_names_); @@ -489,6 +498,19 @@ std::optional EpistemicPlanSolver::getPlan( std::max(1, lc_node_->get_parameter(max_concurrency_parameter_name_).as_int())); options.deadline = deadline; + const std::string estimate = parameter(temporal_estimate_parameter_name_); + if (estimate == "critical_path") { + options.estimate = temporal::SearchOptions::Estimate::CriticalPath; + } else if (estimate != "admissible") { + RCLCPP_ERROR( + lc_node_->get_logger(), + "[epistemic] temporal_estimate is '%s'; it must be 'admissible' or 'critical_path'", + estimate.c_str()); + return std::nullopt; + } + options.bound_growth = std::max( + 1.0, lc_node_->get_parameter(temporal_bound_growth_parameter_name_).as_double()); + temporal::SearchStats stats; const auto durations = durations_from_mapping(task, mapping); const auto policy = temporal::search_policy(task, durations, options, &stats); diff --git a/plansys2_epistemic_planner/test/temporal_plan_test.cpp b/plansys2_epistemic_planner/test/temporal_plan_test.cpp index cea256b5..5a282d76 100644 --- a/plansys2_epistemic_planner/test/temporal_plan_test.cpp +++ b/plansys2_epistemic_planner/test/temporal_plan_test.cpp @@ -140,3 +140,27 @@ TEST(TemporalPlan, OneAtATimeBranchesOnTheLook) } EXPECT_EQ(reports, 2u); } + +TEST(TemporalPlan, TheCriticalPathSearchReturnsAPlanNoShorterThanOptimal) +{ + // The satisficing search under max(h_adm, h_cp): valid, serialisable, and + // never shorter than the optimum, which it usually matches. + const auto task = load_task(task_path("robot-fleet-depot")); + const auto mapping = plansys2::ActionMapping::load(mapping_path("robot-fleet-depot")); + const auto durations = plansys2::durations_from_mapping(task, mapping); + + temporal::SearchOptions cp; + cp.estimate = temporal::SearchOptions::Estimate::CriticalPath; + const auto satisficing = temporal::search_policy(task, durations, cp); + const auto optimal = temporal::search_policy(task, durations); + ASSERT_TRUE(satisficing.has_value()); + ASSERT_TRUE(optimal.has_value()); + EXPECT_GE(satisficing->makespan, optimal->makespan - 1e-9); + + std::string why; + EXPECT_TRUE(temporal::validate_policy(task, durations, *satisficing, &why)) << why; + std::string error; + const auto plan = plansys2::to_temporal_plan(task, *satisficing, mapping, error); + ASSERT_TRUE(plan.has_value()) << error; + EXPECT_TRUE(plan->temporal); +} diff --git a/plansys2_tests/test_8/test_8.cpp b/plansys2_tests/test_8/test_8.cpp index 1efad41f..5920bd60 100644 --- a/plansys2_tests/test_8/test_8.cpp +++ b/plansys2_tests/test_8/test_8.cpp @@ -80,7 +80,7 @@ struct Mission /// cannot supply, since the task designates both a blocked and a clear world /// and neither is the model's to choose; the performer reports it on finish, /// the way a real one would report what its sensor returned. -Mission run_mission(const std::string & observed) +Mission run_mission(const std::string & observed, const std::string & estimate = "admissible") { Mission mission; @@ -190,6 +190,7 @@ Mission run_mission(const std::string & observed) planner_node->set_parameter(rclcpp::Parameter("EPISTEMIC.strategy", "aostar")); // Plan with the mapping's durations and overlap what commutes. planner_node->set_parameter(rclcpp::Parameter("EPISTEMIC.temporal", true)); + planner_node->set_parameter(rclcpp::Parameter("EPISTEMIC.temporal_estimate", estimate)); domain_node->trigger_transition(lifecycle_msgs::msg::Transition::TRANSITION_ACTIVATE); problem_node->trigger_transition(lifecycle_msgs::msg::Transition::TRANSITION_ACTIVATE); @@ -320,6 +321,18 @@ TEST(test_8, the_looks_overlap_whatever_the_corridor_is) EXPECT_TRUE(mission.ran("(inspect_corridor r2)")) << describe(mission); } +TEST(test_8, the_critical_path_search_plans_the_same_mission) +{ + // The satisficing search, chosen by parameter: on this mission it finds + // the same overlapping policy, and the mission runs the same way. + const auto mission = run_mission("e-inspect-blocked", "critical_path"); + ASSERT_TRUE(mission.temporal); + EXPECT_EQ(mission.result, plansys2_msgs::action::ExecutePlan::Result::SUCCESS) + << describe(mission); + EXPECT_TRUE(overlapped(mission, "(inspect_corridor r1)", "(inspect_corridor r2)")) + << describe(mission); +} + // Leave through _exit, so the DDS threads never outlive the process. // // rclcpp::shutdown() does not finalise the global context; that happens in