Skip to content

Commit

Permalink
Merge branch 'issue1082CleBue' into issue1082
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/search/merge_and_shrink/merge_tree_factory.cc
#	src/search/pdbs/pattern_collection_generator_multiple.cc
  • Loading branch information
SimonDold committed Feb 8, 2024
2 parents 52c9451 + ff1c0ce commit d2fae48
Show file tree
Hide file tree
Showing 24 changed files with 298 additions and 77 deletions.
39 changes: 36 additions & 3 deletions src/search/AAA_Mechanical_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ Change constuctor calls in other files.
If possible remove the plugins include as plugins::Options is not needed anymore.
[cf. src/search/cartesian_abstractions/utils.cc]

Mark in the list below what you updated:
Mark in the list below what you updated:

- ❌ not updated yet
- ✅ updated (or no need to update)
- ❓ not checked if it should be updated

```
search
<<<<<<< HEAD
├── ✅ abstract_task.cc
├── ✅ abstract_task.h
├── ✅ algorithms
Expand Down Expand Up @@ -99,7 +100,39 @@ search
│ ├── ✅ max_heuristic.h
│ ├── ✅ relaxation_heuristic.cc
│ └── ✅ relaxation_heuristic.h
├── ❌ landmarks
├── ✅ landmarks
│ ├── ✅ exploration.cc
│ ├── ✅ exploration.h
│ ├── ✅ landmark.cc
│ ├── ✅ landmark.h
│ ├── ✅ landmark_cost_partitioning_algorithms.cc
│ ├── ✅ landmark_cost_partitioning_algorithms.h
│ ├── ✅ landmark_cost_partitioning_heuristic.cc
│ ├── ✅ landmark_cost_partitioning_heuristic.h
│ ├── ✅ landmark_factory.cc
│ ├── ✅ landmark_factory.h
│ ├── ✅ landmark_factory_h_m.cc
│ ├── ✅ landmark_factory_h_m.h
│ ├── ✅ landmark_factory_merged.cc
│ ├── ✅ landmark_factory_merged.h
│ ├── ✅ landmark_factory_reasonable_orders_hps.cc
│ ├── ✅ landmark_factory_reasonable_orders_hps.h
│ ├── ✅ landmark_factory_relaxation.cc
│ ├── ✅ landmark_factory_relaxation.h
│ ├── ✅ landmark_factory_rpg_exhaust.cc
│ ├── ✅ landmark_factory_rpg_exhaust.h
│ ├── ✅ landmark_factory_rpg_sasp.cc
│ ├── ✅ landmark_factory_rpg_sasp.h
│ ├── ✅ landmark_factory_zhu_givan.cc
│ ├── ✅ landmark_factory_zhu_givan.h
│ ├── ✅ landmark_graph.cc
│ ├── ✅ landmark_graph.h
│ ├── ✅ landmark_heuristic.cc
│ ├── ✅ landmark_heuristic.h
│ ├── ✅ landmark_status_manager.cc
│ ├── ✅ landmark_status_manager.h
│ ├── ✅ landmark_sum_heuristic.cc
│ └── ✅ landmark_sum_heuristic.h
├── ❌ lp
├── ✅ merge_and_shrink
├── ✅ open_list_factory.cc
Expand Down Expand Up @@ -148,5 +181,5 @@ search
├── ✅ task_utils
└── ✅ utils
```
9 changes: 2 additions & 7 deletions src/search/cartesian_abstractions/utils_landmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ static FactPair get_fact(const Landmark &landmark) {
}

shared_ptr<LandmarkGraph> get_landmark_graph(const shared_ptr<AbstractTask> &task) {
plugins::Options hm_opts;
hm_opts.set<int>("m", 1);
hm_opts.set<bool>("only_causal_landmarks", false);
hm_opts.set<bool>("conjunctive_landmarks", false);
hm_opts.set<bool>("use_orders", true);
hm_opts.set<utils::Verbosity>("verbosity", utils::Verbosity::SILENT);
LandmarkFactoryHM lm_graph_factory(hm_opts);
LandmarkFactoryHM lm_graph_factory(
1, false, true, utils::Verbosity::SILENT);

return lm_graph_factory.compute_lm_graph(task);
}
Expand Down
42 changes: 36 additions & 6 deletions src/search/landmarks/landmark_cost_partitioning_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ using namespace std;

