Skip to content

Commit

Permalink
remove ByOpts-Constructors, reduce copies.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 15, 2024
1 parent 1ff99aa commit 1ce8c7a
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 75 deletions.
10 changes: 1 addition & 9 deletions src/search/evaluators/combining_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
using namespace std;

namespace combining_evaluator {
CombiningEvaluator::CombiningEvaluator(const plugins::Options &opts)
: Evaluator(opts),
subevaluators(opts.get_list<shared_ptr<Evaluator>>("evals")) {
all_dead_ends_are_reliable = true;
for (const shared_ptr<Evaluator> &subevaluator : subevaluators)
if (!subevaluator->dead_ends_are_reliable())
all_dead_ends_are_reliable = false;
}
CombiningEvaluator::CombiningEvaluator(
vector<shared_ptr<Evaluator>> evals,
const vector<shared_ptr<Evaluator>> &evals,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations,
Expand Down
3 changes: 1 addition & 2 deletions src/search/evaluators/combining_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class CombiningEvaluator : public Evaluator {
protected:
virtual int combine_values(const std::vector<int> &values) = 0;
public:
explicit CombiningEvaluator(const plugins::Options &opts); // TODO issue1082: remove this
CombiningEvaluator(
std::vector<std::shared_ptr<Evaluator>> evals,
const std::vector<std::shared_ptr<Evaluator>> &evals,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations,
Expand Down
3 changes: 0 additions & 3 deletions src/search/evaluators/const_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
using namespace std;

namespace const_evaluator {
ConstEvaluator::ConstEvaluator(const plugins::Options &opts)
: Evaluator(opts), value(opts.get<int>("value")) {
}
ConstEvaluator::ConstEvaluator(
int value,
bool use_for_reporting_minima,
Expand Down
1 change: 0 additions & 1 deletion src/search/evaluators/const_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 0 additions & 3 deletions src/search/evaluators/g_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/search/evaluators/g_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/search/evaluators/max_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
using namespace std;

namespace max_evaluator {
MaxEvaluator::MaxEvaluator(const plugins::Options &opts)
: CombiningEvaluator(opts) {
}
MaxEvaluator::MaxEvaluator(
vector<shared_ptr<Evaluator>> evals,
const vector<shared_ptr<Evaluator>> &evals,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations,
Expand Down
3 changes: 1 addition & 2 deletions src/search/evaluators/max_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class MaxEvaluator : public combining_evaluator::CombiningEvaluator {
virtual int combine_values(const std::vector<int> &values) override;

public:
explicit MaxEvaluator(const plugins::Options &opts); // TODO issue1082 remove this
MaxEvaluator(
std::vector<std::shared_ptr<Evaluator>> evals,
const std::vector<std::shared_ptr<Evaluator>> &evals,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations,
Expand Down
4 changes: 0 additions & 4 deletions src/search/evaluators/pref_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/search/evaluators/pref_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions src/search/evaluators/sum_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
using namespace std;

namespace sum_evaluator {
SumEvaluator::SumEvaluator(const plugins::Options &opts)
: CombiningEvaluator(opts) {
}
SumEvaluator::SumEvaluator(
vector<shared_ptr<Evaluator>> evals,
const vector<shared_ptr<Evaluator>> &evals,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations,
Expand Down
3 changes: 1 addition & 2 deletions src/search/evaluators/sum_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class SumEvaluator : public combining_evaluator::CombiningEvaluator {
protected:
virtual int combine_values(const std::vector<int> &values) override;
public:
explicit SumEvaluator(const plugins::Options &opts); // TODO issue1082 remove this
SumEvaluator(
std::vector<std::shared_ptr<Evaluator>> evals,
const std::vector<std::shared_ptr<Evaluator>> &evals,
bool use_for_reporting_minima,
bool use_for_boosting,
bool use_for_counting_evaluations,
Expand Down
7 changes: 1 addition & 6 deletions src/search/evaluators/weighted_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
using namespace std;

namespace weighted_evaluator {
WeightedEvaluator::WeightedEvaluator(const plugins::Options &opts)
: Evaluator(opts),
evaluator(opts.get<shared_ptr<Evaluator>>("eval")),
w(opts.get<int>("weight")) {
}
WeightedEvaluator::WeightedEvaluator(
shared_ptr<Evaluator> eval,
const shared_ptr<Evaluator> &eval,
int weight,
bool use_for_reporting_minima,
bool use_for_boosting,
Expand Down
3 changes: 1 addition & 2 deletions src/search/evaluators/weighted_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Evaluator> eval,
const std::shared_ptr<Evaluator> &eval,
int weight,
bool use_for_reporting_minima,
bool use_for_boosting,
Expand Down
10 changes: 2 additions & 8 deletions src/search/search_algorithms/enforced_hill_climbing_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ static shared_ptr<OpenListFactory> 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<utils::Verbosity>(
"verbosity", verbosity);
shared_ptr<Evaluator> g_evaluator = make_shared<GEval>(g_evaluator_options); // TODO issue 1082 after Evaluators
shared_ptr<Evaluator> g_evaluator = make_shared<GEval>(false, false, false, "ehc.g_eval", verbosity);

if (!use_preferred ||
preferred_usage == PreferredUsage::PRUNE_BY_PREFERRED) {
Expand All @@ -41,10 +38,7 @@ static shared_ptr<OpenListFactory> 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<utils::Verbosity>(
"verbosity", verbosity);
vector<shared_ptr<Evaluator>> evals = {g_evaluator, make_shared<PrefEval>(pref_evaluator_options)}; // TODO issue 1082 after Evaluators
vector<shared_ptr<Evaluator>> evals = {g_evaluator, make_shared<PrefEval>(false, false, false, "ehc.pref_eval", verbosity)};
return make_shared<tiebreaking_open_list::TieBreakingOpenListFactory>(evals, false, true);
}
}
Expand Down
28 changes: 5 additions & 23 deletions src/search/search_algorithms/search_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,9 @@ static shared_ptr<Evaluator> 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<utils::Verbosity>("verbosity", verbosity);
weighted_evaluator_options.set<shared_ptr<Evaluator>>("eval", h_eval);
weighted_evaluator_options.set<int>("weight", weight);
w_h_eval = make_shared<WeightedEval>(weighted_evaluator_options);
w_h_eval = make_shared<WeightedEval>(h_eval, weight, false, false, false, "wastar.w_h_eval", verbosity);
}
plugins::Options sum_evaluator_options; // TODO issue1082 remove this
sum_evaluator_options.set<utils::Verbosity>("verbosity", verbosity);
sum_evaluator_options.set<vector<shared_ptr<Evaluator>>>("evals", vector<shared_ptr<Evaluator>>({g_eval, w_h_eval}));
return make_shared<SumEval>(sum_evaluator_options);
return make_shared<SumEval>(vector<shared_ptr<Evaluator>>({g_eval, w_h_eval}), false, false, false, "wastar.eval", verbosity);
}

shared_ptr<OpenListFactory> create_wastar_open_list_factory(
Expand All @@ -91,10 +84,7 @@ shared_ptr<OpenListFactory> 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<utils::Verbosity>(
"verbosity", verbosity);
shared_ptr<GEval> g_eval = make_shared<GEval>(g_evaluator_options);
shared_ptr<GEval> g_eval = make_shared<GEval>(false, false, false, "wastar.g_eval", verbosity);
vector<shared_ptr<Evaluator>> f_evals;
f_evals.reserve(base_evals.size());
for (const shared_ptr<Evaluator> &eval : base_evals)
Expand All @@ -115,16 +105,8 @@ create_astar_open_list_factory_and_f_eval(
const shared_ptr<Evaluator> &h_eval,
utils::Verbosity verbosity
) {
plugins::Options g_evaluator_options; // TODO issue1082 remove this
g_evaluator_options.set<utils::Verbosity>(
"verbosity", verbosity);
shared_ptr<GEval> g = make_shared<GEval>(g_evaluator_options);
plugins::Options f_evaluator_options; // TODO issue1082 remove this
f_evaluator_options.set<utils::Verbosity>(
"verbosity", verbosity);
f_evaluator_options.set<vector<shared_ptr<Evaluator>>>(
"evals", vector<shared_ptr<Evaluator>>({g, h_eval}));
shared_ptr<Evaluator> f = make_shared<SumEval>(f_evaluator_options);
shared_ptr<GEval> g = make_shared<GEval>(false, false, false, "astar.g_eval", verbosity);
shared_ptr<Evaluator> f = make_shared<SumEval>(vector<shared_ptr<Evaluator>>({g, h_eval}), false, false, false, "astar.f_eval", verbosity);
vector<shared_ptr<Evaluator>> evals = {f, h_eval};

shared_ptr<OpenListFactory> open =
Expand Down

0 comments on commit 1ce8c7a

Please sign in to comment.