82 {
83 std::priority_queue<std::shared_ptr<Node>, std::vector<std::shared_ptr<Node>>,
NodeComparator> frontier;
84
85 std::unordered_set<std::shared_ptr<State>> explored;
87 auto root = std::make_shared<Node>(
88 nullptr,
89 std::shared_ptr<State>(initial_state),
90 nullptr,
91 0,
93 );
94 frontier.push(root);
95
96 while (!frontier.empty()) {
97 auto node = frontier.top();
98 frontier.pop();
99
100
101 State *state = node->state.get();
103 return node;
104 }
105
106
107 if (explored.find(node->state) != explored.end()) {
108 continue;
109 }
110 explored.insert(node->state);
111
112
113 for (
const auto &action :
problem->actions(node->state)) {
114 auto child = std::make_shared<Node>(
115 std::shared_ptr<Node>(node),
116 action->effect,
117 action,
118 node->path_cost + action->cost,
120 );
121 frontier.push(child);
122 }
123 }
124
125
126 return nullptr;
127}
virtual bool goal_test(State *state)=0
Tests if a given state satisfies the goal condition.
virtual double heuristic(State *state)=0
Computes a heuristic estimate for a given state.
virtual State * initial_state()
Retrieves the initial state of the problem.
Represents an abstract state in a problem.