diff --git a/src/search/heuristics/goal_count_heuristic.cc b/src/search/heuristics/goal_count_heuristic.cc index 38fd55f21b..60623ce0db 100644 --- a/src/search/heuristics/goal_count_heuristic.cc +++ b/src/search/heuristics/goal_count_heuristic.cc @@ -15,15 +15,23 @@ GoalCountHeuristic::GoalCountHeuristic( if (log.is_at_least_normal()) { log << "Initializing goal count heuristic..." << endl; } + goals.reserve(task_proxy.get_goals().size()); + for (FactProxy goal : task_proxy.get_goals()) { + int var = goal.get_variable().get_id(); + int val = goal.get_value(); + goals.push_back({var,val}); + } } int GoalCountHeuristic::compute_heuristic(const State &ancestor_state) { State state = convert_ancestor_state(ancestor_state); int unsatisfied_goal_count = 0; - - for (FactProxy goal : task_proxy.get_goals()) { - const VariableProxy var = goal.get_variable(); - if (state[var] != goal) { + state.unpack(); + const vector &unpacked_state = state.get_unpacked_values(); + for (const auto& it : goals) { + const int& var = it.first; + const int& val = it.second; + if (unpacked_state[var] != val) { ++unsatisfied_goal_count; } } diff --git a/src/search/heuristics/goal_count_heuristic.h b/src/search/heuristics/goal_count_heuristic.h index cba4b55818..71a0a562a3 100644 --- a/src/search/heuristics/goal_count_heuristic.h +++ b/src/search/heuristics/goal_count_heuristic.h @@ -5,6 +5,7 @@ namespace goal_count_heuristic { class GoalCountHeuristic : public Heuristic { + std::vector> goals; protected: virtual int compute_heuristic(const State &ancestor_state) override; public: