boost图库定向多边形edge_range错误 [英] boost graph library directed multigraph edge_range bug

查看:142
本文介绍了boost图库定向多边形edge_range错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有顶点A..C和边缘E1..E4的定向复印件

I have a directed multigraph with vertices A..C and edges E1..E4

A ---E1--> B
A ---E2--> B
A ---E3--> B
B ---E4--> C

我想遍历连接A和B的边。

I wanted to iterate over the edges that connect A and B.

在BGL中,我表示为:

In BGL, I expressed this as:

#include <boost/graph/adjacency_list.hpp>

struct Vertex
{
  std::string code;
};

struct Edge
{
  double distance;
  std::string code;
};

int main()
{
  using namespace boost;
  typedef adjacency_list<listS, vecS, directedS, Vertex, Edge> Graph;
  Graph g;
  auto a= add_vertex(Vertex{ "A" }, g);
  auto b= add_vertex(Vertex{ "B" }, g);
  auto c= add_vertex(Vertex{ "C" }, g);
  add_edge(a, b, Edge{ 10, "E1" }, g);
  add_edge(a, b, Edge{ 10, "E2" }, g);
  add_edge(a, b, Edge{ 10, "E3" }, g);
  add_edge(a, c, Edge{ 10, "E4" }, g);

  // checking number of edges
  std::cout<< num_edges(g)<< std::endl;

  // printing edges branching from A
  auto erange= out_edges(a, g);
  for(auto i= erange.first; i!= erange.second; ++ i)
    std::cout<< g[*i].code<< std::endl;

  // now we want to iterate over edges that connect A and B
  auto wtf= boost::edge_range(a, b, g);
}

这会导致编译错误:

In file included from /usr/include/boost/graph/adjacency_list.hpp:246:
/usr/include/boost/graph/detail/adjacency_list.hpp:1617:25: error: no matching constructor for initialization of 'StoredEdge' (aka
      'boost::detail::stored_edge_property<unsigned long, Edge>')
        equal_range(el, StoredEdge(v, fake_edge_container.end(),
                    ^          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我已阅读文档:

std :: pair< out_edge_iterator,out_edge_iterator>
edge_range(vertex_descriptor u,vertex_descriptor v,
const adjacency_list& g)
返回一对外边缘迭代器,给出所有平行边从u到v。此函数仅在用于adjacency_list的OutEdgeList是根据目标顶点对输出边进行排序并允许平行边缘的容器时有效。 multisetS选择器选择这样一个容器。

http://www.boost.org/doc/libs/1_54_0/libs/graph/doc/adjacency_list.html

修改图表:

typedef adjacency_list<multisetS, vecS, directedS, Vertex, Edge> Graph;

但错误未更改。

我发现了一个快速和肮脏的方式:

I found a quick and dirty way:

auto erange= out_edges(a, g);$
for(auto i= erange.first; i!= erange.second; ++ i)$
  std::cout<< g[*i].code<< " -> "<< g[target(*i, g)].code<< std::endl;$

这将允许我按目标顶点过滤边缘。但是,如何使用 boost :: edge_range

Which will let me filter edge by target vertex. But how do you use boost::edge_range ?

推荐答案

之前已在升级邮件列表



adjacency_list的Directed Selector模板参数设置为directedS时,编译失败, b $ b是无向的S,或双向的。下面是一个简短的
程序说明这个问题。问题是edge_range()
通过一个带有3个参数的构造函数实例化一个StoredEdge,但是当定向选择器被定向时
StoredEdge被类型化为
stored_edge_property,没有
这样的构造函数。一个解决方案可能是创建重载的
edge_range_dispatch()函数,并调度

Config :: on_edge_storage。

it fails to compile when the Directed Selector template argument to adjacency_list is set to directedS, but does work if the argument is either undirectedS, or bidirectionalS. Attached below is a short program illustrating the problem. The problem is that edge_range() instantiates a StoredEdge via a constructor taking 3 arguments, but when the Directed Selector is directedS StoredEdge is typedef'ed to stored_edge_property, which has no such constructor. One solution might be to create overloaded edge_range_dispatch() functions, and dispatch on
Config::on_edge_storage.

在您的程序工作中将 directedS 更改为 undirectedS 在线示例 。但这可能不是你的应用程序所需要的,所以你之前提到的简单过滤器可能会更好。您可以在Boost邮件列表上重新发布此邮件,以获得更多关注。

Changing directedS to undirectedS in your program works. Live Example. But that might not be what you need for your application, so the simple filter you mentioned before might be better. You could repost this on the Boost mailinglist to get more attention for it.

这篇关于boost图库定向多边形edge_range错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