namespace landmarks {
LandmarkCostPartitioningHeuristic::LandmarkCostPartitioningHeuristic(
const plugins::Options &opts)
: LandmarkHeuristic(opts) {
const plugins::Options &options,
bool use_preferred_operators,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const string &description,
utils::Verbosity verbosity)
: LandmarkHeuristic(use_preferred_operators, transform, cache_estimates,
description, verbosity) {
if (log.is_at_least_normal()) {
log << "Initializing landmark cost partitioning heuristic..." << endl;
}
check_unsupported_features(opts);
initialize(opts);
set_cost_partitioning_algorithm(opts);
check_unsupported_features(options);
initialize(options);
set_cost_partitioning_algorithm(options);
}

void LandmarkCostPartitioningHeuristic::check_unsupported_features(
Expand Down Expand Up @@ -107,7 +113,16 @@ class LandmarkCostPartitioningHeuristicFeature : public plugins::TypedFeature<Ev
"IOS Press",
"2010"));

LandmarkHeuristic::add_options_to_feature(*this);
/*
TODO issue1082: We usually move the options of base classes behind the
options of specific implementations. In the case of landmark
heuristics, we decided to keep the common options at the front
because it feels more natural to specify the landmark factory before
the more specific arguments like the used LP solver in the case of
an optimal cost partitioning heuristic.
*/
add_landmark_heuristic_options_to_feature(
*this, "landmark_cost_partitioning");
add_option<CostPartitioningMethod>(
"cost_partitioning",
"strategy for partitioning operator costs among landmarks",
Expand Down Expand Up @@ -152,6 +167,21 @@ class LandmarkCostPartitioningHeuristicFeature : public plugins::TypedFeature<Ev
"no; see document note about consistency");
document_property("safe", "yes");
}

virtual shared_ptr<LandmarkCostPartitioningHeuristic> create_component(
const plugins::Options &options, const utils::Context &) const override {
plugins::Options lmcp_options =
collect_landmark_heuristic_options(options);
lmcp_options.set<CostPartitioningMethod>(
"cost_partitioning",
options.get<CostPartitioningMethod>("cost_partitioning"));
lmcp_options.set<bool>("alm", options.get<bool>("alm"));
lmcp_options.set<lp::LPSolverType>(
"lpsolver", options.get<lp::LPSolverType>("lpsolver"));
return plugins::make_shared_from_arg_tuples<LandmarkCostPartitioningHeuristic>(
lmcp_options,
get_landmark_heuristic_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<LandmarkCostPartitioningHeuristicFeature> _plugin;
Expand Down
16 changes: 15 additions & 1 deletion src/search/landmarks/landmark_cost_partitioning_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ class LandmarkCostPartitioningHeuristic : public LandmarkHeuristic {

int get_heuristic_value(const State &ancestor_state) override;
public:
explicit LandmarkCostPartitioningHeuristic(const plugins::Options &opts);
/*
TODO: issue1082 aimed to remove the options object from constructors.
This is not possible here because we need to wait with initializing the
landmark factory until the task is given (e.g., cost transformation).
Therefore, we can only extract the landmark factory from the options
after this happened, so we allow the landmark heuristics to keep a
(small) options object around for that purpose.
*/
LandmarkCostPartitioningHeuristic(
const plugins::Options &options,
bool use_preferred_operators,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const std::string &description,
utils::Verbosity verbosity);

virtual bool dead_ends_are_reliable() const override;
};
Expand Down
23 changes: 19 additions & 4 deletions src/search/landmarks/landmark_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
using namespace std;

namespace landmarks {
LandmarkFactory::LandmarkFactory(const plugins::Options &opts)
: log(utils::get_log_from_options(opts)), lm_graph(nullptr) {
LandmarkFactory::LandmarkFactory(utils::Verbosity verbosity)
: log(utils::get_log_for_verbosity(verbosity)), lm_graph(nullptr) {
}

/*
Expand Down Expand Up @@ -167,13 +167,22 @@ void add_landmark_factory_options_to_feature(plugins::Feature &feature) {
utils::add_log_options_to_feature(feature);
}

tuple<utils::Verbosity>
get_landmark_factory_arguments_from_options(const plugins::Options &options) {
return utils::get_log_arguments_from_options(options);
}

void add_use_orders_option_to_feature(plugins::Feature &feature) {
feature.add_option<bool>(
"use_orders",
"use orders between landmarks",
"true");
}

bool get_use_orders_arguments_from_options(const plugins::Options &options) {
return options.get<bool>("use_orders");
}

void add_only_causal_landmarks_option_to_feature(
plugins::Feature &feature) {
feature.add_option<bool>(
Expand All @@ -182,14 +191,20 @@ void add_only_causal_landmarks_option_to_feature(
"false");
}

bool get_only_causal_landmarks_arguments_from_options(
const plugins::Options &options) {
return options.get<bool>("only_causal_landmarks");
}

static class LandmarkFactoryCategoryPlugin : public plugins::TypedCategoryPlugin<LandmarkFactory> {
public:
LandmarkFactoryCategoryPlugin() : TypedCategoryPlugin("LandmarkFactory") {
document_synopsis(
"A landmark factory specification is either a newly created "
"instance or a landmark factory that has been defined previously. "
"This page describes how one can specify a new landmark factory instance. "
"For re-using landmark factories, see OptionSyntax#Landmark_Predefinitions.");
"This page describes how one can specify a new landmark factory "
"instance. For re-using landmark factories, see "
"OptionSyntax#Landmark_Predefinitions.");
allow_variable_binding();
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/search/landmarks/landmark_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LandmarkFactory {
}

protected:
explicit LandmarkFactory(const plugins::Options &opts);
explicit LandmarkFactory(utils::Verbosity verbosity);
mutable utils::LogProxy log;
std::shared_ptr<LandmarkGraph> lm_graph;
bool achievers_calculated = false;
Expand All @@ -71,8 +71,14 @@ class LandmarkFactory {
};

extern void add_landmark_factory_options_to_feature(plugins::Feature &feature);
extern std::tuple<utils::Verbosity> get_landmark_factory_arguments_from_options(
const plugins::Options &options);
extern void add_use_orders_option_to_feature(plugins::Feature &feature);
extern bool get_use_orders_arguments_from_options(
const plugins::Options &options);
extern void add_only_causal_landmarks_option_to_feature(plugins::Feature &feature);
extern bool get_only_causal_landmarks_arguments_from_options(
const plugins::Options &options);
}

#endif
23 changes: 17 additions & 6 deletions src/search/landmarks/landmark_factory_h_m.cc
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,13 @@ bool LandmarkFactoryHM::interesting(const VariablesProxy &variables,
variables[fact2.var].get_fact(fact2.value));
}

LandmarkFactoryHM::LandmarkFactoryHM(const plugins::Options &opts)
: LandmarkFactory(opts),
m_(opts.get<int>("m")),
conjunctive_landmarks(opts.get<bool>("conjunctive_landmarks")),
use_orders(opts.get<bool>("use_orders")) {
LandmarkFactoryHM::LandmarkFactoryHM(
int m, bool conjunctive_landmarks, bool use_orders,
utils::Verbosity verbosity)
: LandmarkFactory(verbosity),
m_(m),
conjunctive_landmarks(conjunctive_landmarks),
use_orders(use_orders) {
}

void LandmarkFactoryHM::initialize(const TaskProxy &task_proxy) {
Expand Down Expand Up @@ -1031,13 +1033,22 @@ class LandmarkFactoryHMFeature : public plugins::TypedFeature<LandmarkFactory, L
"conjunctive_landmarks",
"keep conjunctive landmarks",
"true");
add_landmark_factory_options_to_feature(*this);
add_use_orders_option_to_feature(*this);
add_landmark_factory_options_to_feature(*this);

document_language_support(
"conditional_effects",
"ignored, i.e. not supported");
}

virtual shared_ptr<LandmarkFactoryHM> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<LandmarkFactoryHM>(
options.get<int>("m"),
options.get<bool>("conjunctive_landmarks"),
get_use_orders_arguments_from_options(options),
get_landmark_factory_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<LandmarkFactoryHMFeature> _plugin;
Expand Down
3 changes: 2 additions & 1 deletion src/search/landmarks/landmark_factory_h_m.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class LandmarkFactoryHM : public LandmarkFactory {
void print_proposition(const VariablesProxy &variables, const FactPair &fluent) const;

public:
explicit LandmarkFactoryHM(const plugins::Options &opts);
LandmarkFactoryHM(int m, bool conjunctive_landmarks,
bool use_orders, utils::Verbosity verbosity);

virtual bool computes_reasonable_orders() const override;
virtual bool supports_conditional_effects() const override;
Expand Down
11 changes: 7 additions & 4 deletions src/search/landmarks/landmark_factory_merged.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ using utils::ExitCode;
namespace landmarks {
class LandmarkNode;

LandmarkFactoryMerged::LandmarkFactoryMerged(const plugins::Options &opts)
: LandmarkFactory(opts),
lm_factories(opts.get_list<shared_ptr<LandmarkFactory>>("lm_factories")) {
LandmarkFactoryMerged::LandmarkFactoryMerged(
vector<shared_ptr<LandmarkFactory>> &lm_factories,
utils::Verbosity verbosity)
: LandmarkFactory(verbosity), lm_factories(lm_factories) {
}

LandmarkNode *LandmarkFactoryMerged::get_matching_landmark(const Landmark &landmark) const {
Expand Down Expand Up @@ -176,7 +177,9 @@ class LandmarkFactoryMergedFeature : public plugins::TypedFeature<LandmarkFactor

virtual shared_ptr<LandmarkFactoryMerged> create_component(const plugins::Options &options, const utils::Context &context) const override {
plugins::verify_list_non_empty<shared_ptr<LandmarkFactory>>(context, options, "lm_factories");
return make_shared<LandmarkFactoryMerged>(options);
return plugins::make_shared_from_arg_tuples<LandmarkFactoryMerged>(
options.get_list<shared_ptr<LandmarkFactory>>("lm_factories"),
get_landmark_factory_arguments_from_options(options));
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/search/landmarks/landmark_factory_merged.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class LandmarkFactoryMerged : public LandmarkFactory {
void postprocess();
LandmarkNode *get_matching_landmark(const Landmark &landmark) const;
public:
explicit LandmarkFactoryMerged(const plugins::Options &opts);
LandmarkFactoryMerged(
std::vector<std::shared_ptr<LandmarkFactory>> &lm_factories,
utils::Verbosity verbosity);

virtual bool computes_reasonable_orders() const override;
virtual bool supports_conditional_effects() const override;
Expand Down
13 changes: 10 additions & 3 deletions src/search/landmarks/landmark_factory_reasonable_orders_hps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

using namespace std;
namespace landmarks {
LandmarkFactoryReasonableOrdersHPS::LandmarkFactoryReasonableOrdersHPS(const plugins::Options &opts)
: LandmarkFactory(opts),
lm_factory(opts.get<shared_ptr<LandmarkFactory>>("lm_factory")) {
LandmarkFactoryReasonableOrdersHPS::LandmarkFactoryReasonableOrdersHPS(
shared_ptr<LandmarkFactory> &lm_factory, utils::Verbosity verbosity)
: LandmarkFactory(verbosity), lm_factory(lm_factory) {
}

void LandmarkFactoryReasonableOrdersHPS::generate_landmarks(const shared_ptr<AbstractTask> &task) {
Expand Down Expand Up @@ -392,6 +392,13 @@ class LandmarkFactoryReasonableOrdersHPSFeature : public plugins::TypedFeature<L
"conditional_effects",
"supported if subcomponent supports them");
}

virtual shared_ptr<LandmarkFactoryReasonableOrdersHPS> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<LandmarkFactoryReasonableOrdersHPS>(
options.get<shared_ptr<LandmarkFactory>>("lm_factory"),
get_landmark_factory_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<LandmarkFactoryReasonableOrdersHPSFeature> _plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class LandmarkFactoryReasonableOrdersHPS : public LandmarkFactory {
const VariablesProxy &variables, const EffectsProxy &effects,
std::set<FactPair> &eff) const;
public:
LandmarkFactoryReasonableOrdersHPS(const plugins::Options &opts);
LandmarkFactoryReasonableOrdersHPS(
std::shared_ptr<LandmarkFactory> &lm_factory,
utils::Verbosity verbosity);

virtual bool computes_reasonable_orders() const override;
virtual bool supports_conditional_effects() const override;
Expand Down
4 changes: 2 additions & 2 deletions src/search/landmarks/landmark_factory_relaxation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using namespace std;

namespace landmarks {
LandmarkFactoryRelaxation::LandmarkFactoryRelaxation(const plugins::Options &opts)
: LandmarkFactory(opts) {
LandmarkFactoryRelaxation::LandmarkFactoryRelaxation(utils::Verbosity verbosity)
: LandmarkFactory(verbosity) {
}

void LandmarkFactoryRelaxation::generate_landmarks(const shared_ptr<AbstractTask> &task) {
Expand Down
2 changes: 1 addition & 1 deletion src/search/landmarks/landmark_factory_relaxation.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Exploration;

class LandmarkFactoryRelaxation : public LandmarkFactory {
protected:
explicit LandmarkFactoryRelaxation(const plugins::Options &opts);
explicit LandmarkFactoryRelaxation(utils::Verbosity verbosity);

/*
Test whether the relaxed planning task is solvable without
Expand Down
Loading

0 comments on commit d2fae48

Please sign in to comment.