Opened 13 years ago

Closed 13 years ago

#3257 closed Bugs (wontfix)

boost/graph/prim_minimum_spanning_tree doesn't handle complete graph well

Reported by: Li.Long@… Owned by: Andrew Sutton
Milestone: Boost 1.40.0 Component: graph
Version: Boost 1.39.0 Severity: Problem
Keywords: Cc:

Description

prim_minimum_spanning_tree handles "undirected" graph. But when you have a complete graph w/ positive weights, and you specify each edge twice, instead of once, the return results are different. An example is attached. Compile with:

g++ -DSPECIFY_ONCE -I...where-boost-is-installed... mstree_prim.cpp

gives correct answer, while

g++ -I...where-boost-is-installed... mstree_prim.cpp

gives incorrect answer (two spanning trees).

Attachments (1)

mstree_prim.cpp (2.3 KB ) - added by anonymous 13 years ago.

Download all attachments as: .zip

Change History (9)

by anonymous, 13 years ago

Attachment: mstree_prim.cpp added

comment:1 by Jeremiah Willcock, 13 years ago

Component: Nonegraph
Owner: set to Andrew Sutton

Are you using an actual undirected graph (one with undirectedS), or a directed graph with each edge put in twice? If the latter, the algorithm will consider the edges to be completely separate and may not handle that properly. The documentation does not explicitly say what happens with parallel edges, so that might need to be fixed.

in reply to:  1 comment:2 by anonymous, 13 years ago

Replying to jewillco:

Are you using an actual undirected graph (one with undirectedS), or a directed graph with each edge put in twice? If the latter, the algorithm will consider the edges to be completely separate and may not handle that properly. The documentation does not explicitly say what happens with parallel edges, so that might need to be fixed.

In the example in the attached .cpp, it's "undirectedS", when listing edges and their weights, it doesn't handle it well if you have both "(a, b)" and "(b, a)". In these cases, is it smart enough to check if the given info are "consistant" and keep only one copy?

comment:3 by Jeremiah Willcock, 13 years ago

You appear to be getting the spanning tree from the parent map, which is the correct way to do it. How can a single vertex appear in more than one tree since it only has one parent?

comment:4 by Jeremiah Willcock, 13 years ago

BTW, please add your name and email address to your preferences as stated at https://svn.boost.org/trac/boost/wiki so you get email replies to your comments.

comment:5 by Li Long <Li.Long@…>, 13 years ago

I'm not sure about "spanning tree from the parent map", why is it the "correct way"? The two "spanning trees" do NOT share any vertex in the example.

comment:6 by Jeremiah Willcock, 13 years ago

How do you get two separate spanning trees? How do the vertices and edges relate between them? Does either cover the entire input graph?

in reply to:  6 comment:7 by Li.Long@…, 13 years ago

Replying to jewillco:

How do you get two separate spanning trees? How do the vertices and edges relate between them? Does either cover the entire input graph?

The two separate spanning trees do cover the entire input graph, but they cover different edges of the "correct" spanning tree. If you run the examples, it's pretty easy to see. The example input tree contains only 6 nodes, small enough to eye-ball it.

comment:8 by Jeremiah Willcock, 13 years ago

Resolution: wontfix
Status: newclosed

I get an output that has a cycle in the parent map. Changing the graph to directedS (leaving in the duplicated edges) works fine. I added a note to the documentation (in r57914) about parallel edges; I do not believe there is an easy way to fix it using the Boost.Graph implementation of Prim's algorithm, so I am closing the bug.

Note: See TracTickets for help on using tickets.