使用edmonds_karp_max_flow()的命名参数和绑定属性



我试图在Boost-graph库的edmonds_karp_max_flow算法中使用命名参数捆绑属性

为了显示我的问题,我采用了现有的edmonds-karp示例,并将内部属性转换为捆绑属性(我称我的属性为edge_tnode_t),并将命名参数转换为非命名参数。

下面是编译良好的非命名参数版本:

// The "non-named parameters version" (works fine)
edmonds_karp_max_flow(g, s, t,capacity,residual_capacity,rev,col,pred);

下面是命名参数版本,它不能编译,并且会触发很多模板错误:

// 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));

完整的edmonds-karp-eg_modified.cpp源:

#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;
}

返回的错误如下:http://pastebin.com/Vra8ZWHG。

它可以很好地处理非命名参数…但不能使用命名参数。

更新:有人似乎有完全相同的问题:svn.boost.org/trac/boost/ticket/8791。他用Boost 1.50代替1.55修复了它。

  • Boost-graph version: 1.58.0
  • 编译器:g++ 5.0

这看起来像是一个图形错误:named_function_params.hpp,第326行,get_param_type的参数顺序相反。

没有任何Edmonds-Karp与命名参数的测试用例,显然需要有…

相关内容

  • 没有找到相关文章

最新更新