81template <
typename Graph,
typename T,
typename Fn1,
typename Fn2,
typename Mapping>
82auto min_cycle_ratio(
const Graph& gra, T& r0, Fn1&& get_cost, Fn2&& get_time, Mapping&& dist,
83 size_t max_iters = 1000) {
87 auto calc_ratio = [&](
const auto& C) -> T {
88 using cost_T =
decltype(get_cost(std::declval<edge_t>()));
89 using time_T =
decltype(get_time(std::declval<edge_t>()));
90 auto total_cost = cost_T(0);
91 auto total_time = time_T(0);
92 for (
auto&& edge : C) {
93 total_cost += get_cost(edge);
94 total_time += get_time(edge);
96 if (total_time == time_T(0)) {
97 throw std::domain_error(
"min_cycle_ratio: cycle has zero total time");
99 return T(total_cost) / T(total_time);
102 auto calc_weight = [&](
const T& r,
const edge_t& edge) -> T {
103 return get_cost(edge) - r * T(get_time(edge));
106 return max_parametric(gra, r0, std::move(calc_weight), std::move(calc_ratio),
107 std::forward<Mapping>(dist), max_iters);
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:82
Internal implementation helpers shared by the netoptim algorithms.
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:74
std::remove_cv_t< std::remove_reference_t< decltype(_get_val( std::declval< NbrElem >(), std::declval< const Nbrs & >()))> > Edge
Definition netoptim_detail.hpp:36