diff --git a/src/search/CMakeLists.txt b/src/search/CMakeLists.txt index e9a8209a25..3ad4242129 100644 --- a/src/search/CMakeLists.txt +++ b/src/search/CMakeLists.txt @@ -146,6 +146,7 @@ create_fast_downward_library( utils/system_unix utils/system_windows utils/timer + utils/tuples CORE_LIBRARY ) # On Linux, find the rt library for clock_gettime(). diff --git a/src/search/evaluator.cc b/src/search/evaluator.cc index db63a23c9f..e06dad1835 100644 --- a/src/search/evaluator.cc +++ b/src/search/evaluator.cc @@ -100,13 +100,12 @@ void add_evaluator_options_to_feature(plugins::Feature &feature) { utils::add_log_options_to_feature(feature); } -shared_ptr> get_evaluator_parameters_from_options(const plugins::Options &opts) { - return make_shared>( - tuple_cat( +tuple get_evaluator_arguments_from_options( + const plugins::Options &opts) { + return tuple_cat( make_tuple(opts.get("description")), - *utils::get_log_parameters_from_options(opts) - ) - ); + utils::get_log_arguments_from_options(opts) + ); } static class EvaluatorCategoryPlugin : public plugins::TypedCategoryPlugin { diff --git a/src/search/evaluator.h b/src/search/evaluator.h index f098007fde..6f92749407 100644 --- a/src/search/evaluator.h +++ b/src/search/evaluator.h @@ -109,6 +109,6 @@ class Evaluator { extern void add_evaluator_options_to_feature(plugins::Feature &feature, const std::string &description); extern void add_evaluator_options_to_feature(plugins::Feature &feature); // TODO 1082 remove this, just keep the one above -extern std::shared_ptr> get_evaluator_parameters_from_options(const plugins::Options &opts); +extern std::tuple get_evaluator_arguments_from_options(const plugins::Options &opts); #endif diff --git a/src/search/heuristic.cc b/src/search/heuristic.cc index 70271e6283..50422ea1be 100644 --- a/src/search/heuristic.cc +++ b/src/search/heuristic.cc @@ -67,13 +67,14 @@ void Heuristic::add_options_to_feature(plugins::Feature &feature) { } -shared_ptr, bool, string, utils::Verbosity>> Heuristic::get_heuristic_parameters_from_options(const plugins::Options &opts) { - auto parent_parameter_tuple = get_evaluator_parameters_from_options(opts); - auto own_parameter_tuple = make_tuple( +tuple, bool, string, utils::Verbosity> +Heuristic::get_heuristic_arguments_from_options(const plugins::Options &opts) { + auto evaluator_args = get_evaluator_arguments_from_options(opts); + auto heuristic_args = make_tuple( opts.get>("transform"), opts.get("cache_estimates") ); - return make_shared, bool, string, utils::Verbosity>>(tuple_cat(own_parameter_tuple, *parent_parameter_tuple)); + return tuple_cat(heuristic_args, evaluator_args); } EvaluationResult Heuristic::compute_result(EvaluationContext &eval_context) { diff --git a/src/search/heuristic.h b/src/search/heuristic.h index 50c7d5e32f..c865394a7e 100644 --- a/src/search/heuristic.h +++ b/src/search/heuristic.h @@ -88,8 +88,8 @@ class Heuristic : public Evaluator { static void add_options_to_feature(plugins::Feature &feature, const std::string &description); static void add_options_to_feature(plugins::Feature &feature); // TODO 1082 remove this, just keep the one above - static std::shared_ptr, bool, std::string, utils::Verbosity>> - get_heuristic_parameters_from_options(const plugins::Options &opts); + static std::tuple, bool, std::string, utils::Verbosity> + get_heuristic_arguments_from_options(const plugins::Options &opts); virtual EvaluationResult compute_result( EvaluationContext &eval_context) override; diff --git a/src/search/heuristics/additive_heuristic.cc b/src/search/heuristics/additive_heuristic.cc index d1b109d267..92b4b3ae07 100644 --- a/src/search/heuristics/additive_heuristic.cc +++ b/src/search/heuristics/additive_heuristic.cc @@ -148,10 +148,6 @@ void AdditiveHeuristic::compute_heuristic_for_cegar(const State &state) { compute_heuristic(state); } -shared_ptr, bool, string, utils::Verbosity>> get_additive_heuristic_parameters_from_options(const plugins::Options &opts) { - return relaxation_heuristic::get_relaxation_heuristic_parameters_from_options(opts); -} - class AdditiveHeuristicFeature : public plugins::TypedFeature { public: AdditiveHeuristicFeature() : TypedFeature("add") { @@ -175,8 +171,8 @@ class AdditiveHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/additive_heuristic.h b/src/search/heuristics/additive_heuristic.h index 7b746384dc..79be262043 100644 --- a/src/search/heuristics/additive_heuristic.h +++ b/src/search/heuristics/additive_heuristic.h @@ -83,8 +83,6 @@ class AdditiveHeuristic : public relaxation_heuristic::RelaxationHeuristic { return get_proposition(var, value)->cost; } }; - -extern std::shared_ptr, bool, std::string, utils::Verbosity>> get_additive_heuristic_parameters_from_options(const plugins::Options &opts); } #endif diff --git a/src/search/heuristics/blind_search_heuristic.cc b/src/search/heuristics/blind_search_heuristic.cc index 98c04601ae..6e5c2360ad 100644 --- a/src/search/heuristics/blind_search_heuristic.cc +++ b/src/search/heuristics/blind_search_heuristic.cc @@ -54,8 +54,8 @@ class BlindSearchHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/cea_heuristic.cc b/src/search/heuristics/cea_heuristic.cc index df87832a0e..9b7c0a1144 100644 --- a/src/search/heuristics/cea_heuristic.cc +++ b/src/search/heuristics/cea_heuristic.cc @@ -469,8 +469,8 @@ class ContextEnhancedAdditiveHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/cg_heuristic.cc b/src/search/heuristics/cg_heuristic.cc index 400dafc5e3..f5757a2684 100644 --- a/src/search/heuristics/cg_heuristic.cc +++ b/src/search/heuristics/cg_heuristic.cc @@ -314,9 +314,9 @@ class CGHeuristicFeature : public plugins::TypedFeature virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts), - opts.get("max_cache_size") + return plugins::make_shared_from_arg_tuples( + opts.get("max_cache_size"), + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/ff_heuristic.cc b/src/search/heuristics/ff_heuristic.cc index 5307204c3b..7066da76e9 100644 --- a/src/search/heuristics/ff_heuristic.cc +++ b/src/search/heuristics/ff_heuristic.cc @@ -96,8 +96,8 @@ class FFHeuristicFeature : public plugins::TypedFeature virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - additive_heuristic::get_additive_heuristic_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/goal_count_heuristic.cc b/src/search/heuristics/goal_count_heuristic.cc index 9f5c08ec2e..199181c5b6 100644 --- a/src/search/heuristics/goal_count_heuristic.cc +++ b/src/search/heuristics/goal_count_heuristic.cc @@ -51,8 +51,8 @@ class GoalCountHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/hm_heuristic.cc b/src/search/heuristics/hm_heuristic.cc index 153af77fe5..462d50bc9b 100644 --- a/src/search/heuristics/hm_heuristic.cc +++ b/src/search/heuristics/hm_heuristic.cc @@ -293,9 +293,9 @@ class HMHeuristicFeature : public plugins::TypedFeature } virtual shared_ptr create_component(const plugins::Options &options, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(options), - options.get("m") + return plugins::make_shared_from_arg_tuples( + options.get("m"), + Heuristic::get_heuristic_arguments_from_options(options) ); } }; diff --git a/src/search/heuristics/lm_cut_heuristic.cc b/src/search/heuristics/lm_cut_heuristic.cc index 4cdb153a31..0724fe3c88 100644 --- a/src/search/heuristics/lm_cut_heuristic.cc +++ b/src/search/heuristics/lm_cut_heuristic.cc @@ -58,8 +58,8 @@ class LandmarkCutHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/heuristics/max_heuristic.cc b/src/search/heuristics/max_heuristic.cc index b6073efcfb..304ab8b00b 100644 --- a/src/search/heuristics/max_heuristic.cc +++ b/src/search/heuristics/max_heuristic.cc @@ -125,8 +125,8 @@ class HSPMaxHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - relaxation_heuristic::get_relaxation_heuristic_parameters_from_options(opts)); + return plugins::make_shared_from_arg_tuples( + Heuristic::get_heuristic_arguments_from_options(opts)); } }; diff --git a/src/search/heuristics/relaxation_heuristic.cc b/src/search/heuristics/relaxation_heuristic.cc index 4cb1501cfd..f4353b4bc0 100644 --- a/src/search/heuristics/relaxation_heuristic.cc +++ b/src/search/heuristics/relaxation_heuristic.cc @@ -305,8 +305,4 @@ void RelaxationHeuristic::simplify() { log << " done! [" << unary_operators.size() << " unary operators]" << endl; } } - -shared_ptr, bool, string, utils::Verbosity>> get_relaxation_heuristic_parameters_from_options(const plugins::Options &opts) { - return Heuristic::get_heuristic_parameters_from_options(opts); -} } diff --git a/src/search/heuristics/relaxation_heuristic.h b/src/search/heuristics/relaxation_heuristic.h index 197c081e70..4f41497cc6 100644 --- a/src/search/heuristics/relaxation_heuristic.h +++ b/src/search/heuristics/relaxation_heuristic.h @@ -118,8 +118,6 @@ class RelaxationHeuristic : public Heuristic { virtual bool dead_ends_are_reliable() const override; }; - -std::shared_ptr, bool, std::string, utils::Verbosity>> get_relaxation_heuristic_parameters_from_options(const plugins::Options &opts); } #endif diff --git a/src/search/lp/lp_solver.cc b/src/search/lp/lp_solver.cc index 9f34d3d520..eab0a7ca82 100644 --- a/src/search/lp/lp_solver.cc +++ b/src/search/lp/lp_solver.cc @@ -24,6 +24,12 @@ void add_lp_solver_option_to_feature(plugins::Feature &feature) { "See [build instructions https://github.com/aibasel/downward/blob/main/BUILD.md]."); } +tuple get_lp_solver_arguments_from_options( + const plugins::Options &opts) { + return make_tuple(opts.get("lpsolver")); + +} + LPConstraint::LPConstraint(double lower_bound, double upper_bound) : lower_bound(lower_bound), upper_bound(upper_bound) { diff --git a/src/search/lp/lp_solver.h b/src/search/lp/lp_solver.h index a9bdff8c0a..59693ffeab 100644 --- a/src/search/lp/lp_solver.h +++ b/src/search/lp/lp_solver.h @@ -12,6 +12,7 @@ namespace plugins { class Feature; +class Options; } namespace lp { @@ -24,6 +25,8 @@ enum class LPObjectiveSense { }; void add_lp_solver_option_to_feature(plugins::Feature &feature); +std::tuple get_lp_solver_arguments_from_options( + const plugins::Options &opts); class LinearProgram; 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 6952aea77e..5735c18698 100644 --- a/src/search/merge_and_shrink/merge_and_shrink_heuristic.cc +++ b/src/search/merge_and_shrink/merge_and_shrink_heuristic.cc @@ -255,8 +255,7 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature( - Heuristic::get_heuristic_parameters_from_options(options_copy), + return plugins::make_shared_from_arg_tuples( options_copy.get>("merge_strategy"), options_copy.get>("shrink_strategy"), options_copy.get>("label_reduction", nullptr), @@ -265,7 +264,8 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature("threshold_before_merge"), options_copy.get("prune_unreachable_states"), options_copy.get("prune_irrelevant_states"), - options_copy.get("main_loop_max_time") + options_copy.get("main_loop_max_time"), + Heuristic::get_heuristic_arguments_from_options(options_copy) ); } }; diff --git a/src/search/merge_and_shrink/merge_strategy_factory.cc b/src/search/merge_and_shrink/merge_strategy_factory.cc index 4954f5fa95..11f96a3115 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory.cc +++ b/src/search/merge_and_shrink/merge_strategy_factory.cc @@ -24,8 +24,9 @@ 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); +tuple get_merge_strategy_arguments_from_options( + const plugins::Options &opts) { + return utils::get_log_arguments_from_options(opts); } diff --git a/src/search/merge_and_shrink/merge_strategy_factory.h b/src/search/merge_and_shrink/merge_strategy_factory.h index a47ac90bbb..1d54947448 100644 --- a/src/search/merge_and_shrink/merge_strategy_factory.h +++ b/src/search/merge_and_shrink/merge_strategy_factory.h @@ -36,7 +36,8 @@ 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); +extern std::tuple get_merge_strategy_arguments_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 1aca76ab7c..9b9cc2a436 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,9 @@ class MergeStrategyFactoryPrecomputedFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_merge_strategy_parameters_from_options(opts), - opts.get>("merge_tree") + return plugins::make_shared_from_arg_tuples( + opts.get>("merge_tree"), + get_merge_strategy_arguments_from_options(opts) ); } }; 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 1abe0a81bc..2e617a750f 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,11 @@ class MergeStrategyFactorySCCsFeature : public plugins::TypedFeature( - get_merge_strategy_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( opts.get("order_of_sccs"), opts.get> ("merge_tree", nullptr), - opts.get> ("merge_selector", nullptr) + opts.get> ("merge_selector", nullptr), + get_merge_strategy_arguments_from_options(opts) ); } }; 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 09164a077b..3905bf4050 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,9 @@ class MergeStrategyFactoryStatelessFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_merge_strategy_parameters_from_options(opts), - opts.get>("merge_selector") + return plugins::make_shared_from_arg_tuples( + opts.get>("merge_selector"), + get_merge_strategy_arguments_from_options(opts) ); } }; diff --git a/src/search/merge_and_shrink/merge_tree_factory.cc b/src/search/merge_and_shrink/merge_tree_factory.cc index 7d9293a163..6a6f552fc4 100644 --- a/src/search/merge_and_shrink/merge_tree_factory.cc +++ b/src/search/merge_and_shrink/merge_tree_factory.cc @@ -58,13 +58,11 @@ void MergeTreeFactory::add_options_to_feature(plugins::Feature &feature) { "use_random"); } -shared_ptr> get_merge_tree_parameters_from_options(const plugins::Options &opts) { - return make_shared>( - make_tuple( +tuple get_merge_tree_arguments_from_options(const plugins::Options &opts) { + return make_tuple( opts.get("random_seed"), opts.get("update_option") - ) - ); + ); } static class MergeTreeFactoryCategoryPlugin : public plugins::TypedCategoryPlugin { diff --git a/src/search/merge_and_shrink/merge_tree_factory.h b/src/search/merge_and_shrink/merge_tree_factory.h index 296dce8c1f..50bb205d57 100644 --- a/src/search/merge_and_shrink/merge_tree_factory.h +++ b/src/search/merge_and_shrink/merge_tree_factory.h @@ -51,7 +51,8 @@ class MergeTreeFactory { static void add_options_to_feature(plugins::Feature &feature); }; -extern std::shared_ptr> get_merge_tree_parameters_from_options(const plugins::Options &opts); +extern std::tuple get_merge_tree_arguments_from_options( + const plugins::Options &opts); } #endif diff --git a/src/search/merge_and_shrink/merge_tree_factory_linear.cc b/src/search/merge_and_shrink/merge_tree_factory_linear.cc index 9e48e51e69..9cde166a21 100644 --- a/src/search/merge_and_shrink/merge_tree_factory_linear.cc +++ b/src/search/merge_and_shrink/merge_tree_factory_linear.cc @@ -139,9 +139,9 @@ class MergeTreeFactoryLinearFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_merge_tree_parameters_from_options(opts), - opts.get("variable_order") + return plugins::make_shared_from_arg_tuples( + opts.get("variable_order"), + get_merge_tree_arguments_from_options(opts) ); } }; diff --git a/src/search/merge_and_shrink/shrink_bucket_based.cc b/src/search/merge_and_shrink/shrink_bucket_based.cc index 5fbd931f74..49ec490237 100644 --- a/src/search/merge_and_shrink/shrink_bucket_based.cc +++ b/src/search/merge_and_shrink/shrink_bucket_based.cc @@ -101,7 +101,7 @@ StateEquivalenceRelation ShrinkBucketBased::compute_equivalence_relation( return compute_abstraction(buckets, target_size, log); } -shared_ptr> get_shrink_bucket_parameters_from_options(const plugins::Options &opts) { - return make_shared>(make_tuple(opts.get("random_seed"))); +tuple get_shrink_bucket_arguments_from_options(const plugins::Options &opts) { + return make_tuple(opts.get("random_seed")); } } diff --git a/src/search/merge_and_shrink/shrink_bucket_based.h b/src/search/merge_and_shrink/shrink_bucket_based.h index 1284cf6c6b..30477033c9 100644 --- a/src/search/merge_and_shrink/shrink_bucket_based.h +++ b/src/search/merge_and_shrink/shrink_bucket_based.h @@ -60,7 +60,7 @@ class ShrinkBucketBased : public ShrinkStrategy { static void add_options_to_feature(plugins::Feature &feature); }; -extern std::shared_ptr> get_shrink_bucket_parameters_from_options(const plugins::Options &opts); +extern std::tuple get_shrink_bucket_arguments_from_options(const plugins::Options &opts); } #endif diff --git a/src/search/merge_and_shrink/shrink_fh.cc b/src/search/merge_and_shrink/shrink_fh.cc index 6239f37d46..286fbe0762 100644 --- a/src/search/merge_and_shrink/shrink_fh.cc +++ b/src/search/merge_and_shrink/shrink_fh.cc @@ -249,10 +249,10 @@ class ShrinkFHFeature : public plugins::TypedFeature { virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_shrink_bucket_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( opts.get("shrink_f"), - opts.get("shrink_h") + opts.get("shrink_h"), + get_shrink_bucket_arguments_from_options(opts) ); } }; diff --git a/src/search/merge_and_shrink/shrink_random.cc b/src/search/merge_and_shrink/shrink_random.cc index 383bc916f6..abf89f8929 100644 --- a/src/search/merge_and_shrink/shrink_random.cc +++ b/src/search/merge_and_shrink/shrink_random.cc @@ -46,8 +46,8 @@ class ShrinkRandomFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_shrink_bucket_parameters_from_options(opts) + return plugins::make_shared_from_arg_tuples( + get_shrink_bucket_arguments_from_options(opts) ); } }; diff --git a/src/search/operator_counting/operator_counting_heuristic.cc b/src/search/operator_counting/operator_counting_heuristic.cc index 05fa85d698..d5feb3329e 100644 --- a/src/search/operator_counting/operator_counting_heuristic.cc +++ b/src/search/operator_counting/operator_counting_heuristic.cc @@ -10,12 +10,18 @@ using namespace std; namespace operator_counting { -OperatorCountingHeuristic::OperatorCountingHeuristic(const plugins::Options &opts) - : Heuristic(opts), - constraint_generators( - opts.get_list>("constraint_generators")), - lp_solver(opts.get("lpsolver")), - use_integer_operator_counts(opts.get("use_integer_operator_counts")) { +OperatorCountingHeuristic::OperatorCountingHeuristic( + const vector> &constraint_generators, + bool use_integer_operator_counts, + lp::LPSolverType lp_solver_type, + const shared_ptr &transform, + bool cache_estimates, + const string &description, + utils::Verbosity verbosity) + : Heuristic(transform, cache_estimates, description, verbosity), + constraint_generators(constraint_generators), + use_integer_operator_counts(use_integer_operator_counts), + lp_solver(lp_solver_type) { lp_solver.set_mip_gap(0); named_vector::NamedVector variables; double infinity = lp_solver.get_infinity(); @@ -30,9 +36,6 @@ OperatorCountingHeuristic::OperatorCountingHeuristic(const plugins::Options &opt lp_solver.load_problem(lp); } -OperatorCountingHeuristic::~OperatorCountingHeuristic() { -} - int OperatorCountingHeuristic::compute_heuristic(const State &ancestor_state) { State state = convert_ancestor_state(ancestor_state); assert(!lp_solver.has_temporary_constraints()); @@ -91,7 +94,7 @@ class OperatorCountingHeuristicFeature : public plugins::TypedFeature create_component(const plugins::Options &options, const utils::Context &context) const override { plugins::verify_list_non_empty>( context, options, "constraint_generators"); - return make_shared(options); + return plugins::make_shared_from_arg_tuples( + options.get_list>("constraint_generators"), + options.get("use_integer_operator_counts"), + lp::get_lp_solver_arguments_from_options(options), + Heuristic::get_heuristic_arguments_from_options(options) + ); } }; diff --git a/src/search/operator_counting/operator_counting_heuristic.h b/src/search/operator_counting/operator_counting_heuristic.h index ff0b326039..d7fdea3825 100644 --- a/src/search/operator_counting/operator_counting_heuristic.h +++ b/src/search/operator_counting/operator_counting_heuristic.h @@ -17,13 +17,19 @@ class ConstraintGenerator; class OperatorCountingHeuristic : public Heuristic { std::vector> constraint_generators; - lp::LPSolver lp_solver; const bool use_integer_operator_counts; + lp::LPSolver lp_solver; protected: virtual int compute_heuristic(const State &ancestor_state) override; public: - explicit OperatorCountingHeuristic(const plugins::Options &opts); - ~OperatorCountingHeuristic(); + OperatorCountingHeuristic( + const std::vector> &constraint_generators, + bool use_integer_operator_counts, + lp::LPSolverType lp_solver, + const std::shared_ptr &transform, + bool cache_estimates, + const std::string &description, + utils::Verbosity verbosity); }; } diff --git a/src/search/pdbs/canonical_pdbs_heuristic.cc b/src/search/pdbs/canonical_pdbs_heuristic.cc index 587173cf1c..721930a95e 100644 --- a/src/search/pdbs/canonical_pdbs_heuristic.cc +++ b/src/search/pdbs/canonical_pdbs_heuristic.cc @@ -125,10 +125,10 @@ class CanonicalPDBsHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( opts.get>("patterns"), - opts.get("max_time_dominance_pruning") + opts.get("max_time_dominance_pruning"), + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_combo.cc b/src/search/pdbs/pattern_collection_generator_combo.cc index 5e3402b9ca..2ecd07ca6c 100644 --- a/src/search/pdbs/pattern_collection_generator_combo.cc +++ b/src/search/pdbs/pattern_collection_generator_combo.cc @@ -63,9 +63,9 @@ class PatternCollectionGeneratorComboFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), - opts.get("max_states") + return plugins::make_shared_from_arg_tuples( + opts.get("max_states"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc b/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc index d8bde885b8..e0f87834e0 100644 --- a/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc +++ b/src/search/pdbs/pattern_collection_generator_disjoint_cegar.cc @@ -88,13 +88,13 @@ class PatternCollectionGeneratorDisjointCegarFeature : public plugins::TypedFeat virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( 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("random_seed"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_genetic.cc b/src/search/pdbs/pattern_collection_generator_genetic.cc index 86700c77bf..33437165f3 100644 --- a/src/search/pdbs/pattern_collection_generator_genetic.cc +++ b/src/search/pdbs/pattern_collection_generator_genetic.cc @@ -396,14 +396,14 @@ class PatternCollectionGeneratorGeneticFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( 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("random_seed"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_hillclimbing.cc b/src/search/pdbs/pattern_collection_generator_hillclimbing.cc index 38bc127c29..ec1d205be6 100644 --- a/src/search/pdbs/pattern_collection_generator_hillclimbing.cc +++ b/src/search/pdbs/pattern_collection_generator_hillclimbing.cc @@ -664,20 +664,20 @@ class IPDBFeature : public plugins::TypedFeature pgh = - plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), + plugins::make_shared_from_arg_tuples( 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("random_seed"), + get_generator_arguments_from_options(opts) ); - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( pgh, - opts.get("max_time_dominance_pruning") + opts.get("max_time_dominance_pruning"), + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_manual.cc b/src/search/pdbs/pattern_collection_generator_manual.cc index dfda393cf4..6648bee58d 100644 --- a/src/search/pdbs/pattern_collection_generator_manual.cc +++ b/src/search/pdbs/pattern_collection_generator_manual.cc @@ -44,9 +44,9 @@ class PatternCollectionGeneratorManualFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), - opts.get_list("patterns") + return plugins::make_shared_from_arg_tuples( + opts.get_list("patterns"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_multiple.cc b/src/search/pdbs/pattern_collection_generator_multiple.cc index f73e4f5349..1255857e0e 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple.cc +++ b/src/search/pdbs/pattern_collection_generator_multiple.cc @@ -334,18 +334,10 @@ void add_multiple_options_to_feature(plugins::Feature &feature) { add_generator_options_to_feature(feature); } -shared_ptr> get_patter_collection_generators_parameters_from_options(const plugins::Options &opts) { - auto parent = get_generator_parameters_from_options(opts); - tuple own_parameter_tuple = make_tuple( +tuple + get_multiple_arguments_from_options(const plugins::Options &opts) { + auto generator_args = get_generator_arguments_from_options(opts); + tuple multiple_args = make_tuple( opts.get("max_pdb_size"), opts.get("max_collection_size"), opts.get("pattern_generation_max_time"), @@ -355,15 +347,6 @@ shared_ptr("enable_blacklist_on_stagnation"), opts.get("random_seed") ); - return make_shared>(tuple_cat(own_parameter_tuple, *parent)); + return tuple_cat(multiple_args, generator_args); } } diff --git a/src/search/pdbs/pattern_collection_generator_multiple.h b/src/search/pdbs/pattern_collection_generator_multiple.h index 01fa84a248..dd4a0be848 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple.h +++ b/src/search/pdbs/pattern_collection_generator_multiple.h @@ -89,16 +89,8 @@ extern void add_multiple_algorithm_implementation_notes_to_feature( extern void add_multiple_options_to_feature( plugins::Feature &feature); -extern std::shared_ptr> get_patter_collection_generators_parameters_from_options(const plugins::Options &opts); +extern std::tuple + get_multiple_arguments_from_options(const plugins::Options &opts); } #endif diff --git a/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc b/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc index b81b65e089..fe5f982cd0 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc +++ b/src/search/pdbs/pattern_collection_generator_multiple_cegar.cc @@ -78,9 +78,9 @@ class PatternCollectionGeneratorMultipleCegarFeature : public plugins::TypedFeat virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_patter_collection_generators_parameters_from_options(opts), - opts.get("use_wildcard_plans") + return plugins::make_shared_from_arg_tuples( + opts.get("use_wildcard_plans"), + get_multiple_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_multiple_random.cc b/src/search/pdbs/pattern_collection_generator_multiple_random.cc index c66976dcce..96de830e66 100644 --- a/src/search/pdbs/pattern_collection_generator_multiple_random.cc +++ b/src/search/pdbs/pattern_collection_generator_multiple_random.cc @@ -91,9 +91,9 @@ class PatternCollectionGeneratorMultipleRandomFeature : public plugins::TypedFea virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_patter_collection_generators_parameters_from_options(opts), - opts.get("bidirectional") + return plugins::make_shared_from_arg_tuples( + opts.get("bidirectional"), + get_multiple_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_collection_generator_systematic.cc b/src/search/pdbs/pattern_collection_generator_systematic.cc index 3b47523107..6ac9800392 100644 --- a/src/search/pdbs/pattern_collection_generator_systematic.cc +++ b/src/search/pdbs/pattern_collection_generator_systematic.cc @@ -318,10 +318,10 @@ class PatternCollectionGeneratorSystematicFeature : public plugins::TypedFeature virtual shared_ptr create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( opts.get("pattern_max_size"), - opts.get("only_interesting_patterns") + opts.get("only_interesting_patterns"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_generator.cc b/src/search/pdbs/pattern_generator.cc index 6f78a6a9ff..160dec1e1a 100644 --- a/src/search/pdbs/pattern_generator.cc +++ b/src/search/pdbs/pattern_generator.cc @@ -48,8 +48,8 @@ void add_generator_options_to_feature(plugins::Feature &feature) { utils::add_log_options_to_feature(feature); } -shared_ptr> get_generator_parameters_from_options(const plugins::Options &opts) { - return utils::get_log_parameters_from_options(opts); +tuple get_generator_arguments_from_options(const plugins::Options &opts) { + return utils::get_log_arguments_from_options(opts); } static class PatternCollectionGeneratorCategoryPlugin : public plugins::TypedCategoryPlugin { diff --git a/src/search/pdbs/pattern_generator.h b/src/search/pdbs/pattern_generator.h index 3c63728c38..c30e85c046 100644 --- a/src/search/pdbs/pattern_generator.h +++ b/src/search/pdbs/pattern_generator.h @@ -51,7 +51,7 @@ class PatternGenerator { }; extern void add_generator_options_to_feature(plugins::Feature &feature); -extern std::shared_ptr> get_generator_parameters_from_options(const plugins::Options &opts); +extern std::tuple get_generator_arguments_from_options(const plugins::Options &opts); } #endif diff --git a/src/search/pdbs/pattern_generator_cegar.cc b/src/search/pdbs/pattern_generator_cegar.cc index ad2be2127a..7acde339cc 100644 --- a/src/search/pdbs/pattern_generator_cegar.cc +++ b/src/search/pdbs/pattern_generator_cegar.cc @@ -78,12 +78,12 @@ class PatternGeneratorCEGARFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( opts.get("max_pdb_size"), opts.get("max_time"), opts.get("use_wildcard_plans"), - opts.get("random_seed") + opts.get("random_seed"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_generator_greedy.cc b/src/search/pdbs/pattern_generator_greedy.cc index 4579d76716..63479d3c55 100644 --- a/src/search/pdbs/pattern_generator_greedy.cc +++ b/src/search/pdbs/pattern_generator_greedy.cc @@ -65,9 +65,9 @@ class PatternGeneratorGreedyFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), - opts.get("max_states") + return plugins::make_shared_from_arg_tuples( + opts.get("max_states"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_generator_manual.cc b/src/search/pdbs/pattern_generator_manual.cc index e8ca40f670..c5043b750e 100644 --- a/src/search/pdbs/pattern_generator_manual.cc +++ b/src/search/pdbs/pattern_generator_manual.cc @@ -44,9 +44,9 @@ class PatternGeneratorManualFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), - opts.get_list("pattern") + return plugins::make_shared_from_arg_tuples( + opts.get_list("pattern"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pattern_generator_random.cc b/src/search/pdbs/pattern_generator_random.cc index bb50e03cf0..cfdfd2c505 100644 --- a/src/search/pdbs/pattern_generator_random.cc +++ b/src/search/pdbs/pattern_generator_random.cc @@ -83,12 +83,12 @@ class PatternGeneratorRandomFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - get_generator_parameters_from_options(opts), + return plugins::make_shared_from_arg_tuples( opts.get("max_pdb_size"), opts.get("max_time"), opts.get("bidirectional"), - opts.get("random_seed") + opts.get("random_seed"), + get_generator_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/pdb_heuristic.cc b/src/search/pdbs/pdb_heuristic.cc index fa9b614295..5a37f42fa0 100644 --- a/src/search/pdbs/pdb_heuristic.cc +++ b/src/search/pdbs/pdb_heuristic.cc @@ -60,9 +60,9 @@ class PDBHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts), - opts.get>("pattern") + return plugins::make_shared_from_arg_tuples( + opts.get>("pattern"), + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/pdbs/zero_one_pdbs_heuristic.cc b/src/search/pdbs/zero_one_pdbs_heuristic.cc index d8cfc36388..187ab009c8 100644 --- a/src/search/pdbs/zero_one_pdbs_heuristic.cc +++ b/src/search/pdbs/zero_one_pdbs_heuristic.cc @@ -70,9 +70,9 @@ class ZeroOnePDBsHeuristicFeature : public plugins::TypedFeature create_component( const plugins::Options &opts, const utils::Context &) const override { - return plugins::make_shared_from_args_tuple_and_args( - Heuristic::get_heuristic_parameters_from_options(opts), - opts.get>("patterns") + return plugins::make_shared_from_arg_tuples( + opts.get>("patterns"), + Heuristic::get_heuristic_arguments_from_options(opts) ); } }; diff --git a/src/search/plugins/plugin.h b/src/search/plugins/plugin.h index 7f06ecc686..deaf29f304 100644 --- a/src/search/plugins/plugin.h +++ b/src/search/plugins/plugin.h @@ -8,6 +8,7 @@ #include "../utils/strings.h" #include "../utils/system.h" +#include "../utils/tuples.h" #include #include @@ -115,17 +116,19 @@ class TypedFeature : public FeatureAuto { } }; -// Treats first parameter as pointer to a tuple of arguments for the base class, -// the rest as singleton arguments for the class T. +/* + Expects constructor arguments of T. Consecutive arguments may be grouped in a + tuple. All tuples in the arguments will be flattened before calling the + constructor. The resulting arguments will be used as arguments to make_shared. +*/ // TODO issue1082 where should this live? optimize with std::forward? -// Apply the arguments extracted from *parameter_tuple* to make_shared -template -std::shared_ptr make_shared_from_args_tuple_and_args(ParentTuple parent_tuple, ChildSingletons ... child_singletons) { - return std::apply([](auto ... args) { - return std::make_shared(args ...); - }, - std::tuple_cat(std::make_tuple(child_singletons ...), *parent_tuple) - ); +template +std::shared_ptr make_shared_from_arg_tuples(Arguments...arguments) { + return std::apply( + [](auto...flattened_args) { + return std::make_shared(flattened_args...); + }, + utils::flatten_tuple(std::tuple(arguments...))); } class Plugin { diff --git a/src/search/utils/logging.cc b/src/search/utils/logging.cc index 9ff686f91b..aa8cfe1077 100644 --- a/src/search/utils/logging.cc +++ b/src/search/utils/logging.cc @@ -30,14 +30,11 @@ void add_log_options_to_feature(plugins::Feature &feature) { "normal"); } - -shared_ptr> get_log_parameters_from_options(const plugins::Options &opts) { +tuple get_log_arguments_from_options(const plugins::Options &opts) { auto own_tuple = make_tuple(opts.get("verbosity")); - return make_shared>(own_tuple); + return tuple(own_tuple); } - - LogProxy get_log_for_verbosity(const Verbosity &verbosity) { if (verbosity == Verbosity::NORMAL) { return LogProxy(global_log); diff --git a/src/search/utils/logging.h b/src/search/utils/logging.h index da11c4c6ec..7f2c0605dd 100644 --- a/src/search/utils/logging.h +++ b/src/search/utils/logging.h @@ -131,7 +131,7 @@ extern LogProxy g_log; extern void add_log_options_to_feature(plugins::Feature &feature); -extern std::shared_ptr> get_log_parameters_from_options(const plugins::Options &opts); +extern std::tuple get_log_arguments_from_options(const plugins::Options &opts); diff --git a/src/search/utils/tuples.h b/src/search/utils/tuples.h new file mode 100644 index 0000000000..a4271bcf56 --- /dev/null +++ b/src/search/utils/tuples.h @@ -0,0 +1,76 @@ +#ifndef UTILS_TUPLES_H +#define UTILS_TUPLES_H + +#include + +/* + Tuple flattening code is taken from https://stackoverflow.com/a/32168028 + (We could probably simplify this a lot if we assume tuple elements will all be + cheap to copy.) +*/ + +namespace utils { +template +struct wrapper { + T* ptr; + wrapper(T& t) : ptr(std::addressof(t)) {} + + using unwrapped_type = + std::conditional_t{}, T&, T&&>, + std::conditional_t{}, T&&, T&>>; + using tuple_element_type = U; + + unwrapped_type unwrap() const{ + return std::forward(*ptr); + } +}; + +template +auto unwrap_tuple(const std::tuple& t, std::index_sequence) { + return std::tuple(std::get(t).unwrap()...); +} + +template +auto unwrap_tuple(const std::tuple& t) { + return unwrap_tuple(t, std::index_sequence_for()); +} + +template +auto wrap_and_flatten(T& t, char){ + return std::make_tuple(wrapper(t)); +} +template struct is_tuple : std::false_type {}; +template struct is_tuple> : std::true_type {}; +template struct is_tuple : is_tuple {}; +template struct is_tuple : is_tuple {}; + +template>{}>> +auto wrap_and_flatten(Tuple& t, int); + +template +auto wrap_and_flatten(Tuple& t, std::index_sequence) { + return std::tuple_cat(wrap_and_flatten>>(std::get(t), 0)...); +} + +template +auto wrap_and_flatten(Tuple& t, int) { + using seq_type = std::make_index_sequence{}>; + return wrap_and_flatten(t, seq_type()); +} + +template +auto wrap_and_flatten_tuple(Tuple&& t){ + constexpr bool can_move = !std::is_lvalue_reference{}; + using seq_type = std::make_index_sequence>{}>; + return wrap_and_flatten(t, seq_type()); +} + +template +auto flatten_tuple(T&& t) { + return unwrap_tuple(wrap_and_flatten_tuple(std::forward(t))); +} +} + +#endif