UserConstraintLP class
#include <gtopt/user_constraint_lp.hpp>
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>class ObjectLP<UserConstraint>
- Wrapper class that adds LP capabilities to objects.
Public types
- using Element = UserConstraint
- using object_type = UserConstraint
- Type of the wrapped object.
Public static variables
- static std::string_view ConstraintName
- static std::string_view SlackName
- Slack column emitted for one-sided soft constraints (
<=/>=). - static std::string_view SlackNegName
- static std::string_view SlackPosName
Constructors, destructors, conversion operators
- UserConstraintLP(const UserConstraint& uc, InputContext& ic) explicit
Public functions
- auto add_to_global_lp(const SystemContext& sc, const SceneLP& scene, const PhaseLP& phase, LinearProblem& lp) -> bool
- 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 add_to_phase_lp(const SystemContext& sc, const SceneLP& scene, const PhaseLP& phase, LinearProblem& lp) -> bool
- auto class_name(this const Self& self) -> auto noexcept
- auto id() const -> auto noexcept
- auto is_active(const StageLP& stage) const -> bool
- Checks if object is active in given stage.
- auto object() & -> UserConstraint& noexcept
- Gets the wrapped object.
- auto param_rhs(StageUid s, BlockUid b) const -> std::optional<Real>
- auto rows_holder() const -> const STBIndexHolder<RowIndex>& noexcept
- Per-(scenario, stage) row indices produced by the build path.
- auto scale_type() const -> ConstraintScaleType noexcept
- Dual-output scaling parsed from
constraint_type. - auto set_id(Uid uid, Name name) -> auto& noexcept
- Sets the object's identifier.
- auto short_name(this const Self& self) -> auto noexcept
- auto slack_cols_holder() const -> const STBIndexHolder<ColIndex>& noexcept
- Per-(scenario, stage) soft-constraint slack columns (
slack/slack_pos). - auto slack_neg_cols_holder() const -> const STBIndexHolder<ColIndex>& noexcept
- Per-(scenario, stage) negative-deviation slack columns (
slack_neg). - auto sv_key(this const Self& self, const ScenarioLP& scenario, const StageLP& stage, std::string_view col_name) -> auto noexcept
- Generates a state variable key for the object.
- auto sv_key(this const Self& self, const StageLP& stage, std::string_view col_name) -> auto noexcept
- auto uid() const -> auto noexcept
- auto user_constraint(this auto&& self) -> auto&& noexcept
Typedef documentation
using gtopt:: UserConstraintLP:: Element = UserConstraint
#include <gtopt/object_lp.hpp>
Alias for the wrapped data-struct type. Lets generic code reach the canonical LPClassName constant via T::Element::class_name where T is any LP wrapper inheriting from ObjectLP. Single source of truth for the class-name constant lives on the data struct (Bus::class_name, Reservoir::class_name, …); the LP wrappers no longer carry a duplicate ClassName member.
using gtopt:: UserConstraintLP:: object_type = UserConstraint
#include <gtopt/object_lp.hpp>
Type of the wrapped object.
Function documentation
bool gtopt:: UserConstraintLP:: add_to_global_lp(const SystemContext& sc,
const SceneLP& scene,
const PhaseLP& phase,
LinearProblem& lp)
Planning-level build for global-scoped constraints — one un-indexed LP row per (scene, phase) cell (the FCF α terminal-cut / annual-cap shape). Runs in the global sweep, which the planning pass executes after the phase sweep so a global row can reference state columns the phase sweep registered. Block/stage/phase-scoped constraints do nothing here.
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.
bool gtopt:: UserConstraintLP:: add_to_phase_lp(const SystemContext& sc,
const SceneLP& scene,
const PhaseLP& phase,
LinearProblem& lp)
Planning-level build for phase/global-scoped constraints — one LP row per (scene, phase) cell. Dispatched by the planning pass (add_to_planning_lp) AFTER the per-(scenario, stage) operational sweep, so coarse rows can reference any column the stage sweep created. phase-scope routes here; global-scope routes through add_to_global_lp below. Block/stage-scoped constraints do nothing here (they are built in add_to_lp). See ConstraintScope.
auto gtopt:: UserConstraintLP:: class_name(this const Self& self) noexcept
#include <gtopt/object_lp.hpp>
auto gtopt:: UserConstraintLP:: id() const noexcept
#include <gtopt/object_lp.hpp>
| Returns | The object's complete identifier (uid + name) |
|---|
bool gtopt:: UserConstraintLP:: is_active(const StageLP& stage) const
#include <gtopt/object_lp.hpp>
Checks if object is active in given stage.
| Parameters | |
|---|---|
| stage | The stage to check |
| Returns | true if active in stage, false otherwise |
UserConstraint& gtopt:: UserConstraintLP:: object() & noexcept
#include <gtopt/object_lp.hpp>
Gets the wrapped object.
| Returns | Reference to the wrapped object |
|---|
std::optional<Real> gtopt:: UserConstraintLP:: param_rhs(StageUid s,
BlockUid b) const
PAMPL parameter accessor for user_constraint("X").rhs references in other constraints' expressions. Returns the per-(stage, block) override when the schedule is set and resolves at that key; otherwise std::nullopt so the call site can fall back to the expression's scalar.
auto& gtopt:: UserConstraintLP:: set_id(Uid uid,
Name name) noexcept
#include <gtopt/object_lp.hpp>
Sets the object's identifier.
| Parameters | |
|---|---|
| uid | Unique identifier |
| name | Human-readable name |
| Returns | Reference to self for chaining |
auto gtopt:: UserConstraintLP:: short_name(this const Self& self) noexcept
#include <gtopt/object_lp.hpp>
auto gtopt:: UserConstraintLP:: sv_key(this const Self& self,
const ScenarioLP& scenario,
const StageLP& stage,
std::string_view col_name) noexcept
#include <gtopt/object_utils.hpp>
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 |
auto gtopt:: UserConstraintLP:: sv_key(this const Self& self,
const StageLP& stage,
std::string_view col_name) noexcept
#include <gtopt/object_utils.hpp>
auto gtopt:: UserConstraintLP:: uid() const noexcept
#include <gtopt/object_lp.hpp>
| Returns | The object's unique identifier |
|---|
Variable documentation
static std::string_view gtopt:: UserConstraintLP:: SlackNegName
Negative-deviation slack for soft equality constraints (expr = rhs). Sign convention: row gets -1.0 * slack_neg.
static std::string_view gtopt:: UserConstraintLP:: SlackPosName
Positive-deviation slack for soft equality constraints (expr = rhs). Sign convention: row gets +1.0 * slack_pos.