Skip to content

Commit

Permalink
[issue1082] update M&S components.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDold committed Feb 7, 2024
1 parent 4c2bdb1 commit 2b7bf6c
Show file tree
Hide file tree
Showing 22 changed files with 188 additions and 176 deletions.
50 changes: 25 additions & 25 deletions src/search/AAA_Mechanical_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ search
│ └── relaxation_heuristic.h✅
├── landmarks
├── lp
├── merge_and_shrink
├── merge_and_shrink
│ ├── distances.cc✅
│ ├── distances.h✅
│ ├── factored_transition_system.cc✅
Expand Down Expand Up @@ -140,34 +140,34 @@ search
│ ├── 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
│ ├── merge_strategy_sccs.h
│ ├── merge_strategy_stateless.cc
│ ├── merge_strategy_stateless.h
│ ├── merge_tree.cc
│ ├── merge_strategy_precomputed.cc
│ ├── merge_strategy_precomputed.h
│ ├── merge_strategy_sccs.cc
│ ├── merge_strategy_sccs.h
│ ├── merge_strategy_stateless.cc
│ ├── merge_strategy_stateless.h
│ ├── merge_tree.cc
│ ├── merge_tree_factory.cc✅
│ ├── merge_tree_factory.h✅
│ ├── merge_tree_factory_linear.cc✅
│ ├── merge_tree_factory_linear.h✅
│ ├── merge_tree.h
│ ├── shrink_bisimulation.cc
│ ├── shrink_bisimulation.h
│ ├── shrink_bucket_based.cc
│ ├── shrink_bucket_based.h
│ ├── shrink_fh.cc
│ ├── shrink_fh.h
│ ├── shrink_random.cc
│ ├── shrink_random.h
│ ├── shrink_strategy.cc
│ ├── shrink_strategy.h
│ ├── transition_system.cc
│ ├── transition_system.h
│ ├── types.cc
│ ├── types.h
│ ├── utils.cc
│ └── utils.h
│ ├── merge_tree.h
│ ├── shrink_bisimulation.cc
│ ├── shrink_bisimulation.h
│ ├── shrink_bucket_based.cc
│ ├── shrink_bucket_based.h
│ ├── shrink_fh.cc
│ ├── shrink_fh.h
│ ├── shrink_random.cc
│ ├── shrink_random.h
│ ├── shrink_strategy.cc
│ ├── shrink_strategy.h
│ ├── transition_system.cc
│ ├── transition_system.h
│ ├── types.cc
│ ├── types.h
│ ├── utils.cc
│ └── utils.h
├── open_list_factory.cc
├── open_list_factory.h
├── open_list.h
Expand Down
1 change: 0 additions & 1 deletion src/search/merge_and_shrink/label_reduction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ class LabelReductionFeature : public plugins::TypedFeature<LabelReduction, Label
"random");
// Add random_seed option.
utils::add_rng_options(*this);
utils::add_log_options_to_feature(*this);
}

virtual shared_ptr<LabelReduction> create_component(const plugins::Options &opts, const utils::Context &context) const override {
Expand Down
57 changes: 20 additions & 37 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,27 @@ static void log_progress(const utils::Timer &timer, const string &msg, utils::Lo
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
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,
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")),
shrink_strategy(opts.get<shared_ptr<ShrinkStrategy>>("shrink_strategy")),
label_reduction(opts.get<shared_ptr<LabelReduction>>("label_reduction", nullptr)),
max_states(opts.get<int>("max_states")),
max_states_before_merge(opts.get<int>("max_states_before_merge")),
shrink_threshold_before_merge(opts.get<int>("threshold_before_merge")),
prune_unreachable_states(opts.get<bool>("prune_unreachable_states")),
prune_irrelevant_states(opts.get<bool>("prune_irrelevant_states")),
log(utils::get_log_from_options(opts)),
main_loop_max_time(opts.get<double>("main_loop_max_time")),
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);
Expand Down
22 changes: 10 additions & 12 deletions src/search/merge_and_shrink/merge_and_shrink_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,16 @@ class MergeAndShrinkAlgorithm {
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);
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,
utils::Verbosity verbosity);
FactoredTransitionSystem build_factored_transition_system(const TaskProxy &task_proxy);
};

Expand Down
79 changes: 41 additions & 38 deletions src/search/merge_and_shrink/merge_and_shrink_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@ using utils::ExitCode;

namespace merge_and_shrink {
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) {
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(
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
);
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 @@ -196,7 +198,7 @@ class MergeAndShrinkHeuristicFeature : public plugins::TypedFeature<Evaluator, M
"2018")
);

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

document_note(
Expand Down Expand Up @@ -252,18 +254,19 @@ 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 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")
);
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", nullptr),
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
35 changes: 17 additions & 18 deletions src/search/merge_and_shrink/merge_and_shrink_heuristic.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#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 @@ -13,6 +9,10 @@ namespace merge_and_shrink {
class FactoredTransitionSystem;
class MergeAndShrinkRepresentation;

class MergeStrategyFactory;
class ShrinkStrategy;
class LabelReduction;

class MergeAndShrinkHeuristic : public Heuristic {
// The final merge-and-shrink representations, storing goal distances.
std::vector<std::unique_ptr<MergeAndShrinkRepresentation>> mas_representations;
Expand All @@ -25,20 +25,19 @@ class MergeAndShrinkHeuristic : public Heuristic {
virtual int compute_heuristic(const State &ancestor_state) override;
public:
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
);
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 @@ -11,9 +11,9 @@ using namespace std;

namespace merge_and_shrink {
MergeSelectorScoreBasedFiltering::MergeSelectorScoreBasedFiltering(
const vector<shared_ptr<MergeScoringFunction>> &scoring_functions
)
: merge_scoring_functions(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 @@ -119,9 +119,9 @@ class MergeSelectorScoreBasedFilteringFeature : public plugins::TypedFeature<Mer

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")
);
opts.get_list<shared_ptr<MergeScoringFunction>>(
"scoring_functions")
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class MergeSelectorScoreBasedFiltering : public MergeSelector {
virtual void dump_selector_specific_options(utils::LogProxy &log) const override;
public:
explicit MergeSelectorScoreBasedFiltering(
const std::vector<std::shared_ptr<MergeScoringFunction>> &scoring_functions
);
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
2 changes: 1 addition & 1 deletion src/search/merge_and_shrink/merge_strategy_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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){
shared_ptr<tuple<utils::Verbosity>> get_merge_strategy_parameters_from_options(const plugins::Options &opts) {
return utils::get_log_parameters_from_options(opts);
}

Expand Down
4 changes: 1 addition & 3 deletions src/search/merge_and_shrink/merge_strategy_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace merge_and_shrink {
class FactoredTransitionSystem;
class MergeStrategy;

// TODO issue1082 check with tox
class MergeStrategyFactory {
protected:
mutable utils::LogProxy log;
Expand All @@ -26,8 +25,7 @@ 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 Down
Loading

0 comments on commit 2b7bf6c

Please sign in to comment.