Boost logo

Boost Users :

Subject: Re: [Boost-users] Assigning vertex properties
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2011-06-07 03:11:44


On Tuesday, 7. June 2011 01:42:18 David Doria wrote:
> I am trying to assign names to vertices.
> I made a typedef boost::property<boost::vertex_name_t, std::string>
> VertexProperty; and tried to set a label for vertex 0 in two ways:
> A)
> g[0] = "Vertex0";
> and B)
> boost::property_map<Graph, boost::vertex_name_t>::type value =
> boost::get(boost::vertex_name_t(), g);
> boost::put(value, 0, "Vertex0");
> Neither compiles. In the second one, the problem with this:
> boost::put(value, 0, "Vertex0"); is that "0" is not the right type -
> I guess the vertex IDs should be vertex_descriptor's instead of ints?
> How do I get the descriptor of vertex #0 ?
> Here is the full code:

At first sight, your code seems to be valid in general. When looking at the
definition of undirected_graph in the corresponding header, I find the
    typedef adjacency_list<listS,
                listS> graph_type;

So, what I understand is that in an undirected_graph, the edgecontainer and
vertexcontainer are both lists. The problem with that is that you can not
simply access vertices via an index, as you do in your code. You would need a
vertex_descriptor, which is BTW the recommend way-to-go, for (maybe now)
obvious reasons. AFAIK listS works with void*...
So you would need to iterate over the vertices in order to assign them values.
Or simply define your own UndirectedGraph, based on adjacency_list.
Or maybe have a closer look at the interface of undirected_graph which might
offer respective functionality.

> Thanks,
> David
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Hope that it helps.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at