From 1ce8c7a715b1a3a94e7afc4160a8af8149a740b3 Mon Sep 17 00:00:00 2001 From: Simon Dold Date: Thu, 15 Feb 2024 13:15:02 +0100 Subject: [PATCH] remove ByOpts-Constructors, reduce copies. --- src/search/evaluators/combining_evaluator.cc | 10 +------ src/search/evaluators/combining_evaluator.h | 3 +- src/search/evaluators/const_evaluator.cc | 3 -- src/search/evaluators/const_evaluator.h | 1 - src/search/evaluators/g_evaluator.cc | 3 -- src/search/evaluators/g_evaluator.h | 1 - src/search/evaluators/max_evaluator.cc | 5 +--- src/search/evaluators/max_evaluator.h | 3 +- src/search/evaluators/pref_evaluator.cc | 4 --- src/search/evaluators/pref_evaluator.h | 1 - src/search/evaluators/sum_evaluator.cc | 5 +--- src/search/evaluators/sum_evaluator.h | 3 +- src/search/evaluators/weighted_evaluator.cc | 7 +---- src/search/evaluators/weighted_evaluator.h | 3 +- .../enforced_hill_climbing_search.cc | 10 ++----- src/search/search_algorithms/search_common.cc | 28 ++++--------------- 16 files changed, 15 insertions(+), 75 deletions(-) diff --git a/src/search/evaluators/combining_evaluator.cc b/src/search/evaluators/combining_evaluator.cc index d517b83aba..6d1acc3f56 100644 --- a/src/search/evaluators/combining_evaluator.cc +++ b/src/search/evaluators/combining_evaluator.cc @@ -8,16 +8,8 @@ using namespace std; namespace combining_evaluator { -CombiningEvaluator::CombiningEvaluator(const plugins::Options &opts) - : Evaluator(opts), - subevaluators(opts.get_list>("evals")) { - all_dead_ends_are_reliable = true; - for (const shared_ptr &subevaluator : subevaluators) - if (!subevaluator->dead_ends_are_reliable()) - all_dead_ends_are_reliable = false; -} CombiningEvaluator::CombiningEvaluator( - vector> evals, + const vector> &evals, bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/combining_evaluator.h b/src/search/evaluators/combining_evaluator.h index 7ce25b7ae3..e411099989 100644 --- a/src/search/evaluators/combining_evaluator.h +++ b/src/search/evaluators/combining_evaluator.h @@ -19,9 +19,8 @@ class CombiningEvaluator : public Evaluator { protected: virtual int combine_values(const std::vector &values) = 0; public: - explicit CombiningEvaluator(const plugins::Options &opts); // TODO issue1082: remove this CombiningEvaluator( - std::vector> evals, + const std::vector> &evals, bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/const_evaluator.cc b/src/search/evaluators/const_evaluator.cc index d4c1eb6433..9ad9f29631 100644 --- a/src/search/evaluators/const_evaluator.cc +++ b/src/search/evaluators/const_evaluator.cc @@ -5,9 +5,6 @@ using namespace std; namespace const_evaluator { -ConstEvaluator::ConstEvaluator(const plugins::Options &opts) - : Evaluator(opts), value(opts.get("value")) { -} ConstEvaluator::ConstEvaluator( int value, bool use_for_reporting_minima, diff --git a/src/search/evaluators/const_evaluator.h b/src/search/evaluators/const_evaluator.h index c5c607d845..75755c64c6 100644 --- a/src/search/evaluators/const_evaluator.h +++ b/src/search/evaluators/const_evaluator.h @@ -16,7 +16,6 @@ class ConstEvaluator : public Evaluator { EvaluationContext &eval_context) override; public: - explicit ConstEvaluator(const plugins::Options &opts); // TODO issue1082: remove this ConstEvaluator( int value, bool use_for_reporting_minima, diff --git a/src/search/evaluators/g_evaluator.cc b/src/search/evaluators/g_evaluator.cc index c4c823f511..fa7b62f92d 100644 --- a/src/search/evaluators/g_evaluator.cc +++ b/src/search/evaluators/g_evaluator.cc @@ -7,9 +7,6 @@ using namespace std; namespace g_evaluator { -GEvaluator::GEvaluator(const plugins::Options &opts) - : Evaluator(opts) { -} GEvaluator::GEvaluator(bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/g_evaluator.h b/src/search/evaluators/g_evaluator.h index f2177549c6..d82aa4fddd 100644 --- a/src/search/evaluators/g_evaluator.h +++ b/src/search/evaluators/g_evaluator.h @@ -6,7 +6,6 @@ namespace g_evaluator { class GEvaluator : public Evaluator { public: - explicit GEvaluator(const plugins::Options &opts); // TODO issue1082: remove this GEvaluator( bool use_for_reporting_minima, bool use_for_boosting, diff --git a/src/search/evaluators/max_evaluator.cc b/src/search/evaluators/max_evaluator.cc index 4fd95274e6..0ebde36bcd 100644 --- a/src/search/evaluators/max_evaluator.cc +++ b/src/search/evaluators/max_evaluator.cc @@ -7,11 +7,8 @@ using namespace std; namespace max_evaluator { -MaxEvaluator::MaxEvaluator(const plugins::Options &opts) - : CombiningEvaluator(opts) { -} MaxEvaluator::MaxEvaluator( - vector> evals, + const vector> &evals, bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/max_evaluator.h b/src/search/evaluators/max_evaluator.h index acc2df31ef..e41183eff3 100644 --- a/src/search/evaluators/max_evaluator.h +++ b/src/search/evaluators/max_evaluator.h @@ -15,9 +15,8 @@ class MaxEvaluator : public combining_evaluator::CombiningEvaluator { virtual int combine_values(const std::vector &values) override; public: - explicit MaxEvaluator(const plugins::Options &opts); // TODO issue1082 remove this MaxEvaluator( - std::vector> evals, + const std::vector> &evals, bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/pref_evaluator.cc b/src/search/evaluators/pref_evaluator.cc index 14fd3abd65..a89ce261af 100644 --- a/src/search/evaluators/pref_evaluator.cc +++ b/src/search/evaluators/pref_evaluator.cc @@ -7,10 +7,6 @@ using namespace std; namespace pref_evaluator { -PrefEvaluator::PrefEvaluator(const plugins::Options &opts) - : Evaluator(opts) { -} - PrefEvaluator::PrefEvaluator( bool use_for_reporting_minima, bool use_for_boosting, diff --git a/src/search/evaluators/pref_evaluator.h b/src/search/evaluators/pref_evaluator.h index 1aa0bd9d6e..0a6d706e63 100644 --- a/src/search/evaluators/pref_evaluator.h +++ b/src/search/evaluators/pref_evaluator.h @@ -9,7 +9,6 @@ namespace pref_evaluator { class PrefEvaluator : public Evaluator { public: - explicit PrefEvaluator(const plugins::Options &opts); // TODO issue1082 remove this PrefEvaluator( bool use_for_reporting_minima, bool use_for_boosting, diff --git a/src/search/evaluators/sum_evaluator.cc b/src/search/evaluators/sum_evaluator.cc index 5f39d8b4d0..e273a16341 100644 --- a/src/search/evaluators/sum_evaluator.cc +++ b/src/search/evaluators/sum_evaluator.cc @@ -7,11 +7,8 @@ using namespace std; namespace sum_evaluator { -SumEvaluator::SumEvaluator(const plugins::Options &opts) - : CombiningEvaluator(opts) { -} SumEvaluator::SumEvaluator( - vector> evals, + const vector> &evals, bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/sum_evaluator.h b/src/search/evaluators/sum_evaluator.h index 452254e830..b93766fe9d 100644 --- a/src/search/evaluators/sum_evaluator.h +++ b/src/search/evaluators/sum_evaluator.h @@ -15,9 +15,8 @@ class SumEvaluator : public combining_evaluator::CombiningEvaluator { protected: virtual int combine_values(const std::vector &values) override; public: - explicit SumEvaluator(const plugins::Options &opts); // TODO issue1082 remove this SumEvaluator( - std::vector> evals, + const std::vector> &evals, bool use_for_reporting_minima, bool use_for_boosting, bool use_for_counting_evaluations, diff --git a/src/search/evaluators/weighted_evaluator.cc b/src/search/evaluators/weighted_evaluator.cc index 9af5743100..42d5993767 100644 --- a/src/search/evaluators/weighted_evaluator.cc +++ b/src/search/evaluators/weighted_evaluator.cc @@ -10,13 +10,8 @@ using namespace std; namespace weighted_evaluator { -WeightedEvaluator::WeightedEvaluator(const plugins::Options &opts) - : Evaluator(opts), - evaluator(opts.get>("eval")), - w(opts.get("weight")) { -} WeightedEvaluator::WeightedEvaluator( - shared_ptr eval, + const shared_ptr &eval, int weight, bool use_for_reporting_minima, bool use_for_boosting, diff --git a/src/search/evaluators/weighted_evaluator.h b/src/search/evaluators/weighted_evaluator.h index 6755653e67..17e1124f1a 100644 --- a/src/search/evaluators/weighted_evaluator.h +++ b/src/search/evaluators/weighted_evaluator.h @@ -15,9 +15,8 @@ class WeightedEvaluator : public Evaluator { int w; public: - explicit WeightedEvaluator(const plugins::Options &opts); // TODO issue1082 remove this WeightedEvaluator( - std::shared_ptr eval, + const std::shared_ptr &eval, int weight, bool use_for_reporting_minima, bool use_for_boosting, diff --git a/src/search/search_algorithms/enforced_hill_climbing_search.cc b/src/search/search_algorithms/enforced_hill_climbing_search.cc index f2fce939d8..7ab17686b7 100644 --- a/src/search/search_algorithms/enforced_hill_climbing_search.cc +++ b/src/search/search_algorithms/enforced_hill_climbing_search.cc @@ -24,10 +24,7 @@ static shared_ptr create_ehc_open_list_factory( ignore costs since EHC is supposed to implement a breadth-first search, not a uniform-cost search. So this seems to be a bug. */ - plugins::Options g_evaluator_options; - g_evaluator_options.set( - "verbosity", verbosity); - shared_ptr g_evaluator = make_shared(g_evaluator_options); // TODO issue 1082 after Evaluators + shared_ptr g_evaluator = make_shared(false, false, false, "ehc.g_eval", verbosity); if (!use_preferred || preferred_usage == PreferredUsage::PRUNE_BY_PREFERRED) { @@ -41,10 +38,7 @@ static shared_ptr create_ehc_open_list_factory( constructor that encapsulates this work to the tie-breaking open list code. */ - plugins::Options pref_evaluator_options; - pref_evaluator_options.set( - "verbosity", verbosity); - vector> evals = {g_evaluator, make_shared(pref_evaluator_options)}; // TODO issue 1082 after Evaluators + vector> evals = {g_evaluator, make_shared(false, false, false, "ehc.pref_eval", verbosity)}; return make_shared(evals, false, true); } } diff --git a/src/search/search_algorithms/search_common.cc b/src/search/search_algorithms/search_common.cc index b4d42a5786..c43d3b0bc6 100644 --- a/src/search/search_algorithms/search_common.cc +++ b/src/search/search_algorithms/search_common.cc @@ -73,16 +73,9 @@ static shared_ptr create_wastar_eval(utils::Verbosity verbosity, if (weight == 1) { w_h_eval = h_eval; } else { - plugins::Options weighted_evaluator_options; // TODO issue1082 remove this - weighted_evaluator_options.set("verbosity", verbosity); - weighted_evaluator_options.set>("eval", h_eval); - weighted_evaluator_options.set("weight", weight); - w_h_eval = make_shared(weighted_evaluator_options); + w_h_eval = make_shared(h_eval, weight, false, false, false, "wastar.w_h_eval", verbosity); } - plugins::Options sum_evaluator_options; // TODO issue1082 remove this - sum_evaluator_options.set("verbosity", verbosity); - sum_evaluator_options.set>>("evals", vector>({g_eval, w_h_eval})); - return make_shared(sum_evaluator_options); + return make_shared(vector>({g_eval, w_h_eval}), false, false, false, "wastar.eval", verbosity); } shared_ptr create_wastar_open_list_factory( @@ -91,10 +84,7 @@ shared_ptr create_wastar_open_list_factory( int boost, int weight, utils::Verbosity verbosity) { - plugins::Options g_evaluator_options; // TODO issue1082 remove this - g_evaluator_options.set( - "verbosity", verbosity); - shared_ptr g_eval = make_shared(g_evaluator_options); + shared_ptr g_eval = make_shared(false, false, false, "wastar.g_eval", verbosity); vector> f_evals; f_evals.reserve(base_evals.size()); for (const shared_ptr &eval : base_evals) @@ -115,16 +105,8 @@ create_astar_open_list_factory_and_f_eval( const shared_ptr &h_eval, utils::Verbosity verbosity ) { - plugins::Options g_evaluator_options; // TODO issue1082 remove this - g_evaluator_options.set( - "verbosity", verbosity); - shared_ptr g = make_shared(g_evaluator_options); - plugins::Options f_evaluator_options; // TODO issue1082 remove this - f_evaluator_options.set( - "verbosity", verbosity); - f_evaluator_options.set>>( - "evals", vector>({g, h_eval})); - shared_ptr f = make_shared(f_evaluator_options); + shared_ptr g = make_shared(false, false, false, "astar.g_eval", verbosity); + shared_ptr f = make_shared(vector>({g, h_eval}), false, false, false, "astar.f_eval", verbosity); vector> evals = {f, h_eval}; shared_ptr open =