4#include <digraphx/neg_cycle.hpp>
51template <
typename Graph,
typename Mapping,
typename Fn>
54 using node_t =
typename Graph::key_type;
59 NegCycleFinder<Graph> _S;
68 : _gra{gra}, _u{utx}, _S(gra), _h{std::move(h)} {}
78 template <
typename Num>
auto update(
const Num& gamma) ->
void { this->_h.update(gamma); }
118 template <
typename Arr>
119 auto assess_feas(
const Arr& xval) -> std::optional<std::pair<Arr, double>> {
121 "NetworkOracle must model the feasibility-oracle contract");
126 auto best = std::optional<std::pair<Arr, double>>{};
127 auto best_ratio = std::numeric_limits<double>::infinity();
128 for (
auto&& C : this->_S.howard(this->_u, get_weight)) {
132 auto weight_sum = 0.0;
133 for (
auto&& edge : C) {
134 weight_sum += get_weight(edge);
136 const auto ratio = weight_sum /
static_cast<double>(C.size());
137 if (ratio >= best_ratio) {
141 auto grad = [&]() -> Arr {
142 if constexpr (std::is_arithmetic_v<Arr>) {
145 return Arr(xval.size());
149 for (
auto&& edge : C) {
150 fval -= get_weight(edge);
151 grad -= this->_h.grad(edge, xval);
153 best = std::pair{std::move(grad), fval};
164 template <
typename Arr>
165 auto operator()(
const Arr& xvar) -> std::optional<std::pair<Arr, double>> {
auto assess_feas(const Arr &xval) -> std::optional< std::pair< Arr, double > >
Assess feasibility and generate cutting plane if needed.
Definition network_oracle.hpp:119
NetworkOracle(const NetworkOracle &)=default
Copy constructor.
auto operator()(const Arr &xvar) -> std::optional< std::pair< Arr, double > >
Function call operator for cutting plane methods.
Definition network_oracle.hpp:165
auto update(const Num &gamma) -> void
Update the oracle with a new parameter value.
Definition network_oracle.hpp:78
NetworkOracle(const Graph &gra, Mapping &utx, Fn h)
Construct a new network oracle object.
Definition network_oracle.hpp:67
Definition netoptim_detail.hpp:23
Feasibility oracle: assess x and produce a cutting plane if infeasible.
Definition netoptim_detail.hpp:100
auto make_get_weight(Fn &fn, const Arr &xval)
Build the per-edge weight callable used by Howard's method.
Definition netoptim_detail.hpp:145
Internal implementation helpers shared by the netoptim algorithms.
std::remove_cv_t< std::remove_reference_t< decltype(_get_val( std::declval< NbrElem >(), std::declval< const Nbrs & >()))> > Edge
Definition netoptim_detail.hpp:36