Boost C++ Libraries: Ticket #3257: boost/graph/prim_minimum_spanning_tree doesn't handle complete graph well https://svn.boost.org/trac10/ticket/3257 <p> 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: </p> <p> g++ -DSPECIFY_ONCE -I...where-boost-is-installed... mstree_prim.cpp </p> <p> gives correct answer, while </p> <p> g++ -I...where-boost-is-installed... mstree_prim.cpp </p> <p> gives incorrect answer (two spanning trees). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3257 Trac 1.4.3 anonymous Fri, 10 Jul 2009 10:42:28 GMT attachment set https://svn.boost.org/trac10/ticket/3257 https://svn.boost.org/trac10/ticket/3257 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">mstree_prim.cpp</span> </li> </ul> Ticket Jeremiah Willcock Fri, 10 Jul 2009 15:02:48 GMT component changed; owner set https://svn.boost.org/trac10/ticket/3257#comment:1 https://svn.boost.org/trac10/ticket/3257#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Andrew Sutton</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">graph</span> </li> </ul> <p> 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. </p> Ticket anonymous Fri, 10 Jul 2009 15:11:29 GMT <link>https://svn.boost.org/trac10/ticket/3257#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3257#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3257#comment:1" title="Comment 1">jewillco</a>: </p> <blockquote class="citation"> <p> 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. </p> </blockquote> <p> 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? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jeremiah Willcock</dc:creator> <pubDate>Fri, 10 Jul 2009 15:16:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3257#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3257#comment:3</guid> <description> <p> 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? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jeremiah Willcock</dc:creator> <pubDate>Fri, 10 Jul 2009 15:17:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3257#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3257#comment:4</guid> <description> <p> BTW, please add your name and email address to your preferences as stated at <a class="ext-link" href="https://svn.boost.org/trac/boost/wiki"><span class="icon">​</span>https://svn.boost.org/trac/boost/wiki</a> so you get email replies to your comments. </p> </description> <category>Ticket</category> </item> <item> <author>Li Long <Li.Long@…></author> <pubDate>Mon, 13 Jul 2009 09:36:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3257#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3257#comment:5</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jeremiah Willcock</dc:creator> <pubDate>Tue, 04 Aug 2009 16:21:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3257#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3257#comment:6</guid> <description> <p> How do you get two separate spanning trees? How do the vertices and edges relate between them? Does either cover the entire input graph? </p> </description> <category>Ticket</category> </item> <item> <author>Li.Long@…</author> <pubDate>Wed, 05 Aug 2009 08:01:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3257#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3257#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3257#comment:6" title="Comment 6">jewillco</a>: </p> <blockquote class="citation"> <p> How do you get two separate spanning trees? How do the vertices and edges relate between them? Does either cover the entire input graph? </p> </blockquote> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jeremiah Willcock</dc:creator> <pubDate>Tue, 24 Nov 2009 22:35:59 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3257#comment:8 https://svn.boost.org/trac10/ticket/3257#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> 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 <a class="changeset" href="https://svn.boost.org/trac10/changeset/57914" title="Added note about parallel edges to docs">r57914</a>) 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. </p> Ticket