NetOptim 1.2.6
Loading...
Searching...
No Matches
parametric.hpp
Go to the documentation of this file.
1// -*- coding: utf-8 -*-
2#pragma once
3
4#include <digraphx/neg_cycle.hpp> // import NegCycleFinder
5#include <type_traits>
6#include <vector>
7
70template <typename Graph, typename T, typename Fn1, typename Fn2, typename Mapping>
71auto max_parametric(const Graph& gra, T& r_opt, Fn1&& distrance, Fn2&& zero_cancel, Mapping&& dist,
72 size_t max_iters = 1000) {
73 // ponytail: deduce Edge type using the same helpers as NegCycleFinder
74 using Elem = decltype(*std::declval<const Graph&>().begin());
75 using Nbrs = std::remove_cv_t<std::remove_reference_t<decltype(_get_val(
76 std::declval<Elem>(), std::declval<const Graph&>()))>>;
77 using NbrElem = decltype(*std::declval<const Nbrs&>().begin());
78 using Edge = std::remove_cv_t<std::remove_reference_t<decltype(_get_val(
79 std::declval<NbrElem>(), std::declval<const Nbrs&>()))>>;
80 using Cycle = std::vector<Edge>;
81
82 auto get_weight = [&distrance, &r_opt](const Edge& edge) -> T {
83 return static_cast<T>(distrance(r_opt, edge));
84 };
85
86 auto ncf = NegCycleFinder<Graph>(gra);
87 auto r_min = r_opt;
88 auto c_min = Cycle{};
89 auto c_opt = Cycle{};
90
91 for (auto niter = 0U; niter != max_iters; ++niter) {
92 for (auto&& ci : ncf.howard(dist, get_weight)) {
93 auto ri = static_cast<T>(zero_cancel(ci));
94 if (r_min > ri) {
95 r_min = ri;
96 c_min = std::move(ci);
97 }
98 }
99 if (r_min >= r_opt) break;
100 c_opt = std::move(c_min);
101 r_opt = r_min;
102 }
103 return c_opt;
104}
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