Skip to content

Commit

Permalink
[issue1082] style.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 8, 2024
1 parent ae4f482 commit 52c9451
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 86 deletions.
6 changes: 3 additions & 3 deletions src/search/evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ void add_evaluator_options_to_feature(plugins::Feature &feature) {
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_arguments_from_options(opts)
);
make_tuple(opts.get<string>("description")),
utils::get_log_arguments_from_options(opts)
);
}

static class EvaluatorCategoryPlugin : public plugins::TypedCategoryPlugin<Evaluator> {
Expand Down
1 change: 0 additions & 1 deletion src/search/lp/lp_solver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void add_lp_solver_option_to_feature(plugins::Feature &feature) {
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)
Expand Down
31 changes: 15 additions & 16 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,17 @@ void add_merge_and_shrink_algorithm_options_to_feature(plugins::Feature &feature
Bounds("0.0", "infinity"));
}

tuple<shared_ptr < MergeStrategyFactory >,shared_ptr < ShrinkStrategy >,shared_ptr < LabelReduction >,bool,bool,int,int,int,double> get_merge_and_shrink_algorithm_arguments_from_options(const plugins::Options &opts) {

tuple<shared_ptr < MergeStrategyFactory >, shared_ptr < ShrinkStrategy >, shared_ptr < LabelReduction >, bool, bool, int, int, int, double> get_merge_and_shrink_algorithm_arguments_from_options(const plugins::Options &opts) {
return tuple_cat(
make_tuple(
opts.get < shared_ptr < MergeStrategyFactory >> ("merge_strategy"),
opts.get < shared_ptr < ShrinkStrategy >> ("shrink_strategy"),
opts.get < shared_ptr < LabelReduction >> ("label_reduction", nullptr),
opts.get<bool>("prune_unreachable_states"),
opts.get<bool>("prune_irrelevant_states")),
get_transition_system_size_limit_arguments_from_options(opts),
make_tuple(opts.get<double>("main_loop_max_time"))
);
make_tuple(
opts.get < shared_ptr < MergeStrategyFactory >> ("merge_strategy"),
opts.get < shared_ptr < ShrinkStrategy >> ("shrink_strategy"),
opts.get < shared_ptr < LabelReduction >> ("label_reduction", nullptr),
opts.get<bool>("prune_unreachable_states"),
opts.get<bool>("prune_irrelevant_states")),
get_transition_system_size_limit_arguments_from_options(opts),
make_tuple(opts.get<double>("main_loop_max_time"))
);
}

void add_transition_system_size_limit_options_to_feature(plugins::Feature &feature) {
Expand All @@ -498,12 +497,12 @@ void add_transition_system_size_limit_options_to_feature(plugins::Feature &featu
Bounds("-1", "infinity"));
}

tuple<int,int,int> get_transition_system_size_limit_arguments_from_options(const plugins::Options &opts){
tuple<int, int, int> get_transition_system_size_limit_arguments_from_options(const plugins::Options &opts) {
return make_tuple(
opts.get<int>("max_states"),
opts.get<int>("max_states_before_merge"),
opts.get<int>("threshold_before_merge")
);
opts.get<int>("max_states"),
opts.get<int>("max_states_before_merge"),
opts.get<int>("threshold_before_merge")
);
}

void handle_shrink_limit_options_defaults(plugins::Options &opts, const utils::Context &context) {
Expand Down
4 changes: 2 additions & 2 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class MergeAndShrinkAlgorithm {
};

extern void add_merge_and_shrink_algorithm_options_to_feature(plugins::Feature &feature);
std::tuple<std::shared_ptr < MergeStrategyFactory >,std::shared_ptr < ShrinkStrategy >,std::shared_ptr < LabelReduction >,bool,bool,int,int,int,double> get_merge_and_shrink_algorithm_arguments_from_options(const plugins::Options &opts);
std::tuple<std::shared_ptr < MergeStrategyFactory >, std::shared_ptr < ShrinkStrategy >, std::shared_ptr < LabelReduction >, bool, bool, int, int, int, double> get_merge_and_shrink_algorithm_arguments_from_options(const plugins::Options &opts);
extern void add_transition_system_size_limit_options_to_feature(plugins::Feature &feature);
std::tuple<int,int,int> get_transition_system_size_limit_arguments_from_options(const plugins::Options &opts);
std::tuple<int, int, int> get_transition_system_size_limit_arguments_from_options(const plugins::Options &opts);
extern void handle_shrink_limit_options_defaults(plugins::Options &opts, const utils::Context &context);
}

