gtopt::FlowRightLP class

Base classes

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

Public types

using Element = FlowRight
using object_type = FlowRight
Type of the wrapped object.

Public static variables

static std::string_view BypassName
static std::string_view DemandName
static std::string_view ExcessName
static std::string_view FailName
static std::string_view FlowKinkName
static std::string_view FlowName
Per-block primary flow column (flow_b ∈ [fmin_b, fmax_b]).
static std::string_view QavgName
Stage-aggregation row name (qeh − Σ_b dur_ratio_b × flow_b = 0).
static std::string_view QehName
static std::string_view QehSnName
static std::string_view QehSpName
static std::string_view QkinkName

Constructors, destructors, conversion operators

FlowRightLP(const FlowRight& pflow, const InputContext& ic) explicit

Public functions

auto add_to_lp(const SystemContext& sc, const ScenarioLP& scenario, const StageLP& stage, LinearProblem& lp) -> bool
auto add_to_output(OutputContext& out) const -> bool
auto class_name(this const Self& self) -> auto noexcept
auto excess_sol_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const ScaledView& col_sol) const -> double noexcept
auto fail_sol_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const ScaledView& col_sol) const -> double noexcept
auto flow_cols_at(const ScenarioLP& scenario, const StageLP& stage) const -> auto&&
auto flow_right(this auto&& 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() & -> FlowRight& noexcept
Gets the wrapped object.
auto qeh_col_at(const ScenarioLP& scenario, const StageLP& stage) const -> ColIndex
auto reward_objective(const ScenarioLP& scenario, const StageLP& stage, const LinearInterface& li) const -> double
auto set_id(Uid uid, Name name) -> auto& noexcept
Sets the object's identifier.
auto short_name(this const Self& self) -> auto noexcept
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 update_lp(SystemLP& sys, const ScenarioLP& scenario, const StageLP& stage) -> int

Parameter accessors for user constraint resolution

auto param_fmin(StageUid s, BlockUid b) const -> auto
auto param_fmax(StageUid s, BlockUid b) const -> auto
auto param_target(StageUid s, BlockUid b) const -> auto
auto param_fcost(StageUid s, BlockUid b) const -> auto
auto param_uvalue(StageUid s, BlockUid b) const -> auto
auto has_qeh(const ScenarioLP& scenario, const StageLP& stage) const -> bool noexcept
Test-only existence probes for LP entities.
auto has_qeh_slacks(const ScenarioLP& scenario, const StageLP& stage) const -> bool noexcept
auto has_qkink_row(const ScenarioLP& scenario, const StageLP& stage) const -> bool noexcept
auto has_qavg_row(const ScenarioLP& scenario, const StageLP& stage) const -> bool noexcept
auto has_block_slacks(const ScenarioLP& scenario, const StageLP& stage) const -> bool noexcept
auto fail_col_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) const -> std::optional<ColIndex> noexcept
Test-only column-index lookup for the per-block deficit slack. Returns std::nullopt when no slack was installed at the given (scenario, stage, block) — i.e. when the per-block kink machinery did not fire (no target, or both fcost and uvalue inactive, or flow_mode != per_block). Used by tests to inspect the slack's objective coefficient via lp.get_obj_coeff()[col].
auto bypass_col_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) const -> std::optional<ColIndex> noexcept
auto excess_col_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) const -> std::optional<ColIndex> noexcept
Test-only sibling of fail_col_at for the excess (sp) slack.

Typedef documentation

using gtopt::FlowRightLP::Element = FlowRight

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::FlowRightLP::object_type = FlowRight

Type of the wrapped object.

Function documentation

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

double gtopt::FlowRightLP::excess_sol_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const ScaledView& col_sol) const noexcept

Surplus primal at (scenario, stage, block). Reads excess_b directly when the kink slacks are present; returns 0.0 otherwise.

double gtopt::FlowRightLP::fail_sol_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block, const ScaledView& col_sol) const noexcept

Deficit primal at (scenario, stage, block). Reads fail_b directly when the kink slacks are present; returns 0.0 otherwise. col_sol is the LP's primal-solution view (the same span that OutputContext::col_sol_span wraps). Used by SystemLP::accumulate_convergence_indicators to track unserved_flow.

auto gtopt::FlowRightLP::id() const noexcept

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

bool gtopt::FlowRightLP::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

FlowRight& gtopt::FlowRightLP::object() & noexcept

Gets the wrapped object.

Returns Reference to the wrapped object

ColIndex gtopt::FlowRightLP::qeh_col_at(const ScenarioLP& scenario, const StageLP& stage) const

Exceptions
std::out_of_range if not available.

Return the stage-average hourly flow column for (scenario, stage). Only present when use_average = true.

double gtopt::FlowRightLP::reward_objective(const ScenarioLP& scenario, const StageLP& stage, const LinearInterface& li) const

Objective contribution [physical $, same space as LinearInterface::get_obj_value()] of this right's REWARD terms at (scenario, stage) in the last solution of li: every flow / surplus column priced with a negative objective coefficient (positive uvalue). A uvalue-only kink substitution counts the reward beyond its cached target, c · (x − target); an fcost-only substitution (a refunded shortfall penalty, not a reward) is skipped. Always <= 0. Requires a live, optimal backend.

auto& gtopt::FlowRightLP::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

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

auto gtopt::FlowRightLP::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

auto gtopt::FlowRightLP::sv_key(this const Self& self, const StageLP& stage, std::string_view col_name) noexcept

auto gtopt::FlowRightLP::uid() const noexcept

Returns The object's unique identifier

int gtopt::FlowRightLP::update_lp(SystemLP& sys, const ScenarioLP& scenario, const StageLP& stage)

Returns Number of LP column bounds modified (0 if unchanged)

Update volume-dependent column bounds when bound_rule is set. Reads the referenced reservoir's current volume (or the stage month for stage-month axes), evaluates the piecewise-linear bound function, and clamps flow_b's [fmin_b, fmax_b] bounds (and the stage qeh bounds, when use_average = true).

bool gtopt::FlowRightLP::has_qeh(const ScenarioLP& scenario, const StageLP& stage) const noexcept

Test-only existence probes for LP entities.

These return only whether the corresponding LP entity was installed by add_to_lp; they do not expose the indices. The LP shape across the three FlowMode values (per_block, stage_average, stage_uniform) differs in which slack/row maps are populated, and existence checks are the cleanest way for tests to pin the shape independently of solver primals. Each probe is a pure container query (map::find or map::contains), so it can be called on any built FlowRightLP regardless of whether the LP has been solved.

std::optional<ColIndex> gtopt::FlowRightLP::bypass_col_at(const ScenarioLP& scenario, const StageLP& stage, const BlockLP& block) const noexcept

Column of the opt-in pass-through bypass at (scenario, stage, block); std::nullopt when the bypass was not emitted.

Variable documentation

static std::string_view gtopt::FlowRightLP::BypassName

Per-block pass-through bypass column (bypass_b ∈ [0, bypass_fmax]). Emitted only when the bypass is explicitly requested (FlowRight::bypass_requested()) and both junctions are set: contributes −1 to junction_a's balance row and +1 to junction_b's, priced at bypass_cost · cf. Written to the output as FlowRight/bypass_sol and exposed to PAMPL as flow_right('x').bypass.

static std::string_view gtopt::FlowRightLP::ExcessName

Per-block surplus slack (excess_b = max(0, flow_b − target_b)). Cost -uvalue·cf so the LP earns a bonus when overshooting target.

static std::string_view gtopt::FlowRightLP::FailName

Per-block deficit slack (fail_b = max(0, target_b − flow_b)). Cost +fcost·cf so the LP pays a penalty when undershooting target.

static std::string_view gtopt::FlowRightLP::FlowKinkName

Per-block kink equality row name (flow_b − excess_b + fail_b = target_b).

static std::string_view gtopt::FlowRightLP::QehName

Stage-average hourly flow column (qeh ∈ [fmin_e, fmax_e]). Only emitted when use_average = true.

static std::string_view gtopt::FlowRightLP::QehSnName

Stage-level deficit slack (qeh_sn = max(0, target_e − qeh)). Cost +fcost_e·cf (deficit penalty).

static std::string_view gtopt::FlowRightLP::QehSpName

Stage-level surplus slack (qeh_sp = max(0, qeh − target_e)). Cost -uvalue_e·cf (excess bonus).

static std::string_view gtopt::FlowRightLP::QkinkName

Stage-level kink equality row name (qeh − qeh_sp + qeh_sn = target_e).