diff --git a/include/graph/algorithm/bellman_ford_shortest_paths.hpp b/include/graph/algorithm/bellman_ford_shortest_paths.hpp index 3dce0a2..701a974 100644 --- a/include/graph/algorithm/bellman_ford_shortest_paths.hpp +++ b/include/graph/algorithm/bellman_ford_shortest_paths.hpp @@ -164,11 +164,11 @@ requires convertible_to, vertex_id_t> && // } distances[static_cast(source)] = zero; // mark source as discovered if constexpr (has_on_discover_vertex) { - visitor.on_discover_vertex({source, vertex_value(g, source)}); + visitor.on_discover_vertex({source, *find_vertex(g, source)}); } } - // Evalute the shortest paths + // Evaluate the shortest paths bool at_least_one_edge_relaxed = false; for (id_type k = 0; k < N; ++k) { at_least_one_edge_relaxed = false; diff --git a/tests/bellman_shortest_paths_tests.cpp b/tests/bellman_shortest_paths_tests.cpp index 7bb83b8..24d5472 100644 --- a/tests/bellman_shortest_paths_tests.cpp +++ b/tests/bellman_shortest_paths_tests.cpp @@ -714,3 +714,23 @@ TEST_CASE("Bellman-Ford's General Shortest Distances", "[csv][vofl][shortest][di optional> cycle_vertex_id = bellman_ford_shortest_distances( g, frankfurt_id, distance, weight, visitor, std::less(), std::plus()); } + +class Visitor +{ + using G = std::vector>; + using VD = graph::vertex_info, graph::vertex_reference_t, void>; + +public: + void on_discover_vertex(VD const& v) {} +}; + +TEST_CASE("Bellman-Ford compiles with a visitor", "[shortest][distances][bellman][general]") { + init_console(); + + std::vector> g = {{1}, {0}}; + std::vector distances(g.size()); + std::vector predecessor(g.size()); + auto one = [](auto&&) { return 1.0; }; + + (void)graph::bellman_ford_shortest_paths(g, 0, distances, predecessor, one, Visitor{}); +}