in_degree 函数的问题

Issue with in_degree function

我在提升图中使用 in_degree 函数时遇到了麻烦。它失败并显示以下尖锐的消息:

..\boost_lib\boost_1_66_0\boost\graph\detail\adjacency_list.hpp|1673|error: no matching function for call to 'in_edge_list(Graph&, void*&)'|

为什么 vbvoid*& 类型?它应该是 vertex_descriptor.

这是一个重现我的问题的小例子:

#include <string>
#include <iostream>

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>

//The typedef used
typedef boost::adjacency_list<
boost::setS, boost::setS, boost::directedS> graph;
typedef boost::graph_traits<graph>::vertex_descriptor Vertex;

int main()
{
    graph g(1);

    boost::graph_traits<graph>::vertex_iterator vb,ve;
    boost::tie(vb,ve)=boost::vertices(g);
    std::cout << boost::in_degree(*vb,g);
    return 0;
}

Why is vb of void*& type? It is supposed to be a vertex_descriptor.

为什么那个描述符不应该是 void* 类型?这正是它定义的类型。

error: no matching function for call to 'in_edge_list(Graph&, void*&)'

问题是,没有匹配的函数调用,因为 in_degree() 不适用于您的图表。您可以在此处查看图表支持的内容:http://www.boost.org/doc/libs/1_66_0/libs/graph/doc/graph_concepts.html

如您所见,in_degree() 需要 BidirectionalGraph 概念。

你只知道 out-degree:

std::cout << boost::out_degree(*vb, g);

或者您可以切换到双向图模型:

Live On Coliru

#include <iostream>
#include <string>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>

typedef boost::adjacency_list<boost::setS, boost::setS, boost::bidirectionalS> graph;
typedef graph::vertex_descriptor Vertex;

int main() {
    graph g(1);

    boost::graph_traits<graph>::vertex_iterator vb, ve;
    boost::tie(vb, ve) = boost::vertices(g);

    std::cout << boost::out_degree(*vb, g) << std::endl;
    std::cout << boost::in_degree(*vb, g) << std::endl;
}

版画

0
0