Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/graph/algorithm/bellman_ford_shortest_paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ requires convertible_to<range_value_t<Sources>, vertex_id_t<G>> && //
}
distances[static_cast<size_t>(source)] = zero; // mark source as discovered
if constexpr (has_on_discover_vertex<G, Visitor>) {
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;
Expand Down
20 changes: 20 additions & 0 deletions tests/bellman_shortest_paths_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,23 @@ TEST_CASE("Bellman-Ford's General Shortest Distances", "[csv][vofl][shortest][di
optional<vertex_id_t<G>> cycle_vertex_id = bellman_ford_shortest_distances(
g, frankfurt_id, distance, weight, visitor, std::less<Distance>(), std::plus<Distance>());
}

class Visitor
{
using G = std::vector<std::vector<int>>;
using VD = graph::vertex_info<graph::vertex_id_t<G>, graph::vertex_reference_t<G>, 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<std::vector<int>> g = {{1}, {0}};
std::vector<double> distances(g.size());
std::vector<int> predecessor(g.size());
auto one = [](auto&&) { return 1.0; };

(void)graph::bellman_ford_shortest_paths(g, 0, distances, predecessor, one, Visitor{});
}
Loading