From b49e3ae891546a24626c580e1d085e83339a0c9e Mon Sep 17 00:00:00 2001 From: Florian Pommerening Date: Fri, 2 Feb 2024 23:06:20 +0100 Subject: [PATCH] change constructors in pdb code --- src/search/pdbs/canonical_pdbs_heuristic.cc | 36 ++++++--- src/search/pdbs/canonical_pdbs_heuristic.h | 12 ++- .../pattern_collection_generator_combo.cc | 21 ++++- .../pdbs/pattern_collection_generator_combo.h | 10 ++- ...ern_collection_generator_disjoint_cegar.cc | 35 +++++++-- ...tern_collection_generator_disjoint_cegar.h | 9 ++- .../pattern_collection_generator_genetic.cc | 39 +++++++--- .../pattern_collection_generator_genetic.h | 10 ++- ...ttern_collection_generator_hillclimbing.cc | 78 ++++++++++++------- ...attern_collection_generator_hillclimbing.h | 11 ++- .../pattern_collection_generator_manual.cc | 20 ++++- .../pattern_collection_generator_manual.h | 6 +- .../pattern_collection_generator_multiple.cc | 35 +++++---- .../pattern_collection_generator_multiple.h | 16 +++- ...ern_collection_generator_multiple_cegar.cc | 45 ++++++++++- ...tern_collection_generator_multiple_cegar.h | 13 +++- ...rn_collection_generator_multiple_random.cc | 45 ++++++++++- ...ern_collection_generator_multiple_random.h | 13 +++- ...pattern_collection_generator_systematic.cc | 23 ++++-- .../pattern_collection_generator_systematic.h | 6 +- src/search/pdbs/pattern_generator.cc | 16 ++-- src/search/pdbs/pattern_generator.h | 7 +- src/search/pdbs/pattern_generator_cegar.cc | 32 ++++++-- src/search/pdbs/pattern_generator_cegar.h | 8 +- src/search/pdbs/pattern_generator_greedy.cc | 15 +++- src/search/pdbs/pattern_generator_greedy.h | 6 +- src/search/pdbs/pattern_generator_manual.cc | 17 +++- src/search/pdbs/pattern_generator_manual.h | 6 +- src/search/pdbs/pattern_generator_random.cc | 32 ++++++-- src/search/pdbs/pattern_generator_random.h | 8 +- src/search/pdbs/pdb_heuristic.cc | 32 +++++--- src/search/pdbs/pdb_heuristic.h | 14 +++- src/search/pdbs/zero_one_pdbs_heuristic.cc | 31 +++++--- src/search/pdbs/zero_one_pdbs_heuristic.h | 10 ++- src/search/utils/rng_options.cc | 10 +-- src/search/utils/rng_options.h | 6 +- 36 files changed, 554 insertions(+), 179 deletions(-) diff --git a/src/search/pdbs/canonical_pdbs_heuristic.cc b/src/search/pdbs/canonical_pdbs_heuristic.cc index fa7e5b37ac..a031117e7b 100644 --- a/src/search/pdbs/canonical_pdbs_heuristic.cc +++ b/src/search/pdbs/canonical_pdbs_heuristic.cc @@ -1,7 +1,6 @@ #include "canonical_pdbs_heuristic.h" #include "dominance_pruning.h" -#include "pattern_generator.h" #include "utils.h" #include "../plugins/plugin.h" @@ -10,15 +9,15 @@ #include #include -#include using namespace std; namespace pdbs { static CanonicalPDBs get_canonical_pdbs_from_options( - const shared_ptr &task, const plugins::Options &opts, utils::LogProxy &log) { - shared_ptr pattern_generator = - opts.get>("patterns"); + const shared_ptr &task, + const shared_ptr &pattern_generator, + double max_time_dominance_pruning, + utils::LogProxy &log) { utils::Timer timer; if (log.is_at_least_normal()) { log << "Initializing canonical PDB heuristic..." << endl; @@ -36,7 +35,6 @@ static CanonicalPDBs get_canonical_pdbs_from_options( shared_ptr> pattern_cliques = pattern_collection_info.get_pattern_cliques(); - double max_time_dominance_pruning = opts.get("max_time_dominance_pruning"); if (max_time_dominance_pruning > 0.0) { int num_variables = TaskProxy(*task).get_variables().size(); /* @@ -62,9 +60,16 @@ static CanonicalPDBs get_canonical_pdbs_from_options( return CanonicalPDBs(pdbs, pattern_cliques); } -CanonicalPDBsHeuristic::CanonicalPDBsHeuristic(const plugins::Options &opts) - : Heuristic(opts), - canonical_pdbs(get_canonical_pdbs_from_options(task, opts, log)) { +CanonicalPDBsHeuristic::CanonicalPDBsHeuristic( + const shared_ptr &pattern_generator, + double max_time_dominance_pruning, + const shared_ptr &transform, + bool cache_estimates, + const string &name, + utils::Verbosity verbosity) + : Heuristic(transform, cache_estimates, name, verbosity), + canonical_pdbs(get_canonical_pdbs_from_options( + task, pattern_generator, max_time_dominance_pruning, log)) { } int CanonicalPDBsHeuristic::compute_heuristic(const State &ancestor_state) { @@ -106,7 +111,7 @@ class CanonicalPDBsHeuristicFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get>("patterns"), + opts.get("max_time_dominance_pruning"), + opts.get>("transform"), + opts.get("cache_estimates"), + opts.get("name"), + opts.get("verbosity")); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/canonical_pdbs_heuristic.h b/src/search/pdbs/canonical_pdbs_heuristic.h index 3ef85cf5a2..8059251d9d 100644 --- a/src/search/pdbs/canonical_pdbs_heuristic.h +++ b/src/search/pdbs/canonical_pdbs_heuristic.h @@ -2,9 +2,12 @@ #define PDBS_CANONICAL_PDBS_HEURISTIC_H #include "canonical_pdbs.h" +#include "pattern_generator.h" #include "../heuristic.h" +#include + namespace plugins { class Feature; } @@ -18,8 +21,13 @@ class CanonicalPDBsHeuristic : public Heuristic { virtual int compute_heuristic(const State &ancestor_state) override; public: - explicit CanonicalPDBsHeuristic(const plugins::Options &opts); - virtual ~CanonicalPDBsHeuristic() = default; + CanonicalPDBsHeuristic( + const std::shared_ptr &pattern_generator, + double max_time_dominance_pruning, + const std::shared_ptr &transform, + bool cache_estimates, + const std::string &name, + utils::Verbosity verbosity); }; void add_canonical_pdbs_options_to_feature(plugins::Feature &feature); diff --git a/src/search/pdbs/pattern_collection_generator_combo.cc b/src/search/pdbs/pattern_collection_generator_combo.cc index 57623150e0..8cdd0108a2 100644 --- a/src/search/pdbs/pattern_collection_generator_combo.cc +++ b/src/search/pdbs/pattern_collection_generator_combo.cc @@ -18,8 +18,12 @@ using namespace std; namespace pdbs { PatternCollectionGeneratorCombo::PatternCollectionGeneratorCombo( - const plugins::Options &opts) - : PatternCollectionGenerator(opts), opts(opts) { + int max_states, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), max_states(max_states), + sub_generator_name(name + "_nested_generator"), verbosity(verbosity) { + // TODO 1082 does it make sense to store name and verbosity here? At least name conflicts with the function name(). } string PatternCollectionGeneratorCombo::name() const { @@ -31,7 +35,7 @@ PatternCollectionInformation PatternCollectionGeneratorCombo::compute_patterns( TaskProxy task_proxy(*task); shared_ptr patterns = make_shared(); - PatternGeneratorGreedy large_pattern_generator(opts); + PatternGeneratorGreedy large_pattern_generator(max_states, sub_generator_name, verbosity); Pattern large_pattern = large_pattern_generator.generate(task).get_pattern(); set used_vars(large_pattern.begin(), large_pattern.end()); patterns->push_back(move(large_pattern)); @@ -55,7 +59,16 @@ class PatternCollectionGeneratorComboFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("max_states"), + opts.get("name"), + opts.get("verbosity") + ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_combo.h b/src/search/pdbs/pattern_collection_generator_combo.h index ce7d5fb089..ba9e7ea34f 100644 --- a/src/search/pdbs/pattern_collection_generator_combo.h +++ b/src/search/pdbs/pattern_collection_generator_combo.h @@ -9,14 +9,18 @@ namespace pdbs { /* Take one large pattern and then single-variable patterns for all goal variables that are not in the large pattern. */ class PatternCollectionGeneratorCombo : public PatternCollectionGenerator { - plugins::Options opts; + int max_states; + std::string sub_generator_name; + utils::Verbosity verbosity; virtual std::string name() const override; virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorCombo(const plugins::Options &opts); - virtual ~PatternCollectionGeneratorCombo() = default; + PatternCollectionGeneratorCombo( + int max_states, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc b/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc index 58a44f5425..b8220b2fe1 100644 --- a/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc +++ b/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc @@ -11,13 +11,19 @@ using namespace std; namespace pdbs { PatternCollectionGeneratorDisjointCegar::PatternCollectionGeneratorDisjointCegar( - const plugins::Options &opts) - : PatternCollectionGenerator(opts), - max_pdb_size(opts.get("max_pdb_size")), - max_collection_size(opts.get("max_collection_size")), - max_time(opts.get("max_time")), - use_wildcard_plans(opts.get("use_wildcard_plans")), - rng(utils::parse_rng_from_options(opts)) { + int max_pdb_size, + int max_collection_size, + double max_time, + bool use_wildcard_plans, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), + max_pdb_size(max_pdb_size), + max_collection_size(max_collection_size), + max_time(max_time), + use_wildcard_plans(use_wildcard_plans), + rng(utils::get_rng(random_seed)) { } string PatternCollectionGeneratorDisjointCegar::name() const { @@ -75,11 +81,24 @@ class PatternCollectionGeneratorDisjointCegarFeature : public plugins::TypedFeat "infinity", plugins::Bounds("0.0", "infinity")); add_cegar_wildcard_option_to_feature(*this); - add_generator_options_to_feature(*this); utils::add_rng_options(*this); + add_generator_options_to_feature(*this, "disjoint_cegar"); add_cegar_implementation_notes_to_feature(*this); } + + virtual shared_ptr create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("max_pdb_size"), + opts.get("max_collection_size"), + opts.get("max_time"), + opts.get("use_wildcard_plans"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pattern_collection_generator_disjoint_cegar.h b/src/search/pdbs/pattern_collection_generator_disjoint_cegar.h index 5622588ee2..7766fe3ea6 100644 --- a/src/search/pdbs/pattern_collection_generator_disjoint_cegar.h +++ b/src/search/pdbs/pattern_collection_generator_disjoint_cegar.h @@ -23,7 +23,14 @@ class PatternCollectionGeneratorDisjointCegar : public PatternCollectionGenerato virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorDisjointCegar(const plugins::Options &opts); + PatternCollectionGeneratorDisjointCegar( + int max_pdb_size, + int max_collection_size, + double max_time, + bool use_wildcard_plans, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_genetic.cc b/src/search/pdbs/pattern_collection_generator_genetic.cc index 4c4cf4c78a..937055c3dd 100644 --- a/src/search/pdbs/pattern_collection_generator_genetic.cc +++ b/src/search/pdbs/pattern_collection_generator_genetic.cc @@ -25,14 +25,21 @@ using namespace std; namespace pdbs { PatternCollectionGeneratorGenetic::PatternCollectionGeneratorGenetic( - const plugins::Options &opts) - : PatternCollectionGenerator(opts), - pdb_max_size(opts.get("pdb_max_size")), - num_collections(opts.get("num_collections")), - num_episodes(opts.get("num_episodes")), - mutation_probability(opts.get("mutation_probability")), - disjoint_patterns(opts.get("disjoint")), - rng(utils::parse_rng_from_options(opts)) { + int pdb_max_size, + int num_collections, + int num_episodes, + double mutation_probability, + bool disjoint, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), + pdb_max_size(pdb_max_size), + num_collections(num_collections), + num_episodes(num_episodes), + mutation_probability(mutation_probability), + disjoint_patterns(disjoint), + rng(utils::get_rng(random_seed)) { } void PatternCollectionGeneratorGenetic::select( @@ -345,7 +352,7 @@ class PatternCollectionGeneratorGeneticFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("pdb_max_size"), + opts.get("num_collections"), + opts.get("num_episodes"), + opts.get("mutation_probability"), + opts.get("disjoint"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pattern_collection_generator_genetic.h b/src/search/pdbs/pattern_collection_generator_genetic.h index 672eceaf4a..0c32747dff 100644 --- a/src/search/pdbs/pattern_collection_generator_genetic.h +++ b/src/search/pdbs/pattern_collection_generator_genetic.h @@ -113,7 +113,15 @@ class PatternCollectionGeneratorGenetic : public PatternCollectionGenerator { virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorGenetic(const plugins::Options &opts); + PatternCollectionGeneratorGenetic( + int pdb_max_size, + int num_collections, + int num_episodes, + double mutation_probability, + bool disjoint, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_hillclimbing.cc b/src/search/pdbs/pattern_collection_generator_hillclimbing.cc index 322587b8f6..0cdc67bb7f 100644 --- a/src/search/pdbs/pattern_collection_generator_hillclimbing.cc +++ b/src/search/pdbs/pattern_collection_generator_hillclimbing.cc @@ -112,14 +112,22 @@ static vector> compute_relevant_neighbours(const TaskProxy &task_pro } -PatternCollectionGeneratorHillclimbing::PatternCollectionGeneratorHillclimbing(const plugins::Options &opts) - : PatternCollectionGenerator(opts), - pdb_max_size(opts.get("pdb_max_size")), - collection_max_size(opts.get("collection_max_size")), - num_samples(opts.get("num_samples")), - min_improvement(opts.get("min_improvement")), - max_time(opts.get("max_time")), - rng(utils::parse_rng_from_options(opts)), +PatternCollectionGeneratorHillclimbing::PatternCollectionGeneratorHillclimbing( + int pdb_max_size, + int collection_max_size, + int num_samples, + int min_improvement, + double max_time, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), + pdb_max_size(pdb_max_size), + collection_max_size(collection_max_size), + num_samples(num_samples), + min_improvement(min_improvement), + max_time(max_time), + rng(utils::get_rng(random_seed)), num_rejected(0), hill_climbing_timer(nullptr) { } @@ -595,12 +603,22 @@ class PatternCollectionGeneratorHillclimbingFeature : public plugins::TypedFeatu "optimized for the Evaluator#Canonical_PDB heuristic. It it described " "in the following paper:" + paper_references()); add_hillclimbing_options(*this); - add_generator_options_to_feature(*this); + add_generator_options_to_feature(*this, "hillclimbing"); } - virtual shared_ptr create_component(const plugins::Options &options, const utils::Context &context) const override { - check_hillclimbing_options(options, context); - return make_shared(options); + virtual shared_ptr create_component(const plugins::Options &opts, const utils::Context &context) const override { + check_hillclimbing_options(opts, context); + + return make_shared( + opts.get("pdb_max_size"), + opts.get("collection_max_size"), + opts.get("num_samples"), + opts.get("min_improvement"), + opts.get("max_time"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity") + ); } }; @@ -643,25 +661,27 @@ class IPDBFeature : public plugins::TypedFeature create_component(const plugins::Options &options, const utils::Context &context) const override { - check_hillclimbing_options(options, context); + virtual shared_ptr create_component(const plugins::Options &opts, const utils::Context &context) const override { + check_hillclimbing_options(opts, context); shared_ptr pgh = - make_shared(options); - - plugins::Options heuristic_opts; - heuristic_opts.set( - "verbosity", options.get("verbosity")); - heuristic_opts.set>( - "transform", options.get>("transform")); - heuristic_opts.set( - "cache_estimates", options.get("cache_estimates")); - heuristic_opts.set>( - "patterns", pgh); - heuristic_opts.set( - "max_time_dominance_pruning", options.get("max_time_dominance_pruning")); - - return make_shared(heuristic_opts); + make_shared( + opts.get("pdb_max_size"), + opts.get("collection_max_size"), + opts.get("num_samples"), + opts.get("min_improvement"), + opts.get("max_time"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity")); + + return make_shared( + pgh, + opts.get("max_time_dominance_pruning"), + opts.get>("transform"), + opts.get("cache_estimates"), + opts.get("name"), + opts.get("verbosity")); } }; diff --git a/src/search/pdbs/pattern_collection_generator_hillclimbing.h b/src/search/pdbs/pattern_collection_generator_hillclimbing.h index d9cf02097e..3d92d46511 100644 --- a/src/search/pdbs/pattern_collection_generator_hillclimbing.h +++ b/src/search/pdbs/pattern_collection_generator_hillclimbing.h @@ -132,8 +132,15 @@ class PatternCollectionGeneratorHillclimbing : public PatternCollectionGenerator virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorHillclimbing(const plugins::Options &opts); - virtual ~PatternCollectionGeneratorHillclimbing() = default; + PatternCollectionGeneratorHillclimbing( + int pdb_max_size, + int collection_max_size, + int num_samples, + int min_improvement, + double max_time, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_manual.cc b/src/search/pdbs/pattern_collection_generator_manual.cc index 4b642252da..4ff5f46f29 100644 --- a/src/search/pdbs/pattern_collection_generator_manual.cc +++ b/src/search/pdbs/pattern_collection_generator_manual.cc @@ -12,9 +12,12 @@ using namespace std; namespace pdbs { -PatternCollectionGeneratorManual::PatternCollectionGeneratorManual(const plugins::Options &opts) - : PatternCollectionGenerator(opts), - patterns(make_shared(opts.get_list("patterns"))) { +PatternCollectionGeneratorManual::PatternCollectionGeneratorManual( + const vector &patterns, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), + patterns(make_shared(patterns)) { } string PatternCollectionGeneratorManual::name() const { @@ -37,7 +40,16 @@ class PatternCollectionGeneratorManualFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get_list("patterns"), + opts.get("name"), + opts.get("verbosity") + ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_manual.h b/src/search/pdbs/pattern_collection_generator_manual.h index 92ed1d92f9..90d847a203 100644 --- a/src/search/pdbs/pattern_collection_generator_manual.h +++ b/src/search/pdbs/pattern_collection_generator_manual.h @@ -14,8 +14,10 @@ class PatternCollectionGeneratorManual : public PatternCollectionGenerator { virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorManual(const plugins::Options &opts); - virtual ~PatternCollectionGeneratorManual() = default; + explicit PatternCollectionGeneratorManual( + const std::vector &patterns, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_multiple.cc b/src/search/pdbs/pattern_collection_generator_multiple.cc index 6e8ea1cfb7..33b9088e43 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple.cc +++ b/src/search/pdbs/pattern_collection_generator_multiple.cc @@ -16,17 +16,26 @@ using namespace std; namespace pdbs { PatternCollectionGeneratorMultiple::PatternCollectionGeneratorMultiple( - const plugins::Options &opts) - : PatternCollectionGenerator(opts), - max_pdb_size(opts.get("max_pdb_size")), - pattern_generation_max_time(opts.get("pattern_generation_max_time")), - total_max_time(opts.get("total_max_time")), - stagnation_limit(opts.get("stagnation_limit")), - blacklisting_start_time(total_max_time * opts.get("blacklist_trigger_percentage")), - enable_blacklist_on_stagnation(opts.get("enable_blacklist_on_stagnation")), - rng(utils::parse_rng_from_options(opts)), - random_seed(opts.get("random_seed")), - remaining_collection_size(opts.get("max_collection_size")), + int max_pdb_size, + int max_collection_size, + double pattern_generation_max_time, + double total_max_time, + double stagnation_limit, + double blacklist_trigger_percentage, + bool enable_blacklist_on_stagnation, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), + max_pdb_size(max_pdb_size), + pattern_generation_max_time(pattern_generation_max_time), + total_max_time(total_max_time), + stagnation_limit(stagnation_limit), + blacklisting_start_time(total_max_time * blacklist_trigger_percentage), + enable_blacklist_on_stagnation(enable_blacklist_on_stagnation), + rng(utils::get_rng(random_seed)), + random_seed(random_seed), + remaining_collection_size(max_collection_size), blacklisting(false), time_point_of_last_new_pattern(0.0) { } @@ -274,7 +283,7 @@ void add_multiple_algorithm_implementation_notes_to_feature( true); } -void add_multiple_options_to_feature(plugins::Feature &feature) { +void add_multiple_options_to_feature(plugins::Feature &feature, const string &name) { feature.add_option( "max_pdb_size", "maximum number of states for each pattern database, computed " @@ -322,7 +331,7 @@ void add_multiple_options_to_feature(plugins::Feature &feature) { "generation is terminated already the first time stagnation_limit is " "hit.", "true"); - add_generator_options_to_feature(feature); utils::add_rng_options(feature); + add_generator_options_to_feature(feature, name); } } diff --git a/src/search/pdbs/pattern_collection_generator_multiple.h b/src/search/pdbs/pattern_collection_generator_multiple.h index dfd31e1d9a..01b4f8280c 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple.h +++ b/src/search/pdbs/pattern_collection_generator_multiple.h @@ -72,13 +72,23 @@ class PatternCollectionGeneratorMultiple : public PatternCollectionGenerator { virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorMultiple(const plugins::Options &opts); - virtual ~PatternCollectionGeneratorMultiple() override = default; + PatternCollectionGeneratorMultiple( + int max_pdb_size, + int max_collection_size, + double pattern_generation_max_time, + double total_max_time, + double stagnation_limit, + double blacklist_trigger_percentage, + bool enable_blacklist_on_stagnation, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; extern void add_multiple_algorithm_implementation_notes_to_feature( plugins::Feature &feature); -extern void add_multiple_options_to_feature(plugins::Feature &feature); +extern void add_multiple_options_to_feature( + plugins::Feature &feature, const std::string &name); } #endif diff --git a/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc b/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc index 9ed1be1956..3a19439afc 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc +++ b/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc @@ -11,9 +11,29 @@ using namespace std; namespace pdbs { PatternCollectionGeneratorMultipleCegar::PatternCollectionGeneratorMultipleCegar( - const plugins::Options &opts) - : PatternCollectionGeneratorMultiple(opts), - use_wildcard_plans(opts.get("use_wildcard_plans")) { + bool use_wildcard_plans, + int max_pdb_size, + int max_collection_size, + double pattern_generation_max_time, + double total_max_time, + double stagnation_limit, + double blacklist_trigger_percentage, + bool enable_blacklist_on_stagnation, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGeneratorMultiple( + max_pdb_size, + max_collection_size, + pattern_generation_max_time, + total_max_time, + stagnation_limit, + blacklist_trigger_percentage, + enable_blacklist_on_stagnation, + random_seed, + name, + verbosity), + use_wildcard_plans(use_wildcard_plans) { } string PatternCollectionGeneratorMultipleCegar::id() const { @@ -51,12 +71,29 @@ class PatternCollectionGeneratorMultipleCegarFeature : public plugins::TypedFeat "restricted to a single goal variable. See below for descriptions of " "the algorithms."); - add_multiple_options_to_feature(*this); add_cegar_wildcard_option_to_feature(*this); + add_multiple_options_to_feature(*this, "multiple_cegar"); add_cegar_implementation_notes_to_feature(*this); add_multiple_algorithm_implementation_notes_to_feature(*this); } + + virtual shared_ptr create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("use_wildcard_plans"), + opts.get("max_pdb_size"), + opts.get("max_collection_size"), + opts.get("pattern_generation_max_time"), + opts.get("total_max_time"), + opts.get("stagnation_limit"), + opts.get("blacklist_trigger_percentage"), + opts.get("enable_blacklist_on_stagnation"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pattern_collection_generator_multiple_cegar.h b/src/search/pdbs/pattern_collection_generator_multiple_cegar.h index b6d9aaa37b..383df1e35c 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple_cegar.h +++ b/src/search/pdbs/pattern_collection_generator_multiple_cegar.h @@ -17,7 +17,18 @@ class PatternCollectionGeneratorMultipleCegar : public PatternCollectionGenerato const FactPair &goal, std::unordered_set &&blacklisted_variables) override; public: - explicit PatternCollectionGeneratorMultipleCegar(const plugins::Options &opts); + PatternCollectionGeneratorMultipleCegar( + bool use_wildcard_plans, + int max_pdb_size, + int max_collection_size, + double pattern_generation_max_time, + double total_max_time, + double stagnation_limit, + double blacklist_trigger_percentage, + bool enable_blacklist_on_stagnation, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_multiple_random.cc b/src/search/pdbs/pattern_collection_generator_multiple_random.cc index ad5b749334..8885ff6de8 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple_random.cc +++ b/src/search/pdbs/pattern_collection_generator_multiple_random.cc @@ -14,9 +14,29 @@ using namespace std; namespace pdbs { PatternCollectionGeneratorMultipleRandom::PatternCollectionGeneratorMultipleRandom( - const plugins::Options &opts) - : PatternCollectionGeneratorMultiple(opts), - bidirectional(opts.get("bidirectional")) { + bool bidirectional, + int max_pdb_size, + int max_collection_size, + double pattern_generation_max_time, + double total_max_time, + double stagnation_limit, + double blacklist_trigger_percentage, + bool enable_blacklist_on_stagnation, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGeneratorMultiple( + max_pdb_size, + max_collection_size, + pattern_generation_max_time, + total_max_time, + stagnation_limit, + blacklist_trigger_percentage, + enable_blacklist_on_stagnation, + random_seed, + name, + verbosity), + bidirectional(bidirectional) { } string PatternCollectionGeneratorMultipleRandom::id() const { @@ -64,12 +84,29 @@ class PatternCollectionGeneratorMultipleRandomFeature : public plugins::TypedFea "pattern algorithm, called 'single randomized causal graph' (sRCG) " "in the paper. See below for descriptions of the algorithms."); - add_multiple_options_to_feature(*this); add_random_pattern_bidirectional_option_to_feature(*this); + add_multiple_options_to_feature(*this, "random_patterns"); add_random_pattern_implementation_notes_to_feature(*this); add_multiple_algorithm_implementation_notes_to_feature(*this); } + + virtual shared_ptr create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("bidirectional"), + opts.get("max_pdb_size"), + opts.get("max_collection_size"), + opts.get("pattern_generation_max_time"), + opts.get("total_max_time"), + opts.get("stagnation_limit"), + opts.get("blacklist_trigger_percentage"), + opts.get("enable_blacklist_on_stagnation"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pattern_collection_generator_multiple_random.h b/src/search/pdbs/pattern_collection_generator_multiple_random.h index ccc51adc8d..2a3c38f092 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple_random.h +++ b/src/search/pdbs/pattern_collection_generator_multiple_random.h @@ -18,7 +18,18 @@ class PatternCollectionGeneratorMultipleRandom : public PatternCollectionGenerat const FactPair &goal, std::unordered_set &&blacklisted_variables) override; public: - explicit PatternCollectionGeneratorMultipleRandom(const plugins::Options &opts); + PatternCollectionGeneratorMultipleRandom( + bool bidirectional, + int max_pdb_size, + int max_collection_size, + double pattern_generation_max_time, + double total_max_time, + double stagnation_limit, + double blacklist_trigger_percentage, + bool enable_blacklist_on_stagnation, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_collection_generator_systematic.cc b/src/search/pdbs/pattern_collection_generator_systematic.cc index 3cc412a6bb..12fe669c39 100644 --- a/src/search/pdbs/pattern_collection_generator_systematic.cc +++ b/src/search/pdbs/pattern_collection_generator_systematic.cc @@ -47,10 +47,13 @@ static void compute_union_pattern( PatternCollectionGeneratorSystematic::PatternCollectionGeneratorSystematic( - const plugins::Options &opts) - : PatternCollectionGenerator(opts), - max_pattern_size(opts.get("pattern_max_size")), - only_interesting_patterns(opts.get("only_interesting_patterns")) { + int pattern_max_size, + bool only_interesting_patterns, + const string &name, + utils::Verbosity verbosity) + : PatternCollectionGenerator(name, verbosity), + max_pattern_size(pattern_max_size), + only_interesting_patterns(only_interesting_patterns) { } void PatternCollectionGeneratorSystematic::compute_eff_pre_neighbors( @@ -311,7 +314,17 @@ class PatternCollectionGeneratorSystematicFeature : public plugins::TypedFeature "Only consider the union of two disjoint patterns if the union has " "more information than the individual patterns.", "true"); - add_generator_options_to_feature(*this); + add_generator_options_to_feature(*this, "systematic"); + } + + virtual shared_ptr create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("pattern_max_size"), + opts.get("only_interesting_patterns"), + opts.get("name"), + opts.get("verbosity") + ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_systematic.h b/src/search/pdbs/pattern_collection_generator_systematic.h index 8f483104c4..365778d143 100644 --- a/src/search/pdbs/pattern_collection_generator_systematic.h +++ b/src/search/pdbs/pattern_collection_generator_systematic.h @@ -44,7 +44,11 @@ class PatternCollectionGeneratorSystematic : public PatternCollectionGenerator { virtual PatternCollectionInformation compute_patterns( const std::shared_ptr &task) override; public: - explicit PatternCollectionGeneratorSystematic(const plugins::Options &opts); + PatternCollectionGeneratorSystematic( + int pattern_max_size, + bool only_interesting_patterns, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_generator.cc b/src/search/pdbs/pattern_generator.cc index f64751674d..59c8407f37 100644 --- a/src/search/pdbs/pattern_generator.cc +++ b/src/search/pdbs/pattern_generator.cc @@ -7,8 +7,11 @@ using namespace std; namespace pdbs { -PatternCollectionGenerator::PatternCollectionGenerator(const plugins::Options &opts) - : log(utils::get_log_from_options(opts)) { +PatternCollectionGenerator::PatternCollectionGenerator( + const string &name, + utils::Verbosity verbosity) + : log(utils::get_log_for_verbosity(verbosity)) { + // TODO 1082 What should we do with the name here? } PatternCollectionInformation PatternCollectionGenerator::generate( @@ -23,8 +26,9 @@ PatternCollectionInformation PatternCollectionGenerator::generate( return pci; } -PatternGenerator::PatternGenerator(const plugins::Options &opts) - : log(utils::get_log_from_options(opts)) { +PatternGenerator::PatternGenerator(const string &name, utils::Verbosity verbosity) + : log(utils::get_log_for_verbosity(verbosity)) { + // TODO 1082 What should we do with the name here? } PatternInformation PatternGenerator::generate( @@ -42,8 +46,8 @@ PatternInformation PatternGenerator::generate( return pattern_info; } -void add_generator_options_to_feature(plugins::Feature &feature) { - utils::add_log_options_to_feature(feature); +void add_generator_options_to_feature(plugins::Feature &feature, const string &name) { + utils::add_log_options_to_feature(feature, name); } static class PatternCollectionGeneratorCategoryPlugin : public plugins::TypedCategoryPlugin { diff --git a/src/search/pdbs/pattern_generator.h b/src/search/pdbs/pattern_generator.h index a9b6b6fc4c..8bd6a11c9e 100644 --- a/src/search/pdbs/pattern_generator.h +++ b/src/search/pdbs/pattern_generator.h @@ -29,7 +29,8 @@ class PatternCollectionGenerator { protected: mutable utils::LogProxy log; public: - explicit PatternCollectionGenerator(const plugins::Options &opts); + explicit PatternCollectionGenerator(const std::string &name, + utils::Verbosity verbosity); virtual ~PatternCollectionGenerator() = default; PatternCollectionInformation generate( @@ -43,13 +44,13 @@ class PatternGenerator { protected: mutable utils::LogProxy log; public: - explicit PatternGenerator(const plugins::Options &opts); + explicit PatternGenerator(const std::string &name, utils::Verbosity verbosity); virtual ~PatternGenerator() = default; PatternInformation generate(const std::shared_ptr &task); }; -extern void add_generator_options_to_feature(plugins::Feature &feature); +extern void add_generator_options_to_feature(plugins::Feature &feature, const std::string &name); } #endif diff --git a/src/search/pdbs/pattern_generator_cegar.cc b/src/search/pdbs/pattern_generator_cegar.cc index 9bea9e0a6f..5f52c1f546 100644 --- a/src/search/pdbs/pattern_generator_cegar.cc +++ b/src/search/pdbs/pattern_generator_cegar.cc @@ -16,12 +16,18 @@ using namespace std; namespace pdbs { -PatternGeneratorCEGAR::PatternGeneratorCEGAR(const plugins::Options &opts) - : PatternGenerator(opts), - max_pdb_size(opts.get("max_pdb_size")), - max_time(opts.get("max_time")), - use_wildcard_plans(opts.get("use_wildcard_plans")), - rng(utils::parse_rng_from_options(opts)) { +PatternGeneratorCEGAR::PatternGeneratorCEGAR( + int max_pdb_size, + double max_time, + bool use_wildcard_plans, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternGenerator(name, verbosity), + max_pdb_size(max_pdb_size), + max_time(max_time), + use_wildcard_plans(use_wildcard_plans), + rng(utils::get_rng(random_seed)) { } string PatternGeneratorCEGAR::name() const { @@ -65,11 +71,23 @@ class PatternGeneratorCEGARFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("max_pdb_size"), + opts.get("max_time"), + opts.get("use_wildcard_plans"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity")); + } + }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pattern_generator_cegar.h b/src/search/pdbs/pattern_generator_cegar.h index 6a8a7be03c..df111bea9b 100644 --- a/src/search/pdbs/pattern_generator_cegar.h +++ b/src/search/pdbs/pattern_generator_cegar.h @@ -18,7 +18,13 @@ class PatternGeneratorCEGAR : public PatternGenerator { virtual PatternInformation compute_pattern( const std::shared_ptr &task) override; public: - explicit PatternGeneratorCEGAR(const plugins::Options &opts); + PatternGeneratorCEGAR( + int max_pdb_size, + double max_time, + bool use_wildcard_plans, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_generator_greedy.cc b/src/search/pdbs/pattern_generator_greedy.cc index 2698930bee..24998849f8 100644 --- a/src/search/pdbs/pattern_generator_greedy.cc +++ b/src/search/pdbs/pattern_generator_greedy.cc @@ -16,8 +16,9 @@ using namespace std; namespace pdbs { -PatternGeneratorGreedy::PatternGeneratorGreedy(const plugins::Options &opts) - : PatternGenerator(opts), max_states(opts.get("max_states")) { +PatternGeneratorGreedy::PatternGeneratorGreedy( + int max_states, const string &name, utils::Verbosity verbosity) + : PatternGenerator(name, verbosity), max_states(max_states) { } string PatternGeneratorGreedy::name() const { @@ -57,7 +58,15 @@ class PatternGeneratorGreedyFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("max_states"), + opts.get("name"), + opts.get("verbosity")); } }; diff --git a/src/search/pdbs/pattern_generator_greedy.h b/src/search/pdbs/pattern_generator_greedy.h index 8bb9d70557..da20a4b9d9 100644 --- a/src/search/pdbs/pattern_generator_greedy.h +++ b/src/search/pdbs/pattern_generator_greedy.h @@ -11,8 +11,10 @@ class PatternGeneratorGreedy : public PatternGenerator { virtual PatternInformation compute_pattern( const std::shared_ptr &task) override; public: - explicit PatternGeneratorGreedy(const plugins::Options &opts); - virtual ~PatternGeneratorGreedy() = default; + PatternGeneratorGreedy( + int max_states, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_generator_manual.cc b/src/search/pdbs/pattern_generator_manual.cc index 4a177be771..0c4bd0a49f 100644 --- a/src/search/pdbs/pattern_generator_manual.cc +++ b/src/search/pdbs/pattern_generator_manual.cc @@ -12,8 +12,11 @@ using namespace std; namespace pdbs { -PatternGeneratorManual::PatternGeneratorManual(const plugins::Options &opts) - : PatternGenerator(opts), pattern(opts.get_list("pattern")) { +PatternGeneratorManual::PatternGeneratorManual( + const vector pattern, + const string &name, + const utils::Verbosity verbosity) + : PatternGenerator(name, verbosity), pattern(pattern) { } string PatternGeneratorManual::name() const { @@ -36,7 +39,15 @@ class PatternGeneratorManualFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get_list("pattern"), + opts.get("name"), + opts.get("verbosity")); } }; diff --git a/src/search/pdbs/pattern_generator_manual.h b/src/search/pdbs/pattern_generator_manual.h index 4f979ecb2f..85d7d80290 100644 --- a/src/search/pdbs/pattern_generator_manual.h +++ b/src/search/pdbs/pattern_generator_manual.h @@ -12,8 +12,10 @@ class PatternGeneratorManual : public PatternGenerator { virtual PatternInformation compute_pattern( const std::shared_ptr &task) override; public: - explicit PatternGeneratorManual(const plugins::Options &opts); - virtual ~PatternGeneratorManual() = default; + PatternGeneratorManual( + const std::vector pattern, + const std::string &name, + const utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pattern_generator_random.cc b/src/search/pdbs/pattern_generator_random.cc index 757344a407..d80c01dfec 100644 --- a/src/search/pdbs/pattern_generator_random.cc +++ b/src/search/pdbs/pattern_generator_random.cc @@ -16,12 +16,18 @@ using namespace std; namespace pdbs { -PatternGeneratorRandom::PatternGeneratorRandom(const plugins::Options &opts) - : PatternGenerator(opts), - max_pdb_size(opts.get("max_pdb_size")), - max_time(opts.get("max_time")), - bidirectional(opts.get("bidirectional")), - rng(utils::parse_rng_from_options(opts)) { +PatternGeneratorRandom::PatternGeneratorRandom( + int max_pdb_size, + double max_time, + bool bidirectional, + int random_seed, + const string &name, + utils::Verbosity verbosity) + : PatternGenerator(name, verbosity), + max_pdb_size(max_pdb_size), + max_time(max_time), + bidirectional(bidirectional), + rng(utils::get_rng(random_seed)) { } string PatternGeneratorRandom::name() const { @@ -70,11 +76,23 @@ class PatternGeneratorRandomFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get("max_pdb_size"), + opts.get("max_time"), + opts.get("bidirectional"), + opts.get("random_seed"), + opts.get("name"), + opts.get("verbosity") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pattern_generator_random.h b/src/search/pdbs/pattern_generator_random.h index b7081da0a4..e7e4f6633f 100644 --- a/src/search/pdbs/pattern_generator_random.h +++ b/src/search/pdbs/pattern_generator_random.h @@ -18,7 +18,13 @@ class PatternGeneratorRandom : public PatternGenerator { virtual PatternInformation compute_pattern( const std::shared_ptr &task) override; public: - explicit PatternGeneratorRandom(const plugins::Options &opts); + PatternGeneratorRandom( + int max_pdb_size, + double max_time, + bool bidirectional, + int random_seed, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/pdb_heuristic.cc b/src/search/pdbs/pdb_heuristic.cc index edf5f14476..d15c00cab3 100644 --- a/src/search/pdbs/pdb_heuristic.cc +++ b/src/search/pdbs/pdb_heuristic.cc @@ -1,7 +1,6 @@ #include "pdb_heuristic.h" #include "pattern_database.h" -#include "pattern_generator.h" #include "../plugins/plugin.h" @@ -11,17 +10,22 @@ using namespace std; namespace pdbs { -static shared_ptr get_pdb_from_options(const shared_ptr &task, - const plugins::Options &opts) { - shared_ptr pattern_generator = - opts.get>("pattern"); +static shared_ptr get_pdb_from_generator( + const shared_ptr &task, + const shared_ptr &pattern_generator) { PatternInformation pattern_info = pattern_generator->generate(task); return pattern_info.get_pdb(); } -PDBHeuristic::PDBHeuristic(const plugins::Options &opts) - : Heuristic(opts), - pdb(get_pdb_from_options(task, opts)) { +PDBHeuristic::PDBHeuristic( + const shared_ptr &pattern, + const shared_ptr &transform, + bool cache_estimates, + const string &name, + utils::Verbosity verbosity) + : Heuristic(transform, cache_estimates, name, verbosity), + pdb(get_pdb_from_generator(task, pattern)){ + } int PDBHeuristic::compute_heuristic(const State &ancestor_state) { @@ -43,7 +47,7 @@ class PDBHeuristicFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get>("pattern"), + opts.get>("transform"), + opts.get("cache_estimates"), + opts.get("name"), + opts.get("verbosity")); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/pdb_heuristic.h b/src/search/pdbs/pdb_heuristic.h index 721e3a433c..fdf3dde467 100644 --- a/src/search/pdbs/pdb_heuristic.h +++ b/src/search/pdbs/pdb_heuristic.h @@ -1,6 +1,8 @@ #ifndef PDBS_PDB_HEURISTIC_H #define PDBS_PDB_HEURISTIC_H +#include "pattern_generator.h" + #include "../heuristic.h" namespace pdbs { @@ -13,16 +15,20 @@ class PDBHeuristic : public Heuristic { virtual int compute_heuristic(const State &ancestor_state) override; public: /* - Important: It is assumed that the pattern (passed via Options) is - sorted, contains no duplicates and is small enough so that the + Important: It is assumed that the pattern (passed via pattern_generator) + is sorted, contains no duplicates and is small enough so that the number of abstract states is below numeric_limits::max() Parameters: operator_costs: Can specify individual operator costs for each operator. This is useful for action cost partitioning. If left empty, default operator costs are used. */ - PDBHeuristic(const plugins::Options &opts); - virtual ~PDBHeuristic() override = default; + PDBHeuristic( + const std::shared_ptr &pattern_generator, + const std::shared_ptr &transform, + bool cache_estimates, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/zero_one_pdbs_heuristic.cc b/src/search/pdbs/zero_one_pdbs_heuristic.cc index ee5191b8f0..86cce7afb3 100644 --- a/src/search/pdbs/zero_one_pdbs_heuristic.cc +++ b/src/search/pdbs/zero_one_pdbs_heuristic.cc @@ -1,7 +1,5 @@ #include "zero_one_pdbs_heuristic.h" -#include "pattern_generator.h" - #include "../plugins/plugin.h" #include @@ -9,10 +7,9 @@ using namespace std; namespace pdbs { -static ZeroOnePDBs get_zero_one_pdbs_from_options( - const shared_ptr &task, const plugins::Options &opts) { - shared_ptr pattern_generator = - opts.get>("patterns"); +static ZeroOnePDBs get_zero_one_pdbs_from_generator( + const shared_ptr &task, + const shared_ptr &pattern_generator) { PatternCollectionInformation pattern_collection_info = pattern_generator->generate(task); shared_ptr patterns = @@ -22,9 +19,13 @@ static ZeroOnePDBs get_zero_one_pdbs_from_options( } ZeroOnePDBsHeuristic::ZeroOnePDBsHeuristic( - const plugins::Options &opts) - : Heuristic(opts), - zero_one_pdbs(get_zero_one_pdbs_from_options(task, opts)) { + const shared_ptr &patterns, + const shared_ptr &transform, + bool cache_estimates, + const string &name, + utils::Verbosity verbosity) + : Heuristic(transform, cache_estimates, name, verbosity), + zero_one_pdbs(get_zero_one_pdbs_from_generator(task, patterns)) { } int ZeroOnePDBsHeuristic::compute_heuristic(const State &ancestor_state) { @@ -55,7 +56,7 @@ class ZeroOnePDBsHeuristicFeature : public plugins::TypedFeature create_component( + const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get>("patterns"), + opts.get>("transform"), + opts.get("cache_estimates"), + opts.get("name"), + opts.get("verbosity")); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/pdbs/zero_one_pdbs_heuristic.h b/src/search/pdbs/zero_one_pdbs_heuristic.h index 21e246bbdd..095b41ee02 100644 --- a/src/search/pdbs/zero_one_pdbs_heuristic.h +++ b/src/search/pdbs/zero_one_pdbs_heuristic.h @@ -1,10 +1,13 @@ #ifndef PDBS_ZERO_ONE_PDBS_HEURISTIC_H #define PDBS_ZERO_ONE_PDBS_HEURISTIC_H +#include "pattern_generator.h" #include "zero_one_pdbs.h" #include "../heuristic.h" +#include + namespace pdbs { class PatternDatabase; @@ -13,8 +16,11 @@ class ZeroOnePDBsHeuristic : public Heuristic { protected: virtual int compute_heuristic(const State &ancestor_state) override; public: - ZeroOnePDBsHeuristic(const plugins::Options &opts); - virtual ~ZeroOnePDBsHeuristic() = default; + ZeroOnePDBsHeuristic(const std::shared_ptr &patterns, + const std::shared_ptr &transform, + bool cache_estimates, + const std::string &name, + utils::Verbosity verbosity); }; } diff --git a/src/search/utils/rng_options.cc b/src/search/utils/rng_options.cc index 144f37ab5b..740540af77 100644 --- a/src/search/utils/rng_options.cc +++ b/src/search/utils/rng_options.cc @@ -30,14 +30,6 @@ shared_ptr get_rng(int seed) { shared_ptr parse_rng_from_options( const plugins::Options &options) { - int seed = options.get("random_seed"); - if (seed == -1) { - // Use an arbitrary default seed. - static shared_ptr rng = - make_shared(2011); - return rng; - } else { - return make_shared(seed); - } + return get_rng(options.get("random_seed")); } } diff --git a/src/search/utils/rng_options.h b/src/search/utils/rng_options.h index c1a47caf01..e7d2dc0b01 100644 --- a/src/search/utils/rng_options.h +++ b/src/search/utils/rng_options.h @@ -14,13 +14,13 @@ class RandomNumberGenerator; // Add random_seed option to parser. extern void add_rng_options(plugins::Feature &feature); -extern std::shared_ptr get_rng(int seed); - /* - Return an RNG based on the given options, which can either be the global + Return an RNG for the given seed, which can either be the global RNG or a local one with a user-specified seed. Only use this together with "add_rng_options()". */ +extern std::shared_ptr get_rng(int seed); +// TODO 1082 remove this, just keep the one above extern std::shared_ptr parse_rng_from_options( const plugins::Options &options); }