newbie - graph library - vertex properties

Hi 1. In the creation of adjacency list, vertex properties and edge properties could be vecS, listS etc.But how will one access this vertex_properties vector, for example? 2. In the kevin-bacon2.cpp example file available with boost distribution, a struct is used to store vertex properties. But that example does not seem to have used boost_install_property or property_map etc. I thought one would need to use them for having new properties for the vertex. 3. In the kevin-bacon2.cpp approach for adding new properties to the graph, the vertex_properties are read as adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)Thanks suresh

On Mon, 14 Dec 2009, List User wrote:
Hi 1. In the creation of adjacency list, vertex properties and edge properties could be vecS, listS etc.But how will one access this vertex_properties vector, for example?
The vecS, listS, ... tags specify how the vertices and edges of the graph are stored, not anything about properties. You cannot get to the property storage directly except using boost::get and boost::put (and some other ways for bundled properties).
2. In the kevin-bacon2.cpp example file available with boost distribution, a struct is used to store vertex properties. But that example does not seem to have used boost_install_property or property_map etc. I thought one would need to use them for having new properties for the vertex.
That example uses bundled properties (http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html) which remove the need for the operations you named.
3. In the kevin-bacon2.cpp approach for adding new properties to the graph, the vertex_properties are read as adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)
A function defined as const, or taking the graph as const? What error do you get? -- Jeremiah Willcock

Hi Jeremiah Willcock,
Thanks for the reply. I think the const error was something else...
Let me ask you a couple of questions from bundled properties:
1. the prototype of get is, get(name_map, vertex_descriptor) right. But in the bundled properties documentation, it is written as get(&Highway::miles, map). How is it?
2. get(vertex_bundle, map), here what is vertex_bundle?Thanks
suresh
________________________________
From: Jeremiah Willcock
Hi 1. In the creation of adjacency list, vertex properties and edge properties could be vecS, listS etc.But how will one access this vertex_properties vector, for example?
The vecS, listS, ... tags specify how the vertices and edges of the graph are stored, not anything about properties. You cannot get to the property storage directly except using boost::get and boost::put (and some other ways for bundled properties).
2. In the kevin-bacon2.cpp example file available with boost distribution, a struct is used to store vertex properties. But that example does not seem to have used boost_install_property or property_map etc. I thought one would need to use them for having new properties for the vertex.
That example uses bundled properties (http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html) which remove the need for the operations you named.
3. In the kevin-bacon2.cpp approach for adding new properties to the graph, the vertex_properties are read as adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)
A function defined as const, or taking the graph as const? What error do you get? -- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi, In order to understand bundled properties better, I tried to compile the example given in the link below. the code is pasted here: it gives a segmentation violation... using namespace std; using namespace boost; struct City { string name; int population; vector<int> zipcodes; }; struct Highway { string name; double miles; int speed_limit; int lanes; bool divided; }; typedef boost::adjacency_list< boost::listS, boost::vecS, boost::bidirectionalS,City, Highway> Map; int main(){ Map map; // load the map Map::vertex_descriptor v = *vertices(map).first; map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = *out_edges(v, map).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; } How do I add memory for vertices in the above example? suresh That example uses bundled properties (http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html) which remove the need for the operations you named.
3. In the kevin-bacon2.cpp approach for adding new properties to the graph, the vertex_properties are read as adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)
A function defined as const, or taking the graph as const? What error do you get? -- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi,
In order to understand bundled properties better, I tried to compile
Hi suresh, Actually in the example you gave, there is no vertex in Map. Therefore vertices( map ).first is an iterator pointing to the end of vertices( map ) and accessing this element results in a segmentation violation. You first need to add some vertices by Map::vertex_descriptor v = add_vertex( map ); Then v is a vertex of your graph and you may assign properties to it: map[v].name = "Troy"; Regards Tobias On Tuesday 15 December 2009 08:36:46 am List User wrote: the example given in the link below. the code is pasted here: it gives a segmentation violation...
using namespace std; using namespace boost;
struct City { string name; int population; vector<int> zipcodes; };
struct Highway { string name; double miles; int speed_limit; int lanes; bool divided; };
typedef boost::adjacency_list< boost::listS, boost::vecS,
boost::bidirectionalS,City, Highway> Map;
int main(){
Map map; // load the map Map::vertex_descriptor v = *vertices(map).first; map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = *out_edges(v, map).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; }
How do I add memory for vertices in the above example?
suresh
That example uses bundled properties
(http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html) which remove the need for the operations you named.
3. In the kevin-bacon2.cpp approach for adding new properties to
the graph, the vertex_properties are read as
adjacency_list[vertex_descriptior]. How will have a read only
access in such a case? When I use this in a function which is
defined as const in c++, the compiler cribs :)
A function defined as const, or taking the graph as const? What error do you get?
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- __________________________ Tobias Columbus t.columbus@gmx.de

