Boost logo

Boost Users :

Subject: [Boost-users] Boost Graph/Subgraph: Making a "layered graph"
From: Frank Neuhaus (fneuhaus_at_[hidden])
Date: 2011-04-02 13:31:17


Hi,

I want to represent a graph that consists of several layers. I have an
algorithm that is supposed to be run on each layer seperately. I thought
about having all layers in one graph, but each layer in a subgraph of this
graph. That way - I thought - I could leave the algorithm that works on one
layer unchanged.

First off: Is that a reasonable design? Is there a different way to achieve
what I want? Maybe there is another way to pass a subset of the graph to my
algorithm?

Now as for the actual problem with boost subgraphs:

My current code (for one layer only) looks similar to this:

----
struct my_vertex { int x; };
struct my_edge { int y; };
typedef boost::adjacency_list<vecS, listS, undirectedS, my_vertex, my_edge> 
NormalGraph;
NormalGraph ng;
NormalGraph::vertex_descriptor vd=add_vertex(ng);
ng[vd].x=5;
----
So as you can see I am using bundled properties.
Now I want to create the same thing with subgraphs. Just doing
----
typedef boost::subgraph<boost::adjacency_list<vecS, listS, undirectedS, 
my_vertex, my_edge> > SubGraph;
----
Did not work and I suspected it was due to the problem mentioned in the 
"Notes" section at the very bottom of [1] - which I dont quite understand to 
be honest. I still tried to use the workaround that is mentioned there:
----
struct my_vertex { int x; };
struct my_edge { int y; };
typedef boost::property<boost::vertex_index_t, std::size_t, my_vertex> 
vertex_prop;
typedef boost::property<boost::edge_index_t, std::size_t, my_edge> 
edge_prop;
typedef boost::adjacency_list<vecS, listS, undirectedS, vertex_prop, 
edge_prop> Graph;
typedef boost::subgraph<Graph> Subgraph;
Subgraph sg;
Subgraph::vertex_descriptor vd=add_vertex(sg);
sg[vd].x=5; // doesnt work - why?
auto pm=get(boost::vertex_bundle,sg);
my_vertex vert;
vert.x=7;
put(pm,vd,vert); // doesnt work - why?
----
Now I do not understand how to access my vertex and edge properties as you 
can see... Neither using [] nor accessing via property maps appears to work. 
What am I doing wrong here? I couldnt find any documentation or examples on 
this :(
Thanks a lot
   Frank
[1] http://www.boost.org/doc/libs/1_46_0/libs/graph/doc/subgraph.html 

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