• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2006-2009 Dmitry Bufistov and Andrey Parfenov
2 
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 #ifndef BOOST_GRAPH_CYCLE_RATIO_HOWARD_HPP
8 #define BOOST_GRAPH_CYCLE_RATIO_HOWARD_HPP
9 
10 #include <vector>
11 #include <list>
12 #include <algorithm>
13 #include <limits>
14 
15 #include <boost/bind.hpp>
16 #include <boost/type_traits/is_same.hpp>
17 #include <boost/type_traits/remove_const.hpp>
18 #include <boost/concept_check.hpp>
19 #include <boost/pending/queue.hpp>
20 #include <boost/property_map/property_map.hpp>
21 #include <boost/graph/graph_traits.hpp>
22 #include <boost/graph/graph_concepts.hpp>
23 #include <boost/concept/assert.hpp>
24 
25 /** @file howard_cycle_ratio.hpp
26  * @brief The implementation of the maximum/minimum cycle ratio/mean algorithm.
27  * @author Dmitry Bufistov
28  * @author Andrey Parfenov
29  */
30 
31 namespace boost
32 {
33 
34 /**
35  * The mcr_float is like numeric_limits, but only for floating point types
36  * and only defines infinity() and epsilon(). This class is primarily used
37  * to encapsulate a less-precise epsilon than natively supported by the
38  * floating point type.
39  */
40 template < typename Float = double > struct mcr_float
41 {
42     typedef Float value_type;
43 
infinityboost::mcr_float44     static Float infinity()
45     {
46         return std::numeric_limits< value_type >::infinity();
47     }
48 
epsilonboost::mcr_float49     static Float epsilon() { return Float(-0.005); }
50 };
51 
52 namespace detail
53 {
54 
55     template < typename FloatTraits > struct min_comparator_props
56     {
57         typedef std::greater< typename FloatTraits::value_type > comparator;
58         static const int multiplier = 1;
59     };
60 
61     template < typename FloatTraits > struct max_comparator_props
62     {
63         typedef std::less< typename FloatTraits::value_type > comparator;
64         static const int multiplier = -1;
65     };
66 
67     template < typename FloatTraits, typename ComparatorProps >
68     struct float_wrapper
69     {
70         typedef typename FloatTraits::value_type value_type;
71         typedef ComparatorProps comparator_props_t;
72         typedef typename ComparatorProps::comparator comparator;
73 
infinityboost::detail::float_wrapper74         static value_type infinity()
75         {
76             return FloatTraits::infinity() * ComparatorProps::multiplier;
77         }
78 
epsilonboost::detail::float_wrapper79         static value_type epsilon()
80         {
81             return FloatTraits::epsilon() * ComparatorProps::multiplier;
82         }
83     };
84 
85     /*! @class mcr_howard
86      * @brief Calculates optimum (maximum/minimum) cycle ratio of a directed
87      * graph. Uses  Howard's iteration policy algorithm. </br>(It is described
88      * in the paper "Experimental Analysis of the Fastest Optimum Cycle Ratio
89      * and Mean Algorithm" by Ali Dasdan).
90      */
91     template < typename FloatTraits, typename Graph, typename VertexIndexMap,
92         typename EdgeWeight1, typename EdgeWeight2 >
93     class mcr_howard
94     {
95     public:
96         typedef typename FloatTraits::value_type float_t;
97         typedef typename FloatTraits::comparator_props_t cmp_props_t;
98         typedef typename FloatTraits::comparator comparator_t;
99         typedef enum
100         {
101             my_white = 0,
102             my_black
103         } my_color_type;
104         typedef typename graph_traits< Graph >::vertex_descriptor vertex_t;
105         typedef typename graph_traits< Graph >::edge_descriptor edge_t;
106         typedef typename graph_traits< Graph >::vertices_size_type vn_t;
107         typedef std::vector< float_t > vp_t;
108         typedef typename boost::iterator_property_map< typename vp_t::iterator,
109             VertexIndexMap >
110             distance_map_t; // V -> float_t
111 
112         typedef typename std::vector< edge_t > ve_t;
113         typedef std::vector< my_color_type > vcol_t;
114         typedef
115             typename ::boost::iterator_property_map< typename ve_t::iterator,
116                 VertexIndexMap >
117                 policy_t; // Vertex -> Edge
118         typedef
119             typename ::boost::iterator_property_map< typename vcol_t::iterator,
120                 VertexIndexMap >
121                 color_map_t;
122 
123         typedef typename std::list< vertex_t >
124             pinel_t; // The in_edges list of the policy graph
125         typedef typename std::vector< pinel_t > inedges1_t;
126         typedef typename ::boost::iterator_property_map<
127             typename inedges1_t::iterator, VertexIndexMap >
128             inedges_t;
129         typedef typename std::vector< edge_t > critical_cycle_t;
130 
131         // Bad  vertex flag. If true, then the vertex is "bad".
132         // Vertex is "bad" if its out_degree is equal to zero.
133         typedef
134             typename boost::iterator_property_map< std::vector< int >::iterator,
135                 VertexIndexMap >
136                 badv_t;
137 
138         /*!
139          * Constructor
140          * \param g = (V, E) - a directed multigraph.
141          * \param vim  Vertex Index Map. Read property Map: V -> [0,
142          * num_vertices(g)). \param ewm  edge weight map. Read property map: E
143          * -> R \param ew2m  edge weight map. Read property map: E -> R+ \param
144          * infty A big enough value to guaranty that there exist a cycle with
145          *  better ratio.
146          * \param cmp The compare operator for float_ts.
147          */
mcr_howard(const Graph & g,VertexIndexMap vim,EdgeWeight1 ewm,EdgeWeight2 ew2m)148         mcr_howard(const Graph& g, VertexIndexMap vim, EdgeWeight1 ewm,
149             EdgeWeight2 ew2m)
150         : m_g(g)
151         , m_vim(vim)
152         , m_ew1m(ewm)
153         , m_ew2m(ew2m)
154         , m_bound(mcr_bound())
155         , m_cr(m_bound)
156         , m_V(num_vertices(m_g))
157         , m_dis(m_V, 0)
158         , m_dm(m_dis.begin(), m_vim)
159         , m_policyc(m_V)
160         , m_policy(m_policyc.begin(), m_vim)
161         , m_inelc(m_V)
162         , m_inel(m_inelc.begin(), m_vim)
163         , m_badvc(m_V, false)
164         , m_badv(m_badvc.begin(), m_vim)
165         , m_colcv(m_V)
166         , m_col_bfs(m_V)
167         {
168         }
169 
170         /*!
171          * \return maximum/minimum_{for all cycles C}
172          *         [sum_{e in C} w1(e)] / [sum_{e in C} w2(e)],
173          * or FloatTraits::infinity() if graph has no cycles.
174          */
ocr_howard()175         float_t ocr_howard()
176         {
177             construct_policy_graph();
178             int k = 0;
179             float_t mcr = 0;
180             do
181             {
182                 mcr = policy_mcr();
183                 ++k;
184             } while (
185                 try_improve_policy(mcr) && k < 100); // To avoid infinite loop
186 
187             const float_t eps_ = -0.00000001 * cmp_props_t::multiplier;
188             if (m_cmp(mcr, m_bound + eps_))
189             {
190                 return FloatTraits::infinity();
191             }
192             else
193             {
194                 return mcr;
195             }
196         }
~mcr_howard()197         virtual ~mcr_howard() {}
198 
199     protected:
store_critical_edge(edge_t,critical_cycle_t &)200         virtual void store_critical_edge(edge_t, critical_cycle_t&) {}
store_critical_cycle(critical_cycle_t &)201         virtual void store_critical_cycle(critical_cycle_t&) {}
202 
203     private:
204         /*!
205          * \return lower/upper bound for the maximal/minimal cycle ratio
206          */
mcr_bound()207         float_t mcr_bound()
208         {
209             typename graph_traits< Graph >::vertex_iterator vi, vie;
210             typename graph_traits< Graph >::out_edge_iterator oei, oeie;
211             float_t cz = (std::numeric_limits< float_t >::max)(); // Closest to
212                                                                   // zero value
213             float_t s = 0;
214             const float_t eps_ = std::numeric_limits< float_t >::epsilon();
215             for (boost::tie(vi, vie) = vertices(m_g); vi != vie; ++vi)
216             {
217                 for (boost::tie(oei, oeie) = out_edges(*vi, m_g); oei != oeie;
218                      ++oei)
219                 {
220                     s += std::abs(m_ew1m[*oei]);
221                     float_t a = std::abs(m_ew2m[*oei]);
222                     if (a > eps_ && a < cz)
223                     {
224                         cz = a;
225                     }
226                 }
227             }
228             return cmp_props_t::multiplier * (s / cz);
229         }
230 
231         /*!
232          *  Constructs an arbitrary policy graph.
233          */
construct_policy_graph()234         void construct_policy_graph()
235         {
236             m_sink = graph_traits< Graph >().null_vertex();
237             typename graph_traits< Graph >::vertex_iterator vi, vie;
238             typename graph_traits< Graph >::out_edge_iterator oei, oeie;
239             for (boost::tie(vi, vie) = vertices(m_g); vi != vie; ++vi)
240             {
241                 boost::tie(oei, oeie) = out_edges(*vi, m_g);
242                 typename graph_traits< Graph >::out_edge_iterator mei
243                     = std::max_element(oei, oeie,
244                         boost::bind(m_cmp,
245                             boost::bind(&EdgeWeight1::operator[], m_ew1m, _1),
246                             boost::bind(&EdgeWeight1::operator[], m_ew1m, _2)));
247                 if (mei == oeie)
248                 {
249                     if (m_sink == graph_traits< Graph >().null_vertex())
250                     {
251                         m_sink = *vi;
252                     }
253                     m_badv[*vi] = true;
254                     m_inel[m_sink].push_back(*vi);
255                 }
256                 else
257                 {
258                     m_inel[target(*mei, m_g)].push_back(*vi);
259                     m_policy[*vi] = *mei;
260                 }
261             }
262         }
263         /*! Sets the distance value for all vertices "v" such that there is
264          * a path from "v" to "sv". It does "inverse" breadth first visit of the
265          * policy graph, starting from the vertex "sv".
266          */
mcr_bfv(vertex_t sv,float_t cr,color_map_t c)267         void mcr_bfv(vertex_t sv, float_t cr, color_map_t c)
268         {
269             boost::queue< vertex_t > Q;
270             c[sv] = my_black;
271             Q.push(sv);
272             while (!Q.empty())
273             {
274                 vertex_t v = Q.top();
275                 Q.pop();
276                 for (typename pinel_t::const_iterator itr = m_inel[v].begin();
277                      itr != m_inel[v].end(); ++itr)
278                 // For all in_edges of the policy graph
279                 {
280                     if (*itr != sv)
281                     {
282                         if (m_badv[*itr])
283                         {
284                             m_dm[*itr] = m_dm[v] + m_bound - cr;
285                         }
286                         else
287                         {
288                             m_dm[*itr] = m_dm[v] + m_ew1m[m_policy[*itr]]
289                                 - m_ew2m[m_policy[*itr]] * cr;
290                         }
291                         c[*itr] = my_black;
292                         Q.push(*itr);
293                     }
294                 }
295             }
296         }
297 
298         /*!
299          * \param sv an arbitrary (undiscovered) vertex of the policy graph.
300          * \return a vertex in the policy graph that belongs to a cycle.
301          * Performs a depth first visit until a cycle edge is found.
302          */
find_cycle_vertex(vertex_t sv)303         vertex_t find_cycle_vertex(vertex_t sv)
304         {
305             vertex_t gv = sv;
306             std::fill(m_colcv.begin(), m_colcv.end(), my_white);
307             color_map_t cm(m_colcv.begin(), m_vim);
308             do
309             {
310                 cm[gv] = my_black;
311                 if (!m_badv[gv])
312                 {
313                     gv = target(m_policy[gv], m_g);
314                 }
315                 else
316                 {
317                     gv = m_sink;
318                 }
319             } while (cm[gv] != my_black);
320             return gv;
321         }
322 
323         /*!
324          * \param sv - vertex that belongs to a cycle in the policy graph.
325          */
cycle_ratio(vertex_t sv)326         float_t cycle_ratio(vertex_t sv)
327         {
328             if (sv == m_sink)
329                 return m_bound;
330             std::pair< float_t, float_t > sums_(float_t(0), float_t(0));
331             vertex_t v = sv;
332             critical_cycle_t cc;
333             do
334             {
335                 store_critical_edge(m_policy[v], cc);
336                 sums_.first += m_ew1m[m_policy[v]];
337                 sums_.second += m_ew2m[m_policy[v]];
338                 v = target(m_policy[v], m_g);
339             } while (v != sv);
340             float_t cr = sums_.first / sums_.second;
341             if (m_cmp(m_cr, cr))
342             {
343                 m_cr = cr;
344                 store_critical_cycle(cc);
345             }
346             return cr;
347         }
348 
349         /*!
350          *  Finds the optimal cycle ratio of the policy graph
351          */
policy_mcr()352         float_t policy_mcr()
353         {
354             std::fill(m_col_bfs.begin(), m_col_bfs.end(), my_white);
355             color_map_t vcm_ = color_map_t(m_col_bfs.begin(), m_vim);
356             typename graph_traits< Graph >::vertex_iterator uv_itr, vie;
357             boost::tie(uv_itr, vie) = vertices(m_g);
358             float_t mcr = m_bound;
359             while ((uv_itr = std::find_if(uv_itr, vie,
360                         boost::bind(std::equal_to< my_color_type >(), my_white,
361                             boost::bind(&color_map_t::operator[], vcm_, _1))))
362                 != vie)
363             /// While there are undiscovered vertices
364             {
365                 vertex_t gv = find_cycle_vertex(*uv_itr);
366                 float_t cr = cycle_ratio(gv);
367                 mcr_bfv(gv, cr, vcm_);
368                 if (m_cmp(mcr, cr))
369                     mcr = cr;
370                 ++uv_itr;
371             }
372             return mcr;
373         }
374 
375         /*!
376          * Changes the edge m_policy[s] to the new_edge.
377          */
improve_policy(vertex_t s,edge_t new_edge)378         void improve_policy(vertex_t s, edge_t new_edge)
379         {
380             vertex_t t = target(m_policy[s], m_g);
381             typename property_traits< VertexIndexMap >::value_type ti
382                 = m_vim[t];
383             m_inelc[ti].erase(
384                 std::find(m_inelc[ti].begin(), m_inelc[ti].end(), s));
385             m_policy[s] = new_edge;
386             t = target(new_edge, m_g);
387             m_inel[t].push_back(s); /// Maintain in_edge list
388         }
389 
390         /*!
391          * A negative cycle detector.
392          */
try_improve_policy(float_t cr)393         bool try_improve_policy(float_t cr)
394         {
395             bool improved = false;
396             typename graph_traits< Graph >::vertex_iterator vi, vie;
397             typename graph_traits< Graph >::out_edge_iterator oei, oeie;
398             const float_t eps_ = FloatTraits::epsilon();
399             for (boost::tie(vi, vie) = vertices(m_g); vi != vie; ++vi)
400             {
401                 if (!m_badv[*vi])
402                 {
403                     for (boost::tie(oei, oeie) = out_edges(*vi, m_g);
404                          oei != oeie; ++oei)
405                     {
406                         vertex_t t = target(*oei, m_g);
407                         // Current distance from *vi to some vertex
408                         float_t dis_
409                             = m_ew1m[*oei] - m_ew2m[*oei] * cr + m_dm[t];
410                         if (m_cmp(m_dm[*vi] + eps_, dis_))
411                         {
412                             improve_policy(*vi, *oei);
413                             m_dm[*vi] = dis_;
414                             improved = true;
415                         }
416                     }
417                 }
418                 else
419                 {
420                     float_t dis_ = m_bound - cr + m_dm[m_sink];
421                     if (m_cmp(m_dm[*vi] + eps_, dis_))
422                     {
423                         m_dm[*vi] = dis_;
424                     }
425                 }
426             }
427             return improved;
428         }
429 
430     private:
431         const Graph& m_g;
432         VertexIndexMap m_vim;
433         EdgeWeight1 m_ew1m;
434         EdgeWeight2 m_ew2m;
435         comparator_t m_cmp;
436         float_t m_bound; //> The lower/upper bound to the maximal/minimal cycle
437                          // ratio
438         float_t m_cr; //>The best cycle ratio that has been found so far
439 
440         vn_t m_V; //>The number of the vertices in the graph
441         vp_t m_dis; //>Container for the distance map
442         distance_map_t m_dm; //>Distance map
443 
444         ve_t m_policyc; //>Container for the policy graph
445         policy_t m_policy; //>The interface for the policy graph
446 
447         inedges1_t m_inelc; //>Container fot in edges list
448         inedges_t m_inel; //>Policy graph, input edges list
449 
450         std::vector< int > m_badvc;
451         badv_t m_badv; // Marks "bad" vertices
452 
453         vcol_t m_colcv, m_col_bfs; // Color maps
454         vertex_t m_sink; // To convert any graph to "good"
455     };
456 
457     /*! \class mcr_howard1
458      * \brief Finds optimum cycle raio and a critical cycle
459      */
460     template < typename FloatTraits, typename Graph, typename VertexIndexMap,
461         typename EdgeWeight1, typename EdgeWeight2 >
462     class mcr_howard1 : public mcr_howard< FloatTraits, Graph, VertexIndexMap,
463                             EdgeWeight1, EdgeWeight2 >
464     {
465     public:
466         typedef mcr_howard< FloatTraits, Graph, VertexIndexMap, EdgeWeight1,
467             EdgeWeight2 >
468             inhr_t;
mcr_howard1(const Graph & g,VertexIndexMap vim,EdgeWeight1 ewm,EdgeWeight2 ew2m)469         mcr_howard1(const Graph& g, VertexIndexMap vim, EdgeWeight1 ewm,
470             EdgeWeight2 ew2m)
471         : inhr_t(g, vim, ewm, ew2m)
472         {
473         }
474 
get_critical_cycle(typename inhr_t::critical_cycle_t & cc)475         void get_critical_cycle(typename inhr_t::critical_cycle_t& cc)
476         {
477             return cc.swap(m_cc);
478         }
479 
480     protected:
store_critical_edge(typename inhr_t::edge_t ed,typename inhr_t::critical_cycle_t & cc)481         void store_critical_edge(
482             typename inhr_t::edge_t ed, typename inhr_t::critical_cycle_t& cc)
483         {
484             cc.push_back(ed);
485         }
486 
store_critical_cycle(typename inhr_t::critical_cycle_t & cc)487         void store_critical_cycle(typename inhr_t::critical_cycle_t& cc)
488         {
489             m_cc.swap(cc);
490         }
491 
492     private:
493         typename inhr_t::critical_cycle_t m_cc; // Critical cycle
494     };
495 
496     /*!
497      * \param g a directed multigraph.
498      * \param vim Vertex Index Map. A map V->[0, num_vertices(g))
499      * \param ewm Edge weight1 map.
500      * \param ew2m Edge weight2 map.
501      * \param pcc  pointer to the critical edges list.
502      * \return Optimum cycle ratio of g or FloatTraits::infinity() if g has no
503      * cycles.
504      */
505     template < typename FT, typename TG, typename TVIM, typename TEW1,
506         typename TEW2, typename EV >
optimum_cycle_ratio(const TG & g,TVIM vim,TEW1 ewm,TEW2 ew2m,EV * pcc)507     typename FT::value_type optimum_cycle_ratio(
508         const TG& g, TVIM vim, TEW1 ewm, TEW2 ew2m, EV* pcc)
509     {
510         typedef typename graph_traits< TG >::directed_category DirCat;
511         BOOST_STATIC_ASSERT(
512             (is_convertible< DirCat*, directed_tag* >::value == true));
513         BOOST_CONCEPT_ASSERT((IncidenceGraphConcept< TG >));
514         BOOST_CONCEPT_ASSERT((VertexListGraphConcept< TG >));
515         typedef typename graph_traits< TG >::vertex_descriptor Vertex;
516         BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< TVIM, Vertex >));
517         typedef typename graph_traits< TG >::edge_descriptor Edge;
518         BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< TEW1, Edge >));
519         BOOST_CONCEPT_ASSERT((ReadablePropertyMapConcept< TEW2, Edge >));
520 
521         if (pcc == 0)
522         {
523             return detail::mcr_howard< FT, TG, TVIM, TEW1, TEW2 >(
524                 g, vim, ewm, ew2m)
525                 .ocr_howard();
526         }
527 
528         detail::mcr_howard1< FT, TG, TVIM, TEW1, TEW2 > obj(g, vim, ewm, ew2m);
529         double ocr = obj.ocr_howard();
530         obj.get_critical_cycle(*pcc);
531         return ocr;
532     }
533 } // namespace detail
534 
535 // Algorithms
536 // Maximum Cycle Ratio
537 
538 template < typename FloatTraits, typename Graph, typename VertexIndexMap,
539     typename EdgeWeight1Map, typename EdgeWeight2Map >
maximum_cycle_ratio(const Graph & g,VertexIndexMap vim,EdgeWeight1Map ew1m,EdgeWeight2Map ew2m,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0,FloatTraits=FloatTraits ())540 inline typename FloatTraits::value_type maximum_cycle_ratio(const Graph& g,
541     VertexIndexMap vim, EdgeWeight1Map ew1m, EdgeWeight2Map ew2m,
542     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0,
543     FloatTraits = FloatTraits())
544 {
545     typedef detail::float_wrapper< FloatTraits,
546         detail::max_comparator_props< FloatTraits > >
547         Traits;
548     return detail::optimum_cycle_ratio< Traits >(g, vim, ew1m, ew2m, pcc);
549 }
550 
551 template < typename Graph, typename VertexIndexMap, typename EdgeWeight1Map,
552     typename EdgeWeight2Map >
maximum_cycle_ratio(const Graph & g,VertexIndexMap vim,EdgeWeight1Map ew1m,EdgeWeight2Map ew2m,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0)553 inline double maximum_cycle_ratio(const Graph& g, VertexIndexMap vim,
554     EdgeWeight1Map ew1m, EdgeWeight2Map ew2m,
555     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0)
556 {
557     return maximum_cycle_ratio(g, vim, ew1m, ew2m, pcc, mcr_float<>());
558 }
559 
560 // Minimum Cycle Ratio
561 
562 template < typename FloatTraits, typename Graph, typename VertexIndexMap,
563     typename EdgeWeight1Map, typename EdgeWeight2Map >
minimum_cycle_ratio(const Graph & g,VertexIndexMap vim,EdgeWeight1Map ew1m,EdgeWeight2Map ew2m,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0,FloatTraits=FloatTraits ())564 typename FloatTraits::value_type minimum_cycle_ratio(const Graph& g,
565     VertexIndexMap vim, EdgeWeight1Map ew1m, EdgeWeight2Map ew2m,
566     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0,
567     FloatTraits = FloatTraits())
568 {
569     typedef detail::float_wrapper< FloatTraits,
570         detail::min_comparator_props< FloatTraits > >
571         Traits;
572     return detail::optimum_cycle_ratio< Traits >(g, vim, ew1m, ew2m, pcc);
573 }
574 
575 template < typename Graph, typename VertexIndexMap, typename EdgeWeight1Map,
576     typename EdgeWeight2Map >
minimum_cycle_ratio(const Graph & g,VertexIndexMap vim,EdgeWeight1Map ew1m,EdgeWeight2Map ew2m,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0)577 inline double minimum_cycle_ratio(const Graph& g, VertexIndexMap vim,
578     EdgeWeight1Map ew1m, EdgeWeight2Map ew2m,
579     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0)
580 {
581     return minimum_cycle_ratio(g, vim, ew1m, ew2m, pcc, mcr_float<>());
582 }
583 
584 // Maximum Cycle Mean
585 
586 template < typename FloatTraits, typename Graph, typename VertexIndexMap,
587     typename EdgeWeightMap, typename EdgeIndexMap >
maximum_cycle_mean(const Graph & g,VertexIndexMap vim,EdgeWeightMap ewm,EdgeIndexMap eim,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0,FloatTraits ft=FloatTraits ())588 inline typename FloatTraits::value_type maximum_cycle_mean(const Graph& g,
589     VertexIndexMap vim, EdgeWeightMap ewm, EdgeIndexMap eim,
590     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0,
591     FloatTraits ft = FloatTraits())
592 {
593     typedef typename remove_const<
594         typename property_traits< EdgeWeightMap >::value_type >::type Weight;
595     typename std::vector< Weight > ed_w2(boost::num_edges(g), 1);
596     return maximum_cycle_ratio(
597         g, vim, ewm, make_iterator_property_map(ed_w2.begin(), eim), pcc, ft);
598 }
599 
600 template < typename Graph, typename VertexIndexMap, typename EdgeWeightMap,
601     typename EdgeIndexMap >
maximum_cycle_mean(const Graph & g,VertexIndexMap vim,EdgeWeightMap ewm,EdgeIndexMap eim,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0)602 inline double maximum_cycle_mean(const Graph& g, VertexIndexMap vim,
603     EdgeWeightMap ewm, EdgeIndexMap eim,
604     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0)
605 {
606     return maximum_cycle_mean(g, vim, ewm, eim, pcc, mcr_float<>());
607 }
608 
609 // Minimum Cycle Mean
610 
611 template < typename FloatTraits, typename Graph, typename VertexIndexMap,
612     typename EdgeWeightMap, typename EdgeIndexMap >
minimum_cycle_mean(const Graph & g,VertexIndexMap vim,EdgeWeightMap ewm,EdgeIndexMap eim,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0,FloatTraits ft=FloatTraits ())613 inline typename FloatTraits::value_type minimum_cycle_mean(const Graph& g,
614     VertexIndexMap vim, EdgeWeightMap ewm, EdgeIndexMap eim,
615     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0,
616     FloatTraits ft = FloatTraits())
617 {
618     typedef typename remove_const<
619         typename property_traits< EdgeWeightMap >::value_type >::type Weight;
620     typename std::vector< Weight > ed_w2(boost::num_edges(g), 1);
621     return minimum_cycle_ratio(
622         g, vim, ewm, make_iterator_property_map(ed_w2.begin(), eim), pcc, ft);
623 }
624 
625 template < typename Graph, typename VertexIndexMap, typename EdgeWeightMap,
626     typename EdgeIndexMap >
minimum_cycle_mean(const Graph & g,VertexIndexMap vim,EdgeWeightMap ewm,EdgeIndexMap eim,std::vector<typename graph_traits<Graph>::edge_descriptor> * pcc=0)627 inline double minimum_cycle_mean(const Graph& g, VertexIndexMap vim,
628     EdgeWeightMap ewm, EdgeIndexMap eim,
629     std::vector< typename graph_traits< Graph >::edge_descriptor >* pcc = 0)
630 {
631     return minimum_cycle_mean(g, vim, ewm, eim, pcc, mcr_float<>());
632 }
633 
634 } // namespace boost
635 
636 #endif
637