Hi,
In order to understand bundled properties better, I tried to compile
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3
//Map::vertex_descriptor v = *vertices(map).first;
Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out
*** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7e6a604]
/lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231]
../a.out[0x8049e7d]
../a.out[0x8049ea7]
..
..
..
so what to do next?
suresh
________________________________
From: Tobias Columbus
using namespace std; using namespace boost;
struct City { string name; int population; vector<int> zipcodes; };
struct Highway { string name; double miles; int speed_limit; int lanes; bool divided; };
typedef boost::adjacency_list< boost::listS, boost::vecS,
boost::bidirectionalS,City, Highway> Map;
int main(){
Map map; // load the map Map::vertex_descriptor v = *vertices(map).first; map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = *out_edges(v, map).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; }
How do I add memory for vertices in the above example?
suresh
That example uses bundled properties
(http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html) which remove the need for the operations you named.
3. In the kevin-bacon2.cpp approach for adding new properties to
the graph, the vertex_properties are read as
adjacency_list[vertex_descriptior]. How will have a read only
access in such a case? When I use this in a function which is
defined as const in c++, the compiler cribs :)
A function defined as const, or taking the graph as const? What error do you get?
-- Jeremiah Willcock _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- __________________________ Tobias Columbus t.columbus@gmx.de _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi again, Try the following code, which just compiles fine with g++ 4.4.1 on my system: struct City{...}; struct Highway{...}; typedef ... Map; int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; } Generally I would suggest reading http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html which gives a quick overview of how to handle graphs in BGL. If you work through this tutorial, vertex and edge properties will also get explained. Regards Tobias On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh

Hi thanks,
I tried earlier with one add_vertex only. Thats why I got the error.
Now its fine. I will try reading that tutorial and understand
better....
Thanks
suresh
On Tue, Dec 15, 2009 at 3:18 PM, Tobias Columbus
Hi again,
Try the following code, which just compiles fine with g++ 4.4.1 on my system:
struct City{...}; struct Highway{...};
typedef ... Map;
int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; }
Generally I would suggest reading http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html which gives a quick overview of how to handle graphs in BGL.
If you work through this tutorial, vertex and edge properties will also get explained.
Regards Tobias
On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521

Hi Tobias,
Can you just show, how to access the vertex properties using the get()
function?. I know that map[vertex_descriptior] gives me the
vertex_properties of that particular vertex. But I am unable to figure
out how to use the get function for single vertex property as well as
for the vertex_bundle,
Thanks
suresh
On Tue, Dec 15, 2009 at 3:18 PM, Tobias Columbus
Hi again,
Try the following code, which just compiles fine with g++ 4.4.1 on my system:
struct City{...}; struct Highway{...};
typedef ... Map;
int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; }
Generally I would suggest reading http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html which gives a quick overview of how to handle graphs in BGL.
If you work through this tutorial, vertex and edge properties will also get explained.
Regards Tobias
On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521

Hi, For example, I wrote the following: typedef property_map
Hi Tobias,
Can you just show, how to access the vertex properties using the get() function?. I know that map[vertex_descriptior] gives me the vertex_properties of that particular vertex. But I am unable to figure out how to use the get function for single vertex property as well as for the vertex_bundle,
Thanks suresh
On Tue, Dec 15, 2009 at 3:18 PM, Tobias Columbus
wrote: Hi again,
Try the following code, which just compiles fine with g++ 4.4.1 on my system:
struct City{...}; struct Highway{...};
typedef ... Map;
int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; }
Generally I would suggest reading http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html which gives a quick overview of how to handle graphs in BGL.
If you work through this tutorial, vertex and edge properties will also get explained.
Regards Tobias
On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521

Hi Tobias
I managed to figure out how to use the property maps. When we can get
vertex property as graph[vertex_descriptor] why property maps? again,
when the above method is available, what do we gain by vertex_bundle
property tag etc?
Thanks
suresh
On Wed, Dec 16, 2009 at 5:00 PM, Suresh Kumar
Hi,
For example, I wrote the following: typedef property_map
But I am unable to figure out how to get the actual vertex property from the IndexMap index.
Also, how do we use, get(vertex_bundle, map)?
Thanks suresh
On Wed, Dec 16, 2009 at 4:09 PM, Suresh Kumar
wrote: Hi Tobias,
Can you just show, how to access the vertex properties using the get() function?. I know that map[vertex_descriptior] gives me the vertex_properties of that particular vertex. But I am unable to figure out how to use the get function for single vertex property as well as for the vertex_bundle,
Thanks suresh
On Tue, Dec 15, 2009 at 3:18 PM, Tobias Columbus
wrote: Hi again,
Try the following code, which just compiles fine with g++ 4.4.1 on my system:
struct City{...}; struct Highway{...};
typedef ... Map;
int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; }
Generally I would suggest reading http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html which gives a quick overview of how to handle graphs in BGL.
If you work through this tutorial, vertex and edge properties will also get explained.
Regards Tobias
On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521

Hi Tobias
I managed to figure out how to use the property maps. When we can get vertex property as graph[vertex_descriptor] why property maps? again, when the above method is available, what do we gain by vertex_bundle property tag etc?
Thanks suresh
On Wed, Dec 16, 2009 at 5:00 PM, Suresh Kumar
wrote: Hi,
For example, I wrote the following: typedef property_map
But I am unable to figure out how to get the actual vertex property from the IndexMap index.
Also, how do we use, get(vertex_bundle, map)?
Thanks suresh
On Wed, Dec 16, 2009 at 4:09 PM, Suresh Kumar
wrote: Hi Tobias,
Can you just show, how to access the vertex properties using the get() function?. I know that map[vertex_descriptior] gives me the vertex_properties of that particular vertex. But I am unable to
Hi Suresh, One advantage I can think of, is the following: Suppose you're developing in a team and after some while you realize that your graph needs property XY. Then you don't have to mess around in some header file to adapt your team's graph classes, but you only have to adapt your code locally, initialize a property_map in your algorithm, use it and destroy it afterwards. Another scenario would be that a graph is passed through some kind of pipeline and each pipeline step only needs to use local property_maps that saves memory, as the graph doesn't need to have internal all properties. Finally I think the reason that property_maps are used in boost, is that they make generic programming much easier, as the library programmer doesn't fix the implementation of some property but the library user may choose the adequate property_map for his/her code. Regards Tobias On Thursday 17 December 2009 06:54:17 am Suresh Kumar wrote: figure
out how to use the get function for single vertex property as well as for the vertex_bundle,
Thanks suresh
On Tue, Dec 15, 2009 at 3:18 PM, Tobias Columbus
wrote: Hi again,
Try the following code, which just compiles fine with g++ 4.4.1 on my system:
struct City{...}; struct Highway{...};
typedef ... Map;
int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; }
Generally I would suggest reading
http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html
which gives a quick overview of how to handle graphs in BGL.
If you work through this tutorial, vertex and edge properties will also get explained.
Regards Tobias
On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- __________________________ Tobias Columbus t.columbus@gmx.de

