gpt4 book ai didi

c++ - 将命名参数和捆绑属性与 edmonds_karp_max_flow() 结合使用

转载 作者:太空狗 更新时间:2023-10-29 21:40:37 25 4
gpt4 key购买 nike

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

为了显示我的问题,我使用了现有的 edmonds-karp example并将内部属性转换为捆绑属性(我将我的属性称为 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 修复了它。

  • 提升图版本:1.58.0
  • 编译器:g++ 5.0

最佳答案

它看起来像一个 Graph 错误:named_function_params.hpp,第 326 行,get_param_type 的参数以相反的顺序出现。改变这个让它为我编译。

似乎没有任何带有命名参数的 Edmonds-Karp 测试用例,显然需要...

关于c++ - 将命名参数和捆绑属性与 edmonds_karp_max_flow() 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30621255/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com