From 881a8872d5d8b8ef41b6bd7ca0dbaa8a1d5a031e Mon Sep 17 00:00:00 2001 From: ClemensBuechner Date: Sun, 8 Oct 2023 16:05:10 +0200 Subject: [PATCH] [issue1108] Update terminology of landmark cost partitioning. We update variable, function, class and file names. Nothing changes from a user perspective. --- src/search/CMakeLists.txt | 2 +- ... landmark_cost_partitioning_algorithms.cc} | 28 +++++++------- ...> landmark_cost_partitioning_algorithms.h} | 38 +++++++++---------- .../landmark_cost_partitioning_heuristic.cc | 33 ++++++++-------- .../landmark_cost_partitioning_heuristic.h | 9 ++--- 5 files changed, 55 insertions(+), 55 deletions(-) rename src/search/landmarks/{landmark_cost_assignment.cc => landmark_cost_partitioning_algorithms.cc} (91%) rename src/search/landmarks/{landmark_cost_assignment.h => landmark_cost_partitioning_algorithms.h} (51%) diff --git a/src/search/CMakeLists.txt b/src/search/CMakeLists.txt index 9d26b1c3f5..4188220dca 100644 --- a/src/search/CMakeLists.txt +++ b/src/search/CMakeLists.txt @@ -829,7 +829,7 @@ create_fast_downward_library( SOURCES landmarks/exploration landmarks/landmark - landmarks/landmark_cost_assignment + landmarks/landmark_cost_partitioning_algorithms landmarks/landmark_cost_partitioning_heuristic landmarks/landmark_factory landmarks/landmark_factory_h_m diff --git a/src/search/landmarks/landmark_cost_assignment.cc b/src/search/landmarks/landmark_cost_partitioning_algorithms.cc similarity index 91% rename from src/search/landmarks/landmark_cost_assignment.cc rename to src/search/landmarks/landmark_cost_partitioning_algorithms.cc index 822374cfd8..807346007c 100644 --- a/src/search/landmarks/landmark_cost_assignment.cc +++ b/src/search/landmarks/landmark_cost_partitioning_algorithms.cc @@ -1,4 +1,4 @@ -#include "landmark_cost_assignment.h" +#include "landmark_cost_partitioning_algorithms.h" #include "landmark.h" #include "landmark_graph.h" @@ -17,12 +17,12 @@ using namespace std; namespace landmarks { -LandmarkCostAssignment::LandmarkCostAssignment( +CostPartitioningAlgorithm::CostPartitioningAlgorithm( const vector &operator_costs, const LandmarkGraph &graph) : lm_graph(graph), operator_costs(operator_costs) { } -const set &LandmarkCostAssignment::get_achievers( +const set &CostPartitioningAlgorithm::get_achievers( const Landmark &landmark, bool past) const { // Return relevant achievers of the landmark according to its status. if (past) { @@ -33,16 +33,14 @@ const set &LandmarkCostAssignment::get_achievers( } -// Uniform cost partioning -LandmarkUniformSharedCostAssignment::LandmarkUniformSharedCostAssignment( +UniformCostPartitioningAlgorithm::UniformCostPartitioningAlgorithm( const vector &operator_costs, const LandmarkGraph &graph, bool use_action_landmarks) - : LandmarkCostAssignment(operator_costs, graph), + : CostPartitioningAlgorithm(operator_costs, graph), use_action_landmarks(use_action_landmarks) { } - -double LandmarkUniformSharedCostAssignment::cost_sharing_h_value( +double UniformCostPartitioningAlgorithm::get_cost_partitioned_heuristic_value( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) { vector achieved_lms_by_op(operator_costs.size(), 0); @@ -130,8 +128,9 @@ double LandmarkUniformSharedCostAssignment::cost_sharing_h_value( int num_achieved = achieved_lms_by_op[op_id]; assert(num_achieved >= 1); assert(utils::in_bounds(op_id, operator_costs)); - double shared_cost = static_cast(operator_costs[op_id]) / num_achieved; - min_cost = min(min_cost, shared_cost); + double partitioned_cost = + static_cast(operator_costs[op_id]) / num_achieved; + min_cost = min(min_cost, partitioned_cost); } h += min_cost; } @@ -139,15 +138,16 @@ double LandmarkUniformSharedCostAssignment::cost_sharing_h_value( return h; } -LandmarkEfficientOptimalSharedCostAssignment::LandmarkEfficientOptimalSharedCostAssignment( + +OptimalCostPartitioningAlgorithm::OptimalCostPartitioningAlgorithm( const vector &operator_costs, const LandmarkGraph &graph, lp::LPSolverType solver_type) - : LandmarkCostAssignment(operator_costs, graph), + : CostPartitioningAlgorithm(operator_costs, graph), lp_solver(solver_type), lp(build_initial_lp()) { } -lp::LinearProgram LandmarkEfficientOptimalSharedCostAssignment::build_initial_lp() { +lp::LinearProgram OptimalCostPartitioningAlgorithm::build_initial_lp() { /* The LP has one variable (column) per landmark and one inequality (row) per operator. */ int num_cols = lm_graph.get_num_landmarks(); @@ -175,7 +175,7 @@ lp::LinearProgram LandmarkEfficientOptimalSharedCostAssignment::build_initial_lp {}, lp_solver.get_infinity()); } -double LandmarkEfficientOptimalSharedCostAssignment::cost_sharing_h_value( +double OptimalCostPartitioningAlgorithm::get_cost_partitioned_heuristic_value( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) { /* TODO: We could also do the same thing with action landmarks we diff --git a/src/search/landmarks/landmark_cost_assignment.h b/src/search/landmarks/landmark_cost_partitioning_algorithms.h similarity index 51% rename from src/search/landmarks/landmark_cost_assignment.h rename to src/search/landmarks/landmark_cost_partitioning_algorithms.h index bab5651b3b..833ead053f 100644 --- a/src/search/landmarks/landmark_cost_assignment.h +++ b/src/search/landmarks/landmark_cost_partitioning_algorithms.h @@ -1,5 +1,5 @@ -#ifndef LANDMARKS_LANDMARK_COST_ASSIGNMENT_H -#define LANDMARKS_LANDMARK_COST_ASSIGNMENT_H +#ifndef LANDMARKS_LANDMARK_COST_PARTITIONING_ALGORITHMS_H +#define LANDMARKS_LANDMARK_COST_PARTITIONING_ALGORITHMS_H #include "../task_proxy.h" @@ -16,7 +16,7 @@ class LandmarkGraph; class LandmarkNode; class LandmarkStatusManager; -class LandmarkCostAssignment { +class CostPartitioningAlgorithm { protected: const LandmarkGraph &lm_graph; const std::vector operator_costs; @@ -24,30 +24,31 @@ class LandmarkCostAssignment { const std::set &get_achievers( const Landmark &landmark, bool past) const; public: - LandmarkCostAssignment(const std::vector &operator_costs, - const LandmarkGraph &graph); - virtual ~LandmarkCostAssignment() = default; + CostPartitioningAlgorithm(const std::vector &operator_costs, + const LandmarkGraph &graph); + virtual ~CostPartitioningAlgorithm() = default; - virtual double cost_sharing_h_value( + virtual double get_cost_partitioned_heuristic_value( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) = 0; }; -class LandmarkUniformSharedCostAssignment : public LandmarkCostAssignment { +class UniformCostPartitioningAlgorithm : public CostPartitioningAlgorithm { bool use_action_landmarks; public: - LandmarkUniformSharedCostAssignment(const std::vector &operator_costs, - const LandmarkGraph &graph, - bool use_action_landmarks); + UniformCostPartitioningAlgorithm(const std::vector &operator_costs, + const LandmarkGraph &graph, + bool use_action_landmarks); - virtual double cost_sharing_h_value( + virtual double get_cost_partitioned_heuristic_value( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) override; }; -class LandmarkEfficientOptimalSharedCostAssignment : public LandmarkCostAssignment { +class OptimalCostPartitioningAlgorithm : public CostPartitioningAlgorithm { lp::LPSolver lp_solver; - // We keep an additional copy of the constraints around to avoid some effort with recreating the vector (see issue443). + /* We keep an additional copy of the constraints around to avoid + some effort with recreating the vector (see issue443). */ std::vector lp_constraints; /* We keep the vectors for LP variables and constraints around instead of @@ -59,12 +60,11 @@ class LandmarkEfficientOptimalSharedCostAssignment : public LandmarkCostAssignme lp::LinearProgram build_initial_lp(); public: - LandmarkEfficientOptimalSharedCostAssignment( - const std::vector &operator_costs, - const LandmarkGraph &graph, - lp::LPSolverType solver_type); + OptimalCostPartitioningAlgorithm(const std::vector &operator_costs, + const LandmarkGraph &graph, + lp::LPSolverType solver_type); - virtual double cost_sharing_h_value( + virtual double get_cost_partitioned_heuristic_value( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) override; }; diff --git a/src/search/landmarks/landmark_cost_partitioning_heuristic.cc b/src/search/landmarks/landmark_cost_partitioning_heuristic.cc index 028608b577..ea3227f9de 100644 --- a/src/search/landmarks/landmark_cost_partitioning_heuristic.cc +++ b/src/search/landmarks/landmark_cost_partitioning_heuristic.cc @@ -1,6 +1,6 @@ #include "landmark_cost_partitioning_heuristic.h" -#include "landmark_cost_assignment.h" +#include "landmark_cost_partitioning_algorithms.h" #include "landmark_factory.h" #include "landmark_status_manager.h" @@ -17,14 +17,13 @@ using namespace std; namespace landmarks { LandmarkCostPartitioningHeuristic::LandmarkCostPartitioningHeuristic( const plugins::Options &opts) - : LandmarkHeuristic(opts), - cost_partitioning_strategy(opts.get("cost_partitioning")) { + : LandmarkHeuristic(opts) { if (log.is_at_least_normal()) { log << "Initializing landmark cost partitioning heuristic..." << endl; } check_unsupported_features(opts); initialize(opts); - set_cost_assignment(opts); + set_cost_partitioning_algorithm(opts); } void LandmarkCostPartitioningHeuristic::check_unsupported_features( @@ -45,20 +44,21 @@ void LandmarkCostPartitioningHeuristic::check_unsupported_features( } } -void LandmarkCostPartitioningHeuristic::set_cost_assignment( +void LandmarkCostPartitioningHeuristic::set_cost_partitioning_algorithm( const plugins::Options &opts) { - if (cost_partitioning_strategy == CostPartitioningStrategy::OPTIMAL) { - lm_cost_assignment = - utils::make_unique_ptr( + auto method = opts.get("cost_partitioning"); + if (method == CostPartitioningMethod::OPTIMAL) { + cost_partitioning_algorithm = + utils::make_unique_ptr( task_properties::get_operator_costs(task_proxy), *lm_graph, opts.get("lpsolver")); - } else if (cost_partitioning_strategy == CostPartitioningStrategy::UNIFORM) { - lm_cost_assignment = - utils::make_unique_ptr( + } else if (method == CostPartitioningMethod::UNIFORM) { + cost_partitioning_algorithm = + utils::make_unique_ptr( task_properties::get_operator_costs(task_proxy), *lm_graph, opts.get("alm")); } else { - ABORT("Unknown cost partitioning strategy"); + ABORT("Unknown cost partitioning method"); } } @@ -66,8 +66,9 @@ int LandmarkCostPartitioningHeuristic::get_heuristic_value( const State &ancestor_state) { double epsilon = 0.01; - double h_val = lm_cost_assignment->cost_sharing_h_value( - *lm_status_manager, ancestor_state); + double h_val = + cost_partitioning_algorithm->get_cost_partitioned_heuristic_value( + *lm_status_manager, ancestor_state); if (h_val == numeric_limits::max()) { return DEAD_END; } else { @@ -107,7 +108,7 @@ class LandmarkCostPartitioningHeuristicFeature : public plugins::TypedFeature( + add_option( "cost_partitioning", "strategy for partitioning operator costs among landmarks", "uniform"); @@ -155,7 +156,7 @@ class LandmarkCostPartitioningHeuristicFeature : public plugins::TypedFeature _plugin; -static plugins::TypedEnumPlugin _enum_plugin({ +static plugins::TypedEnumPlugin _enum_plugin({ {"optimal", "use optimal (LP-based) cost partitioning"}, {"uniform", diff --git a/src/search/landmarks/landmark_cost_partitioning_heuristic.h b/src/search/landmarks/landmark_cost_partitioning_heuristic.h index 30c81799ec..cd08edff54 100644 --- a/src/search/landmarks/landmark_cost_partitioning_heuristic.h +++ b/src/search/landmarks/landmark_cost_partitioning_heuristic.h @@ -4,19 +4,18 @@ #include "landmark_heuristic.h" namespace landmarks { -class LandmarkCostAssignment; +class CostPartitioningAlgorithm; -enum class CostPartitioningStrategy { +enum class CostPartitioningMethod { OPTIMAL, UNIFORM, }; class LandmarkCostPartitioningHeuristic : public LandmarkHeuristic { - const CostPartitioningStrategy cost_partitioning_strategy; - std::unique_ptr lm_cost_assignment; + std::unique_ptr cost_partitioning_algorithm; void check_unsupported_features(const plugins::Options &opts); - void set_cost_assignment(const plugins::Options &opts); + void set_cost_partitioning_algorithm(const plugins::Options &opts); int get_heuristic_value(const State &ancestor_state) override; public: