Skip to content

Commit

Permalink
[issue1082] Update CGHeuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
grucla committed Feb 7, 2024
1 parent 97246e8 commit adf5127
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/search/AAA_Mechanical_Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/search/heuristics/cg_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> &depends_on, int max_cache_size) const {
/*
Expand Down
1 change: 0 additions & 1 deletion src/search/heuristics/cg_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 16 additions & 7 deletions src/search/heuristics/cg_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractTask> &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),
Expand All @@ -26,7 +31,6 @@ CGHeuristic::CGHeuristic(const plugins::Options &opts)
log << "Initializing causal graph heuristic..." << endl;
}

int max_cache_size = opts.get<int>("max_cache_size");
if (max_cache_size > 0)
cache = utils::make_unique_ptr<CGCache>(task_proxy, max_cache_size, log);

Expand All @@ -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;
}
Expand Down Expand Up @@ -295,7 +296,7 @@ class CGHeuristicFeature : public plugins::TypedFeature<Evaluator, CGHeuristic>
"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");
Expand All @@ -310,6 +311,14 @@ class CGHeuristicFeature : public plugins::TypedFeature<Evaluator, CGHeuristic>
document_property("safe", "no");
document_property("preferred operators", "yes");
}

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")
);
}
};

static plugins::FeaturePlugin<CGHeuristicFeature> _plugin;
Expand Down
8 changes: 6 additions & 2 deletions src/search/heuristics/cg_heuristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractTask> &transform,
bool cache_estimates,
const std::string &name,
utils::Verbosity verbosity);
virtual bool dead_ends_are_reliable() const override;
};
}
Expand Down

0 comments on commit adf5127

Please sign in to comment.