Skip to content

Commit

Permalink
Merge branch 'issue1082-MaS' into issue1082-partial-Mas
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 7, 2024
2 parents 681209e + e023dea commit 4c2bdb1
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 62 deletions.
68 changes: 34 additions & 34 deletions src/search/AAA_Mechanical_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,50 +96,50 @@ search
├── landmarks
├── lp
├── merge_and_shrink
│ ├── distances.cc
│ ├── distances.h
│ ├── factored_transition_system.cc
│ ├── factored_transition_system.h
│ ├── fts_factory.cc
│ ├── fts_factory.h
│ ├── label_reduction.cc
│ ├── label_reduction.h
│ ├── labels.cc
│ ├── labels.h
│ ├── merge_and_shrink_algorithm.cc
│ ├── merge_and_shrink_algorithm.h
│ ├── merge_and_shrink_heuristic.cc
│ ├── merge_and_shrink_heuristic.h
│ ├── merge_and_shrink_representation.cc
│ ├── merge_and_shrink_representation.h
│ ├── merge_scoring_function.cc
│ ├── distances.cc
│ ├── distances.h
│ ├── factored_transition_system.cc
│ ├── factored_transition_system.h
│ ├── fts_factory.cc
│ ├── fts_factory.h
│ ├── label_reduction.cc
│ ├── label_reduction.h
│ ├── labels.cc
│ ├── labels.h
│ ├── merge_and_shrink_algorithm.cc
│ ├── merge_and_shrink_algorithm.h
│ ├── merge_and_shrink_heuristic.cc
│ ├── merge_and_shrink_heuristic.h
│ ├── merge_and_shrink_representation.cc
│ ├── merge_and_shrink_representation.h
│ ├── merge_scoring_function.cc
│ ├── merge_scoring_function_dfp.cc✅
│ ├── merge_scoring_function_dfp.h✅
│ ├── merge_scoring_function_goal_relevance.cc✅
│ ├── merge_scoring_function_goal_relevance.h✅
│ ├── merge_scoring_function.h
│ ├── merge_scoring_function.h
│ ├── merge_scoring_function_miasm.cc✅
│ ├── merge_scoring_function_miasm.h✅
│ ├── merge_scoring_function_miasm_utils.cc
│ ├── merge_scoring_function_miasm_utils.h
│ ├── merge_scoring_function_miasm_utils.cc
│ ├── merge_scoring_function_miasm_utils.h
│ ├── merge_scoring_function_single_random.cc✅
│ ├── merge_scoring_function_single_random.h✅
│ ├── merge_scoring_function_total_order.cc✅
│ ├── merge_scoring_function_total_order.h✅
│ ├── merge_selector.cc
│ ├── merge_selector.h
│ ├── merge_selector_score_based_filtering.cc
│ ├── merge_selector_score_based_filtering.h
│ ├── merge_strategy.cc
│ ├── merge_strategy_factory.cc
│ ├── merge_strategy_factory.h
│ ├── merge_strategy_factory_precomputed.cc
│ ├── merge_strategy_factory_precomputed.h
│ ├── merge_strategy_factory_sccs.cc
│ ├── merge_strategy_factory_sccs.h
│ ├── merge_strategy_factory_stateless.cc
│ ├── merge_strategy_factory_stateless.h
│ ├── merge_strategy.h
│ ├── merge_selector.cc
│ ├── merge_selector.h
│ ├── merge_selector_score_based_filtering.cc
│ ├── merge_selector_score_based_filtering.h
│ ├── merge_strategy.cc
│ ├── merge_strategy_factory.cc
│ ├── merge_strategy_factory.h
│ ├── merge_strategy_factory_precomputed.cc
│ ├── merge_strategy_factory_precomputed.h
│ ├── merge_strategy_factory_sccs.cc
│ ├── merge_strategy_factory_sccs.h
│ ├── merge_strategy_factory_stateless.cc
│ ├── merge_strategy_factory_stateless.h
│ ├── merge_strategy.h
│ ├── merge_strategy_precomputed.cc
│ ├── merge_strategy_precomputed.h
│ ├── merge_strategy_sccs.cc
Expand Down
27 changes: 27 additions & 0 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ namespace merge_and_shrink {
static void log_progress(const utils::Timer &timer, const string &msg, utils::LogProxy &log) {
log << "M&S algorithm timer: " << timer << " (" << msg << ")" << endl;
}
MergeAndShrinkAlgorithm::MergeAndShrinkAlgorithm(
shared_ptr<MergeStrategyFactory> merge_strategy,
shared_ptr<ShrinkStrategy> shrink_strategy,
shared_ptr<LabelReduction> label_reduction,
int max_states,
int max_states_before_merge,
int threshold_before_merge,
bool prune_unreachable_states,
bool prune_irrelevant_states,
double main_loop_max_time,
utils::Verbosity verbosity
) :
merge_strategy_factory(merge_strategy),
shrink_strategy(shrink_strategy),
label_reduction(label_reduction),
max_states(max_states),
max_states_before_merge(max_states_before_merge),
shrink_threshold_before_merge(threshold_before_merge),
prune_unreachable_states(prune_unreachable_states),
prune_irrelevant_states(prune_irrelevant_states),
log(utils::get_log_for_verbosity(verbosity)),
main_loop_max_time(main_loop_max_time),
starting_peak_memory(0) {
assert(max_states_before_merge > 0);
assert(max_states >= max_states_before_merge);
assert(shrink_threshold_before_merge <= max_states_before_merge);
}

MergeAndShrinkAlgorithm::MergeAndShrinkAlgorithm(const plugins::Options &opts) :
merge_strategy_factory(opts.get<shared_ptr<MergeStrategyFactory>>("merge_strategy")),
Expand Down
12 changes: 12 additions & 0 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class MergeAndShrinkAlgorithm {
FactoredTransitionSystem &fts,
const TaskProxy &task_proxy);
public:
MergeAndShrinkAlgorithm(
std::shared_ptr<MergeStrategyFactory> merge_strategy,
std::shared_ptr<ShrinkStrategy> shrink_strategy,
std::shared_ptr<LabelReduction> label_reduction,
int max_states,
int max_states_before_merge,
int threshold_before_merge,
bool prune_unreachable_states,
bool prune_irrelevant_states,
double main_loop_max_time,
utils::Verbosity verbosity
);
explicit MergeAndShrinkAlgorithm(const plugins::Options &opts);
FactoredTransitionSystem build_factored_transition_system(const TaskProxy &task_proxy);
};
Expand Down
44 changes: 40 additions & 4 deletions src/search/merge_and_shrink/merge_and_shrink_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,35 @@ using namespace std;
using utils::ExitCode;

namespace merge_and_shrink {
MergeAndShrinkHeuristic::MergeAndShrinkHeuristic(const plugins::Options &opts)
: Heuristic(opts) {
MergeAndShrinkHeuristic::MergeAndShrinkHeuristic(
const shared_ptr<MergeStrategyFactory> &merge_strategy,
const shared_ptr<ShrinkStrategy> &shrink_strategy,
const shared_ptr<LabelReduction> &label_reduction,
int max_states,
int max_states_before_merge,
int threshold_before_merge,
bool prune_unreachable_states,
bool prune_irrelevant_states,
double main_loop_max_time,
const shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const string &description,
utils::Verbosity verbosity
)
: Heuristic(transform, cache_estimates, description, verbosity) {
log << "Initializing merge-and-shrink heuristic..." << endl;
MergeAndShrinkAlgorithm algorithm(opts);
MergeAndShrinkAlgorithm algorithm(
merge_strategy,
shrink_strategy,
label_reduction,
max_states,
max_states_before_merge,
threshold_before_merge,
prune_unreachable_states,
prune_irrelevant_states,
main_loop_max_time,
verbosity
);
FactoredTransitionSystem fts = algorithm.build_factored_transition_system(task_proxy);
extract_factors(fts);
log << "Done initializing merge-and-shrink heuristic." << endl << endl;
Expand Down Expand Up @@ -227,7 +252,18 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature<Evaluator, M
virtual shared_ptr<MergeAndShrinkHeuristic> create_component(const plugins::Options &options, const utils::Context &context) const override {
plugins::Options options_copy(options);
handle_shrink_limit_options_defaults(options_copy, context);
return make_shared<MergeAndShrinkHeuristic>(options_copy);
return plugins::make_shared_from_args_tuple_and_args<MergeAndShrinkHeuristic>(
Heuristic::get_heuristic_parameters_from_options(options_copy),
options_copy.get<shared_ptr<MergeStrategyFactory>>("merge_strategy"),
options_copy.get<shared_ptr<ShrinkStrategy>>("shrink_strategy"),
options_copy.get<shared_ptr<LabelReduction>>("label_reduction"),
options_copy.get<int>("max_states"),
options_copy.get<int>("max_states_before_merge"),
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")
);
}
};

Expand Down
20 changes: 19 additions & 1 deletion src/search/merge_and_shrink/merge_and_shrink_heuristic.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef MERGE_AND_SHRINK_MERGE_AND_SHRINK_HEURISTIC_H
#define MERGE_AND_SHRINK_MERGE_AND_SHRINK_HEURISTIC_H

#include "merge_strategy_factory.h"
#include "shrink_strategy.h"
#include "label_reduction.h"

#include "../heuristic.h"

#include <memory>
Expand All @@ -20,7 +24,21 @@ class MergeAndShrinkHeuristic : public Heuristic {
protected:
virtual int compute_heuristic(const State &ancestor_state) override;
public:
explicit MergeAndShrinkHeuristic(const plugins::Options &opts);
MergeAndShrinkHeuristic(
const std::shared_ptr<MergeStrategyFactory> &merge_strategy,
const std::shared_ptr<ShrinkStrategy> &shrink_strategy,
const std::shared_ptr<LabelReduction> &label_reduction,
int max_states,
int max_states_before_merge,
int threshold_before_merge,
bool prune_unreachable_states,
bool prune_irrelevant_states,
double main_loop_max_time,
const std::shared_ptr<AbstractTask> &transform,
bool cache_estimates,
const std::string &description,
utils::Verbosity verbosity
);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

#include <memory>

namespace plugins {
class Options;
}

namespace utils {
class RandomNumberGenerator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <memory>

namespace plugins {
class Options;
class Feature;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ using namespace std;

namespace merge_and_shrink {
MergeSelectorScoreBasedFiltering::MergeSelectorScoreBasedFiltering(
const plugins::Options &options)
: merge_scoring_functions(
options.get_list<shared_ptr<MergeScoringFunction>>(
"scoring_functions")) {
const vector<shared_ptr<MergeScoringFunction>> &scoring_functions
)
: merge_scoring_functions(scoring_functions) {
}

static vector<pair<int, int>> get_remaining_candidates(
Expand Down Expand Up @@ -117,6 +116,13 @@ class MergeSelectorScoreBasedFilteringFeature : public plugins::TypedFeature<Mer
"scoring_functions",
"The list of scoring functions used to compute scores for candidates.");
}

virtual shared_ptr<MergeSelectorScoreBasedFiltering> create_component(const plugins::Options &opts, const utils::Context &) const override {
return make_shared<MergeSelectorScoreBasedFiltering>(
opts.get_list<shared_ptr<MergeScoringFunction>>(
"scoring_functions")
);
}
};

static plugins::FeaturePlugin<MergeSelectorScoreBasedFilteringFeature> _plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class MergeSelectorScoreBasedFiltering : public MergeSelector {
virtual std::string name() const override;
virtual void dump_selector_specific_options(utils::LogProxy &log) const override;
public:
explicit MergeSelectorScoreBasedFiltering(const plugins::Options &options);
virtual ~MergeSelectorScoreBasedFiltering() override = default;
explicit MergeSelectorScoreBasedFiltering(
const std::vector<std::shared_ptr<MergeScoringFunction>> &scoring_functions
);
virtual std::pair<int, int> select_merge(
const FactoredTransitionSystem &fts,
const std::vector<int> &indices_subset = std::vector<int>()) const override;
Expand Down
5 changes: 5 additions & 0 deletions src/search/merge_and_shrink/merge_strategy_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ 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);
}


static class MergeStrategyFactoryCategoryPlugin : public plugins::TypedCategoryPlugin<MergeStrategyFactory> {
public:
MergeStrategyFactoryCategoryPlugin() : TypedCategoryPlugin("MergeStrategy") {
Expand Down
4 changes: 3 additions & 1 deletion src/search/merge_and_shrink/merge_strategy_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class MergeStrategyFactory {
virtual void dump_strategy_specific_options() const = 0;
public:
MergeStrategyFactory(
utils::Verbosity verbosity);
utils::Verbosity verbosity
);
virtual ~MergeStrategyFactory() = default;
void dump_options() const;
virtual std::unique_ptr<MergeStrategy> compute_merge_strategy(
Expand All @@ -37,6 +38,7 @@ 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);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ class MergeStrategyFactoryPrecomputedFeature : public plugins::TypedFeature<Merg
}
virtual shared_ptr<MergeStrategyFactoryPrecomputed> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return make_shared<MergeStrategyFactoryPrecomputed>(
opts.get<shared_ptr<MergeTreeFactory>>("merge_tree"),
opts.get<utils::Verbosity>("verbosity"));
return plugins::make_shared_from_args_tuple_and_args<MergeStrategyFactoryPrecomputed>(
get_merge_strategy_parameters_from_options(opts),
opts.get<shared_ptr<MergeTreeFactory>>("merge_tree")
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class MergeStrategyFactoryPrecomputed : public MergeStrategyFactory {
public:
MergeStrategyFactoryPrecomputed(
const std::shared_ptr<MergeTreeFactory> &merge_tree,
utils::Verbosity verbosity);
utils::Verbosity verbosity
);
virtual std::unique_ptr<MergeStrategy> compute_merge_strategy(
const TaskProxy &task_proxy,
const FactoredTransitionSystem &fts) override;
Expand Down
9 changes: 5 additions & 4 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,12 @@ class MergeStrategyFactorySCCsFeature : public plugins::TypedFeature<MergeStrate
"You have to specify exactly one of the options merge_tree "
"and merge_selector!");
}
return make_shared<MergeStrategyFactorySCCs>(
return plugins::make_shared_from_args_tuple_and_args<MergeStrategyFactorySCCs>(
get_merge_strategy_parameters_from_options(opts),
opts.get<OrderOfSCCs>("order_of_sccs"),
opts.get < shared_ptr < MergeTreeFactory >> ("merge_tree", nullptr),
opts.get < shared_ptr < MergeSelector >> ("merge_selector", nullptr),
opts.get<utils::Verbosity>("verbosity"));
opts.get<shared_ptr<MergeTreeFactory>> ("merge_tree", nullptr),
opts.get<shared_ptr<MergeSelector>> ("merge_selector", nullptr)
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ class MergeStrategyFactoryStatelessFeature : public plugins::TypedFeature<MergeS

virtual shared_ptr<MergeStrategyFactoryStateless> create_component(
const plugins::Options &opts, const utils::Context &) const override {
return make_shared<MergeStrategyFactoryStateless>(
opts.get<shared_ptr<MergeSelector>>("merge_selector"),
opts.get<utils::Verbosity>("verbosity"));
return plugins::make_shared_from_args_tuple_and_args<MergeStrategyFactoryStateless>(
get_merge_strategy_parameters_from_options(opts),
opts.get<shared_ptr<MergeSelector>>("merge_selector")
);
}
};

Expand Down

0 comments on commit 4c2bdb1

Please sign in to comment.