
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: http://codepad.org/7VYELJan Thanks, David

Hi, 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 following: public: typedef adjacency_list<listS, listS, undirectedS, vertex_property, edge_property, GraphProp, 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@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hope that it helps. Best, Cedric

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:
Hi David, 1. I never really understood how to use the property maps correctly/efficienty, but I've found using "bundled properties" fairly straightforward. Like so: http://codepad.org/ThR2i2FI documentation: http://www.boost.org/doc/libs/1_40_0/libs/graph/doc/bundles.html 2. if you want/need to use unsigned ints as vertex descriptors then you need to store the vertices in a vector, like so: http://codepad.org/hLBkPtL5 Anders

1. I never really understood how to use the property maps correctly/efficienty, but I've found using "bundled properties" fairly straightforward. Like so: http://codepad.org/ThR2i2FI documentation: http://www.boost.org/doc/libs/1_40_0/libs/graph/doc/bundles.html
2. if you want/need to use unsigned ints as vertex descriptors then you need to store the vertices in a vector, like so: http://codepad.org/hLBkPtL5
Thanks all. This example shows two methods of setting an int property (both using a "bundled property", but different syntax/method to address the vertices): http://programmingexamples.net/index.php?title=CPP/Boost/BGL/VertexPropertie... David
participants (3)
-
Anders Wallin
-
Cedric Laczny
-
David Doria