howard_cycle_ratio.hpp 22 KB

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