|
Boost Users : |
Subject: Re: [Boost-users] [graph] Unique vertices using setS
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2014-08-27 17:48:51
On Wed, Aug 27, 2014 2:47 AM EDT Nicholas Dahm wrote:
>Hi All,
>
>I'm trying to create a graph with unique vertices using setS for vertices, but it doesn't seem to be working.
>
>To test it I've made a simple example simply using int's for the vertex properties:
>
> typedef boost::adjacency_list<boost::setS, boost::setS, boost::undirectedS, int, int> gtype;
> typedef boost::graph_traits<gtype>::vertex_descriptor gvd;
>
> gtype gr;
> int v1 = 4;
> gvd vd1 = add_vertex(v1, gr);
> gvd vd2 = add_vertex(v1, gr);
> printf("vd1: %ld, gr[vd1]: %d\n", vd1, gr[vd1]);
> printf("vd2: %ld, gr[vd2]: %d\n", vd2, gr[vd2]);
> printf("num_vertices: %d\n", num_vertices(gr));
>
>Output:
>
> vd1: 17473168, gr[vd1]: 4
> vd2: 17473248, gr[vd2]: 4
> num_vertices: 2
>
>So my graph has two vertices represented by the int 4, suggesting it's not a set! Any idea what I'm missing? Is the set for vertex descriptors, but the vertices themselves stored elsewhere?
There is a difference between vertex descriptors and properties. There are no requirements that property values are unique for any graph type; those are up to you to set however you want. If gr[vd1] and gr[vd2] had the same address, that would be a problem. However, you initialized both of those property slots with the same value 4, and the graph type has no issue with you doing that. One reason for this is that the same graph can have multiple vertex and edge properties, and so you might want some of them to be unique and some not, so the graph type would not know where to enforce uniqueness.
-- Jeremiah Willcock
>
>cheers
>
>Nick
>_______________________________________________
>Boost-users mailing list
>Boost-users_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/boost-users
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