Boost-Geometry-Utils
view release on metacpan or search on metacpan
src/boost/graph/distributed/eager_dijkstra_shortest_paths.hpp view on Meta::CPAN
namespace boost { namespace graph { namespace distributed {
#ifdef PBGL_ACCOUNTING
struct eager_dijkstra_shortest_paths_stats_t
{
/* The value of the lookahead parameter. */
double lookahead;
/* Total wall-clock time used by the algorithm.*/
accounting::time_type execution_time;
/* The number of vertices deleted in each superstep. */
std::vector<std::size_t> deleted_vertices;
template<typename OutputStream>
void print(OutputStream& out)
{
double avg_deletions = std::accumulate(deleted_vertices.begin(),
deleted_vertices.end(),
0.0);
avg_deletions /= deleted_vertices.size();
out << "Problem = \"Single-Source Shortest Paths\"\n"
<< "Algorithm = \"Eager Dijkstra\"\n"
<< "Function = eager_dijkstra_shortest_paths\n"
<< "(P) Lookahead = " << lookahead << "\n"
<< "Wall clock time = " << accounting::print_time(execution_time)
<< "\nSupersteps = " << deleted_vertices.size() << "\n"
<< "Avg. deletions per superstep = " << avg_deletions << "\n";
}
};
static eager_dijkstra_shortest_paths_stats_t eager_dijkstra_shortest_paths_stats;
#endif
namespace detail {
// Borrowed from BGL's dijkstra_shortest_paths
template <class UniformCostVisitor, class Queue,
class WeightMap, class PredecessorMap, class DistanceMap,
class BinaryFunction, class BinaryPredicate>
struct parallel_dijkstra_bfs_visitor : bfs_visitor<>
{
typedef typename property_traits<DistanceMap>::value_type distance_type;
parallel_dijkstra_bfs_visitor(UniformCostVisitor vis, Queue& Q,
WeightMap w, PredecessorMap p, DistanceMap d,
BinaryFunction combine, BinaryPredicate compare,
distance_type zero)
: m_vis(vis), m_Q(Q), m_weight(w), m_predecessor(p), m_distance(d),
m_combine(combine), m_compare(compare), m_zero(zero) { }
template <class Vertex, class Graph>
void initialize_vertex(Vertex u, Graph& g)
{ m_vis.initialize_vertex(u, g); }
template <class Vertex, class Graph>
void discover_vertex(Vertex u, Graph& g) { m_vis.discover_vertex(u, g); }
template <class Vertex, class Graph>
void examine_vertex(Vertex u, Graph& g) { m_vis.examine_vertex(u, g); }
/* Since the eager formulation of Parallel Dijkstra's algorithm can
loop, we may relax on *any* edge, not just those associated with
white and gray targets. */
template <class Edge, class Graph>
void examine_edge(Edge e, Graph& g) {
if (m_compare(get(m_weight, e), m_zero))
boost::throw_exception(negative_edge());
m_vis.examine_edge(e, g);
boost::parallel::caching_property_map<PredecessorMap> c_pred(m_predecessor);
boost::parallel::caching_property_map<DistanceMap> c_dist(m_distance);
distance_type old_distance = get(c_dist, target(e, g));
bool m_decreased = relax(e, g, m_weight, c_pred, c_dist,
m_combine, m_compare);
/* On x86 Linux with optimization, we sometimes get into a
horrible case where m_decreased is true but the distance hasn't
actually changed. This occurs when the comparison inside
relax() occurs with the 80-bit precision of the x87 floating
point unit, but the difference is lost when the resulting
values are written back to lower-precision memory (e.g., a
double). With the eager Dijkstra's implementation, this results
in looping. */
if (m_decreased && old_distance != get(c_dist, target(e, g))) {
m_Q.update(target(e, g));
m_vis.edge_relaxed(e, g);
} else
m_vis.edge_not_relaxed(e, g);
}
template <class Vertex, class Graph>
void finish_vertex(Vertex u, Graph& g) { m_vis.finish_vertex(u, g); }
UniformCostVisitor m_vis;
Queue& m_Q;
WeightMap m_weight;
PredecessorMap m_predecessor;
DistanceMap m_distance;
BinaryFunction m_combine;
BinaryPredicate m_compare;
distance_type m_zero;
};
/**********************************************************************
* Dijkstra queue that implements arbitrary "lookahead" *
**********************************************************************/
template<typename Graph, typename Combine, typename Compare,
typename VertexIndexMap, typename DistanceMap,
typename PredecessorMap>
class lookahead_dijkstra_queue
: public graph::detail::remote_update_set<
lookahead_dijkstra_queue<
Graph, Combine, Compare, VertexIndexMap, DistanceMap,
PredecessorMap>,
typename boost::graph::parallel::process_group_type<Graph>::type,
typename dijkstra_msg_value<DistanceMap, PredecessorMap>::type,
typename property_map<Graph, vertex_owner_t>::const_type>
{
typedef typename graph_traits<Graph>::vertex_descriptor
( run in 0.630 second using v1.01-cache-2.11-cpan-39bf76dae61 )