|
Boost Users : |
Subject: Re: [Boost-users] newbie - graph library - vertex properties
From: List User (listuser_at_[hidden])
Date: 2009-12-15 11:00:01
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_at_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 <t.columbus_at_[hidden]>
To: boost-users_at_[hidden]
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
On Tuesday 15 December 2009 08:36:46 am List User wrote:
> 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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
>
>
-- __________________________ Tobias Columbus t.columbus_at_[hidden] _______________________________________________ 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