Boost logo

Boost :

From: Douglas Gregor (dgregor_at_[hidden])
Date: 2007-11-07 18:38:03


On Wed, 2007-11-07 at 08:38 +0100, Brian Kallehauge wrote:
> I was wondering if it is possible to define an index property for each
> vertex in the graph and then use that index to get the vertex_descriptor of
> the vertex?
>
>
>
> I have made an example (see below) where I have tried to show what I would
> like to do. The graph should use listS for edges and vertices.

> // Add two vertices with external unique id 1001 and 1002,
> respectively
>
> v = add_vertex(graph);
>
> put(vertex_index, graph, v, 1001);
>
>
>
> v = add_vertex(graph);
>
> put(vertex_index, graph, v, 1002);

It's actually a bit dangerous to use vertex_index in this way, because
vertex_index is meant to give unique integers in [0,
num_vertices(graph)). You should use some other property name for this
field; otherwise, you will likely get segmentation faults from many of
the BGL algorithms.

>
>
> // How do I add an edge between the two vertices with external
> unique
>
> // vertex index 1001 and 1002 by referring to their unique ids
> 1001 and 1002?
>
> EdgeDescriptorBool eb;
>
> eb = add_edge(1001, 1002, graph); // error C2664:
> 'boost::add_edge' : cannot convert parameter 1 from 'int' to 'void *'

This, unfortunately, is harder than it should be. At the moment, your
best bet it to create an std::map<int, vertex_descriptor> that maps from
your unique IDs to the BGL's vertex descriptors. Not the most elegant
solution, but it does work.

  - Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk