most_likely_paths.hpp

Go to the documentation of this file.
00001 /*
00002  * $Id: most_likely_paths.hpp,v 1.3 2007/10/18 02:24:24 brook Exp $
00003  */
00004 
00005 /*
00006  * Copyright (c) 2007 Brook Milligan.
00007  * Distributed under the Boost Software License, Version 1.0. (See
00008  * accompanying file LICENSE_1_0.txt or copy at
00009  * http://www.boost.org/LICENSE_1_0.txt)
00010  */
00011 
00017 #ifndef BOOST_MOST_LIKELY_PATHS_HPP
00018 #define BOOST_MOST_LIKELY_PATHS_HPP
00019 
00020 #include <boost/probability.hpp>
00021 #include <boost/graph/dag_shortest_paths.hpp>
00022 
00023 namespace boost
00024 {
00025 
00026   namespace probabilities
00027   {
00028 
00029     namespace detail
00030     {
00031 
00032       template <typename T, typename U>
00033       struct mpy
00034       {
00035         T operator () (const T& a, const U& b) const { return a * b; }
00036       };
00037 
00038     } // namespace detail
00039 
00041     template <typename VertexListGraph, typename WeightMap,
00042               typename DistanceMap, typename PredecessorMap, typename ColorMap,
00043               typename IndexMap>
00044     inline void
00045     most_likely_paths
00046     (const VertexListGraph& g,
00047      typename graph_traits<VertexListGraph>::vertex_descriptor s,
00048      WeightMap weight, DistanceMap distance, PredecessorMap pred,
00049      ColorMap color, IndexMap id)
00050     {
00051       // XXX - assert that the graph is directed...
00052 
00053       typedef typename boost::property_traits<DistanceMap>::value_type
00054         distance_type;
00055       typedef typename boost::property_traits<WeightMap>::value_type
00056         weight_type;
00057 
00058       typedef std::greater<distance_type> compare_type;
00059       typedef detail::mpy<distance_type,weight_type> combine_type;
00060 
00061       distance_type identity
00062         (probability<linear_domain,typename distance_type::value_type>(1));
00063       distance_type infinity
00064         (probability<linear_domain,typename distance_type::value_type>(0));
00065 
00066       boost::dag_shortest_paths
00067         (g, s, weight_map(weight).distance_map(distance)
00068          .predecessor_map(pred).color_map(color)
00069          .distance_compare(compare_type()).distance_combine(combine_type())
00070          .distance_zero(identity).distance_inf(infinity).vertex_index_map(id)
00071          );
00072     }
00073 
00074     namespace detail
00075     {
00076 
00077       template <typename VertexListGraph,
00078                 typename WeightMap, typename DistanceMap, typename IndexMap,
00079                 typename Param, typename Tag, typename Rest>
00080       inline void
00081       dispatch
00082       (const VertexListGraph& g,
00083        typename graph_traits<VertexListGraph>::vertex_descriptor s,
00084        WeightMap weight, DistanceMap distance, IndexMap id,
00085        const bgl_named_params<Param,Tag,Rest>& params)
00086       {
00087         typedef typename property_traits<WeightMap>::value_type T;
00088         typename std::vector<T>::size_type n;
00089         n = is_default_param(distance) ? num_vertices(g) : 1;
00090         std::vector<T> distance_map(n);
00091 
00092         most_likely_paths
00093           (g, s,
00094            choose_const_pmap(get_param(params, edge_weight), g, edge_weight),
00095            choose_param(distance, make_iterator_property_map
00096                         (distance_map.begin(), id, distance_map[0])),
00097            get_param(params, vertex_predecessor),
00098            get_param(params, vertex_color),
00099            id
00100            );
00101       }
00102 
00103     } // namespace detail
00104 
00194     template <typename VertexListGraph,
00195               typename Param, typename Tag, typename Rest>
00196     inline void
00197     most_likely_paths
00198     (const VertexListGraph& g,
00199      typename graph_traits<VertexListGraph>::vertex_descriptor s,
00200      const bgl_named_params<Param,Tag,Rest>& params)
00201     {
00202       detail::dispatch
00203         (g, s,
00204          choose_const_pmap(get_param(params, edge_weight), g, edge_weight),
00205          get_param(params, vertex_distance),
00206          choose_const_pmap(get_param(params, vertex_index), g, vertex_index),
00207          params);
00208     }
00209 
00210   } // namespace probabilities
00211 
00212 } // namespace boost
00213 
00214 #endif

Generated on Thu Oct 18 11:10:28 2007 for Boost.Probability: C++ Probability and Likelihood Library by  doxygen 1.4.5