c++ - boost::graph :从一对顶点获取边缘的独立实现方式

标签 c++ boost-graph

我看过 Boost 图概念,但它没有提供任何从一对顶点获取任何边的接口(interface)。 我试过:

boost::graph_traits<G>::edge_descriptor edge(u, v); // does not work

但它需要一个额外的指向属性类型的指针。我怎样才能得到它?

最佳答案

boost::edge() 的第三个参数是您的图表。

另请注意,该函数不会直接返回边描述符,而是返回一对包含边描述符和一个 bool 值(取决于边是否存在)

像这样:

G myGraph;   // construct the graph
....         // populate it
....         // select a pair of vertices u, v

// get the edge between the vertices, if it exists
typedef boost::graph_traits<G>::edge_descriptor edge_t;
edge_t found_edge;
std::pair < edge_t, bool > p = boost::edge( u, v, myGraph ); 
if( ! p.second) {
   // edge does not exist
   ...
} else {
   found_edge = p.first;
   ...
}

关于c++ - boost::graph :从一对顶点获取边缘的独立实现方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17734386/

相关文章:

c++ - C++编译错误

C++ 二进制文件方法正在从文件中删除内容?

c++ - Boost Graph 边缘比较不起作用

c++ - 基于最大深度迭代 boost 图顶点

c++ - 在类模板外部或内部定义的结构

c++ - 如何使用逗号分隔值读写文本文件

c++ - QThread 创建和通过槽交换数据

C++ 语法 - 条件运算符和算术运算符的组合

c++ - BGL 顶点的随机顺序迭代

c++ - 使用 boost spirit qi 解析器迭代填充 BGL 图