Skip to content

Commit

Permalink
[issue1082] move add_heuristic_options_to_feature outside of class.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 8, 2024
1 parent fa28521 commit 1b2acb9
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class AdditiveCartesianHeuristicFeature
"use_general_costs",
"allow negative costs in cost partitioning",
"true");
Heuristic::add_options_to_feature(*this);
add_heuristic_options_to_feature(*this, "cegar");
utils::add_rng_options_to_feature(*this);

document_language_support("action costs", "supported");
Expand Down
24 changes: 12 additions & 12 deletions src/search/heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ State Heuristic::convert_ancestor_state(const State &ancestor_state) const {
return task_proxy.convert_ancestor_state(ancestor_state);
}

void Heuristic::add_options_to_feature(plugins::Feature &feature, const string &description) {
void add_heuristic_options_to_feature(plugins::Feature &feature, const string &description) {
feature.add_option<shared_ptr<AbstractTask>>(
"transform",
"Optional task transformation for the heuristic."
Expand All @@ -55,8 +55,9 @@ void Heuristic::add_options_to_feature(plugins::Feature &feature, const string &
add_evaluator_options_to_feature(feature, description);
}

/*
// TODO 1082 remove this, just keep the one above
void Heuristic::add_options_to_feature(plugins::Feature &feature) {
void add_options_to_feature(plugins::Feature &feature) {
feature.add_option<shared_ptr<AbstractTask>>(
"transform",
"Optional task transformation for the heuristic."
Expand All @@ -65,16 +66,15 @@ void Heuristic::add_options_to_feature(plugins::Feature &feature) {
feature.add_option<bool>("cache_estimates", "cache heuristic estimates", "true");
add_evaluator_options_to_feature(feature);
}


tuple<shared_ptr<AbstractTask>, 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<shared_ptr<AbstractTask>>("transform"),
opts.get<bool>("cache_estimates")
);
return tuple_cat(heuristic_args, evaluator_args);
*/

tuple<shared_ptr<AbstractTask>, bool, string, utils::Verbosity> get_heuristic_arguments_from_options(const plugins::Options &opts) {
return tuple_cat(
make_tuple(
opts.get<shared_ptr<AbstractTask>>("transform"),
opts.get<bool>("cache_estimates")
),
get_evaluator_arguments_from_options(opts));
}

EvaluationResult Heuristic::compute_result(EvaluationContext &eval_context) {
Expand Down
9 changes: 3 additions & 6 deletions src/search/heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ class Heuristic : public Evaluator {
std::set<Evaluator *> & /*evals*/) override {
}

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::tuple<std::shared_ptr<AbstractTask>, bool, std::string, utils::Verbosity>
get_heuristic_arguments_from_options(const plugins::Options &opts);

virtual EvaluationResult compute_result(
EvaluationContext &eval_context) override;

Expand All @@ -99,4 +93,7 @@ class Heuristic : public Evaluator {
virtual int get_cached_estimate(const State &state) const override;
};

extern void add_heuristic_options_to_feature(plugins::Feature &feature, const std::string &description);
extern void add_options_to_feature(plugins::Feature &feature); // TODO 1082 remove this, just keep the one above
extern std::tuple<std::shared_ptr<AbstractTask>, bool, std::string, utils::Verbosity> get_heuristic_arguments_from_options(const plugins::Options &opts);
#endif
4 changes: 2 additions & 2 deletions src/search/heuristics/additive_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class AdditiveHeuristicFeature : public plugins::TypedFeature<Evaluator, Additiv
AdditiveHeuristicFeature() : TypedFeature("add") {
document_title("Additive heuristic");

Heuristic::add_options_to_feature(*this, "add");
add_heuristic_options_to_feature(*this, "add");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "supported");
Expand All @@ -172,7 +172,7 @@ class AdditiveHeuristicFeature : public plugins::TypedFeature<Evaluator, Additiv
virtual shared_ptr<AdditiveHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<AdditiveHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/blind_search_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class BlindSearchHeuristicFeature : public plugins::TypedFeature<Evaluator, Blin
"Returns cost of cheapest action for non-goal states, "
"0 for goal states");

Heuristic::add_options_to_feature(*this, "blind");
add_heuristic_options_to_feature(*this, "blind");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "supported");
Expand All @@ -55,7 +55,7 @@ class BlindSearchHeuristicFeature : public plugins::TypedFeature<Evaluator, Blin
virtual shared_ptr<BlindSearchHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<BlindSearchHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/cea_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class ContextEnhancedAdditiveHeuristicFeature : public plugins::TypedFeature<Eva
ContextEnhancedAdditiveHeuristicFeature() : TypedFeature("cea") {
document_title("Context-enhanced additive heuristic");

Heuristic::add_options_to_feature(*this, "cea");
add_heuristic_options_to_feature(*this, "cea");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "supported");
Expand All @@ -470,7 +470,7 @@ class ContextEnhancedAdditiveHeuristicFeature : public plugins::TypedFeature<Eva
virtual shared_ptr<ContextEnhancedAdditiveHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<ContextEnhancedAdditiveHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/cg_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class CGHeuristicFeature : public plugins::TypedFeature<Evaluator, CGHeuristic>
"maximum number of cached entries per variable (set to 0 to disable cache)",
"1000000",
plugins::Bounds("0", "infinity"));
Heuristic::add_options_to_feature(*this, "cg");
add_heuristic_options_to_feature(*this, "cg");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "supported");
Expand All @@ -316,7 +316,7 @@ class CGHeuristicFeature : public plugins::TypedFeature<Evaluator, CGHeuristic>
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<CGHeuristic>(
opts.get<int>("max_cache_size"),
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/ff_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class FFHeuristicFeature : public plugins::TypedFeature<Evaluator, FFHeuristic>
FFHeuristicFeature() : TypedFeature("ff") {
document_title("FF heuristic");

Heuristic::add_options_to_feature(*this, "ff");
add_heuristic_options_to_feature(*this, "ff");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "supported");
Expand All @@ -97,7 +97,7 @@ class FFHeuristicFeature : public plugins::TypedFeature<Evaluator, FFHeuristic>
virtual shared_ptr<FFHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<FFHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/goal_count_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GoalCountHeuristicFeature : public plugins::TypedFeature<Evaluator, GoalCo
GoalCountHeuristicFeature() : TypedFeature("goalcount") {
document_title("Goal count heuristic");

Heuristic::add_options_to_feature(*this, "goalcount");
add_heuristic_options_to_feature(*this, "goalcount");

document_language_support("action costs", "ignored by design");
document_language_support("conditional effects", "supported");
Expand All @@ -52,7 +52,7 @@ class GoalCountHeuristicFeature : public plugins::TypedFeature<Evaluator, GoalCo
virtual shared_ptr<GoalCountHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<GoalCountHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/hm_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class HMHeuristicFeature : public plugins::TypedFeature<Evaluator, HMHeuristic>
document_title("h^m heuristic");

add_option<int>("m", "subset size", "2", plugins::Bounds("1", "infinity"));
Heuristic::add_options_to_feature(*this, "hm");
add_heuristic_options_to_feature(*this, "hm");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "ignored");
Expand All @@ -295,7 +295,7 @@ class HMHeuristicFeature : public plugins::TypedFeature<Evaluator, HMHeuristic>
virtual shared_ptr<HMHeuristic> create_component(const plugins::Options &options, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<HMHeuristic>(
options.get<int>("m"),
Heuristic::get_heuristic_arguments_from_options(options)
get_heuristic_arguments_from_options(options)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/lm_cut_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LandmarkCutHeuristicFeature : public plugins::TypedFeature<Evaluator, Land
LandmarkCutHeuristicFeature() : TypedFeature("lmcut") {
document_title("Landmark-cut heuristic");

Heuristic::add_options_to_feature(*this, "lmcut");
add_heuristic_options_to_feature(*this, "lmcut");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "not supported");
Expand All @@ -59,7 +59,7 @@ class LandmarkCutHeuristicFeature : public plugins::TypedFeature<Evaluator, Land
virtual shared_ptr<LandmarkCutHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<LandmarkCutHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristics/max_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class HSPMaxHeuristicFeature : public plugins::TypedFeature<Evaluator, HSPMaxHeu
HSPMaxHeuristicFeature() : TypedFeature("hmax") {
document_title("Max heuristic");

Heuristic::add_options_to_feature(*this, "hmax");
add_heuristic_options_to_feature(*this, "hmax");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "supported");
Expand All @@ -126,7 +126,7 @@ class HSPMaxHeuristicFeature : public plugins::TypedFeature<Evaluator, HSPMaxHeu
virtual shared_ptr<HSPMaxHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<HSPMaxHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts));
get_heuristic_arguments_from_options(opts));
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/search/landmarks/landmark_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ void add_landmark_heuristic_options_to_feature(plugins::Feature &feature,
"prog_gn", "Use greedy-necessary ordering progression.", "true");
feature.add_option<bool>(
"prog_r", "Use reasonable ordering progression.", "true");
Heuristic::add_options_to_feature(feature, description);
add_heuristic_options_to_feature(feature, description);

feature.document_property("preferred operators",
"yes (if enabled; see ``pref`` option)");
Expand All @@ -251,6 +251,6 @@ get_landmark_heuristic_arguments_from_options(const plugins::Options &options) {
options.get<bool>("prog_gn"),
options.get<bool>("prog_r")
),
Heuristic::get_heuristic_arguments_from_options(options));
get_heuristic_arguments_from_options(options));
}
}
4 changes: 2 additions & 2 deletions src/search/merge_and_shrink/merge_and_shrink_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature<Evaluator, M
"2018")
);

Heuristic::add_options_to_feature(*this, "merge_and_shrink");
add_heuristic_options_to_feature(*this, "merge_and_shrink");
add_merge_and_shrink_algorithm_options_to_feature(*this);

document_note(
Expand Down Expand Up @@ -257,7 +257,7 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature<Evaluator, M

return plugins::make_shared_from_arg_tuples<MergeAndShrinkHeuristic>(
get_merge_and_shrink_algorithm_arguments_from_options(options_copy),
Heuristic::get_heuristic_arguments_from_options(options_copy)
get_heuristic_arguments_from_options(options_copy)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/operator_counting/operator_counting_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class OperatorCountingHeuristicFeature : public plugins::TypedFeature<Evaluator,
"increase the runtime.",
"false");
lp::add_lp_solver_option_to_feature(*this);
Heuristic::add_options_to_feature(*this, "operatorcounting");
add_heuristic_options_to_feature(*this, "operatorcounting");

document_language_support("action costs", "supported");
document_language_support(
Expand Down Expand Up @@ -121,7 +121,7 @@ class OperatorCountingHeuristicFeature : public plugins::TypedFeature<Evaluator,
options.get_list<shared_ptr<ConstraintGenerator>>("constraint_generators"),
options.get<bool>("use_integer_operator_counts"),
lp::get_lp_solver_arguments_from_options(options),
Heuristic::get_heuristic_arguments_from_options(options)
get_heuristic_arguments_from_options(options)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/pdbs/canonical_pdbs_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CanonicalPDBsHeuristicFeature : public plugins::TypedFeature<Evaluator, Ca
"pattern generation method",
"systematic(1)");
add_canonical_pdbs_options_to_feature(*this);
Heuristic::add_options_to_feature(*this, "cpdbs");
add_heuristic_options_to_feature(*this, "cpdbs");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "not supported");
Expand All @@ -128,7 +128,7 @@ class CanonicalPDBsHeuristicFeature : public plugins::TypedFeature<Evaluator, Ca
return plugins::make_shared_from_arg_tuples<CanonicalPDBsHeuristic>(
opts.get<shared_ptr<PatternCollectionGenerator>>("patterns"),
opts.get<double>("max_time_dominance_pruning"),
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/search/pdbs/pattern_collection_generator_hillclimbing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ class IPDBFeature : public plugins::TypedFeature<Evaluator, CanonicalPDBsHeurist
are added. We thus only use dominance pruning on the resulting collection.
*/
add_canonical_pdbs_options_to_feature(*this);
Heuristic::add_options_to_feature(*this, "cpdbs"); // TODO issue1082 this adds a description parameter that is
// only used for the heuristic, not for the generator.
add_heuristic_options_to_feature(*this, "cpdbs"); // TODO issue1082 this adds a description parameter that is
// only used for the heuristic, not for the generator.

document_language_support("action costs", "supported");
document_language_support("conditional effects", "not supported");
Expand All @@ -678,7 +678,7 @@ class IPDBFeature : public plugins::TypedFeature<Evaluator, CanonicalPDBsHeurist
return plugins::make_shared_from_arg_tuples<CanonicalPDBsHeuristic>(
pgh,
opts.get<double>("max_time_dominance_pruning"),
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/pdbs/pdb_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PDBHeuristicFeature : public plugins::TypedFeature<Evaluator, PDBHeuristic
"pattern",
"pattern generation method",
"greedy()");
Heuristic::add_options_to_feature(*this, "pdb");
add_heuristic_options_to_feature(*this, "pdb");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "not supported");
Expand All @@ -62,7 +62,7 @@ class PDBHeuristicFeature : public plugins::TypedFeature<Evaluator, PDBHeuristic
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<PDBHeuristic>(
opts.get<shared_ptr<PatternGenerator>>("pattern"),
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/pdbs/zero_one_pdbs_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ZeroOnePDBsHeuristicFeature : public plugins::TypedFeature<Evaluator, Zero
"patterns",
"pattern generation method",
"systematic(1)");
Heuristic::add_options_to_feature(*this, "zopdbs");
add_heuristic_options_to_feature(*this, "zopdbs");

