howard_cycle_ratio.hpp 23 KB

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