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 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.
- auto lp_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args) -> constexpr auto
- auto lp_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args) -> constexpr auto
- auto lp_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, Args && ... args) -> constexpr auto
- auto lp_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args) -> constexpr auto
- 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
- 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.
- auto state_col_label(this const Self& self, SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, Args && ... args) -> constexpr auto
- 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.
- 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
#include <gtopt/object_lp.hpp>
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
#include <gtopt/object_lp.hpp>
constexpr auto gtopt:: UserConstraintLP:: id() const noexcept
#include <gtopt/object_lp.hpp>
| Returns | The object's complete identifier (uid + name) |
|---|
#include <gtopt/object_utils.hpp>
constexpr auto gtopt:: UserConstraintLP:: lp_col_label(this const Self& self,
SystemContext& sc,
const ScenarioLP& scenario,
const StageLP& stage,
Args && ... args)
#include <gtopt/object_utils.hpp>
constexpr auto gtopt:: UserConstraintLP:: lp_col_label(this const Self& self,
SystemContext& sc,
const ScenarioLP& scenario,
const StageLP& stage,
const BlockLP& block,
Args && ... args)
#include <gtopt/object_utils.hpp>
constexpr auto gtopt:: UserConstraintLP:: lp_label(this const Self& self,
SystemContext& sc,
const ScenarioLP& scenario,
const StageLP& stage,
Args && ... args)
#include <gtopt/object_utils.hpp>
constexpr auto gtopt:: UserConstraintLP:: lp_label(this const Self& self,
SystemContext& sc,
const ScenarioLP& scenario,
const StageLP& stage,
const BlockLP& block,
Args && ... args)
constexpr UserConstraint&& gtopt:: UserConstraintLP:: object() && noexcept
#include <gtopt/object_lp.hpp>
constexpr UserConstraint& gtopt:: UserConstraintLP:: object() & noexcept
#include <gtopt/object_lp.hpp>
Gets the wrapped object.
| Returns | Reference to the wrapped object |
|---|
constexpr const UserConstraint&& gtopt:: UserConstraintLP:: object() const && noexcept
#include <gtopt/object_lp.hpp>
constexpr const UserConstraint& gtopt:: UserConstraintLP:: object() const & noexcept
#include <gtopt/object_lp.hpp>
constexpr auto gtopt:: UserConstraintLP:: short_name(this const Self& self) noexcept
#include <gtopt/object_lp.hpp>
#include <gtopt/object_utils.hpp>
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 |
#include <gtopt/object_utils.hpp>
constexpr auto gtopt:: UserConstraintLP:: state_col_label(this const Self& self,
SystemContext& sc,
const ScenarioLP& scenario,
const StageLP& stage,
const BlockLP& block,
Args && ... args)
#include <gtopt/object_utils.hpp>
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 |
constexpr auto gtopt:: UserConstraintLP:: uid() const noexcept
#include <gtopt/object_lp.hpp>
| Returns | The object's unique identifier |
|---|