howard_cycle_ratio.hpp 22 KB

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