Thanks Tobias,
with warm regards
suresh
On Thu, Dec 17, 2009 at 12:13 AM, Tobias Columbus
Hi Suresh,
One advantage I can think of, is the following: Suppose you're developing in a team and after some while you realize that your graph needs property XY. Then you don't have to mess around in some header file to adapt your team's graph classes, but you only have to adapt your code locally, initialize a property_map in your algorithm, use it and destroy it afterwards.
Another scenario would be that a graph is passed through some kind of pipeline and each pipeline step only needs to use local property_maps that saves memory, as the graph doesn't need to have internal all properties.
Finally I think the reason that property_maps are used in boost, is that they make generic programming much easier, as the library programmer doesn't fix the implementation of some property but the library user may choose the adequate property_map for his/her code.
Regards Tobias
Hi Tobias
I managed to figure out how to use the property maps. When we can get vertex property as graph[vertex_descriptor] why property maps? again, when the above method is available, what do we gain by vertex_bundle property tag etc?
Thanks suresh
On Wed, Dec 16, 2009 at 5:00 PM, Suresh Kumar
wrote: Hi,
For example, I wrote the following: typedef property_map
But I am unable to figure out how to get the actual vertex property from the IndexMap index.
Also, how do we use, get(vertex_bundle, map)?
Thanks suresh
On Wed, Dec 16, 2009 at 4:09 PM, Suresh Kumar
wrote: Hi Tobias,
Can you just show, how to access the vertex properties using the get() function?. I know that map[vertex_descriptior] gives me the vertex_properties of that particular vertex. But I am unable to
On Thursday 17 December 2009 06:54:17 am Suresh Kumar wrote: figure
out how to use the get function for single vertex property as well as for the vertex_bundle,
Thanks suresh
On Tue, Dec 15, 2009 at 3:18 PM, Tobias Columbus
wrote: Hi again,
Try the following code, which just compiles fine with g++ 4.4.1 on my system:
struct City{...}; struct Highway{...};
typedef ... Map;
int main(){ Map map; Map::vertex_descriptor v = add_vertex( map ); Map::vertex_descriptor u = add_vertex( map ); map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = add_edge( u, v, map ).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true; return 0; }
Generally I would suggest reading
http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/quick_tour.html
which gives a quick overview of how to handle graphs in BGL.
If you work through this tutorial, vertex and edge properties will also get explained.
Regards Tobias
On Tuesday 15 December 2009 05:00:01 pm List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064
======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ../a.out[0x8049e7d] ../a.out[0x8049ea7] .. .. ..
so what to do next?
suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521 _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- __________________________ Tobias Columbus t.columbus@gmx.de _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- R. Suresh Kumar PhD Student, Vislab #216, Engineering II Bldg University of California, Riverside, CA 92521

