Skip to content

Commit

Permalink
NetworkOperations: Use const ref to network
Browse files Browse the repository at this point in the history
NetworkOperations needs a const reference to NetworkBase

Co-authored-by: Moritz Sallermann <moritzsallermann@gmail.com>
  • Loading branch information
amritagos and MSallermann committed May 31, 2024
1 parent 17c39e2 commit dc405cc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions graph_lib/include/network_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template <typename WeightType = double> class NetworkOperations {
public:
using WeightT = WeightType;

NetworkOperations(NetworkBase<WeightT> network)
NetworkOperations(const NetworkBase<WeightT> &network)
: network(network), marked(std::vector<bool>(network.n_agents(), false)),
count(0), edge_to_vertex(std::vector<size_t>(network.n_agents())) {}

Expand All @@ -28,14 +28,16 @@ template <typename WeightType = double> class NetworkOperations {
return std::nullopt; // the path does not exist
}
// If the path exists, return it
// Start from v
for (int x = v; x != s; x = edge_to_vertex[x]) {
path.push_back(x);
}
path.push_back(s); // Finally, add the source
return path;
}

private:
NetworkBase<WeightT> network{}; // UndirectedNetwork or DirectedNetwork
const NetworkBase<WeightT> &network; // UndirectedNetwork or DirectedNetwork
std::vector<bool>
marked{}; // Chronicles whether a vertex has been visited or not
size_t count{}; // Number of vertices visited
Expand Down

0 comments on commit dc405cc

Please sign in to comment.