gtopt::UserConstraintLP class

LP element wrapping a single user-defined constraint.

Follows the same pattern as DemandLP, GeneratorLP, etc.:

  • Constructor parses and caches the constraint expression.
  • add_to_lp() is called once per (scenario, stage) by the system LP loop; it adds one SparseRow per block to the LinearProblem.
  • add_to_output() writes the LP dual values after solving.

An empty or unparseable expression is silently skipped (no rows added).

Base classes

template<typename ObjectType ObjectType>
class ObjectLP<UserConstraint>
Wrapper class that adds LP capabilities to objects.

Public types

using object_type = UserConstraint
Type of the wrapped object.

Public static variables

static constexpr LPClassName ClassName

Constructors, destructors, conversion operators

UserConstraintLP(const UserConstraint& uc, InputContext& ic) explicit

Public functions

auto add_to_lp(const SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, LinearProblem& lp) -> bool
Add LP rows for this constraint for one (scenario, stage) pair.
auto add_to_output(OutputContext& out) const -> bool
Write dual (shadow-price) values for this constraint to output.
auto class_name(this const Self& self) -> constexpr auto noexcept
auto id() const -> constexpr auto noexcept
auto is_active(const StageLP& stage) const -> constexpr bool
Checks if object is active in given stage.
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto lp_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args) -> constexpr auto
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto lp_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args) -> constexpr auto
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto lp_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args) -> constexpr auto
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto lp_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args) -> constexpr auto
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto lp_label(this const Self& self, SystemContext& sc, const StageLP& stage, Args && ... args) -> constexpr auto
auto object() && -> constexpr UserConstraint&& noexcept
auto object() & -> constexpr UserConstraint& noexcept
Gets the wrapped object.
auto object() const && -> constexpr const UserConstraint&& noexcept
auto object() const & -> constexpr const UserConstraint& noexcept
auto set_id(Uid uid, Name name) -> constexpr auto& noexcept
Sets the object's identifier.
auto short_name(this const Self& self) -> constexpr auto noexcept
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto state_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args) -> constexpr auto
Generates a label for a variable in the optimization problem.
template<typename Self Self, typename SystemContext SystemContext, typename... Args>
auto state_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args) -> constexpr auto
template<typename Self Self, typename ScenarioLP ScenarioLP, typename StageLP StageLP>
auto sv_key(this const Self& self, const ScenarioLP& scenario, const StageLP& stage, std::string_view col_name) -> constexpr auto noexcept
Generates a state variable key for the object.
template<typename Self Self, typename StageLP StageLP>
auto sv_key(this const Self& self, const StageLP& stage, std::string_view col_name) -> constexpr auto noexcept
auto uid() const -> constexpr auto noexcept
auto user_constraint(this auto&& self) -> constexpr auto&& noexcept

Typedef documentation

using gtopt::UserConstraintLP::object_type = UserConstraint

Type of the wrapped object.

Function documentation

bool gtopt::UserConstraintLP::add_to_lp(const SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, LinearProblem& lp)

Add LP rows for this constraint for one (scenario, stage) pair.

Returns true (always; skipped blocks are not errors)

Iterates over all blocks in stage; for each block that falls within the constraint's domain, builds one SparseRow with the constraint coefficients and bounds, and adds it to lp. Stores the resulting RowIndex values for later use in add_to_output().

bool gtopt::UserConstraintLP::add_to_output(OutputContext& out) const

Write dual (shadow-price) values for this constraint to output.

Returns true (always)

Writes per-(scenario, stage, block) duals to output/UserConstraint/constraint_dual.{csv,parquet}. Scaling is determined by the constraint_type field on the underlying UserConstraint object.

constexpr auto gtopt::UserConstraintLP::class_name(this const Self& self) noexcept

constexpr auto gtopt::UserConstraintLP::id() const noexcept

Returns The object's complete identifier (uid + name)

constexpr bool gtopt::UserConstraintLP::is_active(const StageLP& stage) const

Checks if object is active in given stage.

Parameters
stage The stage to check
Returns true if active in stage, false otherwise

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::lp_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args)

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::lp_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args)

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::lp_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args)

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::lp_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args)

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::lp_label(this const Self& self, SystemContext& sc, const StageLP& stage, Args && ... args)

constexpr UserConstraint&& gtopt::UserConstraintLP::object() && noexcept

constexpr UserConstraint& gtopt::UserConstraintLP::object() & noexcept

Gets the wrapped object.

Returns Reference to the wrapped object

constexpr const UserConstraint&& gtopt::UserConstraintLP::object() const && noexcept

constexpr const UserConstraint& gtopt::UserConstraintLP::object() const & noexcept

constexpr auto& gtopt::UserConstraintLP::set_id(Uid uid, Name name) noexcept

Sets the object's identifier.

Parameters
uid Unique identifier
name Human-readable name
Returns Reference to self for chaining

constexpr auto gtopt::UserConstraintLP::short_name(this const Self& self) noexcept

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::state_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args)

Generates a label for a variable in the optimization problem.

Parameters
self Reference to the object
sc System context
scenario Scenario context
stage Stage context
args Additional arguments to include in the label
Returns Label string

template<typename Self Self, typename SystemContext SystemContext, typename... Args>
constexpr auto gtopt::UserConstraintLP::state_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args)

template<typename Self Self, typename ScenarioLP ScenarioLP, typename StageLP StageLP>
constexpr auto gtopt::UserConstraintLP::sv_key(this const Self& self, const ScenarioLP& scenario, const StageLP& stage, std::string_view col_name) noexcept

Generates a state variable key for the object.

Parameters
self Reference to the object
scenario Scenario context
stage Stage context
col_name The column name for the state variable
Returns StateVariable::Key

template<typename Self Self, typename StageLP StageLP>
constexpr auto gtopt::UserConstraintLP::sv_key(this const Self& self, const StageLP& stage, std::string_view col_name) noexcept

constexpr auto gtopt::UserConstraintLP::uid() const noexcept

Returns The object's unique identifier