Expand Down
6 changes: 3 additions & 3 deletions src/search/merge_and_shrink/merge_tree_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void add_merge_tree_options_to_feature(plugins::Feature &feature) {

tuple<int, UpdateOption> get_merge_tree_arguments_from_options(const plugins::Options &opts) {
return tuple_cat(
utils::get_rng_arguments_from_options(opts),
make_tuple(opts.get<UpdateOption>("update_option"))
);
utils::get_rng_arguments_from_options(opts),
make_tuple(opts.get<UpdateOption>("update_option"))
);
}

static class MergeTreeFactoryCategoryPlugin : public plugins::TypedCategoryPlugin<MergeTreeFactory> {
Expand Down
16 changes: 8 additions & 8 deletions src/search/operator_counting/operator_counting_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ using namespace std;

namespace operator_counting {
OperatorCountingHeuristic::OperatorCountingHeuristic(
const vector<shared_ptr<ConstraintGenerator>> &constraint_generators,
bool use_integer_operator_counts,
lp::LPSolverType lp_solver_type,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const string &description,
utils::Verbosity verbosity)
const vector<shared_ptr<ConstraintGenerator>> &constraint_generators,
bool use_integer_operator_counts,
lp::LPSolverType lp_solver_type,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const string &description,
utils::Verbosity verbosity)
: Heuristic(transform, cache_estimates, description, verbosity),
constraint_generators(constraint_generators),
use_integer_operator_counts(use_integer_operator_counts),
Expand Down Expand Up @@ -123,7 +123,7 @@ class OperatorCountingHeuristicFeature : public plugins::TypedFeature<Evaluator,
options.get<bool>("use_integer_operator_counts"),
lp::get_lp_solver_arguments_from_options(options),
Heuristic::get_heuristic_arguments_from_options(options)
);
);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/cegar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ void add_cegar_wildcard_option_to_feature(plugins::Feature &feature) {
"plans which are sequences of single operators",
"true");
}
tuple<bool> get_cegar_wildcard_arguments_from_options(const plugins::Options &opts){
tuple<bool> get_cegar_wildcard_arguments_from_options(const plugins::Options &opts) {
return make_tuple(opts.get<bool>("use_wildcard_plans"));
}
}
1 change: 0 additions & 1 deletion src/search/pdbs/cegar.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ extern PatternInformation generate_pattern_with_cegar(
extern void add_cegar_implementation_notes_to_feature(plugins::Feature &feature);
extern void add_cegar_wildcard_option_to_feature(plugins::Feature &feature);
std::tuple<bool> get_cegar_wildcard_arguments_from_options(const plugins::Options &opts);

}

#endif
14 changes: 7 additions & 7 deletions src/search/pdbs/pattern_collection_generator_hillclimbing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,13 @@ void add_hillclimbing_options_to_feature(plugins::Feature &feature) {

tuple<int, int, int, int, double, int> get_hillclimbing_arguments_from_options(const plugins::Options &opts) {
return tuple_cat(
make_tuple(
opts.get<int>("pdb_max_size"),
opts.get<int>("collection_max_size"),
opts.get<int>("num_samples"),
opts.get<int>("min_improvement"),
opts.get<double>("max_time")),
utils::get_rng_arguments_from_options(opts));
make_tuple(
opts.get<int>("pdb_max_size"),
opts.get<int>("collection_max_size"),
opts.get<int>("num_samples"),
opts.get<int>("min_improvement"),
opts.get<double>("max_time")),
utils::get_rng_arguments_from_options(opts));
}

static void check_hillclimbing_options(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ class PatternCollectionGeneratorHillclimbing : public PatternCollectionGenerator

extern void add_hillclimbing_options_to_feature(plugins::Feature &feature);
std::tuple<int, int, int, int, double, int> get_hillclimbing_arguments_from_options(const plugins::Options &opts);

}

#endif
18 changes: 9 additions & 9 deletions src/search/pdbs/pattern_collection_generator_multiple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,16 @@ void add_multiple_options_to_feature(plugins::Feature &feature) {
}

tuple<int, int, double, double, double, double, bool, int, utils::Verbosity>
get_multiple_arguments_from_options(const plugins::Options &opts) {
get_multiple_arguments_from_options(const plugins::Options &opts) {
return tuple_cat(make_tuple(
opts.get<int>("max_pdb_size"),
opts.get<int>("max_collection_size"),
opts.get<double>("pattern_generation_max_time"),
opts.get<double>("total_max_time"),
opts.get<double>("stagnation_limit"),
opts.get<double>("blacklist_trigger_percentage"),
opts.get<bool>("enable_blacklist_on_stagnation")
),
opts.get<int>("max_pdb_size"),
opts.get<int>("max_collection_size"),
opts.get<double>("pattern_generation_max_time"),
opts.get<double>("total_max_time"),
opts.get<double>("stagnation_limit"),
opts.get<double>("blacklist_trigger_percentage"),
opts.get<bool>("enable_blacklist_on_stagnation")
),
utils::get_rng_arguments_from_options(opts),
get_generator_arguments_from_options(opts));
}
Expand Down
2 changes: 1 addition & 1 deletion src/search/pdbs/pattern_collection_generator_multiple.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ extern void add_multiple_options_to_feature(
plugins::Feature &feature);

extern std::tuple<int, int, double, double, double, double, bool, int, utils::Verbosity>
get_multiple_arguments_from_options(const plugins::Options &opts);
get_multiple_arguments_from_options(const plugins::Options &opts);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class PatternCollectionGeneratorMultipleRandomFeature : public plugins::TypedFea
virtual shared_ptr<PatternCollectionGeneratorMultipleRandom> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return plugins::make_shared_from_arg_tuples<PatternCollectionGeneratorMultipleRandom>(
get_random_pattern_bidirectional_arguments_from_options(opts),
get_multiple_arguments_from_options(opts)
get_random_pattern_bidirectional_arguments_from_options(opts),
get_multiple_arguments_from_options(opts)
);
}
};
Expand Down
10 changes: 5 additions & 5 deletions src/search/plugins/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ class TypedFeature : public FeatureAuto<Constructed> {
constructor. The resulting arguments will be used as arguments to make_shared.
*/
// TODO issue1082 where should this live? optimize with std::forward?
template<typename T, typename ...Arguments>
std::shared_ptr<T> make_shared_from_arg_tuples(Arguments...arguments) {
template<typename T, typename ... Arguments>
std::shared_ptr<T> make_shared_from_arg_tuples(Arguments... arguments) {
return std::apply(
[](auto...flattened_args) {
return std::make_shared<T>(flattened_args...);
[](auto... flattened_args) {
return std::make_shared<T>(flattened_args ...);
},
utils::flatten_tuple(std::tuple<Arguments...>(arguments...)));
utils::flatten_tuple(std::tuple<Arguments...>(arguments ...)));
}

class Plugin {
Expand Down
4 changes: 2 additions & 2 deletions src/search/utils/rng_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ void add_rng_options_to_feature(plugins::Feature &feature) {

tuple<int> get_rng_arguments_from_options(const plugins::Options &opts) {
return make_tuple(
opts.get<int>("random_seed")
);
opts.get<int>("random_seed")
);
}

shared_ptr<RandomNumberGenerator> get_rng(int seed) {
Expand Down
54 changes: 30 additions & 24 deletions src/search/utils/tuples.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,69 @@
namespace utils {
template<class U, class T, bool can_move>
struct wrapper {
T* ptr;
wrapper(T& t) : ptr(std::addressof(t)) {}
T *ptr;
wrapper(T &t) : ptr(std::addressof(t)) {}

using unwrapped_type =
std::conditional_t<can_move,
std::conditional_t<std::is_lvalue_reference<U>{}, T&, T&&>,
std::conditional_t<std::is_rvalue_reference<U>{}, T&&, T&>>;
std::conditional_t < can_move,
std::conditional_t < std::is_lvalue_reference<U> {}, T &, T && >,
std::conditional_t < std::is_rvalue_reference<U> {}, T &&, T & >>;
using tuple_element_type = U;

unwrapped_type unwrap() const{
unwrapped_type unwrap() const {
return std::forward<unwrapped_type>(*ptr);
}
};

template<class... Wrappers, std::size_t... Is>
auto unwrap_tuple(const std::tuple<Wrappers...>& t, std::index_sequence<Is...>) {
template<class ... Wrappers, std::size_t... Is>
auto unwrap_tuple(const std::tuple<Wrappers...> &t, std::index_sequence<Is...>) {
return std::tuple<typename Wrappers::tuple_element_type...>(std::get<Is>(t).unwrap()...);
}

template<class... Wrappers>
auto unwrap_tuple(const std::tuple<Wrappers...>& t) {
template<class ... Wrappers>
auto unwrap_tuple(const std::tuple<Wrappers...> &t) {
return unwrap_tuple(t, std::index_sequence_for<Wrappers...>());
}

template<bool can_move, class V, class T>
auto wrap_and_flatten(T& t, char){
auto wrap_and_flatten(T &t, char) {
return std::make_tuple(wrapper<V, T, can_move>(t));
}
template<class T> struct is_tuple : std::false_type {};
template<class... Ts> struct is_tuple<std::tuple<Ts...>> : std::true_type {};
template<class T> struct is_tuple<const T> : is_tuple<T> {};
template<class T> struct is_tuple<volatile T> : is_tuple<T> {};
template<class T>
struct is_tuple : std::false_type {};
template<class ... Ts>
struct is_tuple<std::tuple<Ts...>> : std::true_type {};
template<class T>
struct is_tuple<const T> : is_tuple<T> {};
template<class T>
struct is_tuple<volatile T> : is_tuple<T> {};

template<bool can_move, class, class Tuple,
class = std::enable_if_t<is_tuple<std::decay_t<Tuple>>{}>>
auto wrap_and_flatten(Tuple& t, int);
class = std::enable_if_t < is_tuple<std::decay_t<Tuple>>{} > >
auto wrap_and_flatten(Tuple &t, int);

template<bool can_move, class Tuple, std::size_t... Is>
auto wrap_and_flatten(Tuple& t, std::index_sequence<Is...>) {
auto wrap_and_flatten(Tuple &t, std::index_sequence<Is...>) {
return std::tuple_cat(wrap_and_flatten<can_move, std::tuple_element_t<Is, std::remove_cv_t<Tuple>>>(std::get<Is>(t), 0)...);
}

template<bool can_move, class V, class Tuple, class>
auto wrap_and_flatten(Tuple& t, int) {
using seq_type = std::make_index_sequence<std::tuple_size<Tuple>{}>;
auto wrap_and_flatten(Tuple &t, int) {
using seq_type = std::make_index_sequence < std::tuple_size<Tuple> {}
>;
return wrap_and_flatten<can_move>(t, seq_type());
}

template<class Tuple>
auto wrap_and_flatten_tuple(Tuple&& t){
auto wrap_and_flatten_tuple(Tuple &&t) {
constexpr bool can_move = !std::is_lvalue_reference<Tuple>{};
using seq_type = std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>{}>;
using seq_type = std::make_index_sequence < std::tuple_size<std::decay_t<Tuple>> {}
>;
return wrap_and_flatten<can_move>(t, seq_type());
}

template <typename T>
auto flatten_tuple(T&& t) {
template<typename T>
auto flatten_tuple(T &&t) {
return unwrap_tuple(wrap_and_flatten_tuple(std::forward<T>(t)));
}
}
Expand Down

0 comments on commit 52c9451

Please sign in to comment.