Boost C++ Libraries: Ticket #9770: Finish_edge event misbehavior. https://svn.boost.org/trac10/ticket/9770 <p> Consider the following diamond DAG: </p> <pre class="wiki"> 3 / \ 1 2 \ / 0 </pre><p> A depth first search on this graph with a visitor that records the on-finish-vertex and on-vinish-edge events should output something that: </p> <pre class="wiki">Finish vertex: 3 Finish vertex: 1 Finish edge: (1,3) Finish edge: (2,3) Finish vertex: 2 Finish edge: (0,1) Finish vertex: 0 Finish edge: (0,2 </pre><p> But it acually outputs: </p> <pre class="wiki">Finish vertex: 3 Finish edge: (1,3) Finish vertex: 1 Finish edge: (1,3) Finish edge: (2,3) Finish vertex: 2 Finish edge: (0,2) Finish vertex: 0 Finish edge: (0,2) </pre><p> The edge (0,2) is seen twice while (0,1) not at all (see the attachment). </p> <p> The problem comes from "boost/graph/depth_first_search.hpp" in depth_first_visit_impl(). The variable "src_e" is overwritten during the propagation with another tree edge. </p> <p> The following simple fix solves the problem: </p> <pre class="wiki">--- /tmp/depth_first_search.hpp 2014-03-11 15:11:53.616272419 +0100 +++ boost/graph/depth_first_search.hpp 2014-03-11 15:11:14.854137441 +0100 @@ -143,8 +143,8 @@ ColorValue v_color = get(color, v); if (v_color == Color::white()) { vis.tree_edge(*ei, g); - src_e = *ei; + Edge src_e = *ei; stack.push_back(std::make_pair(u, std::make_pair(src_e, std::make_pair(++ei, ei_end)))); u = v; put(color, u, Color::gray()); </pre><p> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9770 Trac 1.4.3 anonymous Tue, 11 Mar 2014 14:21:05 GMT attachment set https://svn.boost.org/trac10/ticket/9770 https://svn.boost.org/trac10/ticket/9770 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">test.cc</span> </li> </ul> <p> Minimum bug example. </p> Ticket edwin.carlinet@… Tue, 11 Mar 2014 18:07:44 GMT <link>https://svn.boost.org/trac10/ticket/9770#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9770#comment:1</guid> <description> <p> The fix I proposed a few hours ago is just as wrong as the original code. The problem is still related to the source edge but not in the way I thought: the source edge inserted in the stack is not the right one. </p> <p> Hope that this really fix the problem. </p> <pre class="wiki">@@ -25,6 +25,7 @@ #include &lt;boost/parameter.hpp&gt; #include &lt;boost/concept/assert.hpp&gt; #include &lt;boost/tti/has_member_function.hpp&gt; +#include &lt;boost/utility.hpp&gt; #include &lt;vector&gt; #include &lt;utility&gt; @@ -143,8 +144,8 @@ ColorValue v_color = get(color, v); if (v_color == Color::white()) { vis.tree_edge(*ei, g); + stack.push_back(std::make_pair(u, std::make_pair(src_e, std::make_pair(boost::next(ei), ei_end)))); src_e = *ei; - stack.push_back(std::make_pair(u, std::make_pair(src_e, std::make_pair(++ei, ei_end)))); u = v; put(color, u, Color::gray()); vis.discover_vertex(u, g); </pre><p> The outputs of the test code attached below makes more sense: </p> <pre class="wiki">Finish vertex: 3 Finish edge: (1,3) Finish vertex: 1 Finish edge: (0,1) Finish edge: (2,3) Finish vertex: 2 Finish edge: (0,2) Finish vertex: 0 </pre><p> </p> </description> <category>Ticket</category> </item> </channel> </rss>