Skip to content
Snippets Groups Projects
Commit 256a20d3 authored by p-hamann's avatar p-hamann
Browse files

Optimize edmonds karp

parent 156a8359
Branches
1 merge request!9Perf optimization
......@@ -36,7 +36,7 @@ void edmonds_karp::reset(std::vector<node_id>& sources, std::vector<node_id>& si
std::pair<int, node_id> edmonds_karp::bfs(std::vector<unsigned int> &pred) const {
pred.clear();
pred.resize(g_.num_nodes() + 1, -1); // undiscovered nodes are marked with -1
pred.assign(g_.num_nodes() + 1, -1); // undiscovered nodes are marked with -1
std::vector<int> gain(g_.num_nodes() + 1, 0);
bool sink_reached = false;
node_id sink;
......@@ -57,16 +57,12 @@ std::pair<int, node_id> edmonds_karp::bfs(std::vector<unsigned int> &pred) const
node_id u = q.front();
q.pop();
const std::vector<node_id> & neighbors = g_.get_adjacency(u);
const auto& adjacency = g_.get_adjacency(u);
const auto& edge_ids = g_.get_edge_ids(u);
// iterate through neighbors of u
for (node_id v : neighbors) {
unsigned int edge_id;
if ( u < v )
edge_id = g_.get_edge_id(u, v);
else
edge_id = g_.get_edge_id(v, u);
for (node_id i = 0; i < adjacency.size(); ++i) {
node_id v = adjacency[i];
edge_id edge_id = edge_ids[i];
int edge_weight = 1; // unweighted graph
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment