epoc32/include/stdapis/boost/graph/prim_minimum_spanning_tree.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
//=======================================================================
williamr@2
     2
// Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
williamr@2
     3
// Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
williamr@2
     4
//
williamr@2
     5
// Distributed under the Boost Software License, Version 1.0. (See
williamr@2
     6
// accompanying file LICENSE_1_0.txt or copy at
williamr@2
     7
// http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     8
//=======================================================================
williamr@2
     9
//
williamr@2
    10
#ifndef BOOST_GRAPH_MST_PRIM_HPP
williamr@2
    11
#define BOOST_GRAPH_MST_PRIM_HPP
williamr@2
    12
williamr@2
    13
#include <functional>
williamr@2
    14
#include <boost/graph/graph_traits.hpp>
williamr@2
    15
#include <boost/graph/dijkstra_shortest_paths.hpp>
williamr@2
    16
williamr@2
    17
namespace boost {
williamr@2
    18
  
williamr@2
    19
  namespace detail {
williamr@2
    20
    // this should be somewhere else in boost...
williamr@2
    21
    template <class U, class V> struct _project2nd {
williamr@2
    22
      V operator()(U, V v) const { return v; }
williamr@2
    23
    };
williamr@2
    24
  }
williamr@2
    25
williamr@2
    26
  namespace detail {
williamr@2
    27
williamr@2
    28
    // This is Prim's algorithm to calculate the Minimum Spanning Tree
williamr@2
    29
    // for an undirected graph with weighted edges.
williamr@2
    30
williamr@2
    31
    template <class Graph, class P, class T, class R, class Weight>
williamr@2
    32
    inline void
williamr@2
    33
    prim_mst_impl(const Graph& G,
williamr@2
    34
                  typename graph_traits<Graph>::vertex_descriptor s,
williamr@2
    35
                  const bgl_named_params<P,T,R>& params,
williamr@2
    36
                  Weight)
williamr@2
    37
    {
williamr@2
    38
      typedef typename property_traits<Weight>::value_type W;
williamr@2
    39
      std::less<W> compare;
williamr@2
    40
      detail::_project2nd<W,W> combine;
williamr@2
    41
      dijkstra_shortest_paths(G, s, params.distance_compare(compare).
williamr@2
    42
                              distance_combine(combine));
williamr@2
    43
    }
williamr@2
    44
  } // namespace detail
williamr@2
    45
williamr@2
    46
  template <class VertexListGraph, class DijkstraVisitor, 
williamr@2
    47
            class PredecessorMap, class DistanceMap,
williamr@2
    48
            class WeightMap, class IndexMap>
williamr@2
    49
  inline void
williamr@2
    50
  prim_minimum_spanning_tree
williamr@2
    51
    (const VertexListGraph& g,
williamr@2
    52
     typename graph_traits<VertexListGraph>::vertex_descriptor s, 
williamr@2
    53
     PredecessorMap predecessor, DistanceMap distance, WeightMap weight, 
williamr@2
    54
     IndexMap index_map,
williamr@2
    55
     DijkstraVisitor vis)
williamr@2
    56
  {
williamr@2
    57
    typedef typename property_traits<WeightMap>::value_type W;
williamr@2
    58
    std::less<W> compare;
williamr@2
    59
    detail::_project2nd<W,W> combine;
williamr@2
    60
    dijkstra_shortest_paths(g, s, predecessor, distance, weight, index_map,
williamr@2
    61
                            compare, combine, (std::numeric_limits<W>::max)(), 0,
williamr@2
    62
                            vis);
williamr@2
    63
  }
williamr@2
    64
williamr@2
    65
  template <class VertexListGraph, class PredecessorMap,
williamr@2
    66
            class P, class T, class R>
williamr@2
    67
  inline void prim_minimum_spanning_tree
williamr@2
    68
    (const VertexListGraph& g,
williamr@2
    69
     PredecessorMap p_map,
williamr@2
    70
     const bgl_named_params<P,T,R>& params)
williamr@2
    71
  {
williamr@2
    72
    detail::prim_mst_impl
williamr@2
    73
      (g, 
williamr@2
    74
       choose_param(get_param(params, root_vertex_t()), *vertices(g).first), 
williamr@2
    75
       params.predecessor_map(p_map),
williamr@2
    76
       choose_const_pmap(get_param(params, edge_weight), g, edge_weight));
williamr@2
    77
  }
williamr@2
    78
williamr@2
    79
  template <class VertexListGraph, class PredecessorMap>
williamr@2
    80
  inline void prim_minimum_spanning_tree
williamr@2
    81
    (const VertexListGraph& g, PredecessorMap p_map)
williamr@2
    82
  {
williamr@2
    83
    detail::prim_mst_impl
williamr@2
    84
      (g, *vertices(g).first, predecessor_map(p_map).
williamr@2
    85
       weight_map(get(edge_weight, g)),
williamr@2
    86
       get(edge_weight, g));
williamr@2
    87
  }
williamr@2
    88
williamr@2
    89
} // namespace boost
williamr@2
    90
williamr@2
    91
#endif // BOOST_GRAPH_MST_PRIM_HPP