Skip to content

Commit b7b55ba

Browse files
committed
Fix Bellman with visitor
1 parent 5d69193 commit b7b55ba

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

include/graph/algorithm/bellman_ford_shortest_paths.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ requires convertible_to<range_value_t<Sources>, vertex_id_t<G>> && //
164164
}
165165
distances[static_cast<size_t>(source)] = zero; // mark source as discovered
166166
if constexpr (has_on_discover_vertex<G, Visitor>) {
167-
visitor.on_discover_vertex({source, vertex_value(g, source)});
167+
visitor.on_discover_vertex({source, *find_vertex(g, source)});
168168
}
169169
}
170170

171-
// Evalute the shortest paths
171+
// Evaluate the shortest paths
172172
bool at_least_one_edge_relaxed = false;
173173
for (id_type k = 0; k < N; ++k) {
174174
at_least_one_edge_relaxed = false;

tests/bellman_shortest_paths_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,23 @@ TEST_CASE("Bellman-Ford's General Shortest Distances", "[csv][vofl][shortest][di
714714
optional<vertex_id_t<G>> cycle_vertex_id = bellman_ford_shortest_distances(
715715
g, frankfurt_id, distance, weight, visitor, std::less<Distance>(), std::plus<Distance>());
716716
}
717+
718+
class Visitor
719+
{
720+
using G = std::vector<std::vector<int>>;
721+
using VD = graph::vertex_info<graph::vertex_id_t<G>, graph::vertex_reference_t<G>, void>;
722+
723+
public:
724+
void on_discover_vertex(VD const& v) {}
725+
};
726+
727+
TEST_CASE("Bellman-Ford compiles with a visitor", "[shortest][distances][bellman][general]") {
728+
init_console();
729+
730+
std::vector<std::vector<int>> g = {{1}, {0}};
731+
std::vector<double> distances(g.size());
732+
std::vector<int> predecessor(g.size());
733+
auto one = [](auto&&) { return 1.0; };
734+
735+
(void)graph::bellman_ford_shortest_paths(g, 0, distances, predecessor, one, Visitor{});
736+
}

0 commit comments

Comments
 (0)