NetOptim 1.2.8
Loading...
Searching...
No Matches
netoptim_detail::Ratio< Graph, Fn > Class Template Reference

Adapter: evaluates the scaling-ratio constraint for one edge. More...

#include <optscaling_oracle.hpp>

Public Types

using Vec = std::valarray<double>

Public Member Functions

 Ratio (const Graph &gra, Fn get_cost)
 Construct a new Ratio object.
 Ratio (const Ratio &)=default
 Copy constructor.
auto eval (const auto &edge, const Vec &x) const -> double
 Evaluate the constraint function for an edge.
auto make_weight_fn (const Vec &x) const
 Build a weight callable with the iterate bound once.
auto grad (const auto &edge, const Vec &x) const -> Vec
 Compute the gradient of the constraint function.

Detailed Description

template<typename Graph, typename Fn>
class netoptim_detail::Ratio< Graph, Fn >

Adapter: evaluates the scaling-ratio constraint for one edge.

Provides the eval / grad interface expected by NetworkOracle, adapting a cost function (edge -> (a_ij, a_ji)) to the constraint h_ij(x) = min(pi - a_ji, a_ij - psi) with x = (pi, psi) in log scale.

Template Parameters
GraphType of the directed graph representing matrix sparsity
FnType of the cost function (edge -> matrix entry pair)

Member Typedef Documentation

◆ Vec

template<typename Graph, typename Fn>
using netoptim_detail::Ratio< Graph, Fn >::Vec = std::valarray<double>

Constructor & Destructor Documentation

◆ Ratio() [1/2]

template<typename Graph, typename Fn>
netoptim_detail::Ratio< Graph, Fn >::Ratio ( const Graph & gra,
Fn get_cost )
inline

Construct a new Ratio object.

Parameters
[in]gragraph representing matrix sparsity pattern
[in]get_costfunction to extract matrix entry pairs

◆ Ratio() [2/2]

template<typename Graph, typename Fn>
netoptim_detail::Ratio< Graph, Fn >::Ratio ( const Ratio< Graph, Fn > & )
default

Copy constructor.

Member Function Documentation

◆ eval()

template<typename Graph, typename Fn>
auto netoptim_detail::Ratio< Graph, Fn >::eval ( const auto & edge,
const Vec & x ) const->double
inline

Evaluate the constraint function for an edge.

Computes min(pi - a_ji, a_ij - psi) where x = (pi, psi) in log scale. A positive result indicates the constraint is satisfied. The edge parameter is the graph's native edge data (e.g., the (a_ij, a_ji) cost pair from the adjacency structure).

Parameters
[in]edgethe matrix entry (edge) to evaluate
[in]xvector containing (pi, psi) in log scale
Returns
constraint value (positive if satisfied)

◆ grad()

template<typename Graph, typename Fn>
auto netoptim_detail::Ratio< Graph, Fn >::grad ( const auto & edge,
const Vec & x ) const->Vec
inline

Compute the gradient of the constraint function.

Returns a subgradient vector indicating which bound is active: [1.0, 0.0] if the upper bound (pi) is active, or [0.0, -1.0] if the lower bound (psi) is active.

Parameters
[in]edgethe matrix entry (edge) for gradient computation
[in]xvector containing (pi, psi) in log scale
Returns
gradient vector [d/d(pi), d/d(psi)]

◆ make_weight_fn()

template<typename Graph, typename Fn>
auto netoptim_detail::Ratio< Graph, Fn >::make_weight_fn ( const Vec & x) const
inline

Build a weight callable with the iterate bound once.

Optional fast path consumed by NetworkOracle (see netoptim_detail::make_get_weight): binds x[0] / x[1] and the cost function a single time, so the per-edge hot loop avoids re-indexing the iterate for every edge.

Parameters
[in]xvector containing (pi, psi) in log scale
Returns
callable (edge) -> double evaluating the ratio constraint

The documentation for this class was generated from the following file: