Skip to content

Commit

Permalink
move hill_climb and shrink_limit_defaults errors into constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 5, 2025
1 parent fb00024 commit 384120f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
24 changes: 13 additions & 11 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "../plugins/plugin.h"
#include "../task_utils/task_properties.h"
#include "../utils/component_errors.h"
#include "../utils/countdown_timer.h"
#include "../utils/markup.h"
#include "../utils/math.h"
Expand Down Expand Up @@ -526,30 +527,31 @@ void handle_shrink_limit_options_defaults(plugins::Options &opts, const utils::C
max_states = INF;
}
}


//utils::verify_comparison(max_states_before_merge, max_states, less_equal<>{},
// "warning: max_states_before_merge exceeds max_states, correcting XXX.");
if (max_states_before_merge > max_states) {
context.warn(
"warning: max_states_before_merge exceeds max_states, correcting.");
max_states_before_merge = max_states;
}

if (max_states < 1) {
context.error("Transition system size must be at least 1");
}
utils::verify_comparison(max_states, 1, greater_equal<>(),
"Transition system size must be at least 1.");

if (max_states_before_merge < 1) {
context.error("Transition system size before merge must be at least 1");
}
utils::verify_comparison(max_states_before_merge, 1, greater_equal<>(),
"Transition system size before merge must be at least 1.");

if (threshold == -1) {
threshold = max_states;
}
if (threshold < 1) {
context.error("Threshold must be at least 1");
}

utils::verify_comparison(threshold, 1, greater_equal<>(),
"Threshold must be at least 1.");

if (threshold > max_states) {
context.warn(
"warning: threshold exceeds max_states, correcting");
"warning: threshold exceeds max_states, correcting.");
threshold = max_states;
}

Expand Down
16 changes: 4 additions & 12 deletions src/search/pdbs/pattern_collection_generator_hillclimbing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ PatternCollectionGeneratorHillclimbing::PatternCollectionGeneratorHillclimbing(
rng(utils::get_rng(random_seed)),
num_rejected(0),
hill_climbing_timer(nullptr) {
utils::verify_comparison(min_improvement, num_samples, less_equal<>(),
"Minimum improvement must not be higher than number of samples.");
}

int PatternCollectionGeneratorHillclimbing::generate_candidate_pdbs(
Expand Down Expand Up @@ -569,14 +571,6 @@ get_hillclimbing_arguments_from_options(const plugins::Options &opts) {
utils::get_rng_arguments_from_options(opts));
}

static void check_hillclimbing_options(
const plugins::Options &opts, const utils::Context &context) {
if (opts.get<int>("min_improvement") > opts.get<int>("num_samples")) {
context.error(
"Minimum improvement must not be higher than number of samples");
}
}

static basic_string<char> paper_references() {
return utils::format_conference_reference(
{"Patrik Haslum", "Adi Botea", "Malte Helmert", "Blai Bonet",
Expand Down Expand Up @@ -616,8 +610,7 @@ class PatternCollectionGeneratorHillclimbingFeature

virtual shared_ptr<PatternCollectionGeneratorHillclimbing>
create_component(const plugins::Options &opts,
const utils::Context &context) const override {
check_hillclimbing_options(opts, context); // TODO316
const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<PatternCollectionGeneratorHillclimbing>(
get_hillclimbing_arguments_from_options(opts),
get_generator_arguments_from_options(opts)
Expand Down Expand Up @@ -667,8 +660,7 @@ class IPDBFeature

virtual shared_ptr<CanonicalPDBsHeuristic> create_component(
const plugins::Options &opts,
const utils::Context &context) const override {
check_hillclimbing_options(opts, context); // TODO316
const utils::Context &) const override {

shared_ptr<PatternCollectionGeneratorHillclimbing> pgh =
plugins::make_shared_from_arg_tuples<PatternCollectionGeneratorHillclimbing>(
Expand Down
7 changes: 7 additions & 0 deletions src/search/utils/component_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ void verify_list_not_empty(const std::vector<T> list, const std::string &name) {
throw ComponentArgumentError("List argument '" + name + "' has to be non-empty.");
}
}

template <typename T, typename F>
void verify_comparison(const T arg1, const T arg2, F comparator, const std::string &message) {
if (!comparator(arg1, arg2)){
throw ComponentArgumentError(message);
}
}
}
#endif

0 comments on commit 384120f

Please sign in to comment.