NetOptim 1.2.6
Loading...
Searching...
No Matches
min_cycle_ratio.hpp
Go to the documentation of this file.
1// -*- coding: utf-8 -*-
2#pragma once
3
4#include <algorithm>
5#include <py2cpp/py2cpp.hpp>
6
7#include "parametric.hpp" // import max_parametric
8
79template <typename Graph, typename T, typename Fn1, typename Fn2, typename Mapping>
80auto min_cycle_ratio(const Graph& gra, T& r0, Fn1&& get_cost, Fn2&& get_time, Mapping&& dist,
81 size_t max_iters = 1000) {
82 // ponytail: deduce Edge type using the same helpers as NegCycleFinder
83 using Elem = decltype(*std::declval<const Graph&>().begin());
84 using Nbrs = std::remove_cv_t<std::remove_reference_t<decltype(_get_val(
85 std::declval<Elem>(), std::declval<const Graph&>()))>>;
86 using NbrElem = decltype(*std::declval<const Nbrs&>().begin());
87 using Edge = std::remove_cv_t<std::remove_reference_t<decltype(_get_val(
88 std::declval<NbrElem>(), std::declval<const Nbrs&>()))>>;
89 using edge_t = Edge;
90
91 auto calc_ratio = [&](const auto& C) -> T {
92 using cost_T = decltype(get_cost(std::declval<edge_t>()));
93 using time_T = decltype(get_time(std::declval<edge_t>()));
94 auto total_cost = cost_T(0);
95 auto total_time = time_T(0);
96 for (auto&& edge : C) {
97 total_cost += get_cost(edge);
98 total_time += get_time(edge);
99 }
100 return T(total_cost) / total_time;
101 };
102
103 auto calc_weight = [&](const T& r, const edge_t& edge) -> T {
104 return get_cost(edge) - r * T(get_time(edge));
105 };
106
107 return max_parametric(gra, r0, std::move(calc_weight), std::move(calc_ratio),
108 std::forward<Mapping>(dist), max_iters);
109}
auto min_cycle_ratio(const Graph &gra, T &r0, Fn1 &&get_cost, Fn2 &&get_time, Mapping &&dist, size_t max_iters=1000)
Solve the minimum cost-to-time cycle ratio problem.
Definition min_cycle_ratio.hpp:80
Maximum parametric problem solver for network optimization.
auto max_parametric(const Graph &gra, T &r_opt, Fn1 &&distrance, Fn2 &&zero_cancel, Mapping &&dist, size_t max_iters=1000)
Solve the maximum parametric problem.
Definition parametric.hpp:71
typename boost::graph_traits< graph_t >::edge_iterator edge_t
Type alias for edge iterator.
Definition test_cases2_boost.hpp:39