|
12 | 12 | #define BFS_HPP |
13 | 13 |
|
14 | 14 | #include <limits> |
| 15 | +#include <queue> |
| 16 | +#include <unordered_set> |
15 | 17 | #include "graph/search/search_algorithm.hpp" |
16 | 18 | #include "graph/search/search_strategy.hpp" |
17 | 19 |
|
@@ -182,11 +184,32 @@ class BFS final { |
182 | 184 | auto start_it = graph->FindVertex(start); |
183 | 185 | if (start_it == graph->vertex_end()) return false; |
184 | 186 |
|
185 | | - auto strategy = MakeBfsStrategy<State, Transition, StateIndexer>(); |
186 | | - auto dummy_goal = graph->vertex_end(); // No specific goal - traverse all |
| 187 | + // Manual BFS traversal |
| 188 | + using VertexIteratorType = decltype(start_it); |
| 189 | + std::queue<VertexIteratorType> q; |
| 190 | + std::unordered_set<int64_t> visited; |
| 191 | + |
| 192 | + q.push(start_it); |
| 193 | + visited.insert(start_it->vertex_id); |
187 | 194 |
|
188 | | - SearchAlgorithm<decltype(strategy), State, Transition, StateIndexer> |
189 | | - ::Search(graph, context, start_it, dummy_goal, strategy); |
| 195 | + while (!q.empty()) { |
| 196 | + auto current = q.front(); |
| 197 | + q.pop(); |
| 198 | + |
| 199 | + // Mark as visited in context |
| 200 | + auto& current_info = context.GetSearchInfo(current); |
| 201 | + current_info.SetChecked(true); |
| 202 | + |
| 203 | + for (const auto& edge : current->edges_to) { |
| 204 | + auto neighbor = edge.dst; |
| 205 | + int64_t neighbor_id = neighbor->vertex_id; |
| 206 | + |
| 207 | + if (visited.find(neighbor_id) == visited.end()) { |
| 208 | + q.push(neighbor); |
| 209 | + visited.insert(neighbor_id); |
| 210 | + } |
| 211 | + } |
| 212 | + } |
190 | 213 |
|
191 | 214 | return true; |
192 | 215 | } |
|
0 commit comments