134 {
135
136 using Beam = std::vector<std::shared_ptr<Node>>;
137 Beam beam;
138
139
141 auto root = std::make_shared<Node>(
142 nullptr,
143 std::shared_ptr<State>(initial_state),
144 nullptr,
145 0,
147 );
148
149 beam.push_back(root);
150
151 while (!beam.empty()) {
152
153 std::sort(beam.begin(), beam.end(), [](const std::shared_ptr<Node>& a, const std::shared_ptr<Node>& b) {
154 return (a->path_cost + a->heuristic) < (b->path_cost + b->heuristic);
155 });
156
157
160 }
161
162 Beam next_beam;
163
164
165 for (const auto& node : beam) {
167 return node;
168 }
169
170
171 for (
const auto& action :
problem->actions(node->state)) {
172 auto child = std::make_shared<Node>(
173 node,
174 action->effect,
175 action,
176 node->path_cost + action->cost,
178 );
179 next_beam.push_back(child);
180 }
181 }
182
183 beam = std::move(next_beam);
184 }
185
186 return nullptr;
187}
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.