简体   繁体   中英

Boost Graph Library Undirected Graph No parallel edges enforcement

I'm using the Boost Graph Library to process an undirected graph, and declared my graph has

typedef property<vertex_index_t, int, property<vertex_name_t, string> > VertexProperty;
typedef adjacency_list<vecS, setS, undirectedS, VertexProperty > UndirectedGraph; 

As you can see, the OutEdgeList is of the type std::set and I chose it because the documentation says that this type will enforce the absence of parallel edges.

Now, my program reads a text file which indicates edges between nodes, creates the nodes if not previously seen and adds the edge between them.

I recently run the code with a large amount of data and found strange results. After some hours I discovered some user which had more degree than the number of vertices in the graph, so I tried the code with a simple text file that only described two edges between the same pair of nodes but with reversed source,target, such that boost will execute the following:

add_edge(A,B)
add_edge(B,A)

And noticed Boost ended up adding both edges. out_degree returns 2 for both of them.

Now, the question: am I doing something wrong? Shouldn't add_edge(a,b) be the same as add_edge(b,a) for an undirected graph with setS as the OutEdgeList type?

Thanks. ;)

问题是OutEdgeList是第一个模板参数,而不是第二个,所以我实际上使用的是vecS而不是setS。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM