42 template <
typename Graph,
typename Fn>
class Ratio {
44 using Vec = std::valarray<double>;
49 Ratio(
const Graph& gra, Fn get_cost) : _gra{gra}, _get_cost{std::move(get_cost)} {}
63 auto eval(
const auto& edge,
const Vec& x)
const ->
double {
65 throw std::invalid_argument(
"OptScalingOracle: x must have at least 2 entries");
67 const auto [aij, aji] = this->_get_cost(edge);
68 return std::min(x[0] - aji, aij - x[1]);
82 throw std::invalid_argument(
"OptScalingOracle: x must have at least 2 entries");
86 auto get_cost = this->_get_cost;
87 return [get_cost, x0, x1](
const auto& edge) ->
double {
88 const auto [aij, aji] = get_cost(edge);
89 return std::min(x0 - aji, aij - x1);
103 throw std::invalid_argument(
"OptScalingOracle: x must have at least 2 entries");
105 const auto [aij, aji] = this->_get_cost(edge);
106 return (x[0] - aji < aij - x[1]) ?
Vec{1., 0.} :
Vec{0., -1.};
133template <
typename Graph,
typename Mapping,
typename Fn>
136 using Vec = std::valarray<double>;
137 using node_t =
typename Graph::key_type;
138 using Cut = std::pair<Vec, double>;
149 : _network(gra, utx, Ratio{gra, get_cost}) {}
195 throw std::invalid_argument(
"OptScalingOracle: x must have at least 2 entries");
199 "OptScalingOracle must model the optimality-oracle contract");
202 return {*cut,
false};
204 auto s = x[0] - x[1];
208 return {{Vec{1., -1.}, 0.},
true};
210 return {{Vec{1., -1.}, fj},
false};
Oracle for Parametric Network Problems.
Definition network_oracle.hpp:53
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
OptScalingOracle & operator=(const OptScalingOracle &)=default
auto assess_optim(const Vec &x, double &t) -> std::tuple< Cut, bool >
Assess optimality at point x (cutting plane interface).
Definition optscaling_oracle.hpp:193
OptScalingOracle(OptScalingOracle &&)=default
OptScalingOracle & operator=(OptScalingOracle &&)=default
OptScalingOracle(const OptScalingOracle &)=default
Copy constructor.
OptScalingOracle(const Graph &gra, Mapping &utx, Fn get_cost)
Construct a new optscaling oracle object.
Definition optscaling_oracle.hpp:148
auto operator()(const Vec &x, double &t) -> std::tuple< Cut, bool >
Function call operator for cutting_plane_optim().
Definition optscaling_oracle.hpp:217
~OptScalingOracle()=default
Adapter: evaluates the scaling-ratio constraint for one edge.
Definition optscaling_oracle.hpp:42
auto make_weight_fn(const Vec &x) const
Build a weight callable with the iterate bound once.
Definition optscaling_oracle.hpp:80
auto eval(const auto &edge, const Vec &x) const -> double
Evaluate the constraint function for an edge.
Definition optscaling_oracle.hpp:63
auto grad(const auto &edge, const Vec &x) const -> Vec
Compute the gradient of the constraint function.
Definition optscaling_oracle.hpp:101
Ratio(const Graph &gra, Fn get_cost)
Construct a new Ratio object.
Definition optscaling_oracle.hpp:49
Ratio(const Ratio &)=default
Copy constructor.
std::valarray< double > Vec
Definition optscaling_oracle.hpp:44
Definition netoptim_detail.hpp:23
Optimality oracle: assess x against a best-so-far value g.
Definition netoptim_detail.hpp:112
Definition css_oracle.hpp:13
Internal implementation helpers shared by the netoptim algorithms.
Oracle for Parametric Network Problems.