Using Named Parameters and Bound Properties with edmonds_karp_max_flow ()
I am trying to use Named Parameters with added properties in the edmonds_karp_max_flow
Boost-graph library algorithm .
To illustrate my problem, I took the existing edmonds-karp example and turned the internal properties into Bundled properties (I named my properties edge_t
and node_t
), and the Named parameters into unnamed parameters.
Here is a non-named version that compiles fine:
// The "non-named parameters version" (works fine)
edmonds_karp_max_flow(g, s, t,capacity,residual_capacity,rev,col,pred);
Here's a version of Named Parameters that doesn't compile and doesn't throw many template errors:
// The "named parameters version" (produces errors)
flow = edmonds_karp_max_flow(g, s, t,
capacity_map(capacity)
.residual_capacity_map(residual_capacity)
.reverse_edge_map(rev)
.color_map(col)
.predecessor_map(pred));
Full edmonds-karp-eg_modified.cpp
source:
#include <boost/config.hpp>
#include <iostream>
#include <string>
#include <boost/graph/edmonds_karp_max_flow.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/read_dimacs.hpp>
#include <boost/graph/graph_utility.hpp>
using namespace boost;
typedef adjacency_list_traits<vecS,vecS,directedS> traits;
struct edge_t {
double capacity;
float cost;
float residual_capacity;
traits::edge_descriptor reversed_edge;
};
struct node_t {
std::string name;
boost::default_color_type color;
traits::edge_descriptor predecessor;
};
typedef adjacency_list < listS, vecS, directedS, node_t, edge_t > Graph;
int main()
{
Graph g;
property_map < Graph, double edge_t::* >::type capacity = get(&edge_t::capacity, g);
property_map < Graph, float edge_t::* >::type cost = get(&edge_t::cost, g);
property_map < Graph, float edge_t::* >::type residual_capacity = get(&edge_t::residual_capacity, g);
property_map < Graph, traits::edge_descriptor edge_t::* >::type rev = get(&edge_t::reversed_edge, g);
property_map < Graph, std::string node_t::* >::type name = get(&node_t::name, g);
property_map < Graph, boost::default_color_type node_t::* >::type col = get(&node_t::color, g);
property_map < Graph, traits::edge_descriptor node_t::* >::type pred = get(&node_t::predecessor, g);
traits::vertex_descriptor s, t;
read_dimacs_max_flow(g, capacity, rev, s, t);
long flow;
// XXX The "non-named parameters version" (works fine)
// flow = edmonds_karp_max_flow(g, s, t,capacity,residual_capacity,rev,col,pred);
// XXX The "named parameters version" (produces errors)
flow = edmonds_karp_max_flow(g, s, t,
capacity_map(capacity)
.residual_capacity_map(residual_capacity)
.reverse_edge_map(rev)
.color_map(col)
.predecessor_map(pred));
std::cout << "c The total flow:" << std::endl;
std::cout << "s " << flow << std::endl << std::endl;
std::cout << "c flow values:" << std::endl;
graph_traits < Graph >::vertex_iterator u_iter, u_end;
graph_traits < Graph >::out_edge_iterator ei, e_end;
for (boost::tie(u_iter, u_end) = vertices(g); u_iter != u_end; ++u_iter)
for (boost::tie(ei, e_end) = out_edges(*u_iter, g); ei != e_end; ++ei)
if (capacity[*ei] > 0)
std::cout << "a " << *u_iter << " " << target(*ei, g) << " "
<< (capacity[*ei] - residual_capacity[*ei]) << std::endl;
return EXIT_SUCCESS;
}
Here are the returned errors: http://pastebin.com/Vra8ZWHG .
It works fine with unnamed parameters ... But not with the specified parameters.
Update: Someone seems to have the same problem: svn.boost.org/trac/boost/ticket/8791. He fixed it using Boost 1.50
instead 1.55
.
- Boost-graph version: 1.58.0
- Compiler: g ++ 5.0
source to share