Boost C++ Libraries: Ticket #7387: marginal improvements to dijkstra_shortest_paths https://svn.boost.org/trac10/ticket/7387 <p> There are a couple of details in the dijkstra_shortest_path calculation that potentially make the implementation less efficient than strictly necessary. All considered the change in performance is marginal. But the code will be more to the point and I was happy to no longer use boost::closed_plus. </p> <ol><li>The tree_edge member function and the gray_target member function call the relax() function. In case of undirected graphs, this function attempts to relax both the target and the source of the edge. This is right for some algorithms (e.g. Bellman-Ford) but not for others (e.g. Dijkstra Shortest Paths). It would therefore be preferred to introduce a new function relax_target(), that only relaxes the target of an edge. </li></ol><ol start="2"><li>The defaults algorithm for summing weights and distances is boost::closed_plus&lt;T&gt;. This implements a simple plus operation with the extension that x + inf = inf, where inf is a special value set upon initialization. Note that this is not a generic guard against overflows, but only works if one of the inputs is equal to inf. If the new relax_target() is used, then it is no longer necessary to use boost::closed_plus and simple std::plus will suffice. (*) </li></ol><ol start="3"><li>The tree_edge member function of the dijkstra_bfs_visitor is called when a new vertex is found. The distance for this vertex must always reduce. Several checks in relax() or relax_target() are therefore not necessary, and it is recommended to add a function relax_target_confident().(*) </li></ol><ol start="4"><li>If the relax_target_confident function is used, then any comparison with distance_inf values is avoided. Strictly speaking it is not longer necessary to initialize the values of the distance map, and the precise value becomes irrelevant to the algorithm. </li></ol><ol start="5"><li>The update() function for the d-ary-heap does not need the old_distance therefore the gray_target member function does not need to call it. </li></ol><p> (*). There could possibly be one other reason to use boost::closed_plus and that is the case of edge_weights being equal to distance_inf. This could be a hackish way of excluding edges from the shortest path search and IMO does not need to be supported. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7387 Trac 1.4.3 Alex Hagen-Zanker <ahh34@…> Tue, 18 Sep 2012 12:27:54 GMT attachment set https://svn.boost.org/trac10/ticket/7387 https://svn.boost.org/trac10/ticket/7387 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">minor_improvements.patch</span> </li> </ul> <p> minor improvements </p> Ticket Luis G. Torres <lgtorres42@…> Mon, 15 Apr 2013 19:37:12 GMT <link>https://svn.boost.org/trac10/ticket/7387#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7387#comment:1</guid> <description> <p> Is there any word on whether this will be included? This looks really useful (especially point 4, which would remove an entire argument from the dijkstra function and allows for some edge cost functions where distance_inf is hard to define). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 24 Sep 2013 13:33:43 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7387#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7387#comment:2</guid> <description> <p> The documentation since 1.53 clarifies that edge weights are assumed to have a value smaller than distance_inf. So the possibility of edge weight == distance_inf is no longer an issue (hurray). </p> <p> www.boost.org/doc/libs/1_53_0/libs/graph/doc/dijkstra_shortest_paths.html </p> </description> <category>Ticket</category> </item> </channel> </rss>