Skip to content

Commit

Permalink
Update terminology -- first draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
ClemensBuechner committed Sep 7, 2023
1 parent 791125c commit b466e8c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
24 changes: 12 additions & 12 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 {
LandmarkCostAssignment::LandmarkCostAssignment(
LandmarkCostPartitioningAlgorithm::LandmarkCostPartitioningAlgorithm(
const vector<int> &operator_costs, const LandmarkGraph &graph)
: lm_graph(graph), operator_costs(operator_costs) {
}

const set<int> &LandmarkCostAssignment::get_achievers(
const set<int> &LandmarkCostPartitioningAlgorithm::get_achievers(
const Landmark &landmark, bool past) const {
// Return relevant achievers of the landmark according to its status.
if (past) {
Expand All @@ -33,16 +33,14 @@ const set<int> &LandmarkCostAssignment::get_achievers(
}


// Uniform cost partioning
LandmarkUniformSharedCostAssignment::LandmarkUniformSharedCostAssignment(
UniformCostPartitioningAlgorithm::UniformCostPartitioningAlgorithm(
const vector<int> &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<int> achieved_lms_by_op(operator_costs.size(), 0);
Expand Down Expand Up @@ -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<double>(operator_costs[op_id]) / num_achieved;
double shared_cost =
static_cast<double>(operator_costs[op_id]) / num_achieved;
min_cost = min(min_cost, shared_cost);
}
h += min_cost;
Expand All @@ -139,15 +138,16 @@ double LandmarkUniformSharedCostAssignment::cost_sharing_h_value(
return h;
}

LandmarkEfficientOptimalSharedCostAssignment::LandmarkEfficientOptimalSharedCostAssignment(

OptimalCostPartitioningAlgorithm::OptimalCostPartitioningAlgorithm(
const vector<int> &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();
Expand Down Expand Up @@ -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
Expand Down
34 changes: 17 additions & 17 deletions src/search/landmarks/landmark_cost_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,39 @@ class LandmarkGraph;
class LandmarkNode;
class LandmarkStatusManager;

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

const std::set<int> &get_achievers(
const Landmark &landmark, bool past) const;
public:
LandmarkCostAssignment(const std::vector<int> &operator_costs,
const LandmarkGraph &graph);
virtual ~LandmarkCostAssignment() = default;
LandmarkCostPartitioningAlgorithm(const std::vector<int> &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<int> &operator_costs,
const LandmarkGraph &graph,
bool use_action_landmarks);
UniformCostPartitioningAlgorithm(const std::vector<int> &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::LPConstraint> lp_constraints;
/*
We keep the vectors for LP variables and constraints around instead of
Expand All @@ -59,12 +60,11 @@ class LandmarkEfficientOptimalSharedCostAssignment : public LandmarkCostAssignme

lp::LinearProgram build_initial_lp();
public:
LandmarkEfficientOptimalSharedCostAssignment(
const std::vector<int> &operator_costs,
const LandmarkGraph &graph,
lp::LPSolverType solver_type);
OptimalCostPartitioningAlgorithm(const std::vector<int> &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;
};
Expand Down
17 changes: 9 additions & 8 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ namespace landmarks {
LandmarkCostPartitioningHeuristic::LandmarkCostPartitioningHeuristic(
const plugins::Options &opts)
: LandmarkHeuristic(opts),
cost_partitioning_strategy(opts.get<CostPartitioningStrategy>("cost_partitioning")) {
cost_partitioning_strategy(
opts.get<CostPartitioningStrategy>("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(
Expand All @@ -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<LandmarkEfficientOptimalSharedCostAssignment>(
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) {
lm_cost_assignment =
utils::make_unique_ptr<LandmarkUniformSharedCostAssignment>(
cost_partitioning_algorithm =
utils::make_unique_ptr<UniformCostPartitioningAlgorithm>(
task_properties::get_operator_costs(task_proxy),
*lm_graph, opts.get<bool>("alm"));
} else {
Expand All @@ -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<double>::max()) {
return DEAD_END;
Expand Down
6 changes: 3 additions & 3 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "landmark_heuristic.h"

namespace landmarks {
class LandmarkCostAssignment;
class LandmarkCostPartitioningAlgorithm;

enum class CostPartitioningStrategy {
OPTIMAL,
Expand All @@ -13,10 +13,10 @@ enum class CostPartitioningStrategy {

class LandmarkCostPartitioningHeuristic : public LandmarkHeuristic {
const CostPartitioningStrategy cost_partitioning_strategy;
std::unique_ptr<LandmarkCostAssignment> lm_cost_assignment;
std::unique_ptr<LandmarkCostPartitioningAlgorithm> 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:
Expand Down

0 comments on commit b466e8c

Please sign in to comment.