Skip to content

Commit

Permalink
Merge pull request #304 from sebrockm/fix-max-flows
Browse files Browse the repository at this point in the history
Fix named parameter overload of `boykov_kolmogorov_max_flow`
  • Loading branch information
jeremy-murphy authored Jul 25, 2022
2 parents fcfc152 + f62a183 commit 2862644
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
3 changes: 1 addition & 2 deletions include/boost/graph/boykov_kolmogorov_max_flow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,7 @@ boykov_kolmogorov_max_flow(Graph& g, CapacityEdgeMap cap,
* named-parameter version, some given
*/
template < class Graph, class P, class T, class R >
typename property_traits<
typename property_map< Graph, edge_capacity_t >::const_type >::value_type
typename detail::edge_capacity_value< Graph, P, T, R >::type
boykov_kolmogorov_max_flow(Graph& g,
typename graph_traits< Graph >::vertex_descriptor src,
typename graph_traits< Graph >::vertex_descriptor sink,
Expand Down
30 changes: 22 additions & 8 deletions test/boykov_kolmogorov_max_flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fill_random_max_flow_graph(Graph& g, CapacityMap cap, ReverseEdgeMap rev,
// cannot use this, as we have no idea how properties are stored, right?
typename graph_traits< Graph >::edge_iterator ei, e_end;
for (boost::tie(ei, e_end) = edges(g); ei != e_end; ++ei)
cap[*ei] = int_gen();
put(cap, *ei, int_gen());

// get source and sink node
vertex_descriptor s = random_vertex(g, gen);
Expand All @@ -96,9 +96,9 @@ fill_random_max_flow_graph(Graph& g, CapacityMap cap, ReverseEdgeMap rev,
boost::tie(new_edge, inserted)
= add_edge(source_vertex, target_vertex, g);
assert(inserted);
rev[old_edge] = new_edge;
rev[new_edge] = old_edge;
cap[new_edge] = 0;
put(rev, old_edge, new_edge);
put(rev, new_edge, old_edge);
put(cap, new_edge, 0);
}
return std::make_pair(s, t);
}
Expand Down Expand Up @@ -188,10 +188,24 @@ long test_bundled_properties(int n_verts, int n_edges, std::size_t seed)
boost::tie(src, sink)
= fill_random_max_flow_graph(g, get(&tEdge::edge_capacity, g),
get(&tEdge::edge_reverse, g), n_verts, n_edges, seed);
return boykov_kolmogorov_max_flow(g, get(&tEdge::edge_capacity, g),
get(&tEdge::edge_residual_capacity, g), get(&tEdge::edge_reverse, g),
get(&tVertex::vertex_predecessor, g), get(&tVertex::vertex_color, g),
get(&tVertex::vertex_distance, g), get(vertex_index, g), src, sink);

long flow_unnamed_overload = boykov_kolmogorov_max_flow(g,
get(&tEdge::edge_capacity, g), get(&tEdge::edge_residual_capacity, g),
get(&tEdge::edge_reverse, g), get(&tVertex::vertex_predecessor, g),
get(&tVertex::vertex_color, g), get(&tVertex::vertex_distance, g),
get(vertex_index, g), src, sink);

long flow_named_overload = boykov_kolmogorov_max_flow(g, src, sink,
capacity_map(get(&tEdge::edge_capacity, g))
.residual_capacity_map(get(&tEdge::edge_residual_capacity, g))
.reverse_edge_map(get(&tEdge::edge_reverse, g))
.predecessor_map(get(&tVertex::vertex_predecessor, g))
.color_map(get(&tVertex::vertex_color, g))
.distance_map(get(&tVertex::vertex_distance, g))
.vertex_index_map(get(vertex_index, g)));

BOOST_TEST(flow_unnamed_overload == flow_named_overload);
return flow_named_overload;
}

long test_overloads(int n_verts, int n_edges, std::size_t seed)
Expand Down

0 comments on commit 2862644

Please sign in to comment.