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<setS, setS, undirectedS, NodeData, EdgeData> 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 <boost/graph/iteration_macros.
hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
struct NodeData
{
int label;
float influance;
/* etc ... */
};
struct EdgeData
{
int age;
/* etc ... */
};
typedef map<vecS, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);
typedef adjacency_list<setS, setS, undirectedS, NodeData, EdgeData> 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.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
> 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<setS, setS, undirectedS, NodeData, EdgeData> 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):
If you are going to use an associative_property_map, the key type of the
map needs to be your graph's vertex_descriptor type, not vecS (which
probably doesn't have any data members and is just a tag). You can then
pass that property map to algorithms. Alternatively, as stated in the
other reply to your post, you can add a vertex index member (with whatever
name) into your NodeData structure and use that as the property map (e.g.,
using syntax such as "get(&NodeData::index, g)").
-- Jeremiah Willcock
2011/11/2 Jeremiah Willcock <jewi...@osl.iu.edu>
> ______________________________**_________________
> Unsubscribe & other changes: http://lists.boost.org/**
> mailman/listinfo.cgi/boost<http://lists.boost.org/mailman/listinfo.cgi/boost>
> Thanks for your answer, now after adding this associative property map,
> should I care about any problem with the vertex/edge iterator stability or
> invalidation (like it is the case for vecS) if I use the method described
> here
> http://www.cs.brown.edu/~jwicks/boost/libs/graph/doc/adjacency_list.html(using
> next etc) ?
If you are adding or removing vertices, you will need to regenerate the
vertex numbering each time you call an algorithm that needs the vertex
index map (mostly to make sure the numbers are contiguous). If you are
just adding vertices, you can give them consecutive numbers without any
trouble. I think listS vertex descriptors are stable when other vertices
are added or removed, so invalidation of the descriptors themselves is not
likely to be a problem.
-- Jeremiah Willcock