Using Named parameters and Bundled properties with edmonds_karp_max_flow()

153 views Asked by At

I am trying to use Named parameters with Bundled properties in the edmonds_karp_max_flow algorithm of the Boost-graph library.

To show my problem, I took the existing edmonds-karp example and turned the Internal properties into Bundled properties (I called my properties edge_t and node_t), and the Named parameters into Non-named parameters.

Here is the Non-named parameter 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 is the Named parameters version that doesn't compile and triggers a lot of 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));

The 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 errors returned : http://pastebin.com/Vra8ZWHG.

It works fine with non-named parameters... But not with the named parameters.

Update: Someone seems to have the exact same issue: svn.boost.org/trac/boost/ticket/8791. He fixed it using Boost 1.50 instead of 1.55.

  • Boost-graph version: 1.58.0
  • Compiler: g++ 5.0
1

There are 1 answers

3
Jeff Trull On BEST ANSWER

It looks like a Graph bug: named_function_params.hpp, line 326, has the arguments to get_param_type in reverse order. Changing this makes it compile for me.

There don't appear to be any test cases for Edmonds-Karp with named parameters and clearly there need to be...