Skip to content

Commit

Permalink
Issue1082 with fixed order in make_shared (#5)
Browse files Browse the repository at this point in the history
* new approach for argument tuples

* use flattened arguments in make_shared_from_arg_tuples
  • Loading branch information
FlorianPommerening authored Feb 8, 2024
1 parent b2ef706 commit 1ea373a
Show file tree
Hide file tree
Showing 57 changed files with 254 additions and 190 deletions.
1 change: 1 addition & 0 deletions src/search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
11 changes: 5 additions & 6 deletions src/search/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,12 @@ void add_evaluator_options_to_feature(plugins::Feature &feature) {
utils::add_log_options_to_feature(feature);
}

shared_ptr<tuple<string, utils::Verbosity>> get_evaluator_parameters_from_options(const plugins::Options &opts) {
return make_shared<tuple<string, utils::Verbosity>>(
tuple_cat(
tuple<string, utils::Verbosity> get_evaluator_arguments_from_options(
const plugins::Options &opts) {
return tuple_cat(
make_tuple(opts.get<string>("description")),
*utils::get_log_parameters_from_options(opts)
)
);
utils::get_log_arguments_from_options(opts)
);
}

static class EvaluatorCategoryPlugin : public plugins::TypedCategoryPlugin<Evaluator> {
Expand Down
2 changes: 1 addition & 1 deletion src/search/evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<std::string, utils::Verbosity>> get_evaluator_parameters_from_options(const plugins::Options &opts);
extern std::tuple<std::string, utils::Verbosity> get_evaluator_arguments_from_options(const plugins::Options &opts);

#endif
9 changes: 5 additions & 4 deletions src/search/heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ void Heuristic::add_options_to_feature(plugins::Feature &feature) {
}


shared_ptr<tuple<shared_ptr<AbstractTask>, 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<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 make_shared<tuple<shared_ptr<AbstractTask>, 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) {
Expand Down
4 changes: 2 additions & 2 deletions src/search/heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::tuple<std::shared_ptr<AbstractTask>, bool, std::string, utils::Verbosity>>
get_heuristic_parameters_from_options(const plugins::Options &opts);
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 Down
8 changes: 2 additions & 6 deletions src/search/heuristics/additive_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ void AdditiveHeuristic::compute_heuristic_for_cegar(const State &state) {
compute_heuristic(state);
}

shared_ptr<tuple<shared_ptr<AbstractTask>, 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<Evaluator, AdditiveHeuristic> {
public:
AdditiveHeuristicFeature() : TypedFeature("add") {
Expand All @@ -175,8 +171,8 @@ 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_args_tuple_and_args<AdditiveHeuristic>(
Heuristic::get_heuristic_parameters_from_options(opts)
return plugins::make_shared_from_arg_tuples<AdditiveHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
2 changes: 0 additions & 2 deletions src/search/heuristics/additive_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ class AdditiveHeuristic : public relaxation_heuristic::RelaxationHeuristic {
return get_proposition(var, value)->cost;
}
};

extern std::shared_ptr<std::tuple<std::shared_ptr<AbstractTask>, bool, std::string, utils::Verbosity>> get_additive_heuristic_parameters_from_options(const plugins::Options &opts);
}

#endif
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 @@ -54,8 +54,8 @@ 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_args_tuple_and_args<BlindSearchHeuristic>(
Heuristic::get_heuristic_parameters_from_options(opts)
return plugins::make_shared_from_arg_tuples<BlindSearchHeuristic>(
Heuristic::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 @@ -469,8 +469,8 @@ 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_args_tuple_and_args<ContextEnhancedAdditiveHeuristic>(
Heuristic::get_heuristic_parameters_from_options(opts)
return plugins::make_shared_from_arg_tuples<ContextEnhancedAdditiveHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/search/heuristics/cg_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ class CGHeuristicFeature : public plugins::TypedFeature<Evaluator, CGHeuristic>

virtual shared_ptr<CGHeuristic> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_args_tuple_and_args<CGHeuristic>(
Heuristic::get_heuristic_parameters_from_options(opts),
opts.get<int>("max_cache_size")
return plugins::make_shared_from_arg_tuples<CGHeuristic>(
opts.get<int>("max_cache_size"),
Heuristic::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 @@ -96,8 +96,8 @@ 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_args_tuple_and_args<FFHeuristic>(
additive_heuristic::get_additive_heuristic_parameters_from_options(opts)
return plugins::make_shared_from_arg_tuples<FFHeuristic>(
Heuristic::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 @@ -51,8 +51,8 @@ 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_args_tuple_and_args<GoalCountHeuristic>(
Heuristic::get_heuristic_parameters_from_options(opts)
return plugins::make_shared_from_arg_tuples<GoalCountHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts)
);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/search/heuristics/hm_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ 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_args_tuple_and_args<HMHeuristic>(
Heuristic::get_heuristic_parameters_from_options(options),
options.get<int>("m")
return plugins::make_shared_from_arg_tuples<HMHeuristic>(
options.get<int>("m"),
Heuristic::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 @@ -58,8 +58,8 @@ 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_args_tuple_and_args<LandmarkCutHeuristic>(
Heuristic::get_heuristic_parameters_from_options(opts)
return plugins::make_shared_from_arg_tuples<LandmarkCutHeuristic>(
Heuristic::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 @@ -125,8 +125,8 @@ 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_args_tuple_and_args<HSPMaxHeuristic>(
relaxation_heuristic::get_relaxation_heuristic_parameters_from_options(opts));
return plugins::make_shared_from_arg_tuples<HSPMaxHeuristic>(
Heuristic::get_heuristic_arguments_from_options(opts));
}
};

Expand Down
4 changes: 0 additions & 4 deletions src/search/heuristics/relaxation_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,4 @@ void RelaxationHeuristic::simplify() {
log << " done! [" << unary_operators.size() << " unary operators]" << endl;
}
}

shared_ptr<tuple<shared_ptr<AbstractTask>, bool, string, utils::Verbosity>> get_relaxation_heuristic_parameters_from_options(const plugins::Options &opts) {
return Heuristic::get_heuristic_parameters_from_options(opts);
}
}
2 changes: 0 additions & 2 deletions src/search/heuristics/relaxation_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class RelaxationHeuristic : public Heuristic {

virtual bool dead_ends_are_reliable() const override;
};

std::shared_ptr<std::tuple<std::shared_ptr<AbstractTask>, bool, std::string, utils::Verbosity>> get_relaxation_heuristic_parameters_from_options(const plugins::Options &opts);
}

#endif
6 changes: 6 additions & 0 deletions src/search/lp/lp_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<LPSolverType> get_lp_solver_arguments_from_options(
const plugins::Options &opts) {
return make_tuple(opts.get<LPSolverType>("lpsolver"));

}

LPConstraint::LPConstraint(double lower_bound, double upper_bound)
: lower_bound(lower_bound),
upper_bound(upper_bound) {
Expand Down
3 changes: 3 additions & 0 deletions src/search/lp/lp_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace plugins {
class Feature;
class Options;
}

namespace lp {
Expand All @@ -24,6 +25,8 @@ enum class LPObjectiveSense {
};

void add_lp_solver_option_to_feature(plugins::Feature &feature);
std::tuple<LPSolverType> get_lp_solver_arguments_from_options(
const plugins::Options &opts);

class LinearProgram;

Expand Down
6 changes: 3 additions & 3 deletions src/search/merge_and_shrink/merge_and_shrink_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature<Evaluator, M
plugins::Options options_copy(options);
handle_shrink_limit_options_defaults(options_copy, context);

return plugins::make_shared_from_args_tuple_and_args<MergeAndShrinkHeuristic>(
Heuristic::get_heuristic_parameters_from_options(options_copy),
return plugins::make_shared_from_arg_tuples<MergeAndShrinkHeuristic>(
options_copy.get<shared_ptr<MergeStrategyFactory>>("merge_strategy"),
options_copy.get<shared_ptr<ShrinkStrategy>>("shrink_strategy"),
options_copy.get<shared_ptr<LabelReduction>>("label_reduction", nullptr),
Expand All @@ -265,7 +264,8 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature<Evaluator, M
options_copy.get<int>("threshold_before_merge"),
options_copy.get<bool>("prune_unreachable_states"),
options_copy.get<bool>("prune_irrelevant_states"),
options_copy.get<double>("main_loop_max_time")
options_copy.get<double>("main_loop_max_time"),
Heuristic::get_heuristic_arguments_from_options(options_copy)
);
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/search/merge_and_shrink/merge_strategy_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ void add_merge_strategy_options_to_feature(plugins::Feature &feature) {
utils::add_log_options_to_feature(feature);
}

shared_ptr<tuple<utils::Verbosity>> get_merge_strategy_parameters_from_options(const plugins::Options &opts) {
return utils::get_log_parameters_from_options(opts);
tuple<utils::Verbosity> get_merge_strategy_arguments_from_options(
const plugins::Options &opts) {
return utils::get_log_arguments_from_options(opts);
}


Expand Down
3 changes: 2 additions & 1 deletion src/search/merge_and_shrink/merge_strategy_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class MergeStrategyFactory {
};

extern void add_merge_strategy_options_to_feature(plugins::Feature &feature);
extern std::shared_ptr<std::tuple<utils::Verbosity>> get_merge_strategy_parameters_from_options(const plugins::Options &opts);
extern std::tuple<utils::Verbosity> get_merge_strategy_arguments_from_options(
const plugins::Options &opts);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ class MergeStrategyFactoryPrecomputedFeature : public plugins::TypedFeature<Merg
}
virtual shared_ptr<MergeStrategyFactoryPrecomputed> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_args_tuple_and_args<MergeStrategyFactoryPrecomputed>(
get_merge_strategy_parameters_from_options(opts),
opts.get<shared_ptr<MergeTreeFactory>>("merge_tree")
return plugins::make_shared_from_arg_tuples<MergeStrategyFactoryPrecomputed>(
opts.get<shared_ptr<MergeTreeFactory>>("merge_tree"),
get_merge_strategy_arguments_from_options(opts)
);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/search/merge_and_shrink/merge_strategy_factory_sccs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ class MergeStrategyFactorySCCsFeature : public plugins::TypedFeature<MergeStrate
"You have to specify exactly one of the options merge_tree "
"and merge_selector!");
}
return plugins::make_shared_from_args_tuple_and_args<MergeStrategyFactorySCCs>(
get_merge_strategy_parameters_from_options(opts),
return plugins::make_shared_from_arg_tuples<MergeStrategyFactorySCCs>(
opts.get<OrderOfSCCs>("order_of_sccs"),
opts.get<shared_ptr<MergeTreeFactory>> ("merge_tree", nullptr),
opts.get<shared_ptr<MergeSelector>> ("merge_selector", nullptr)
opts.get<shared_ptr<MergeSelector>> ("merge_selector", nullptr),
get_merge_strategy_arguments_from_options(opts)
);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class MergeStrategyFactoryStatelessFeature : public plugins::TypedFeature<MergeS

virtual shared_ptr<MergeStrategyFactoryStateless> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_args_tuple_and_args<MergeStrategyFactoryStateless>(
get_merge_strategy_parameters_from_options(opts),
opts.get<shared_ptr<MergeSelector>>("merge_selector")
return plugins::make_shared_from_arg_tuples<MergeStrategyFactoryStateless>(
opts.get<shared_ptr<MergeSelector>>("merge_selector"),
get_merge_strategy_arguments_from_options(opts)
);
}
};
Expand Down
8 changes: 3 additions & 5 deletions src/search/merge_and_shrink/merge_tree_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ void MergeTreeFactory::add_options_to_feature(plugins::Feature &feature) {
"use_random");
}

shared_ptr<tuple<int, UpdateOption>> get_merge_tree_parameters_from_options(const plugins::Options &opts) {
return make_shared<tuple<int, UpdateOption>>(
make_tuple(
tuple<int, UpdateOption> get_merge_tree_arguments_from_options(const plugins::Options &opts) {
return make_tuple(
opts.get<int>("random_seed"),
opts.get<UpdateOption>("update_option")
)
);
);
}

static class MergeTreeFactoryCategoryPlugin : public plugins::TypedCategoryPlugin<MergeTreeFactory> {
Expand Down
3 changes: 2 additions & 1 deletion src/search/merge_and_shrink/merge_tree_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class MergeTreeFactory {
static void add_options_to_feature(plugins::Feature &feature);
};

extern std::shared_ptr<std::tuple<int, UpdateOption>> get_merge_tree_parameters_from_options(const plugins::Options &opts);
extern std::tuple<int, UpdateOption> get_merge_tree_arguments_from_options(
const plugins::Options &opts);
}

#endif
6 changes: 3 additions & 3 deletions src/search/merge_and_shrink/merge_tree_factory_linear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class MergeTreeFactoryLinearFeature : public plugins::TypedFeature<MergeTreeFact

virtual shared_ptr<MergeTreeFactoryLinear> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_args_tuple_and_args<MergeTreeFactoryLinear>(
get_merge_tree_parameters_from_options(opts),
opts.get<variable_order_finder::VariableOrderType>("variable_order")
return plugins::make_shared_from_arg_tuples<MergeTreeFactoryLinear>(
opts.get<variable_order_finder::VariableOrderType>("variable_order"),
get_merge_tree_arguments_from_options(opts)
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/search/merge_and_shrink/shrink_bucket_based.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ StateEquivalenceRelation ShrinkBucketBased::compute_equivalence_relation(
return compute_abstraction(buckets, target_size, log);
}

shared_ptr<tuple<int>> get_shrink_bucket_parameters_from_options(const plugins::Options &opts) {
return make_shared<tuple<int>>(make_tuple(opts.get<int>("random_seed")));
tuple<int> get_shrink_bucket_arguments_from_options(const plugins::Options &opts) {
return make_tuple(opts.get<int>("random_seed"));
}
}
2 changes: 1 addition & 1 deletion src/search/merge_and_shrink/shrink_bucket_based.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ShrinkBucketBased : public ShrinkStrategy {
static void add_options_to_feature(plugins::Feature &feature);
};

extern std::shared_ptr<std::tuple<int>> get_shrink_bucket_parameters_from_options(const plugins::Options &opts);
extern std::tuple<int> get_shrink_bucket_arguments_from_options(const plugins::Options &opts);
}

#endif
6 changes: 3 additions & 3 deletions src/search/merge_and_shrink/shrink_fh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ class ShrinkFHFeature : public plugins::TypedFeature<ShrinkStrategy, ShrinkFH> {

virtual shared_ptr<ShrinkFH> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_args_tuple_and_args<ShrinkFH>(
get_shrink_bucket_parameters_from_options(opts),
return plugins::make_shared_from_arg_tuples<ShrinkFH>(
opts.get<ShrinkFH::HighLow>("shrink_f"),
opts.get<ShrinkFH::HighLow>("shrink_h")
opts.get<ShrinkFH::HighLow>("shrink_h"),
get_shrink_bucket_arguments_from_options(opts)
);
}
};
Expand Down
Loading

0 comments on commit 1ea373a

Please sign in to comment.