Skip to content

Commit

Permalink
update pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianPommerening committed Feb 8, 2024
1 parent ea73ee6 commit 4f13d8a
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 31 deletions.
23 changes: 18 additions & 5 deletions src/search/pruning/limited_pruning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
using namespace std;

namespace limited_pruning {
LimitedPruning::LimitedPruning(const plugins::Options &opts)
: PruningMethod(opts),
pruning_method(opts.get<shared_ptr<PruningMethod>>("pruning")),
min_required_pruning_ratio(opts.get<double>("min_required_pruning_ratio")),
LimitedPruning::LimitedPruning(
const shared_ptr<PruningMethod> &pruning,
double min_required_pruning_ratio,
int expansions_before_checking_pruning_ratio,
utils::Verbosity verbosity)
: PruningMethod(verbosity),
pruning_method(pruning),
min_required_pruning_ratio(min_required_pruning_ratio),
num_expansions_before_checking_pruning_ratio(
opts.get<int>("expansions_before_checking_pruning_ratio")),
expansions_before_checking_pruning_ratio),
num_pruning_calls(0),
is_pruning_disabled(false) {
}
Expand Down Expand Up @@ -83,6 +87,15 @@ class LimitedPruningFeature : public plugins::TypedFeature<PruningMethod, Limite
"min_required_pruning_ratio=0.2,expansions_before_checking_pruning_ratio=1000)\n}}}\n"
"in an eager search such as astar.");
}

virtual shared_ptr<LimitedPruning> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<LimitedPruning>(
options.get<shared_ptr<PruningMethod>>("pruning"),
options.get<double>("min_required_pruning_ratio"),
options.get<int>("expansions_before_checking_pruning_ratio"),
get_pruning_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<LimitedPruningFeature> _plugin;
Expand Down
5 changes: 4 additions & 1 deletion src/search/pruning/limited_pruning.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class LimitedPruning : public PruningMethod {
virtual void prune(
const State &state, std::vector<OperatorID> &op_ids) override;
public:
explicit LimitedPruning(const plugins::Options &opts);
explicit LimitedPruning(const std::shared_ptr<PruningMethod> &pruning,
double min_required_pruning_ratio,
int expansions_before_checking_pruning_ratio,
utils::Verbosity verbosity);
virtual void initialize(const std::shared_ptr<AbstractTask> &) override;
};
}
Expand Down
10 changes: 8 additions & 2 deletions src/search/pruning/null_pruning_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using namespace std;

