Skip to content

Commit

Permalink
[issue1108] Update terminology of landmark cost partitioning.
Browse files Browse the repository at this point in the history
We update variable, function, class and file names. Nothing changes from a user
perspective.
  • Loading branch information
ClemensBuechner authored Oct 8, 2023
1 parent 8fe7ad9 commit 881a887
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "landmark_cost_assignment.h"
#include "landmark_cost_partitioning_algorithms.h"

#include "landmark.h"
#include "landmark_graph.h"
Expand All @@ -17,12 +17,12 @@
using namespace std;

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

const set<int> &LandmarkCostAssignment::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 @@ -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),
: 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<int> achieved_lms_by_op(operator_costs.size(), 0);
Expand Down Expand Up @@ -130,24 +128,26 @@ 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;
min_cost = min(min_cost, shared_cost);
double partitioned_cost =
static_cast<double>(operator_costs[op_id]) / num_achieved;
min_cost = min(min_cost, partitioned_cost);
}
h += min_cost;
}

return h;
}

LandmarkEfficientOptimalSharedCostAssignment::LandmarkEfficientOptimalSharedCostAssignment(

OptimalCostPartitioningAlgorithm::OptimalCostPartitioningAlgorithm(
const vector<int> &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();
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::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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -16,38 +16,39 @@ class LandmarkGraph;
class LandmarkNode;
class LandmarkStatusManager;

class LandmarkCostAssignment {
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:
LandmarkCostAssignment(const std::vector<int> &operator_costs,
const LandmarkGraph &graph);
virtual ~LandmarkCostAssignment() = default;
CostPartitioningAlgorithm(const std::vector<int> &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<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 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::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 get_cost_partitioned_heuristic_value(
const LandmarkStatusManager &lm_status_manager,
const State &ancestor_state) override;
};
Expand Down
33 changes: 17 additions & 16 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.cc
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -17,14 +17,13 @@ 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;
}
check_unsupported_features(opts);
initialize(opts);
set_cost_assignment(opts);
set_cost_partitioning_algorithm(opts);
}

void LandmarkCostPartitioningHeuristic::check_unsupported_features(
Expand All @@ -45,29 +44,31 @@ 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>(
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) {
lm_cost_assignment =
utils::make_unique_ptr<LandmarkUniformSharedCostAssignment>(
} else if (method == CostPartitioningMethod::UNIFORM) {
cost_partitioning_algorithm =
utils::make_unique_ptr<UniformCostPartitioningAlgorithm>(
task_properties::get_operator_costs(task_proxy),
*lm_graph, opts.get<bool>("alm"));
} else {
ABORT("Unknown cost partitioning strategy");
ABORT("Unknown cost partitioning method");
}
}

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<double>::max()) {
return DEAD_END;
} else {
Expand Down Expand Up @@ -107,7 +108,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 @@ -155,7 +156,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
9 changes: 4 additions & 5 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<LandmarkCostAssignment> lm_cost_assignment;
std::unique_ptr<CostPartitioningAlgorithm> 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 881a887

Please sign in to comment.