From 23d98a337116f0496f8fb100b4c00038794252de Mon Sep 17 00:00:00 2001 From: Florian Pommerening Date: Wed, 11 Dec 2024 01:06:47 +0100 Subject: [PATCH] get rid of g_axiom_evaluators --- src/search/abstract_task.h | 4 ++++ src/search/axioms.cc | 2 -- src/search/axioms.h | 5 ----- src/search/state_registry.cc | 2 +- src/search/task_proxy.cc | 2 +- src/search/task_proxy.h | 4 ++++ src/search/tasks/default_value_axioms_task.cc | 8 ++++++-- src/search/tasks/default_value_axioms_task.h | 3 +++ src/search/tasks/delegating_task.cc | 4 ++++ src/search/tasks/delegating_task.h | 2 ++ src/search/tasks/root_task.cc | 12 +++++++++--- 11 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/search/abstract_task.h b/src/search/abstract_task.h index be0eb10375..955d41cb85 100644 --- a/src/search/abstract_task.h +++ b/src/search/abstract_task.h @@ -11,6 +11,8 @@ #include #include +class AxiomEvaluator; + struct FactPair { int var; int value; @@ -101,6 +103,8 @@ class AbstractTask : public subscriber::SubscriberService { virtual void convert_ancestor_state_values( std::vector &values, const AbstractTask *ancestor_task) const = 0; + + virtual AxiomEvaluator &get_axiom_evaluator() const = 0; }; #endif diff --git a/src/search/axioms.cc b/src/search/axioms.cc index 235234e759..5e1c5e9c6c 100644 --- a/src/search/axioms.cc +++ b/src/search/axioms.cc @@ -151,5 +151,3 @@ void AxiomEvaluator::evaluate(vector &state) { } } } - -PerTaskInformation g_axiom_evaluators; diff --git a/src/search/axioms.h b/src/search/axioms.h index 351bfc506b..8f788a2a1d 100644 --- a/src/search/axioms.h +++ b/src/search/axioms.h @@ -1,10 +1,8 @@ #ifndef AXIOMS_H #define AXIOMS_H -#include "per_task_information.h" #include "task_proxy.h" -#include #include class AxiomEvaluator { @@ -61,7 +59,4 @@ class AxiomEvaluator { void evaluate(std::vector &state); }; - -extern PerTaskInformation g_axiom_evaluators; - #endif diff --git a/src/search/state_registry.cc b/src/search/state_registry.cc index 22a874856b..46219bcb97 100644 --- a/src/search/state_registry.cc +++ b/src/search/state_registry.cc @@ -11,7 +11,7 @@ using namespace std; StateRegistry::StateRegistry(const TaskProxy &task_proxy) : task_proxy(task_proxy), state_packer(task_properties::g_state_packers[task_proxy]), - axiom_evaluator(g_axiom_evaluators[task_proxy]), + axiom_evaluator(task_proxy.get_axiom_evaluator()), num_variables(task_proxy.get_variables().size()), state_data_pool(get_bins_per_state()), registered_states( diff --git a/src/search/task_proxy.cc b/src/search/task_proxy.cc index 6bf02d2c42..a70738bb03 100644 --- a/src/search/task_proxy.cc +++ b/src/search/task_proxy.cc @@ -49,7 +49,7 @@ State State::get_unregistered_successor(const OperatorProxy &op) const { } if (task->get_num_axioms() > 0) { - AxiomEvaluator &axiom_evaluator = g_axiom_evaluators[TaskProxy(*task)]; + AxiomEvaluator &axiom_evaluator = TaskProxy(*task).get_axiom_evaluator(); axiom_evaluator.evaluate(new_values); } return State(*task, move(new_values)); diff --git a/src/search/task_proxy.h b/src/search/task_proxy.h index 4a07f81518..389887c15a 100644 --- a/src/search/task_proxy.h +++ b/src/search/task_proxy.h @@ -18,6 +18,7 @@ #include +class AxiomEvaluator; class AxiomsProxy; class ConditionsProxy; class EffectProxy; @@ -725,6 +726,9 @@ class TaskProxy { } const causal_graph::CausalGraph &get_causal_graph() const; + AxiomEvaluator &get_axiom_evaluator() const { + return task->get_axiom_evaluator(); + } }; diff --git a/src/search/tasks/default_value_axioms_task.cc b/src/search/tasks/default_value_axioms_task.cc index e080bcf494..eeb63a2ffc 100644 --- a/src/search/tasks/default_value_axioms_task.cc +++ b/src/search/tasks/default_value_axioms_task.cc @@ -105,6 +105,7 @@ DefaultValueAxiomsTask::DefaultValueAxiomsTask( FactPair(var, default_value), axiom_ids); } } + axiom_evaluator = make_unique(TaskProxy(*this)); } /* @@ -388,13 +389,16 @@ int DefaultValueAxiomsTask::get_num_axioms() const { return parent->get_num_axioms() + default_value_axioms.size(); } +AxiomEvaluator &DefaultValueAxiomsTask::get_axiom_evaluator() const { + return *axiom_evaluator; +} + shared_ptr get_default_value_axioms_task_if_needed( const shared_ptr &task, AxiomHandlingType axioms) { TaskProxy proxy(*task); if (task_properties::has_axioms(proxy)) { - return make_shared( - DefaultValueAxiomsTask(task, axioms)); + return make_shared(task, axioms); } return task; } diff --git a/src/search/tasks/default_value_axioms_task.h b/src/search/tasks/default_value_axioms_task.h index 1511a0d631..1e85ca3957 100644 --- a/src/search/tasks/default_value_axioms_task.h +++ b/src/search/tasks/default_value_axioms_task.h @@ -3,6 +3,7 @@ #include "delegating_task.h" +#include "../axioms.h" #include "../plugins/plugin.h" #include @@ -49,6 +50,7 @@ class DefaultValueAxiomsTask : public DelegatingTask { AxiomHandlingType axioms; std::vector default_value_axioms; int default_value_axioms_start_index; + std::unique_ptr axiom_evaluator; std::unordered_set get_vars_with_relevant_default_value( const std::vector> &nondefault_dependencies, @@ -81,6 +83,7 @@ class DefaultValueAxiomsTask : public DelegatingTask { int op_index, int eff_index, bool is_axiom) const override; virtual int get_num_axioms() const override; + virtual AxiomEvaluator &get_axiom_evaluator() const override; }; extern std::shared_ptr get_default_value_axioms_task_if_needed( diff --git a/src/search/tasks/delegating_task.cc b/src/search/tasks/delegating_task.cc index be1a6a6cc5..0b108970c3 100644 --- a/src/search/tasks/delegating_task.cc +++ b/src/search/tasks/delegating_task.cc @@ -108,4 +108,8 @@ void DelegatingTask::convert_ancestor_state_values( parent->convert_ancestor_state_values(values, ancestor_task); convert_state_values_from_parent(values); } + +AxiomEvaluator &DelegatingTask::get_axiom_evaluator() const { + return parent->get_axiom_evaluator(); +} } diff --git a/src/search/tasks/delegating_task.h b/src/search/tasks/delegating_task.h index cc7da0b162..89351c92f1 100644 --- a/src/search/tasks/delegating_task.h +++ b/src/search/tasks/delegating_task.h @@ -61,6 +61,8 @@ class DelegatingTask : public AbstractTask { const AbstractTask *ancestor_task) const final override; virtual void convert_state_values_from_parent(std::vector &) const { } + + virtual AxiomEvaluator &get_axiom_evaluator() const override; }; } diff --git a/src/search/tasks/root_task.cc b/src/search/tasks/root_task.cc index 3e7d2996c9..0ec6b15cf6 100644 --- a/src/search/tasks/root_task.cc +++ b/src/search/tasks/root_task.cc @@ -58,6 +58,7 @@ class RootTask : public AbstractTask { vector>> mutexes; vector operators; vector axioms; + unique_ptr axiom_evaluator; vector initial_state_values; vector goals; @@ -105,6 +106,7 @@ class RootTask : public AbstractTask { virtual void convert_ancestor_state_values( vector &values, const AbstractTask *ancestor_task) const override; + virtual AxiomEvaluator &get_axiom_evaluator() const override; }; @@ -351,11 +353,11 @@ RootTask::RootTask(istream &in) { have reached the end of "in". */ /* - HACK: We use a TaskProxy to access g_axiom_evaluators here which assumes + HACK: We use a TaskProxy here which assumes that this task is completely constructed. */ - AxiomEvaluator &axiom_evaluator = g_axiom_evaluators[TaskProxy(*this)]; - axiom_evaluator.evaluate(initial_state_values); + axiom_evaluator = make_unique(TaskProxy(*this)); + axiom_evaluator->evaluate(initial_state_values); } const ExplicitVariable &RootTask::get_variable(int var) const { @@ -492,6 +494,10 @@ void RootTask::convert_ancestor_state_values( } } +AxiomEvaluator &RootTask::get_axiom_evaluator() const { + return *axiom_evaluator; +} + void read_root_task(istream &in) { assert(!g_root_task); g_root_task = make_shared(in);