C++ 在BOOST图中查找给定2个顶点的多条边

C++ 在BOOST图中查找给定2个顶点的多条边,c++,boost,graph,boost-graph,C++,Boost,Graph,Boost Graph,我正在为某个项目使用Boost图形库,我想找出一条边在图形中重复的次数。比如说, typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node_Info, Edge_Info > Graph_t; //node_info and Edge_info are external node and edge properties (structures) 我知道,在一个boost图中,

我正在为某个项目使用Boost图形库,我想找出一条边在图形中重复的次数。比如说,

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node_Info, Edge_Info > Graph_t;  
//node_info and Edge_info are external node and edge properties (structures)
我知道,在一个boost图中,给定两个顶点,我们可以使用以下公式来确定图中是否存在边

std::pair < edge_t, bool > p = boost::edge( node1, node2, myGraph );
if(p.second == 1)  cout << "edge exists!" << endl;
else cout << " does not exist " << endl;
std::pairp=boost::edge(node1,node2,myGraph);

如果(p.second==1)不能有几种方法可以做到这一点

1) 只需检查所有指向所需目标的边:

boost::graph_traits<Graph_t>::out_edge_iterator ei, ei_end;
boost::tie(ei, ei_end) = out_edges( node1, myGraph );
int parallel_count = 0;
for( ; ei != ei_end; ++ei) {
  if( target(*ei, myGraph) == node2 ) {
    cout << "Found edge (node1, node2) with property: " << myGraph[*ei] << endl;
    ++parallel_count;
  };
};
cout << "There are a total of " << parallel_count << " parallel edges." << endl;
返回一对out edge迭代器,该迭代器给出从u到v的所有平行边的范围。仅当邻接_列表的OutEdgeList是根据目标顶点对边进行排序并允许平行边的容器时,此函数才起作用。多集选择器选择这样一个容器


此函数仅适用于
multiset
的原因是,为了(轻松地)为平行边提供一系列迭代器,需要将边分组在一起,这对于
multiset
是如此,因为它们是按顶点描述符排序的,因此,所有平行出的边都分组在一起。这是唯一的容器选择,否则,你必须使用选项(1)(注意:如果你真的经常使用它,创建一个
过滤器\u迭代器(请参阅)可能会派上用场)。

嗨,Mikael,我刚刚在下面贴了一个答案,我有点不舒服。你能建议一下吗?
boost::graph_traits<Graph_t>::out_edge_iterator ei, ei_end;
boost::tie(ei, ei_end) = out_edges( node1, myGraph );
int parallel_count = 0;
for( ; ei != ei_end; ++ei) {
  if( target(*ei, myGraph) == node2 ) {
    cout << "Found edge (node1, node2) with property: " << myGraph[*ei] << endl;
    ++parallel_count;
  };
};
cout << "There are a total of " << parallel_count << " parallel edges." << endl;
std::pair<out_edge_iterator, out_edge_iterator>
edge_range(vertex_descriptor u, vertex_descriptor v,
           const adjacency_list& g)