Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost Graph: add_edge causes compiler error
From: Andrew Sutton (andrew.n.sutton_at_[hidden])
Date: 2010-03-26 21:55:38


> you should just be able to write:
>>
>> add_edge(0, 1, g)
>>
>
> Is there a way to add an edge if I don't know the vertex indices? For
> instance, let's say I've only got the two Foo pointers and I want to add an
> edge between them.
>
> I suppose I could iterate through all vertices in the graph, find the Foo
> pointer, and thus know its index, but I feel like there must be a better
> (and faster) way.
>

A common approach is to keep a map or unordered_map from Foo to vertex
descriptor. You can think of a descriptor is a kind of generalized index.
For example:

typedef graph_traits<Graph>::vertex_descriptor Vertex;
map<Foo*, Vertex> verts;

g.add_edge(verts[f], verts[g]);

assuming f and g are Foo objects.

Andrew Sutton
andrew.n.sutton_at_[hidden]



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net