namespace null_pruning_method {
NullPruningMethod::NullPruningMethod(const plugins::Options &opts)
: PruningMethod(opts) {
NullPruningMethod::NullPruningMethod(utils::Verbosity verbosity)
: PruningMethod(verbosity) {
}

void NullPruningMethod::initialize(const shared_ptr<AbstractTask> &task) {
Expand All @@ -26,6 +26,12 @@ class NullPruningMethodFeature : public plugins::TypedFeature<PruningMethod, Nul

add_pruning_options_to_feature(*this);
}

virtual shared_ptr<NullPruningMethod> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<NullPruningMethod>(
get_pruning_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<NullPruningMethodFeature> _plugin;
Expand Down
2 changes: 1 addition & 1 deletion src/search/pruning/null_pruning_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class NullPruningMethod : public PruningMethod {
virtual void prune(
const State &, std::vector<OperatorID> &) override {}
public:
explicit NullPruningMethod(const plugins::Options &opts);
explicit NullPruningMethod(utils::Verbosity verbosity);
virtual void initialize(const std::shared_ptr<AbstractTask> &) override;
virtual void print_statistics() const override {}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/pruning/stubborn_sets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using namespace std;

namespace stubborn_sets {
StubbornSets::StubbornSets(const plugins::Options &opts)
: PruningMethod(opts),
StubbornSets::StubbornSets(utils::Verbosity verbosity)
: PruningMethod(verbosity),
num_operators(-1) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/pruning/stubborn_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class StubbornSets : public PruningMethod {

virtual void compute_stubborn_set(const State &state) = 0;
public:
explicit StubbornSets(const plugins::Options &opts);
explicit StubbornSets(utils::Verbosity verbosity);
virtual void initialize(const std::shared_ptr<AbstractTask> &task) override;
};

Expand Down
4 changes: 2 additions & 2 deletions src/search/pruning/stubborn_sets_action_centric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ static bool contain_conflicting_fact(const vector<FactPair> &facts1,
return false;
}

StubbornSetsActionCentric::StubbornSetsActionCentric(const plugins::Options &opts)
: StubbornSets(opts) {
StubbornSetsActionCentric::StubbornSetsActionCentric(utils::Verbosity verbosity)
: StubbornSets(verbosity) {
}

void StubbornSetsActionCentric::compute_stubborn_set(const State &state) {
Expand Down
2 changes: 1 addition & 1 deletion src/search/pruning/stubborn_sets_action_centric.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class StubbornSetsActionCentric : public stubborn_sets::StubbornSets {
virtual void handle_stubborn_operator(const State &state, int op_no) = 0;
virtual void compute_stubborn_set(const State &state) override;
protected:
explicit StubbornSetsActionCentric(const plugins::Options &opts);
explicit StubbornSetsActionCentric(utils::Verbosity verbosity);
bool can_disable(int op1_no, int op2_no) const;
bool can_conflict(int op1_no, int op2_no) const;

Expand Down
18 changes: 14 additions & 4 deletions src/search/pruning/stubborn_sets_atom_centric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
using namespace std;

namespace stubborn_sets_atom_centric {
StubbornSetsAtomCentric::StubbornSetsAtomCentric(const plugins::Options &opts)
: StubbornSets(opts),
use_sibling_shortcut(opts.get<bool>("use_sibling_shortcut")),
atom_selection_strategy(opts.get<AtomSelectionStrategy>("atom_selection_strategy")) {
StubbornSetsAtomCentric::StubbornSetsAtomCentric(
bool use_sibling_shortcut, AtomSelectionStrategy atom_selection_strategy,
utils::Verbosity verbosity)
: StubbornSets(verbosity),
use_sibling_shortcut(use_sibling_shortcut),
atom_selection_strategy(atom_selection_strategy) {
}

void StubbornSetsAtomCentric::initialize(const shared_ptr<AbstractTask> &task) {
Expand Down Expand Up @@ -275,6 +277,14 @@ class StubbornSetsAtomCentricFeature : public plugins::TypedFeature<PruningMetho
"quick_skip");
add_pruning_options_to_feature(*this);
}

virtual shared_ptr<StubbornSetsAtomCentric> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<StubbornSetsAtomCentric>(
options.get<bool>("use_sibling_shortcut"),
options.get<AtomSelectionStrategy>("atom_selection_strategy"),
get_pruning_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<StubbornSetsAtomCentricFeature> _plugin;
Expand Down
3 changes: 2 additions & 1 deletion src/search/pruning/stubborn_sets_atom_centric.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class StubbornSetsAtomCentric : public stubborn_sets::StubbornSets {
void handle_stubborn_operator(const State &state, int op);
virtual void compute_stubborn_set(const State &state) override;
public:
explicit StubbornSetsAtomCentric(const plugins::Options &opts);
explicit StubbornSetsAtomCentric(bool use_sibling_shortcut,
AtomSelectionStrategy atom_selection_strategy, utils::Verbosity verbosity);
virtual void initialize(const std::shared_ptr<AbstractTask> &task) override;
};
}
Expand Down
10 changes: 8 additions & 2 deletions src/search/pruning/stubborn_sets_ec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ static void get_conflicting_vars(const vector<FactPair> &facts1,
}
}

StubbornSetsEC::StubbornSetsEC(const plugins::Options &opts)
: StubbornSetsActionCentric(opts) {
StubbornSetsEC::StubbornSetsEC(utils::Verbosity verbosity)
: StubbornSetsActionCentric(verbosity) {
}

void StubbornSetsEC::initialize(const shared_ptr<AbstractTask> &task) {
Expand Down Expand Up @@ -346,6 +346,12 @@ class StubbornSetsECFeature : public plugins::TypedFeature<PruningMethod, Stubbo
"2013"));
add_pruning_options_to_feature(*this);
}

virtual shared_ptr<StubbornSetsEC> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<StubbornSetsEC>(
get_pruning_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<StubbornSetsECFeature> _plugin;
Expand Down
2 changes: 1 addition & 1 deletion src/search/pruning/stubborn_sets_ec.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StubbornSetsEC : public stubborn_sets::StubbornSetsActionCentric {
virtual void initialize_stubborn_set(const State &state) override;
virtual void handle_stubborn_operator(const State &state, int op_no) override;
public:
explicit StubbornSetsEC(const plugins::Options &opts);
explicit StubbornSetsEC(utils::Verbosity verbosity);
virtual void initialize(const std::shared_ptr<AbstractTask> &task) override;
};
}
Expand Down
10 changes: 8 additions & 2 deletions src/search/pruning/stubborn_sets_simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using namespace std;

namespace stubborn_sets_simple {
StubbornSetsSimple::StubbornSetsSimple(const plugins::Options &opts)
: StubbornSetsActionCentric(opts) {
StubbornSetsSimple::StubbornSetsSimple(utils::Verbosity verbosity)
: StubbornSetsActionCentric(verbosity) {
}

void StubbornSetsSimple::initialize(const shared_ptr<AbstractTask> &task) {
Expand Down Expand Up @@ -104,6 +104,12 @@ class StubbornSetsSimpleFeature : public plugins::TypedFeature<PruningMethod, St
"2014"));
add_pruning_options_to_feature(*this);
}

virtual shared_ptr<StubbornSetsSimple> create_component(
const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<StubbornSetsSimple>(
get_pruning_arguments_from_options(options));
}
};

static plugins::FeaturePlugin<StubbornSetsSimpleFeature> _plugin;
Expand Down
2 changes: 1 addition & 1 deletion src/search/pruning/stubborn_sets_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class StubbornSetsSimple : public stubborn_sets::StubbornSetsActionCentric {
virtual void handle_stubborn_operator(const State &state,
int op_no) override;
public:
explicit StubbornSetsSimple(const plugins::Options &opts);
explicit StubbornSetsSimple(utils::Verbosity verbosity);
virtual void initialize(const std::shared_ptr<AbstractTask> &task) override;
};
}
Expand Down
8 changes: 6 additions & 2 deletions src/search/pruning_method.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

using namespace std;

PruningMethod::PruningMethod(const plugins::Options &opts)
PruningMethod::PruningMethod(utils::Verbosity verbosity)
: timer(false),
log(utils::get_log_from_options(opts)),
log(utils::get_log_for_verbosity(verbosity)),
task(nullptr) {
}

Expand Down Expand Up @@ -69,6 +69,10 @@ void add_pruning_options_to_feature(plugins::Feature &feature) {
"normal verbosity for running experiments.");
}

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

static class PruningMethodCategoryPlugin : public plugins::TypedCategoryPlugin<PruningMethod> {
public:
PruningMethodCategoryPlugin() : TypedCategoryPlugin("PruningMethod") {
Expand Down
4 changes: 3 additions & 1 deletion src/search/pruning_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ class PruningMethod {
long num_successors_before_pruning;
long num_successors_after_pruning;
public:
explicit PruningMethod(const plugins::Options &opts);
explicit PruningMethod(utils::Verbosity verbosity);
virtual ~PruningMethod() = default;
virtual void initialize(const std::shared_ptr<AbstractTask> &task);
void prune_operators(const State &state, std::vector<OperatorID> &op_ids);
virtual void print_statistics() const;
};

extern void add_pruning_options_to_feature(plugins::Feature &feature);
extern std::tuple<utils::Verbosity> get_pruning_arguments_from_options(
const plugins::Options &opts);

#endif
3 changes: 1 addition & 2 deletions src/search/utils/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ void add_log_options_to_feature(plugins::Feature &feature) {
}

tuple<Verbosity> get_log_arguments_from_options(const plugins::Options &opts) {
auto own_tuple = make_tuple<Verbosity>(opts.get<Verbosity>("verbosity"));
return tuple<Verbosity>(own_tuple);
return make_tuple<Verbosity>(opts.get<Verbosity>("verbosity"));
}

LogProxy get_log_for_verbosity(const Verbosity &verbosity) {
Expand Down

0 comments on commit 4f13d8a

Please sign in to comment.