document_language_support("action costs", "supported");
document_language_support("conditional effects", "not supported");
Expand All @@ -72,7 +72,7 @@ class ZeroOnePDBsHeuristicFeature : public plugins::TypedFeature<Evaluator, Zero
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<ZeroOnePDBsHeuristic>(
opts.get<shared_ptr<PatternCollectionGenerator>>("patterns"),
Heuristic::get_heuristic_arguments_from_options(opts)
get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/search/potentials/diverse_potential_heuristics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class DiversePotentialMaxHeuristicFeature : public plugins::TypedFeature<Evaluat
"maximum number of potential heuristics",
"infinity",
plugins::Bounds("0", "infinity"));
prepare_parser_for_admissible_potentials(*this);
add_admissible_potentials_options_to_feature(*this, "diverse_potentials");
utils::add_rng_options_to_feature(*this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/search/potentials/sample_based_potential_heuristics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SampleBasedPotentialMaxHeuristicFeature : public plugins::TypedFeature<Eva
"Number of states to sample",
"1000",
plugins::Bounds("0", "infinity"));
prepare_parser_for_admissible_potentials(*this);
add_admissible_potentials_options_to_feature(*this, "sample_based_potentials");
utils::add_rng_options_to_feature(*this);
}

Expand Down
Loading

0 comments on commit 1b2acb9

Please sign in to comment.