Ben
Ben

Reputation: 83

Boost Subgraph and Bundled properties

I'm using bundled properties and adjacency_list and would like to use the subgraph class.

struct Vertex
{
   int index;
   int seed;
}; 

struct Edge
{
 bool visted;
 double weight;
};

typedef adjacency_list<listS, listS, undirectedS, Vertex, property<edge_index_t,int,Edge> > Graph;
typedef subgraph<Graph> testSubgraph;

The property<edge_index_t,int,Edge> part is needed, as subgraph needs edge_index_t to compare two edges.

Now my question is how do I add an Edge using bundled properties in a Subgraph? In the normal graph without property<edge_index_t,int,Edge> I add an edge as following:

Edge e;
vertex_descriptor u,v; 
// fill in u and v;
e.weight = 1.0;
e.visted=false;
add_edge(u,v,e,graph);

But this doesn't work for Subgraph.

Hope someone knows a solution for this.

Thanks

Ben

Upvotes: 6

Views: 2063

Answers (3)

breiters
breiters

Reputation: 158

I am also just learning BGL and the following code works for adding the bundled edge property within the add_edge call.

boost::add_edge(vd1, vd2, testSubgraph::edge_property_type{0, Edge{/* ... */}}, graph);

0 is a dummy edge index and, according to my experience, it is overwritten with the proper edge index by BGL. I don't know whether that's always true (any comment welcome).

You can also just add the edge to the subgraph without using the bundle and use the edge descriptor returned by add_edge to add the properties later.

auto pair = boost::add_edge(vd1, vd2, graph);
boost::put(boost::get(&Edge::member_name1, graph), pair.first, member_value1);
/* ... */

Don't know whether it is possible to put a complete property bundle using the second method.

Upvotes: 0

Slizzered
Slizzered

Reputation: 899

I just ran into the a similar issue when trying to add a vertex with the add_vertex() function and found that there is a (very old) unresolved issue on the boost bugtracker:

Ticket #380: Support for bundled properties in graph adaptors:

The graph adaptors (such as subgraph) do not support bundled properties, but they should.


Further searching lead to the following 2 patches, which are not yet merged but appear to finally bring the support for bundled properties in subgraphs:

So I guess the answer is: For now, don't use bundled properties. But in the future, the issue should disappear.

Upvotes: 2

carlpett
carlpett

Reputation: 12583

An adjacency list do not have edge_index:es. You need to assign an index yourself, but that is as simple as adding a size_t index to the Edge, and assigning an index as you create the edges.

You probably do not need to create edges for the subgraph, since the boost subgraphs are induced subgraphs. Therefore, all edges in the graph of which both endpoints are in the subgraph will be included in your subgraphs.

Upvotes: 1

Related Questions