Ticket #7387: minor_improvements.patch

File minor_improvements.patch, 4.4 KB (added by Alex Hagen-Zanker <ahh34@…>, 10 years ago)

minor improvements

  • dijkstra_shortest_paths.hpp

     
    128128
    129129      template <class Edge, class Graph>
    130130      void tree_edge(Edge e, Graph& g) {
    131         bool decreased = relax(e, g, m_weight, m_predecessor, m_distance,
    132                                m_combine, m_compare);
    133         if (decreased)
    134           m_vis.edge_relaxed(e, g);
    135         else
    136           m_vis.edge_not_relaxed(e, g);
     131        relax_target_confident(e, g, m_weight, m_predecessor, m_distance
     132          , m_combine);
     133        m_vis.edge_relaxed(e, g);
    137134      }
     135     
    138136      template <class Edge, class Graph>
    139137      void gray_target(Edge e, Graph& g) {
     138
     139#ifdef BOOST_GRAPH_DIJKSTRA_USE_RELAXED_HEAP
    140140        D old_distance = get(m_distance, target(e, g));
     141#endif
     142#ifdef BOOST_GRAPH_DIJKSTRA_TESTING
     143        D old_distance = get(m_distance, target(e, g));
     144#endif
    141145
    142         bool decreased = relax(e, g, m_weight, m_predecessor, m_distance,
     146         bool decreased = relax_target(e, g, m_weight, m_predecessor, m_distance,
    143147                               m_combine, m_compare);
    144148        if (decreased) {
    145           dijkstra_queue_update(m_Q, target(e, g), old_distance);
     149
     150#ifdef BOOST_GRAPH_DIJKSTRA_USE_RELAXED_HEAP
     151        dijkstra_queue_update(m_Q, target(e, g), old_distance);
     152#endif
     153#ifdef BOOST_GRAPH_DIJKSTRA_TESTING
     154        dijkstra_queue_update(m_Q, target(e, g), old_distance);
     155#endif
     156          m_Q.update(target(e, g));
    146157          m_vis.edge_relaxed(e, g);
    147158        } else
    148159          m_vis.edge_not_relaxed(e, g);
     
    431442         choose_param(get_param(params, distance_compare_t()),
    432443                      std::less<D>()),
    433444         choose_param(get_param(params, distance_combine_t()),
    434                       closed_plus<D>(inf)),
     445                      std::plus<D>()),
    435446         inf,
    436447         choose_param(get_param(params, distance_zero_t()),
    437448                      D()),
  • relax.hpp

     
    3434       return a + b;
    3535      }
    3636    };
     37
     38    template <class Graph, class WeightMap,
     39      class PredecessorMap, class DistanceMap,
     40      class BinaryFunction, class BinaryPredicate>
     41    bool relax_target(const typename graph_traits<Graph>::edge_descriptor& e,
     42      const Graph& g, const WeightMap& w,
     43      PredecessorMap& p, DistanceMap& d,
     44      const BinaryFunction& combine, const BinaryPredicate& compare)
     45    {
     46      typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
     47      typedef typename property_traits<DistanceMap>::value_type D;
     48      typedef typename property_traits<WeightMap>::value_type W;
     49      const Vertex u = source(e, g);
     50      const Vertex v = target(e, g);
     51      const D& d_u = get(d, u);
     52      const D d_v = get(d, v);
     53      const W& w_e = get(w, e);
     54     
     55      // The redundant gets in the return statements are to ensure that extra
     56      // floating-point precision in x87 registers does not lead to relax_target()
     57      // returning true when the distance did not actually change.
     58      if ( compare(combine(d_u, w_e), d_v) ) {
     59        put(d, v, combine(d_u, w_e));
     60        if(compare(get(d, v), d_v) ) {
     61          put(p, v, u);
     62          return true;
     63        };
     64      }
     65      return false;
     66    }
     67
     68    template <class Graph, class WeightMap, class PredecessorMap, class DistanceMap,
     69      class BinaryFunction>
     70    void relax_target_confident(
     71      const typename graph_traits<Graph>::edge_descriptor& e,
     72      const Graph& g, const WeightMap& w, PredecessorMap& p, DistanceMap& d,
     73      const BinaryFunction& combine)
     74    {
     75      typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
     76      typedef typename property_traits<DistanceMap>::value_type D;
     77      typedef typename property_traits<WeightMap>::value_type W;
     78      const Vertex u = source(e, g);
     79      const Vertex v = target(e, g);
     80      const D& d_u = get(d, source(e, g));
     81      const W& w_e = get(w, e);
     82     
     83      put(d, v, combine(d_u, w_e));
     84      put(p, v, u);
     85    }
    3786   
    3887    template <class Graph, class WeightMap,
    3988            class PredecessorMap, class DistanceMap,