gtopt::LinearProblem class

Main class for building and manipulating linear planning problems.

This class provides functionality to construct a linear problem by adding variables (columns) and constraints (rows), setting coefficients, and converting to solver-ready formats.

Public types

using cols_t = std::vector<SparseCol>
using index_t = FlatLinearProblem::index_t
using rows_t = std::vector<SparseRow>
using SparseMatrix = std::vector<SparseVector>
using SparseVector = flat_map<ColIndex, double>

Public static variables

static constexpr double DblMax

Public functions

template<typename SparseCol SparseCol = gtopt::SparseCol>
auto add_col(SparseCol&& col) -> constexpr ColIndex
template<typename SparseRow SparseRow = gtopt::SparseRow>
auto add_row(SparseRow&& row) -> constexpr RowIndex
template<typename Self Self>
auto col_at(this Self&& self, ColIndex index) -> constexpr auto&&
auto flatten(const LpMatrixOptions& opts = {}) -> FlatLinearProblem
auto get_coeff(RowIndex row, ColIndex col) const -> constexpr double
auto get_col_lowb(ColIndex index) const -> constexpr auto
auto get_col_scale(ColIndex index) const -> constexpr auto
auto get_col_uppb(ColIndex index) const -> constexpr auto
auto get_numcols() const -> constexpr index_t
auto get_numrows() const -> constexpr index_t
auto infinity() const -> constexpr double noexcept
Current infinity value (DblMax if not explicitly set).
auto LinearProblem(std::string name = {}) -> constexpr explicit noexcept
auto reserve(size_t est_cols, size_t est_rows) -> constexpr void
template<typename Self Self>
auto row_at(this Self&& self, RowIndex index) -> constexpr auto&&
auto set_coeff(RowIndex row, ColIndex col, double coeff) -> constexpr void
auto set_infinity(double inf) -> constexpr void noexcept

Function documentation

template<typename SparseCol SparseCol = gtopt::SparseCol>
constexpr ColIndex gtopt::LinearProblem::add_col(SparseCol&& col)

Parameters
col Column (variable) definition
Returns Index of the added column

Adds a new variable to the problem

template<typename SparseRow SparseRow = gtopt::SparseRow>
constexpr RowIndex gtopt::LinearProblem::add_row(SparseRow&& row)

Parameters
row Row (constraint) definition
Returns Index of the added row

Adds a new constraint to the problem

template<typename Self Self>
constexpr auto&& gtopt::LinearProblem::col_at(this Self&& self, ColIndex index)

Parameters
self Deduced object reference
index Column index
Returns Reference to the column

Gets a reference to a column by index

FlatLinearProblem gtopt::LinearProblem::flatten(const LpMatrixOptions& opts = {})

Parameters
opts LP build options
Returns Flat representation of the problem

Builds the flat (column-major) LP representation

constexpr double gtopt::LinearProblem::get_coeff(RowIndex row, ColIndex col) const

Parameters
row Row index
col Column index
Returns Coefficient value

Gets a coefficient from the constraint matrix

constexpr auto gtopt::LinearProblem::get_col_lowb(ColIndex index) const

Parameters
index Column index
Returns Lower bound value

Gets the lower bound of a column

constexpr auto gtopt::LinearProblem::get_col_scale(ColIndex index) const

Parameters
index Column index
Returns Scale factor (1.0 = no scaling)

Gets the physical-to-LP scale factor of a column. physical_value = LP_value × scale.

constexpr auto gtopt::LinearProblem::get_col_uppb(ColIndex index) const

Parameters
index Column index
Returns Upper bound value

Gets the upper bound of a column

constexpr index_t gtopt::LinearProblem::get_numcols() const

Returns Number of columns (variables) in the problem

constexpr index_t gtopt::LinearProblem::get_numrows() const

Returns Number of rows (constraints) in the problem

constexpr gtopt::LinearProblem::LinearProblem(std::string name = {}) explicit noexcept

Parameters
name Problem name

Constructs a new linear problem

constexpr void gtopt::LinearProblem::reserve(size_t est_cols, size_t est_rows)

Parameters
est_cols Estimated number of columns (variables)
est_rows Estimated number of rows (constraints)

Pre-reserves capacity for columns, rows, and coefficients. Call before the build loop to avoid repeated reallocations.

template<typename Self Self>
constexpr auto&& gtopt::LinearProblem::row_at(this Self&& self, RowIndex index)

Parameters
self Deduced object reference
index Row index
Returns Reference to the row

Gets a reference to a row by index

constexpr void gtopt::LinearProblem::set_coeff(RowIndex row, ColIndex col, double coeff)

Parameters
row Row index
col Column index
coeff Coefficient value

Sets a coefficient in the constraint matrix

constexpr void gtopt::LinearProblem::set_infinity(double inf) noexcept

Parameters
inf Target infinity value (e.g. LinearInterface::infinity())

Sets the infinity value used for bound normalization.

When set to a value smaller than DblMax (e.g. from the solver backend's infinity()), add_col()/add_row() will clamp DblMax bounds to ±infinity. This ensures that flattened LP vectors never contain raw DblMax values, avoiding noisy solver warnings (e.g. HiGHS "bounds >= 1e20 treated as +Infinity").