Boost C++ Libraries: Ticket #7341: Vector subscript out of range exception when calling weighted_core_numbers https://svn.boost.org/trac10/ticket/7341 <p> I get a vector subscript out of range exception when calling the weighted_core_numbers function in the boost graph library. The exception is actually thrown from within the mutable_queue::update function, but I can't tell if the error is in mutable_queue or in weighted_core_numbers. </p> <p> The attached test program is sufficient to show the problem. The test network is taken from Figure 1 of the Batagelj-Zaversnik paper (<a class="ext-link" href="http://vlado.fmf.uni-lj.si/pub/networks/doc/cores/cores.pdf"><span class="icon">​</span>http://vlado.fmf.uni-lj.si/pub/networks/doc/cores/cores.pdf</a>), with random integer weights of 1, 2, or 3 added to each edge. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7341 Trac 1.4.3 Ian Robertson <irober67@…> Thu, 06 Sep 2012 15:07:52 GMT attachment set https://svn.boost.org/trac10/ticket/7341 https://svn.boost.org/trac10/ticket/7341 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">weighted_core_numbers_bug.txt</span> </li> </ul> <p> Short self-contained test program </p> Ticket Jeremiah Willcock Thu, 06 Sep 2012 15:31:46 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7341#comment:1 https://svn.boost.org/trac10/ticket/7341#comment:1 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/80421" title="Changed core_numbers to use d_ary_heap and only update queue elements ...">[80421]</a>) Changed core_numbers to use d_ary_heap and only update queue elements that are in the queue; fixes <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/7341" title="#7341: Bugs: Vector subscript out of range exception when calling weighted_core_numbers (reopened)">#7341</a> </p> Ticket Jeremiah Willcock Thu, 06 Sep 2012 15:33:08 GMT <link>https://svn.boost.org/trac10/ticket/7341#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7341#comment:2</guid> <description> <p> Could you please check the version that I just committed? One thing that I changed was to only update elements in the heap when they were already there (i.e., not re-push elements that had been removed). Doing otherwise seemed to cause an infinite loop, but I don't know the algorithm well enough to tell if what I did was correct. </p> </description> <category>Ticket</category> </item> <item> <author>Ian Robertson <irober67@…></author> <pubDate>Mon, 10 Sep 2012 14:08:45 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/7341#comment:3 https://svn.boost.org/trac10/ticket/7341#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7341#comment:2" title="Comment 2">jewillco</a>: </p> <blockquote class="citation"> <p> Could you please check the version that I just committed? One thing that I changed was to only update elements in the heap when they were already there (i.e., not re-push elements that had been removed). Doing otherwise seemed to cause an infinite loop, but I don't know the algorithm well enough to tell if what I did was correct. </p> </blockquote> <p> Thank you for the fix - dropping the mutable_queue in favour of the d_ary_heap has fixed the subscript-out-of-range problem. Unfortunately this has now exposed a bug in the logic of the weighted cores algorithm itself. The core numbers coming back from the test network I submitted are not correct. </p> <p> I have taken a look at the code, and the problem seems to lie in the vertex priority adjustment in procedure <code>core_numbers_impl(Graph&amp; g, CoreMap c, EdgeWeightMap wm, MutableQueue&amp; Q, Visitor vis)</code>. The coded adjustment is incorrectly allowing the priority (core number) of vertices adjacent to the current vertex to fall below that of the current vertex itself. The correct adjustment formula is given in line 4.3.1 of Algorithm 3.2 on page 6 of the generalised cores paper by Batagelj and Zaversnik <a class="ext-link" href="http://vlado.fmf.uni-lj.si/pub/preprint/imfm0799.pdf"><span class="icon">​</span>http://vlado.fmf.uni-lj.si/pub/preprint/imfm0799.pdf</a>. </p> <p> I am enclosing a corrected version of the procedure, which fixes the problem. The required correction lies on the line immediately preceding the Q.update(u) call. The modified procedure also eliminates the redundant test for graph/queue membership, which is now tested explicitly and robustly through the Q.contains(u) call. </p> <pre class="wiki">// the version for weighted graphs is a little different template &lt;typename Graph, typename CoreMap, typename EdgeWeightMap, typename MutableQueue, typename Visitor&gt; typename property_traits&lt;CoreMap&gt;::value_type core_numbers_impl(Graph&amp; g, CoreMap c, EdgeWeightMap wm, MutableQueue&amp; Q, Visitor vis) { typename property_traits&lt;CoreMap&gt;::value_type v_cn = 0; typedef typename graph_traits&lt;Graph&gt;::vertex_descriptor vertex; while (!Q.empty()) { // remove v from the Q, and then adjust // the core numbers of its successors vertex v = Q.top(); vis.examine_vertex(v,g); Q.pop(); v_cn = get(c,v); typename graph_traits&lt;Graph&gt;::out_edge_iterator oi,oi_end; for (boost::tie(oi,oi_end) = out_edges(v,g); oi!=oi_end; ++oi) { vis.examine_edge(*oi,g); vertex u = target(*oi,g); // if the Q contains u, then u is still in the graph if (Q.contains(u)) { // remove the edge, and adjust the core-number for u put(c, u, std::max(v_cn, get(c, u) - get(wm, *oi))); Q.update(u); } } vis.finish_vertex(v,g); } return (v_cn); } </pre><p> I think this is a good fix, but if you would like more supporting material or test examples, I would be happy to provide them. </p> <p> Thank you. Ian Robertson </p> Ticket Jeremiah Willcock Mon, 10 Sep 2012 14:12:29 GMT <link>https://svn.boost.org/trac10/ticket/7341#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7341#comment:4</guid> <description> <p> Are you fine with releasing that code under the Boost license? Could you please attach a patch that makes the change that you want plus adds your name to the author list at the top of the file (if you think your changes are major enough for that)? Thank you. </p> </description> <category>Ticket</category> </item> </channel> </rss>