【问题标题】:C++ BOOST library and bundled propertiesC++ BOOST 库和捆绑属性
【发布时间】:2015-02-26 20:36:26
【问题描述】:

我正在尝试使用 Boost 制作一个图挖掘程序,所以我从图结构开始,这是我制作的代码:

#include <iostream>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;



//vertex
struct VertexProperties
{
    int id;
    int label;
    VertexProperties()= default;
    VertexProperties(unsigned i, unsigned l) : id(i), label(l) {}
};



//edge
struct EdgeProperties
{
    unsigned id;
    unsigned label;
    EdgeProperties()= default;
    EdgeProperties(unsigned i, unsigned l) : id(i), label(l) {}
};

//Graph
struct GraphProperties
{
    unsigned id;
    unsigned label;
    GraphProperties()= default;
    GraphProperties(unsigned i, unsigned l) : id(i), label(l) {}
};


//adjency list
typedef boost::adjacency_list<
    boost::vecS, boost::vecS, boost::directedS,
    VertexProperties,
    EdgeProperties,
    GraphProperties
> Graph;


//iterators
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;
/***********************************************/
int main()
{
    Graph g;
    vertex_t v1 = boost::add_vertex(VertexProperties(1,10),g);
    vertex_t v2 = boost::add_vertex(VertexProperties(2,20),g);
    //edge_t e1= boost::add_edge(EdgeProperties(3,55),g);
    std::cout << "Vertice: " <<num_vertices(g) << std::endl;
    std::cout << "edges: " <<num_edges(g) << std::endl;

    return 0;
}

这行有问题:

edge_t e1= boost::add_edge(EdgeProperties(3,55),g);

我怎样才能创建这个边缘? PS:请告诉代码是否正确(我是指vue的概念)

【问题讨论】:

    标签: c++ qt boost graph mining


    【解决方案1】:

    注意:我使用的是 GCC 4.8(带有 -std=c++11 标志)和 Boost 1.48。

    我发现您的代码存在两个问题。首先,传递给 boost::add_edge(...) 的前两个参数应该是与边关联的顶点。所以在你的情况下,电话是

    edge_t e1= boost::add_edge(v1, v2, EdgeProperties(3,55),g);
    

    第二,我理解的e1的类型应该是

    std::pair<edge_descriptor, bool>
    

    所以你的第二个 typedef 将是

    typedef std::pair<boost::graph_traits<Graph>::edge_descriptor, bool> edge_t;
    

    或者,您可以只使用 auto 关键字来描述 e1 的类型。例如,

    auto e1= boost::add_edge(v1, v2, EdgeProperties(3,55),g);
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 2012-12-25
    • 1970-01-01
    相关资源
    最近更新 更多