
I'd like to have unique vertices in a graph based on index of type std::string. I did the following coding. typedef property<edge_weight_t,float> EProperty; typedef property<vertex_index_t,string> VIndex; typedef adjacency_list<setS,listS,directedS,VIndex,EProperty> Graph; typedef property_map<Graph, vertex_index_t>::type VIndexMap; graph_traits<Graph>::vertex_descriptor addv(property_traits<VIndexMap>::value_type v,Graph &g) { graph_traits<Graph>::vertex_descriptor vd; vd = add_vertex(VIndex(v),g); return vd; } Does "add_vertex" check the existence of added vertices of given index? No, it doesn't. Or I do something wrong. Regards liquid

Does "add_vertex" check the existence of added vertices of given index? No, it doesn't. Or I do something wrong.
For a short answer: never. For a longer answer... It looks like vertices are dynamically allocated and the vertex set (listS, setS, etc.) stores pointers to those vertices. In the case of associate containers, the key_type is just the pionter value. In otherwords, add_vertex will never look for a previous instance of the vertex. Andrew Sutton andrew.n.sutton@gmail.com

Andrew Sutton pisze:
Does "add_vertex" check the existence of added vertices of given index? No, it doesn't. Or I do something wrong.
For a short answer: never.
Well, it seemed that sometimes yes. I looked at the piece of code of add_vertex in a boost/graph header file: template <class Graph, class Config, class Base> inline typename Config::vertex_descriptor add_vertex(const typename Config::vertex_property_type& p, vec_adj_list_impl<Graph, Config, Base>& g_) { typedef typename Config::vertex_descriptor vertex_descriptor; Graph& g = static_cast<Graph&>(g_); if (optional<vertex_descriptor> v = g.vertex_by_property(get_property_value(p, vertex_bundle))) return *v; typedef typename Config::stored_vertex stored_vertex; g.m_vertices.push_back(stored_vertex(p)); g.added_vertex(g.m_vertices.size() - 1); return g.m_vertices.size() - 1; } So, with property defined as follows property_type: typedef property<vertex_index_t,string> VIndex; Undoubtedly, above add_vertex function searches vertex by properties and should return descriptor of found vertex. Indeed, it doesn't. I'm a little bit confused.
For a longer answer... It looks like vertices are dynamically allocated and the vertex set (listS, setS, etc.) stores pointers to those vertices. In the case of associate containers, the key_type is just the pionter value. In otherwords, add_vertex will never look for a previous instance of the vertex.
Andrew Sutton andrew.n.sutton@gmail.com <mailto:andrew.n.sutton@gmail.com>
Regards liquid

For a short answer: never.
Well, it seemed that sometimes yes.
We'll compromise: sometimes :)
Undoubtedly, above add_vertex function searches vertex by properties and should return descriptor of found vertex. Indeed, it doesn't.
I'm a little bit confused.
I'm a little confused to. The vertex_by_property call will only actually search the vertices if the adjacency_list is using the named_graph framework. If you're not using - and its almost certain that you aren't - the function call evaluates to a no-op. I would say that for the most part - it's just a push_back. Andrew Sutton andrew.n.sutton@gmail.com
participants (2)
-
Andrew Sutton
-
liquid