簡體   English   中英

C ++ BOOST庫和捆綁的屬性

[英]C++ BOOST library and bundled properties

我試圖使用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的構想)

注意:我使用的是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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM