gtopt::SparseCol class

Represents a variable column in a linear program.

This class provides a fluent interface for setting variable properties including bounds, objective coefficients, integrality constraints, and a physical-to-LP scale factor.

The scale field records the relationship between the LP variable and the corresponding physical quantity:

physical_value = LP_value × scale

For example, a voltage angle column with scale_theta = 0.0001 stores scale = 0.0001 because theta_physical = theta_LP × 0.0001. A reservoir energy column with energy_scale = 100000 stores scale = 100000 because volume_physical = volume_LP × 100000. All scales follow the same convention — no inversions.

The scale is used by:

  • Output rescaling: primal x_phys = x_LP × scale, reduced cost rc_phys = rc_LP / scale.
  • User constraints (PAMPL): LinearProblem::get_col_scale() returns the scale so that constraint coefficients are correctly adjusted.
  • Cross-element references (e.g. ReservoirSeepageLP reading reservoir volume scale to convert seepage slope to LP units).

All methods are constexpr to enable compile-time construction of problems.

Public functions

auto equal(double value) -> constexpr SparseCol& noexcept
auto free() -> constexpr SparseCol& noexcept
auto integer() -> constexpr SparseCol& noexcept

Public variables

double cost
Objective coefficient (default: 0.0)
bool is_integer
is integer-constrained (default: false)
double lowb
Lower bound (default: 0.0)
std::string name
Variable name (empty for anonymous variables)
double scale
double uppb
Upper bound (default: +infinity)

Function documentation

constexpr SparseCol& gtopt::SparseCol::equal(double value) noexcept

Parameters
value Fixed value to set
Returns Reference to this column for method chaining

Sets variable to a fixed value (equality constraint)

constexpr SparseCol& gtopt::SparseCol::free() noexcept

Returns Reference to this column for method chaining

Sets variable to be free (unbounded in both directions)

constexpr SparseCol& gtopt::SparseCol::integer() noexcept

Returns Reference to this column for method chaining

Marks variable as integer-constrained

Variable documentation

double gtopt::SparseCol::scale

Physical-to-LP scale: physical_value = LP_value × scale (default: 1.0 = no scaling)