diff --git a/graph_lib/include/network_operations.hpp b/graph_lib/include/network_operations.hpp index afa1b8f..835a0dc 100644 --- a/graph_lib/include/network_operations.hpp +++ b/graph_lib/include/network_operations.hpp @@ -12,7 +12,7 @@ template class NetworkOperations { public: using WeightT = WeightType; - NetworkOperations(NetworkBase network) + NetworkOperations(const NetworkBase &network) : network(network), marked(std::vector(network.n_agents(), false)), count(0), edge_to_vertex(std::vector(network.n_agents())) {} @@ -28,14 +28,16 @@ template 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 network{}; // UndirectedNetwork or DirectedNetwork + const NetworkBase &network; // UndirectedNetwork or DirectedNetwork std::vector marked{}; // Chronicles whether a vertex has been visited or not size_t count{}; // Number of vertices visited