Skip to content

Commit

Permalink
Apply review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensBuechner committed Sep 7, 2023
1 parent b466e8c commit 69a875f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
16 changes: 8 additions & 8 deletions src/search/landmarks/landmark_cost_assignment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
using namespace std;

namespace landmarks {
LandmarkCostPartitioningAlgorithm::LandmarkCostPartitioningAlgorithm(
CostPartitioningAlgorithm::CostPartitioningAlgorithm(
const vector<int> &operator_costs, const LandmarkGraph &graph)
: lm_graph(graph), operator_costs(operator_costs) {
}

const set<int> &LandmarkCostPartitioningAlgorithm::get_achievers(
const set<int> &CostPartitioningAlgorithm::get_achievers(
const Landmark &landmark, bool past) const {
// Return relevant achievers of the landmark according to its status.
if (past) {
Expand All @@ -36,11 +36,11 @@ const set<int> &LandmarkCostPartitioningAlgorithm::get_achievers(
UniformCostPartitioningAlgorithm::UniformCostPartitioningAlgorithm(
const vector<int> &operator_costs, const LandmarkGraph &graph,
bool use_action_landmarks)
: LandmarkCostPartitioningAlgorithm(operator_costs, graph),
: CostPartitioningAlgorithm(operator_costs, graph),
use_action_landmarks(use_action_landmarks) {
}

double UniformCostPartitioningAlgorithm::compute_cost_partitioning(
double UniformCostPartitioningAlgorithm::compute_cost_partitioned_h_value(
const LandmarkStatusManager &lm_status_manager,
const State &ancestor_state) {
vector<int> achieved_lms_by_op(operator_costs.size(), 0);
Expand Down Expand Up @@ -128,9 +128,9 @@ double UniformCostPartitioningAlgorithm::compute_cost_partitioning(
int num_achieved = achieved_lms_by_op[op_id];
assert(num_achieved >= 1);
assert(utils::in_bounds(op_id, operator_costs));
double shared_cost =
double partitioned_cost =
static_cast<double>(operator_costs[op_id]) / num_achieved;
min_cost = min(min_cost, shared_cost);
min_cost = min(min_cost, partitioned_cost);
}
h += min_cost;
}
Expand All @@ -142,7 +142,7 @@ double UniformCostPartitioningAlgorithm::compute_cost_partitioning(
OptimalCostPartitioningAlgorithm::OptimalCostPartitioningAlgorithm(
const vector<int> &operator_costs, const LandmarkGraph &graph,
lp::LPSolverType solver_type)
: LandmarkCostPartitioningAlgorithm(operator_costs, graph),
: CostPartitioningAlgorithm(operator_costs, graph),
lp_solver(solver_type),
lp(build_initial_lp()) {
}
Expand Down Expand Up @@ -175,7 +175,7 @@ lp::LinearProgram OptimalCostPartitioningAlgorithm::build_initial_lp() {
{}, lp_solver.get_infinity());
}

double OptimalCostPartitioningAlgorithm::compute_cost_partitioning(
double OptimalCostPartitioningAlgorithm::compute_cost_partitioned_h_value(
const LandmarkStatusManager &lm_status_manager,
const State &ancestor_state) {
/* TODO: We could also do the same thing with action landmarks we
Expand Down
18 changes: 9 additions & 9 deletions src/search/landmarks/landmark_cost_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ class LandmarkGraph;
class LandmarkNode;
class LandmarkStatusManager;

class LandmarkCostPartitioningAlgorithm {
class CostPartitioningAlgorithm {
protected:
const LandmarkGraph &lm_graph;
const std::vector<int> operator_costs;

const std::set<int> &get_achievers(
const Landmark &landmark, bool past) const;
public:
LandmarkCostPartitioningAlgorithm(const std::vector<int> &operator_costs,
const LandmarkGraph &graph);
virtual ~LandmarkCostPartitioningAlgorithm() = default;
CostPartitioningAlgorithm(const std::vector<int> &operator_costs,
const LandmarkGraph &graph);
virtual ~CostPartitioningAlgorithm() = default;

virtual double compute_cost_partitioning(
virtual double compute_cost_partitioned_h_value(
const LandmarkStatusManager &lm_status_manager,
const State &ancestor_state) = 0;
};

class UniformCostPartitioningAlgorithm : public LandmarkCostPartitioningAlgorithm {
class UniformCostPartitioningAlgorithm : public CostPartitioningAlgorithm {
bool use_action_landmarks;
public:
UniformCostPartitioningAlgorithm(const std::vector<int> &operator_costs,
const LandmarkGraph &graph,
bool use_action_landmarks);

virtual double compute_cost_partitioning(
virtual double compute_cost_partitioned_h_value(
const LandmarkStatusManager &lm_status_manager,
const State &ancestor_state) override;
};

class OptimalCostPartitioningAlgorithm : public LandmarkCostPartitioningAlgorithm {
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). */
Expand All @@ -64,7 +64,7 @@ class OptimalCostPartitioningAlgorithm : public LandmarkCostPartitioningAlgorith
const LandmarkGraph &graph,
lp::LPSolverType solver_type);

virtual double compute_cost_partitioning(
virtual double compute_cost_partitioned_h_value(
const LandmarkStatusManager &lm_status_manager,
const State &ancestor_state) override;
};
Expand Down
15 changes: 7 additions & 8 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ using namespace std;
namespace landmarks {
LandmarkCostPartitioningHeuristic::LandmarkCostPartitioningHeuristic(
const plugins::Options &opts)
: LandmarkHeuristic(opts),
cost_partitioning_strategy(
opts.get<CostPartitioningStrategy>("cost_partitioning")) {
: LandmarkHeuristic(opts) {
if (log.is_at_least_normal()) {
log << "Initializing landmark cost partitioning heuristic..." << endl;
}
Expand Down Expand Up @@ -48,12 +46,13 @@ void LandmarkCostPartitioningHeuristic::check_unsupported_features(

void LandmarkCostPartitioningHeuristic::set_cost_partitioning_algorithm(
const plugins::Options &opts) {
if (cost_partitioning_strategy == CostPartitioningStrategy::OPTIMAL) {
auto method = opts.get<CostPartitioningMethod>("cost_partitioning");
if (method == CostPartitioningMethod::OPTIMAL) {
cost_partitioning_algorithm =
utils::make_unique_ptr<OptimalCostPartitioningAlgorithm>(
task_properties::get_operator_costs(task_proxy),
*lm_graph, opts.get<lp::LPSolverType>("lpsolver"));
} else if (cost_partitioning_strategy == CostPartitioningStrategy::UNIFORM) {
} else if (method == CostPartitioningMethod::UNIFORM) {
cost_partitioning_algorithm =
utils::make_unique_ptr<UniformCostPartitioningAlgorithm>(
task_properties::get_operator_costs(task_proxy),
Expand All @@ -67,7 +66,7 @@ int LandmarkCostPartitioningHeuristic::get_heuristic_value(
const State &ancestor_state) {
double epsilon = 0.01;

double h_val = cost_partitioning_algorithm->compute_cost_partitioning(
double h_val = cost_partitioning_algorithm->compute_cost_partitioned_h_value(
*lm_status_manager, ancestor_state);
if (h_val == numeric_limits<double>::max()) {
return DEAD_END;
Expand Down Expand Up @@ -108,7 +107,7 @@ class LandmarkCostPartitioningHeuristicFeature : public plugins::TypedFeature<Ev
"2010"));

LandmarkHeuristic::add_options_to_feature(*this);
add_option<CostPartitioningStrategy>(
add_option<CostPartitioningMethod>(
"cost_partitioning",
"strategy for partitioning operator costs among landmarks",
"uniform");
Expand Down Expand Up @@ -156,7 +155,7 @@ class LandmarkCostPartitioningHeuristicFeature : public plugins::TypedFeature<Ev

static plugins::FeaturePlugin<LandmarkCostPartitioningHeuristicFeature> _plugin;

static plugins::TypedEnumPlugin<CostPartitioningStrategy> _enum_plugin({
static plugins::TypedEnumPlugin<CostPartitioningMethod> _enum_plugin({
{"optimal",
"use optimal (LP-based) cost partitioning"},
{"uniform",
Expand Down
7 changes: 3 additions & 4 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
#include "landmark_heuristic.h"

namespace landmarks {
class LandmarkCostPartitioningAlgorithm;
class CostPartitioningAlgorithm;

enum class CostPartitioningStrategy {
enum class CostPartitioningMethod {
OPTIMAL,
UNIFORM,
};

class LandmarkCostPartitioningHeuristic : public LandmarkHeuristic {
const CostPartitioningStrategy cost_partitioning_strategy;
std::unique_ptr<LandmarkCostPartitioningAlgorithm> cost_partitioning_algorithm;
std::unique_ptr<CostPartitioningAlgorithm> cost_partitioning_algorithm;

void check_unsupported_features(const plugins::Options &opts);
void set_cost_partitioning_algorithm(const plugins::Options &opts);
Expand Down

0 comments on commit 69a875f

Please sign in to comment.