Boost Subgraph and Bundled properties

2019-06-21 23:21发布

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

2条回答
何必那么认真
2楼-- · 2019-06-22 00:02

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-06-22 00:20

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.

查看更多
登录 后发表回答