Re: [Boost-users] [BGL] How to provide a vertex_index property for my graph

"ShNaYkHs ShNaYkHs" 写入消息 news:CA+GAXM2Kt7KjUamMuXUeo2_SL-GTWg0k2UjerJTNQi7sizUipQ@mail.gmail.com...
Hello,
Since my graph use setS as a VertexList, I have to either provide a vertex_index property map for my graph to be able to use some functions requiring a vertex_index (e.g. write_graphviz). My graph is defined as: typedef adjacency_list
Graph; Where NodeData and EdgeData are structures. Can you please give me a very simple example of how to provide a vertex_index property map for my graph ? I mean, since an adjacency_list that uses listS or setS as the vertex container does not automatically provide this vertex_id property, how can I add it to the code bellow ?
I tried to use an associative_property_map to include index for vertices, but it doesn't work (errors):
#include
#include
using namespace std; using namespace boost;
struct NodeData { int label; float influance; /* etc ... */ };
struct EdgeData { int age; /* etc ... */ };
typedef map
IndexMap; IndexMap mapIndex; associative_property_map<IndexMap> propmapIndex(mapIndex);
typedef adjacency_list
Graph; typedef Graph::vertex_descriptor NodeID; typedef Graph::edge_descriptor EdgeID;
int main() { Graph g;
NodeID n0 = add_vertex(g); g[n0].label = -1; NodeID n1 = add_vertex(g); g[n1].label = -1;
EdgeID edge; bool ok; tie(edge, ok) = boost::add_edge(n0, n1, g); if (ok) g[edge].age = 10;
int i=0; BGL_FORALL_VERTICES(v, g, Graph) { put(propmapIndex, v, i++); }
return 0; }
Thanks for answer.
--------------------------------------------------------------------------------
you can using vertex bundle property as you vertex index,
here is the code I modified according to above:
#include

"gongyiling" 写入消息 news:SNT144-ds19B02F1512F761280919EAD1D40@phx.gbl... "ShNaYkHs ShNaYkHs" 写入消息 news:CA+GAXM2Kt7KjUamMuXUeo2_SL-GTWg0k2UjerJTNQi7sizUipQ@mail.gmail.com...
Hello,
Since my graph use setS as a VertexList, I have to either provide a vertex_index property map for my graph to be able to use some functions requiring a vertex_index (e.g. write_graphviz). My graph is defined as: typedef adjacency_list
Graph; Where NodeData and EdgeData are structures. Can you please give me a very simple example of how to provide a vertex_index property map for my graph ? I mean, since an adjacency_list that uses listS or setS as the vertex container does not automatically provide this vertex_id property, how can I add it to the code bellow ?
I tried to use an associative_property_map to include index for vertices, but it doesn't work (errors):
#include
#include
using namespace std; using namespace boost;
struct NodeData { int label; float influance; /* etc ... */ };
struct EdgeData { int age; /* etc ... */ };
typedef map
IndexMap; IndexMap mapIndex; associative_property_map<IndexMap> propmapIndex(mapIndex);
typedef adjacency_list
Graph; typedef Graph::vertex_descriptor NodeID; typedef Graph::edge_descriptor EdgeID;
int main() { Graph g;
NodeID n0 = add_vertex(g); g[n0].label = -1; NodeID n1 = add_vertex(g); g[n1].label = -1;
EdgeID edge; bool ok; tie(edge, ok) = boost::add_edge(n0, n1, g); if (ok) g[edge].age = 10;
int i=0; BGL_FORALL_VERTICES(v, g, Graph) { put(propmapIndex, v, i++); }
return 0; }
Thanks for answer.
--------------------------------------------------------------------------------
you can using vertex bundle property as you vertex index,
here is the code I modified according to above:
#include
participants (1)
-
gongyiling