Hi Suresh, That's a good start, now try adding a second vertex and joining them together with the edge "e" of the sample code. Hint: add_edge. :) The problem is caused by this bit here (notice the similarity):
Map::edge_descriptor e = *out_edges(v, map).first;
Geoff List User wrote:
Hi Tobias Columbus,
In fact I had tried that also. But then I got a funny message while executing like this: Ubuntu 9.04, g++ 4.3.3 //Map::vertex_descriptor v = *vertices(map).first; Map::vertex_descriptor v = add_vertex(map);
suresh@suresh-laptop:~/C++$ ./a.out *** glibc detected *** ./a.out: free(): invalid pointer: 0x09f9c064 *** ======= Backtrace: ========= /lib/tls/i686/cmov/libc.so.6[0xb7e6a604] /lib/tls/i686/cmov/libc.so.6(cfree+0x96)[0xb7e6c5b6] /usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb804d231] ./a.out[0x8049e7d] ./a.out[0x8049ea7] . . .
so what to do next?* suresh
* * * * ------------------------------------------------------------------------ *From:* Tobias Columbus
*To:* boost-users@lists.boost.org *Sent:* Tue, December 15, 2009 3:45:42 AM *Subject:* Re: [Boost-users] newbie - graph library - vertex properties Hi suresh,
Actually in the example you gave, there is no vertex in Map. Therefore vertices( map ).first is an iterator pointing to the end of vertices( map ) and accessing this element results in a segmentation violation.
You first need to add some vertices by
Map::vertex_descriptor v = add_vertex( map );
Then v is a vertex of your graph and you may assign properties to it:
map[v].name = "Troy";
Regards Tobias
Hi,
In order to understand bundled properties better, I tried to compile
On Tuesday 15 December 2009 08:36:46 am List User wrote: the example given in the link below. the code is pasted here: it gives a segmentation violation...
using namespace std; using namespac e boost;
struct City { string name; int population; vector<int> zipcodes; };
struct Highway { string name; double miles; int speed_limit; int lanes; bool divided; };
typedef boost::adjacency_list< boost::listS, boost::vecS,
boost::bidirectionalS,City, Highway> Map;
int main(){
Map map; // load the map Map::vertex_descriptor v = *vertices(map).first; map[v].name = "Troy"; map[v].population = 49170; map[v].zipcodes.push_back(12180); Map::edge_descriptor e = *out_edges(v, map).first; map[e].name = "I-87"; map[e].miles = 10; map[e].speed_limit = 65; map[e].lanes = 4; map[e].divided = true;< br>> }
How do I add memory for vertices in the above example?
suresh
That example uses bundled properties
(http://www.boost.org/doc/libs/1_41_0/libs/graph/doc/bundles.html) which remove the need for the operations you named.
3. In the kevin-bacon2.cpp approach for adding new properties to
the graph, the vertex_properties are read as
adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)
A function defined as const, or taking the graph as const? What error do you get?
-- Jeremiah Willcock ___________________ ____________________________ Boost-users mailing list Boost-users@lists.boost.org mailto:Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- __________________________ Tobias Columbus t.columbus@gmx.de mailto:t.columbus@gmx.de

Hello, Have you tried using bundled properties? http://www.boost.org/libs/graph/doc/bundles.html Geoff List User wrote:
Hi
1. In the creation of adjacency list, vertex properties and edge properties could be vecS, listS etc.But how will one access this vertex_properties vector, for example? 2. In the kevin-bacon2.cpp example file available with boost distribution, a struct is used to store vertex properties. But that example does not seem to have used boost_install_property or property_map etc. I thought one would need to use them for having new properties for the vertex. 3. In the kevin-bacon2.cpp approach for adding new properties to the graph, the vertex_properties are read as adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)
Thanks suresh

thanks Geoff Hilton, I heard about bundled properties just now only. Will read it
suresh
________________________________
From: Geoff Hilton
Hi
1. In the creation of adjacency list, vertex properties and edge properties could be vecS, listS etc.But how will one access this vertex_properties vector, for example? 2. In the kevin-bacon2.cpp example file available with boost distribution, a struct is used to store vertex properties. But that example does not seem to have used boost_install_property or property_map etc. I thought one would need to use them for having new properties for the vertex. 3. In the kevin-bacon2.cpp approach for adding new properties to the graph, the vertex_properties are read as adjacency_list[vertex_descriptior]. How will have a read only access in such a case? When I use this in a function which is defined as const in c++, the compiler cribs :)
Thanks suresh
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
Geoff Hilton
-
Jeremiah Willcock
-
List User
-
Suresh Kumar
-
Tobias Columbus