From e023dea9064379cffc736f370191755f1beb0bde Mon Sep 17 00:00:00 2001 From: Simon Dold Date: Wed, 7 Feb 2024 17:56:09 +0100 Subject: [PATCH] [issue1082] BREAKING update many M&S components. --- src/search/AAA_Mechanical_Changes.md | 68 +++++++++---------- .../merge_and_shrink_algorithm.cc | 27 ++++++++ .../merge_and_shrink_algorithm.h | 12 ++++ .../merge_and_shrink_heuristic.cc | 44 ++++++++++-- .../merge_and_shrink_heuristic.h | 20 +++++- .../merge_scoring_function_single_random.h | 4 -- .../merge_scoring_function_total_order.h | 1 - .../merge_selector_score_based_filtering.cc | 14 ++-- .../merge_selector_score_based_filtering.h | 5 +- .../merge_strategy_factory.cc | 5 ++ .../merge_and_shrink/merge_strategy_factory.h | 4 +- .../merge_strategy_factory_precomputed.cc | 7 +- .../merge_strategy_factory_precomputed.h | 3 +- .../merge_strategy_factory_sccs.cc | 9 +-- .../merge_strategy_factory_stateless.cc | 7 +- 15 files changed, 168 insertions(+), 62 deletions(-) diff --git a/src/search/AAA_Mechanical_Changes.md b/src/search/AAA_Mechanical_Changes.md index 3b334fe459..eb044b962b 100644 --- a/src/search/AAA_Mechanical_Changes.md +++ b/src/search/AAA_Mechanical_Changes.md @@ -96,50 +96,50 @@ search ├── landmarks ├── lp ├── merge_and_shrink -│ ├── distances.cc -│ ├── distances.h -│ ├── factored_transition_system.cc -│ ├── factored_transition_system.h -│ ├── fts_factory.cc -│ ├── fts_factory.h -│ ├── label_reduction.cc -│ ├── label_reduction.h -│ ├── labels.cc -│ ├── labels.h -│ ├── merge_and_shrink_algorithm.cc -│ ├── merge_and_shrink_algorithm.h -│ ├── merge_and_shrink_heuristic.cc -│ ├── merge_and_shrink_heuristic.h -│ ├── merge_and_shrink_representation.cc -│ ├── merge_and_shrink_representation.h -│ ├── merge_scoring_function.cc +│ ├── distances.cc✅ +│ ├── distances.h✅ +│ ├── factored_transition_system.cc✅ +│ ├── factored_transition_system.h✅ +│ ├── fts_factory.cc✅ +│ ├── fts_factory.h✅ +│ ├── label_reduction.cc✅ +│ ├── label_reduction.h✅ +│ ├── labels.cc✅ +│ ├── labels.h✅ +│ ├── merge_and_shrink_algorithm.cc✅ +│ ├── merge_and_shrink_algorithm.h✅ +│ ├── merge_and_shrink_heuristic.cc✅ +│ ├── merge_and_shrink_heuristic.h✅ +│ ├── merge_and_shrink_representation.cc✅ +│ ├── merge_and_shrink_representation.h✅ +│ ├── merge_scoring_function.cc✅ │ ├── merge_scoring_function_dfp.cc✅ │ ├── merge_scoring_function_dfp.h✅ │ ├── merge_scoring_function_goal_relevance.cc✅ │ ├── merge_scoring_function_goal_relevance.h✅ -│ ├── merge_scoring_function.h +│ ├── merge_scoring_function.h✅ │ ├── merge_scoring_function_miasm.cc✅ │ ├── merge_scoring_function_miasm.h✅ -│ ├── merge_scoring_function_miasm_utils.cc -│ ├── merge_scoring_function_miasm_utils.h +│ ├── merge_scoring_function_miasm_utils.cc✅ +│ ├── merge_scoring_function_miasm_utils.h✅ │ ├── merge_scoring_function_single_random.cc✅ │ ├── merge_scoring_function_single_random.h✅ │ ├── merge_scoring_function_total_order.cc✅ │ ├── merge_scoring_function_total_order.h✅ -│ ├── merge_selector.cc -│ ├── merge_selector.h -│ ├── merge_selector_score_based_filtering.cc -│ ├── merge_selector_score_based_filtering.h -│ ├── merge_strategy.cc -│ ├── merge_strategy_factory.cc -│ ├── merge_strategy_factory.h -│ ├── merge_strategy_factory_precomputed.cc -│ ├── merge_strategy_factory_precomputed.h -│ ├── merge_strategy_factory_sccs.cc -│ ├── merge_strategy_factory_sccs.h -│ ├── merge_strategy_factory_stateless.cc -│ ├── merge_strategy_factory_stateless.h -│ ├── merge_strategy.h +│ ├── merge_selector.cc✅ +│ ├── merge_selector.h✅ +│ ├── merge_selector_score_based_filtering.cc✅ +│ ├── merge_selector_score_based_filtering.h✅ +│ ├── merge_strategy.cc✅ +│ ├── merge_strategy_factory.cc✅ +│ ├── merge_strategy_factory.h✅ +│ ├── merge_strategy_factory_precomputed.cc✅ +│ ├── merge_strategy_factory_precomputed.h✅ +│ ├── merge_strategy_factory_sccs.cc✅ +│ ├── merge_strategy_factory_sccs.h✅ +│ ├── merge_strategy_factory_stateless.cc✅ +│ ├── merge_strategy_factory_stateless.h✅ +│ ├── merge_strategy.h✅ │ ├── merge_strategy_precomputed.cc │ ├── merge_strategy_precomputed.h │ ├── merge_strategy_sccs.cc diff --git a/src/search/merge_and_shrink/merge_and_shrink_algorithm.cc b/src/search/merge_and_shrink/merge_and_shrink_algorithm.cc index c1037f7df5..f580882ea5 100644 --- a/src/search/merge_and_shrink/merge_and_shrink_algorithm.cc +++ b/src/search/merge_and_shrink/merge_and_shrink_algorithm.cc @@ -36,6 +36,33 @@ namespace merge_and_shrink { static void log_progress(const utils::Timer &timer, const string &msg, utils::LogProxy &log) { log << "M&S algorithm timer: " << timer << " (" << msg << ")" << endl; } +MergeAndShrinkAlgorithm::MergeAndShrinkAlgorithm( + shared_ptr merge_strategy, + shared_ptr shrink_strategy, + shared_ptr label_reduction, + int max_states, + int max_states_before_merge, + int threshold_before_merge, + bool prune_unreachable_states, + bool prune_irrelevant_states, + double main_loop_max_time, + utils::Verbosity verbosity + ) : + merge_strategy_factory(merge_strategy), + shrink_strategy(shrink_strategy), + label_reduction(label_reduction), + max_states(max_states), + max_states_before_merge(max_states_before_merge), + shrink_threshold_before_merge(threshold_before_merge), + prune_unreachable_states(prune_unreachable_states), + prune_irrelevant_states(prune_irrelevant_states), + log(utils::get_log_for_verbosity(verbosity)), + main_loop_max_time(main_loop_max_time), + starting_peak_memory(0) { + assert(max_states_before_merge > 0); + assert(max_states >= max_states_before_merge); + assert(shrink_threshold_before_merge <= max_states_before_merge); +} MergeAndShrinkAlgorithm::MergeAndShrinkAlgorithm(const plugins::Options &opts) : merge_strategy_factory(opts.get>("merge_strategy")), diff --git a/src/search/merge_and_shrink/merge_and_shrink_algorithm.h b/src/search/merge_and_shrink/merge_and_shrink_algorithm.h index 24285dcdef..5e17a494fc 100644 --- a/src/search/merge_and_shrink/merge_and_shrink_algorithm.h +++ b/src/search/merge_and_shrink/merge_and_shrink_algorithm.h @@ -57,6 +57,18 @@ class MergeAndShrinkAlgorithm { FactoredTransitionSystem &fts, const TaskProxy &task_proxy); public: + MergeAndShrinkAlgorithm( + std::shared_ptr merge_strategy, + std::shared_ptr shrink_strategy, + std::shared_ptr label_reduction, + int max_states, + int max_states_before_merge, + int threshold_before_merge, + bool prune_unreachable_states, + bool prune_irrelevant_states, + double main_loop_max_time, + utils::Verbosity verbosity + ); explicit MergeAndShrinkAlgorithm(const plugins::Options &opts); FactoredTransitionSystem build_factored_transition_system(const TaskProxy &task_proxy); }; diff --git a/src/search/merge_and_shrink/merge_and_shrink_heuristic.cc b/src/search/merge_and_shrink/merge_and_shrink_heuristic.cc index c35f251c93..30d1b0af6c 100644 --- a/src/search/merge_and_shrink/merge_and_shrink_heuristic.cc +++ b/src/search/merge_and_shrink/merge_and_shrink_heuristic.cc @@ -20,10 +20,35 @@ using namespace std; using utils::ExitCode; namespace merge_and_shrink { -MergeAndShrinkHeuristic::MergeAndShrinkHeuristic(const plugins::Options &opts) - : Heuristic(opts) { +MergeAndShrinkHeuristic::MergeAndShrinkHeuristic( + const shared_ptr &merge_strategy, + const shared_ptr &shrink_strategy, + const shared_ptr &label_reduction, + int max_states, + int max_states_before_merge, + int threshold_before_merge, + bool prune_unreachable_states, + bool prune_irrelevant_states, + double main_loop_max_time, + const shared_ptr &transform, + bool cache_estimates, + const string &description, + utils::Verbosity verbosity + ) + : Heuristic(transform, cache_estimates, description, verbosity) { log << "Initializing merge-and-shrink heuristic..." << endl; - MergeAndShrinkAlgorithm algorithm(opts); + MergeAndShrinkAlgorithm algorithm( + merge_strategy, + shrink_strategy, + label_reduction, + max_states, + max_states_before_merge, + threshold_before_merge, + prune_unreachable_states, + prune_irrelevant_states, + main_loop_max_time, + verbosity + ); FactoredTransitionSystem fts = algorithm.build_factored_transition_system(task_proxy); extract_factors(fts); log << "Done initializing merge-and-shrink heuristic." << endl << endl; @@ -227,7 +252,18 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature create_component(const plugins::Options &options, const utils::Context &context) const override { plugins::Options options_copy(options); handle_shrink_limit_options_defaults(options_copy, context); - return make_shared(options_copy); + return plugins::make_shared_from_args_tuple_and_args( + Heuristic::get_heuristic_parameters_from_options(options_copy), + options_copy.get>("merge_strategy"), + options_copy.get>("shrink_strategy"), + options_copy.get>("label_reduction"), + options_copy.get("max_states"), + options_copy.get("max_states_before_merge"), + options_copy.get("threshold_before_merge"), + options_copy.get("prune_unreachable_states"), + options_copy.get("prune_irrelevant_states"), + options_copy.get("main_loop_max_time") + ); } }; diff --git a/src/search/merge_and_shrink/merge_and_shrink_heuristic.h b/src/search/merge_and_shrink/merge_and_shrink_heuristic.h index 701c0144d7..c3d0e00f7c 100644 --- a/src/search/merge_and_shrink/merge_and_shrink_heuristic.h +++ b/src/search/merge_and_shrink/merge_and_shrink_heuristic.h @@ -1,6 +1,10 @@ #ifndef MERGE_AND_SHRINK_MERGE_AND_SHRINK_HEURISTIC_H #define MERGE_AND_SHRINK_MERGE_AND_SHRINK_HEURISTIC_H +#include "merge_strategy_factory.h" +#include "shrink_strategy.h" +#include "label_reduction.h" + #include "../heuristic.h" #include @@ -20,7 +24,21 @@ class MergeAndShrinkHeuristic : public Heuristic { protected: virtual int compute_heuristic(const State &ancestor_state) override; public: - explicit MergeAndShrinkHeuristic(const plugins::Options &opts); + MergeAndShrinkHeuristic( + const std::shared_ptr &merge_strategy, + const std::shared_ptr &shrink_strategy, + const std::shared_ptr &label_reduction, + int max_states, + int max_states_before_merge, + int threshold_before_merge, + bool prune_unreachable_states, + bool prune_irrelevant_states, + double main_loop_max_time, + const std::shared_ptr &transform, + bool cache_estimates, + const std::string &description, + utils::Verbosity verbosity + ); }; } diff --git a/src/search/merge_and_shrink/merge_scoring_function_single_random.h b/src/search/merge_and_shrink/merge_scoring_function_single_random.h index d3913bcb8f..285cf1fff5 100644 --- a/src/search/merge_and_shrink/merge_scoring_function_single_random.h +++ b/src/search/merge_and_shrink/merge_scoring_function_single_random.h @@ -5,10 +5,6 @@ #include -namespace plugins { -class Options; -} - namespace utils { class RandomNumberGenerator; } diff --git a/src/search/merge_and_shrink/merge_scoring_function_total_order.h b/src/search/merge_and_shrink/merge_scoring_function_total_order.h index 053af10ff9..158fe85ea4 100644 --- a/src/search/merge_and_shrink/merge_scoring_function_total_order.h +++ b/src/search/merge_and_shrink/merge_scoring_function_total_order.h @@ -6,7 +6,6 @@ #include namespace plugins { -class Options; class Feature; } diff --git a/src/search/merge_and_shrink/merge_selector_score_based_filtering.cc b/src/search/merge_and_shrink/merge_selector_score_based_filtering.cc index 772378a889..44e7fb19e8 100644 --- a/src/search/merge_and_shrink/merge_selector_score_based_filtering.cc +++ b/src/search/merge_and_shrink/merge_selector_score_based_filtering.cc @@ -11,10 +11,9 @@ using namespace std; namespace merge_and_shrink { MergeSelectorScoreBasedFiltering::MergeSelectorScoreBasedFiltering( - const plugins::Options &options) - : merge_scoring_functions( - options.get_list>( - "scoring_functions")) { + const vector> &scoring_functions + ) + : merge_scoring_functions(scoring_functions) { } static vector> get_remaining_candidates( @@ -117,6 +116,13 @@ class MergeSelectorScoreBasedFilteringFeature : public plugins::TypedFeature create_component(const plugins::Options &opts, const utils::Context &) const override { + return make_shared( + opts.get_list>( + "scoring_functions") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/merge_and_shrink/merge_selector_score_based_filtering.h b/src/search/merge_and_shrink/merge_selector_score_based_filtering.h index 71a1c3a885..7a4f173838 100644 --- a/src/search/merge_and_shrink/merge_selector_score_based_filtering.h +++ b/src/search/merge_and_shrink/merge_selector_score_based_filtering.h @@ -18,8 +18,9 @@ class MergeSelectorScoreBasedFiltering : public MergeSelector { virtual std::string name() const override; virtual void dump_selector_specific_options(utils::LogProxy &log) const override; public: - explicit MergeSelectorScoreBasedFiltering(const plugins::Options &options); - virtual ~MergeSelectorScoreBasedFiltering() override = default; + explicit MergeSelectorScoreBasedFiltering( + const std::vector> &scoring_functions + ); virtual std::pair select_merge( const FactoredTransitionSystem &fts, const std::vector &indices_subset = std::vector()) const override; diff --git a/src/search/merge_and_shrink/merge_strategy_factory.cc b/src/search/merge_and_shrink/merge_strategy_factory.cc index 6f72481614..4c04644676 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory.cc +++ b/src/search/merge_and_shrink/merge_strategy_factory.cc @@ -24,6 +24,11 @@ void add_merge_strategy_options_to_feature(plugins::Feature &feature) { utils::add_log_options_to_feature(feature); } +shared_ptr> get_merge_strategy_parameters_from_options(const plugins::Options &opts){ + return utils::get_log_parameters_from_options(opts); +} + + static class MergeStrategyFactoryCategoryPlugin : public plugins::TypedCategoryPlugin { public: MergeStrategyFactoryCategoryPlugin() : TypedCategoryPlugin("MergeStrategy") { diff --git a/src/search/merge_and_shrink/merge_strategy_factory.h b/src/search/merge_and_shrink/merge_strategy_factory.h index f1b1bd7b61..6bae465ae5 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory.h +++ b/src/search/merge_and_shrink/merge_strategy_factory.h @@ -25,7 +25,8 @@ class MergeStrategyFactory { virtual void dump_strategy_specific_options() const = 0; public: MergeStrategyFactory( - utils::Verbosity verbosity); + utils::Verbosity verbosity + ); virtual ~MergeStrategyFactory() = default; void dump_options() const; virtual std::unique_ptr compute_merge_strategy( @@ -36,6 +37,7 @@ class MergeStrategyFactory { }; extern void add_merge_strategy_options_to_feature(plugins::Feature &feature); +extern std::shared_ptr> get_merge_strategy_parameters_from_options(const plugins::Options &opts); } #endif diff --git a/src/search/merge_and_shrink/merge_strategy_factory_precomputed.cc b/src/search/merge_and_shrink/merge_strategy_factory_precomputed.cc index 4bf5381b64..553d026d03 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory_precomputed.cc +++ b/src/search/merge_and_shrink/merge_strategy_factory_precomputed.cc @@ -69,9 +69,10 @@ class MergeStrategyFactoryPrecomputedFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return make_shared( - opts.get>("merge_tree"), - opts.get("verbosity")); + return plugins::make_shared_from_args_tuple_and_args( + get_merge_strategy_parameters_from_options(opts), + opts.get>("merge_tree") + ); } }; diff --git a/src/search/merge_and_shrink/merge_strategy_factory_precomputed.h b/src/search/merge_and_shrink/merge_strategy_factory_precomputed.h index 4e5a308d3f..0897f80dfb 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory_precomputed.h +++ b/src/search/merge_and_shrink/merge_strategy_factory_precomputed.h @@ -14,7 +14,8 @@ class MergeStrategyFactoryPrecomputed : public MergeStrategyFactory { public: MergeStrategyFactoryPrecomputed( const std::shared_ptr &merge_tree, - utils::Verbosity verbosity); + utils::Verbosity verbosity + ); virtual std::unique_ptr compute_merge_strategy( const TaskProxy &task_proxy, const FactoredTransitionSystem &fts) override; diff --git a/src/search/merge_and_shrink/merge_strategy_factory_sccs.cc b/src/search/merge_and_shrink/merge_strategy_factory_sccs.cc index d16b925e70..018408d77c 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory_sccs.cc +++ b/src/search/merge_and_shrink/merge_strategy_factory_sccs.cc @@ -202,11 +202,12 @@ class MergeStrategyFactorySCCsFeature : public plugins::TypedFeature( + return plugins::make_shared_from_args_tuple_and_args( + get_merge_strategy_parameters_from_options(opts), opts.get("order_of_sccs"), - opts.get < shared_ptr < MergeTreeFactory >> ("merge_tree", nullptr), - opts.get < shared_ptr < MergeSelector >> ("merge_selector", nullptr), - opts.get("verbosity")); + opts.get> ("merge_tree", nullptr), + opts.get> ("merge_selector", nullptr) + ); } }; diff --git a/src/search/merge_and_shrink/merge_strategy_factory_stateless.cc b/src/search/merge_and_shrink/merge_strategy_factory_stateless.cc index 62a1508625..07c85b0694 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory_stateless.cc +++ b/src/search/merge_and_shrink/merge_strategy_factory_stateless.cc @@ -72,9 +72,10 @@ class MergeStrategyFactoryStatelessFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return make_shared( - opts.get>("merge_selector"), - opts.get("verbosity")); + return plugins::make_shared_from_args_tuple_and_args( + get_merge_strategy_parameters_from_options(opts), + opts.get>("merge_selector") + ); } };