SparseRow class
#include <gtopt/sparse_row.hpp>
Represents a constraint row in a linear program with sparse coefficients.
This class provides a sparse representation of a linear constraint row, storing only non-zero coefficients. It supports various constraint types through fluent interface methods and can convert to dense or flat representations.
Public types
Public static variables
- static double DblMax
- Maximum representable double, same as gtopt::DblMax.
Public functions
- auto bound(double lb, double ub) -> SparseRow& noexcept
- auto equal(double rhs = 0) -> SparseRow& noexcept
- auto get_coeff(ColIndex key) const -> double noexcept
- auto greater_equal(double lb) -> SparseRow& noexcept
- auto less_equal(double ub) -> SparseRow& noexcept
-
template<typename Self>auto operator[](this Self&& self, ColIndex key) -> decltype(auto)
-
void reserve(size_
type n) - auto set_coeff(ColIndex c, double e) -> SparseRow&
-
auto size() const -> size_
type noexcept -
template<typename Int Int = size_t, typename Dbl = double, typename KVec = std::vector<Int>, typename VVec = std::vector<Dbl>>auto to_flat(double eps = 0.0) const -> std::pair<KVec, VVec>
Public variables
- std::string_view class_name
- Class name (e.g. "Bus", "Reservoir").
-
cmap_
t cmap - Sparse coefficient map (physical values).
- std::string_view constraint_name
- Constraint type (e.g. "bal", "cap", "kvl").
- LpContext context
- LP hierarchy context (scenario, stage, block, ...).
- ConstraintScaleType cost_scale_type
- double dual_hint
- double lowb
- Physical lower bound (default: 0).
- bool pin_scale
- ColIndex pivot_col
- double post_scale
- double scale
- double uppb
- Physical upper bound (default: 0).
- Uid variable_uid
- Element UID.
Function documentation
SparseRow& gtopt:: SparseRow:: greater_equal(double lb) noexcept
| Parameters | |
|---|---|
| lb | Lower bound value |
| Returns | Reference to this row for method chaining |
Sets a lower bound (>= constraint)
SparseRow& gtopt:: SparseRow:: less_equal(double ub) noexcept
| Parameters | |
|---|---|
| ub | Upper bound value |
| Returns | Reference to this row for method chaining |
Sets an upper bound (<= constraint)
template<typename Self>
decltype(auto) gtopt:: SparseRow:: operator[](this Self&& self,
ColIndex key)
| Parameters | |
|---|---|
| self | Deduced row object (enables const/non-const overload). |
| key | Column index |
| Returns | Reference to coefficient value (or value for const) |
Gets or sets a coefficient (non-const version)
template<typename Int Int = size_t, typename Dbl = double, typename KVec = std::vector<Int>, typename VVec = std::vector<Dbl>>
std::pair<KVec, VVec> gtopt:: SparseRow:: to_flat(double eps = 0.0) const
| Parameters | |
|---|---|
| eps | Epsilon for zero comparison (values < eps are treated as 0) |
| Returns | Pair of vectors containing indices and values |
Converts to flat representation for solver interfaces
Variable documentation
ConstraintScaleType gtopt:: SparseRow:: cost_scale_type
Time-basis of this row's dual, used to choose the inverse factor family when the LP dual is read back to physical units in OutputContext.
Power→ readback ÷ (prob·disc·duration) (DEFAULT — per-block power-balance LMP $/MWh, current behaviour).Energy→ readback ÷ (prob·disc) (STOCK / commodity dual: storage energy-balance water value $/CMD, fuel offtake $/fuel-unit, emission cap $/tonne — duration-INdependent).Raw→ readback ÷ 1 (face-value, no prob/disc/duration descale). SeeSparseCol::cost_scale_typefor the full rationale.
double gtopt:: SparseRow:: dual_hint
Expected magnitude of this row's dual in "folded physical" units (prob*disc-folded $ / row-unit, i.e. the dual of the row with scale = 1, scale_objective = 1, no equilibration). 0 = unknown. When LpMatrixOptions::water_dual_target > 0 and post_scale == 1, flatten() picks c so the expected |y_LP| equals the target.
bool gtopt:: SparseRow:: pin_scale
Row-side counterpart of SparseCol::pin_scale: when true (and LpMatrixOptions::pin_logic_rows, default off, allows it) the row keeps row factor 1 in every equilibration pass — bulk row_max and Ruiz in LinearProblem::flatten, and the per-row normalisation of LinearInterface::add_row / add_rows. Column scales are still folded into its coefficients, and the row still enters the column norms of Ruiz. For pure commitment-logic rows (every nonzero on a pinned binary column, small integer coefficients, RHS 0 / 1 / N), which need no balancing.
ColIndex gtopt:: SparseRow:: pivot_col
Optional pivot column for cut-row equilibration. When set (!= unknown_index), LinearInterface::add_row will normalize step-3 row equilibration by elements[pivot_col] instead of by max-abs. Used for SDDP optimality / feasibility cuts to keep the α coefficient at 1.0 in LP-space — row-max would otherwise pick a state-link coefficient (often O(10⁵-10⁸) once col_scale is folded), driving α to O(10⁻⁹) and producing a basis-amplification factor ≈ 10⁹ on every binding cut. See build_benders_cut_* callers. Default unknown_index preserves legacy row-max behavior.
double gtopt:: SparseRow:: post_scale
Post-equilibration dual-conditioning factor c (default 1 = off). flatten() multiplies the already-equilibrated row (coefficients and bounds) by c and divides the stored row scale by c, so the LP dual becomes y_LP / c while the physical dual (dual_LP * scale_objective / row_scale) is unchanged. Unlike scale it is applied AFTER equilibration (row_max / ruiz would otherwise cancel it). Explicit values win over dual_hint.
double gtopt:: SparseRow:: scale
Row scale: LP = physical / scale (default: 1.0)