From b466e8c0b0c78e165517ae57c4d8f8fe2023c9d9 Mon Sep 17 00:00:00 2001 From: ClemensBuechner Date: Thu, 7 Sep 2023 14:45:52 +0200 Subject: [PATCH] Update terminology -- first draft. --- .../landmarks/landmark_cost_assignment.cc | 24 ++++++------- .../landmarks/landmark_cost_assignment.h | 34 +++++++++---------- .../landmark_cost_partitioning_heuristic.cc | 17 +++++----- .../landmark_cost_partitioning_heuristic.h | 6 ++-- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/search/landmarks/landmark_cost_assignment.cc b/src/search/landmarks/landmark_cost_assignment.cc index 822374cfd8..4be4b57b62 100644 --- a/src/search/landmarks/landmark_cost_assignment.cc +++ b/src/search/landmarks/landmark_cost_assignment.cc @@ -17,12 +17,12 @@ using namespace std; namespace landmarks { -LandmarkCostAssignment::LandmarkCostAssignment( +LandmarkCostPartitioningAlgorithm::LandmarkCostPartitioningAlgorithm( const vector &operator_costs, const LandmarkGraph &graph) : lm_graph(graph), operator_costs(operator_costs) { } -const set &LandmarkCostAssignment::get_achievers( +const set &LandmarkCostPartitioningAlgorithm::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), + : LandmarkCostPartitioningAlgorithm(operator_costs, graph), use_action_landmarks(use_action_landmarks) { } - -double LandmarkUniformSharedCostAssignment::cost_sharing_h_value( +double UniformCostPartitioningAlgorithm::compute_cost_partitioning( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) { vector achieved_lms_by_op(operator_costs.size(), 0); @@ -130,7 +128,8 @@ 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; + double shared_cost = + static_cast(operator_costs[op_id]) / num_achieved; min_cost = min(min_cost, shared_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), + : LandmarkCostPartitioningAlgorithm(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::compute_cost_partitioning( 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_assignment.h index bab5651b3b..33a4cd2d40 100644 --- a/src/search/landmarks/landmark_cost_assignment.h +++ b/src/search/landmarks/landmark_cost_assignment.h @@ -16,7 +16,7 @@ class LandmarkGraph; class LandmarkNode; class LandmarkStatusManager; -class LandmarkCostAssignment { +class LandmarkCostPartitioningAlgorithm { 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; + LandmarkCostPartitioningAlgorithm(const std::vector &operator_costs, + const LandmarkGraph &graph); + virtual ~LandmarkCostPartitioningAlgorithm() = default; - virtual double cost_sharing_h_value( + virtual double compute_cost_partitioning( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) = 0; }; -class LandmarkUniformSharedCostAssignment : public LandmarkCostAssignment { +class UniformCostPartitioningAlgorithm : public LandmarkCostPartitioningAlgorithm { 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 compute_cost_partitioning( const LandmarkStatusManager &lm_status_manager, const State &ancestor_state) override; }; -class LandmarkEfficientOptimalSharedCostAssignment : public LandmarkCostAssignment { +class OptimalCostPartitioningAlgorithm : public LandmarkCostPartitioningAlgorithm { 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 compute_cost_partitioning( 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..f923da58c7 100644 --- a/src/search/landmarks/landmark_cost_partitioning_heuristic.cc +++ b/src/search/landmarks/landmark_cost_partitioning_heuristic.cc @@ -18,13 +18,14 @@ namespace landmarks { LandmarkCostPartitioningHeuristic::LandmarkCostPartitioningHeuristic( const plugins::Options &opts) : LandmarkHeuristic(opts), - cost_partitioning_strategy(opts.get("cost_partitioning")) { + cost_partitioning_strategy( + opts.get("cost_partitioning")) { 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,16 +46,16 @@ 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( + 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( + cost_partitioning_algorithm = + utils::make_unique_ptr( task_properties::get_operator_costs(task_proxy), *lm_graph, opts.get("alm")); } else { @@ -66,7 +67,7 @@ int LandmarkCostPartitioningHeuristic::get_heuristic_value( const State &ancestor_state) { double epsilon = 0.01; - double h_val = lm_cost_assignment->cost_sharing_h_value( + double h_val = cost_partitioning_algorithm->compute_cost_partitioning( *lm_status_manager, ancestor_state); if (h_val == numeric_limits::max()) { return DEAD_END; diff --git a/src/search/landmarks/landmark_cost_partitioning_heuristic.h b/src/search/landmarks/landmark_cost_partitioning_heuristic.h index 30c81799ec..2d3b77ea68 100644 --- a/src/search/landmarks/landmark_cost_partitioning_heuristic.h +++ b/src/search/landmarks/landmark_cost_partitioning_heuristic.h @@ -4,7 +4,7 @@ #include "landmark_heuristic.h" namespace landmarks { -class LandmarkCostAssignment; +class LandmarkCostPartitioningAlgorithm; enum class CostPartitioningStrategy { OPTIMAL, @@ -13,10 +13,10 @@ enum class CostPartitioningStrategy { 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: