From adf5127d79305d0155b444a2e208af6067428410 Mon Sep 17 00:00:00 2001 From: Claudia Grundke Date: Wed, 7 Feb 2024 16:44:47 +0100 Subject: [PATCH] [issue1082] Update CGHeuristic --- src/search/AAA_Mechanical_Changes.md | 12 ++++++------ src/search/heuristics/cg_cache.cc | 3 --- src/search/heuristics/cg_cache.h | 1 - src/search/heuristics/cg_heuristic.cc | 23 ++++++++++++++++------- src/search/heuristics/cg_heuristic.h | 8 ++++++-- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/search/AAA_Mechanical_Changes.md b/src/search/AAA_Mechanical_Changes.md index 0bfba91112..b7e54b6e1a 100644 --- a/src/search/AAA_Mechanical_Changes.md +++ b/src/search/AAA_Mechanical_Changes.md @@ -73,12 +73,12 @@ search │ ├── blind_search_heuristic.h✅ │ ├── cea_heuristic.cc✅ │ ├── cea_heuristic.h✅ -│ ├── cg_cache.cc -│ ├── cg_cache.h -│ ├── cg_heuristic.cc -│ ├── cg_heuristic.h -│ ├── domain_transition_graph.cc -│ ├── domain_transition_graph.h +│ ├── cg_cache.cc✅ +│ ├── cg_cache.h✅ +│ ├── cg_heuristic.cc✅ +│ ├── cg_heuristic.h✅ +│ ├── domain_transition_graph.cc✅ +│ ├── domain_transition_graph.h✅ │ ├── ff_heuristic.cc✅ │ ├── ff_heuristic.h✅ │ ├── goal_count_heuristic.cc diff --git a/src/search/heuristics/cg_cache.cc b/src/search/heuristics/cg_cache.cc index 822940e66d..2479136d34 100644 --- a/src/search/heuristics/cg_cache.cc +++ b/src/search/heuristics/cg_cache.cc @@ -71,9 +71,6 @@ CGCache::CGCache(const TaskProxy &task_proxy, int max_cache_size, utils::LogProx } } -CGCache::~CGCache() { -} - int CGCache::compute_required_cache_size( int var_id, const vector &depends_on, int max_cache_size) const { /* diff --git a/src/search/heuristics/cg_cache.h b/src/search/heuristics/cg_cache.h index 06ca91d1ea..87e43da766 100644 --- a/src/search/heuristics/cg_cache.h +++ b/src/search/heuristics/cg_cache.h @@ -27,7 +27,6 @@ class CGCache { static const int NOT_COMPUTED = -2; CGCache(const TaskProxy &task_proxy, int max_cache_size, utils::LogProxy &log); - ~CGCache(); bool is_cached(int var) const { return !cache[var].empty(); diff --git a/src/search/heuristics/cg_heuristic.cc b/src/search/heuristics/cg_heuristic.cc index 6b491451c2..f70bde62ac 100644 --- a/src/search/heuristics/cg_heuristic.cc +++ b/src/search/heuristics/cg_heuristic.cc @@ -16,8 +16,13 @@ using namespace std; using namespace domain_transition_graph; namespace cg_heuristic { -CGHeuristic::CGHeuristic(const plugins::Options &opts) - : Heuristic(opts), +CGHeuristic::CGHeuristic( + int max_cache_size, + const shared_ptr &transform, + bool cache_estimates, + const string &name, + utils::Verbosity verbosity) + : Heuristic(transform, cache_estimates, name, verbosity), cache_hits(0), cache_misses(0), helpful_transition_extraction_counter(0), @@ -26,7 +31,6 @@ CGHeuristic::CGHeuristic(const plugins::Options &opts) log << "Initializing causal graph heuristic..." << endl; } - int max_cache_size = opts.get("max_cache_size"); if (max_cache_size > 0) cache = utils::make_unique_ptr(task_proxy, max_cache_size, log); @@ -41,9 +45,6 @@ CGHeuristic::CGHeuristic(const plugins::Options &opts) transition_graphs = factory.build_dtgs(); } -CGHeuristic::~CGHeuristic() { -} - bool CGHeuristic::dead_ends_are_reliable() const { return false; } @@ -295,7 +296,7 @@ class CGHeuristicFeature : public plugins::TypedFeature "maximum number of cached entries per variable (set to 0 to disable cache)", "1000000", plugins::Bounds("0", "infinity")); - Heuristic::add_options_to_feature(*this); + Heuristic::add_options_to_feature(*this, "cg"); document_language_support("action costs", "supported"); document_language_support("conditional effects", "supported"); @@ -310,6 +311,14 @@ class CGHeuristicFeature : public plugins::TypedFeature document_property("safe", "no"); document_property("preferred operators", "yes"); } + + virtual shared_ptr create_component( + const plugins::Options &opts, const utils::Context &) const override { + return plugins::make_shared_from_args_tuple_and_args( + Heuristic::get_heuristic_parameters_from_options(opts), + opts.get("max_cache_size") + ); + } }; static plugins::FeaturePlugin _plugin; diff --git a/src/search/heuristics/cg_heuristic.h b/src/search/heuristics/cg_heuristic.h index 3ec02aedb4..f565ce4cf5 100644 --- a/src/search/heuristics/cg_heuristic.h +++ b/src/search/heuristics/cg_heuristic.h @@ -43,8 +43,12 @@ class CGHeuristic : public Heuristic { protected: virtual int compute_heuristic(const State &ancestor_state) override; public: - explicit CGHeuristic(const plugins::Options &opts); - ~CGHeuristic(); + explicit CGHeuristic( + int max_cache_size, + const std::shared_ptr &transform, + bool cache_estimates, + const std::string &name, + utils::Verbosity verbosity); virtual bool dead_ends_are_reliable() const override; }; }