gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:30:56 26 4
gpt4 key购买 nike

我看过 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/

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