gtopt::SparseRow class

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

using cmap_t = flat_map<ColIndex, double>
Type for coefficient storage.
using size_type = cmap_t::size_type

Public static variables

static constexpr double DblMax
Maximum representable double, same as gtopt::DblMax.

Public functions

auto bound(double lb, double ub) -> constexpr SparseRow& noexcept
auto equal(double rhs = 0) -> constexpr SparseRow& noexcept
auto get_coeff(ColIndex key) const -> double noexcept
auto greater_equal(double lb) -> constexpr SparseRow& noexcept
auto less_equal(double ub) -> constexpr SparseRow& noexcept
template<typename Self Self>
auto operator[](this Self&& self, ColIndex key) -> constexpr decltype(auto)
auto reserve(size_type n) -> void
auto set_coeff(ColIndex c, double e) -> constexpr SparseRow&
auto size() const -> constexpr size_type noexcept
template<typename Int Int = size_t, typename Dbl Dbl = double, typename KVec KVec = std::vector<Int>, typename VVec VVec = std::vector<Dbl>>
auto to_flat(double eps = 0.0) const -> std::pair< KVec, VVec > -> constexpr auto

Public variables

cmap_t cmap
Sparse coefficient map.
double lowb
Lower bound (default: 0)
std::string name
Row/constraint name.
double uppb
Upper bound (default: 0)

Function documentation

constexpr SparseRow& gtopt::SparseRow::bound(double lb, double ub) noexcept

Parameters
lb Lower bound value
ub Upper bound value
Returns Reference to this row for method chaining

Sets both lower and upper bounds for the constraint

constexpr SparseRow& gtopt::SparseRow::equal(double rhs = 0) noexcept

Parameters
rhs Right-hand side value (default: 0)
Returns Reference to this row for method chaining

Sets an equality constraint (=)

double gtopt::SparseRow::get_coeff(ColIndex key) const noexcept

Parameters
key Column index
Returns Coefficient value (0 if not found)bl

Gets a coefficient value

constexpr 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)

constexpr 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 Self>
constexpr 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)

void gtopt::SparseRow::reserve(size_type n)

Parameters
n Number of coefficients to reserve space for

Reserves space for coefficients

constexpr SparseRow& gtopt::SparseRow::set_coeff(ColIndex c, double e)

Parameters
c Column index
e Coefficient value
Returns Reference to this row for method chaining

Sets a coefficient value

constexpr size_type gtopt::SparseRow::size() const noexcept

Returns Number of non-zero coefficients

Gets the number of non-zero coefficients

template<typename Int Int = size_t, typename Dbl Dbl = double, typename KVec KVec = std::vector<Int>, typename VVec VVec = std::vector<Dbl>>
constexpr auto gtopt::SparseRow::to_flat(double eps = 0.0) const -> std::pair< KVec, VVec >

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