Line struct
#include <gtopt/line.hpp>
Represents a transmission line (branch) connecting two buses.
A line carries active power flow f ∈ [-tmax_ba, tmax_ab] between bus_a and bus_b. In Kirchhoff mode the flow is constrained by f = V² / X · (θ_a − θ_b) where V is the line voltage and X the reactance. When voltage is omitted (defaults to 1.0) both V and X are in per-unit; when voltage is in kV, reactance must be in Ω. Optional expansion variables allow the solver to invest in additional transfer capacity.
Public static variables
- static LPClassName class_name
Public functions
- auto flow_direction_enum() const -> std::optional<LineFlowDirection> noexcept
- Parse flow_direction (nullopt = follow the global mode).
- auto has_rating_limits() const -> bool noexcept
- auto line_losses_mode_enum() const -> std::optional<LineLossesMode> noexcept
- Parse line_losses_mode string to enum (nullopt = inherit from global).
- auto line_thermal_limit_mode_enum() const -> std::optional<LineThermalLimitMode> noexcept
- Parse line_thermal_limit_mode (nullopt = inherit from global).
- auto loss_allocation_mode_enum() const -> LossAllocationMode noexcept
- Parse loss_allocation_mode string to enum (receiver if unset).
- auto loss_pwl_layout_enum() const -> LinePwlLayout noexcept
- Parse loss_pwl_layout string to enum (defaults to
uniform). - auto overload_slack_bound_enum() const -> std::optional<LineOverloadSlackBound> noexcept
- Parse overload_slack_bound (nullopt = inherit from global).
Public variables
- OptActive active
- Activation status (default: active).
- OptTRealFieldSched annual_capcost
- Annualized investment cost [$/MW-year].
- OptTRealFieldSched annual_derating
- Annual capacity derating factor [p.u./year].
- SingleId bus_a
- Sending-end (from) bus ID.
- SingleId bus_b
- Receiving-end (to) bus ID.
- OptTRealFieldSched capacity
- Installed transfer capacity [MW].
- OptTRealFieldSched capmax
- Absolute maximum capacity after expansion [MW].
- OptTBRealFieldSched conductor_rating_ab
- OptTBRealFieldSched conductor_rating_ba
- OptName description
- OptLineDlr dlr
- OptInt enforce_level
- OptTBRealFieldSched equipment_rating_ab
- OptTBRealFieldSched equipment_rating_ba
- OptTRealFieldSched expcap
- Capacity added per expansion module [MW].
- OptTRealFieldSched expmod
- Maximum number of expansion modules [dimensionless].
- OptName flow_direction
- OptTBIntBoolFieldSched in_service
- OptBool integer_expmod
- Integer-constrain the expmod variable.
- OptTBRealFieldSched limit_penalty
- OptName line_losses_mode
- OptName line_thermal_limit_mode
- OptName loss_allocation_mode
- OptReal loss_cost_eps
- OptTRealFieldSched loss_envelope
- OptReal loss_flow_abs_cost
- OptReal loss_overflow_cost
- OptName loss_pwl_layout
- OptInt loss_secant_segments
- OptInt loss_segments
- OptBool loss_use_sos2
- OptTBRealFieldSched lossfactor
- OptTBRealFieldSched max_flow
- PLEXOS
Max Flow[MW]: alias oftmax_ab(give one, not both). - OptReal max_overload_ratio
- OptTBRealFieldSched max_rating
- OptTBRealFieldSched min_flow
- PLEXOS
Min Flow[MW, ≤ 0]: alias of-tmax_ba. - OptTBRealFieldSched min_rating
- Name name
- Line name.
- OptTBRealFieldSched outage_max_rating
- OptTBRealFieldSched outage_min_rating
- OptTBRealFieldSched overload_max_rating
- OptTBRealFieldSched overload_min_rating
- OptTBRealFieldSched overload_penalty
- OptName overload_slack_bound
- OptTRealFieldSched phase_shift_deg
- OptTRealFieldSched reactance
- OptTRealFieldSched resistance
- OptTBRealFieldSched security_limit_ab
- OptTBRealFieldSched security_limit_ba
- OptTRealFieldSched tap_ratio
- OptReal tap_ratio_max
- OptReal tap_ratio_min
- OptTBRealFieldSched tcost
- OptTBRealFieldSched tmax_ab
- OptTBRealFieldSched tmax_ba
- Maximum power flow in B→A direction [MW].
- OptTBRealFieldSched tmax_normal_ab
- OptTBRealFieldSched tmax_normal_ba
- OptName type
- Optional line type tag (e.g. "ac", "dc", "transformer").
- Uid uid
- Unique identifier.
- OptTBRealFieldSched units_out
- OptBool use_line_losses deprecated
- OptTRealFieldSched voltage
Annuity from overnight cost (per-candidate private rate)
Used only when annual_capcost is unset: the LP charges annual_capcost = overnight_capcost × CRF(wacc, economic_life), CRF(r, n) = r(1+r)^n / ((1+r)^n − 1). wacc unset → the social annual_discount_rate (the stage discount factors are never changed). All unset (default) → today's LP.
Function documentation
bool gtopt:: Line:: has_rating_limits() const noexcept
True when any rating / classified limit beyond the plain flow limit is set (these lines report per-component limit duals).
Variable documentation
static LPClassName gtopt:: Line:: class_name
Canonical class-name constant used in LP row labels and config fields like VariableScale::class_name. Single source of truth — LineLP exposes no separate ClassName member; callers reach the constant via Line::class_name directly (or LineLP::Element::class_name in generic contexts).
OptTBRealFieldSched gtopt:: Line:: conductor_rating_ab
Conductor thermal rating [MW] (weather-dependent; CEN ERST cause "Conductor"). The DLR rating replaces it under dlr.limit_mode = replace (the default when it is set).
OptName gtopt:: Line:: description
Optional free-text description (e.g. conversion provenance)
OptLineDlr gtopt:: Line:: dlr
Dynamic line rating through critical spans (see line_dlr.hpp). When set, the per-block thermal limit is the DLR rating computed from each span's weather with IEEE Std 738 (or a precomputed rating). dlr.limit_mode = "replace" drops the conductor rating (or, when set explicitly without one, max_rating); "min" keeps min(static, DLR). Every other set limit applies on top.
OptInt gtopt:: Line:: enforce_level
Thermal-limit enforcement mode, mirroring PLEXOS's Line.Enforce Limits property:
0— never enforce. The LP does NOT add the hard|flow| <= tmax_{ab,ba}bound;tmax_ab/tmax_baare carried purely for loss-segment discretization (the piecewise-linear loss approximation needs an upper envelope to pick segment widths; without itseg_width = DblMax / nsegproduces meaningless segments). Use this for lines that PLEXOS labels EL=0 ("Never enforce") and for selectively-lifted EL=1 lines whose flow physically exceeds the rating (e.g. Capricornio110→LaNegra110 on the CEN PCP weekly bundle, where AC voltage support requires flows well above the steady-state rating).1— voltage-conditional (PLEXOS). In our LP we treat this identically to level2(hard cap), because we have no AC voltage-feasibility iteration to consult. Lines that must exceed their rating (e.g. Capricornio) are lifted to0explicitly.2— always enforce (the historical hard-cap behaviour and the schema default).
Default = 2.
OptTBRealFieldSched gtopt:: Line:: equipment_rating_ab
Fixed series-equipment limit [MW]: current transformers (TTCC), series capacitors (CCSS), wave traps, breakers. Never replaced.
OptName gtopt:: Line:: flow_direction
Allowed flow direction: "both", "ab", "ba" or "auto" (see LineFlowDirection, line_enums.hpp). "ab" / "ba" declare a one-way line (the opposite direction gets a zero limit, so its flow column(s), loss segments and rows are not emitted); "auto" applies the structural radial-line certificate. Unset → follows model_options.line_direction_mode (default "off" = both).
OptTBIntBoolFieldSched gtopt:: Line:: in_service
Per-(stage, block) in-service flag mirroring PLEXOS Line.Units (the Lin_Units.csv DataFile): 1 = line in service, 0 = line out (maintenance / forced outage) for that block. Unlike the per-stage active element-activation flag, this resolves at block granularity so an intra-stage maintenance window can be modelled. When a block resolves to 0 the LP emits no flow column, capacity row, loss segment, balance contribution, or KVL angle row for that block — the line is a true open circuit and its two buses are decoupled. Absent (default) = in service in every block.
OptTBRealFieldSched gtopt:: Line:: limit_penalty
PLEXOS Limit Penalty [$/MWh]: alias of overload_penalty (give one, not both).
OptName gtopt:: Line:: line_losses_mode
Loss model selection (per-line override). See LineLossesMode for valid values: "none", "linear", "piecewise", "bidirectional", "adaptive", "dynamic". When unset, inherits from ModelOptions.
OptName gtopt:: Line:: line_thermal_limit_mode
How the thermal limit (tmax_ab / tmax_ba, and the installed capacity of an expandable line) treats the loss: "flow" (limit on the flow variable only), "sending" (limit on the sending-end power f + a_s·ℓ, a_s = sending-bus share of the loss under loss_allocation_mode) or "full" (limit on f + ℓ). See LineThermalLimitMode (line_enums.hpp). Unset → inherits model_options.line_thermal_limit_mode (default "flow").
OptName gtopt:: Line:: loss_allocation_mode
How losses are allocated between sender and receiver buses: "receiver" (default), "sender", or "split" (50/50, PLP default).
OptReal gtopt:: Line:: loss_cost_eps
Small positive cost per MWh of dissipated loss, breaks LP-relax bidirectional-flow degeneracy.
In piecewise / bidirectional modes the LP has a per-direction loss column (loss_p / loss_n). For any required net flow f = fp − fn ≥ 0 the convex PWL of the loss curve is strictly minimised at fn = 0 (single-direction dispatch). Adding a tiny positive cost ε on the loss columns makes the LP STRICTLY pick that single-direction optimum, eliminating LP-degeneracy phantom bidirectional flow without SOS1, MIP, or binaries.
Default: 0.1 $/MWh of loss energy, stamped like any other energy cost (weighted by block duration, scenario probability and discount) — small next to energy prices yet large enough to break the degeneracy robustly and to guard against mild negative-LMP loss arbitrage. Unset falls back to the global model_options.loss_cost_eps (itself defaulting to 0.1 $/MWh); an explicit 0 disables ε on this line. Per-line override beats the global default. Inert for none, linear and piecewise_direct — those have no loss column.
SIZING for negative-price exposure: ε lands on the LOSS columns in every mode — in tangent_signed_flow the abs-flow proxy v carries only the loss_flow_abs_cost degeneracy pin (activated when ε > 0) — so its incidence is loss-scaled: overhead ≈ ε·2λ per marginal MWh (λ = R·fmax/V², a few %), NOT a flow toll. Loss dumping earns |π_a + π_b|/2 per MWh whenever the bus-dual pair-sum goes negative (KVL congestion or curtailment produce this with all-positive costs), hence ε ≥ ½·|worst credible pair-sum| (+ margin) closes the arbitrage on the guarded line — typical per-line values 1–20 $/MWh cost only centavos of LMP distortion. Set it per line on flagged corridors and RE-RUN: the sink migrates to the next unguarded lossy line, iterate until no new flags. linear / piecewise_direct cannot be ε-guarded (no loss column). The exact fix remains the SOS2 λ-form (loss_use_sos2 + loss_secant_segments ≥ 2). See test_line_losses_negative_lmp_kvl.cpp.
OptTRealFieldSched gtopt:: Line:: loss_envelope
Upper envelope [MW] over which the K loss-PWL segments are spread. DECOUPLED from the flow cap (tmax_ab/tmax_ba): set this to the ORIGINAL line rating when the cap is inflated by a soft-cap / enforce_level lift, so the segments concentrate over the realistic loading range instead of the lifted cap. When unset (default), the envelope falls back to fmax = max(tmax_ab, tmax_ba) (backward compatible). The envelope never caps the flow: flow may run past it up to tmax_ab/tmax_ba, and losses there stay QUADRATIC (R·f²/V², as PLEXOS) — coarser geometric tangent points / secant segments (ratio ≤ 1.4, error ≤ ≈ 2.8 %) cover [loss_envelope, tmax], while the K fine segments stay on [0, loss_envelope].
OptReal gtopt:: Line:: loss_flow_abs_cost
Per-MWh degeneracy pin [$/MWh, real cost units] on this line's tangent_signed_flow abs-flow proxy columns v_l (Σ v_l ≥ |f|). Makes Σ v_l = |f| at the LP optimum so the secant chord upper bound on the loss stays anchored. It acts as a tiny transport toll: the LMP difference across the line shifts by at most ≈ loss_flow_abs_cost in the flow direction. Unset → model_options.loss_flow_abs_cost (default 0.001 $/MWh); 0 disables the pin; 1e-6 reproduces the pre-option internal constant. Applied only when the resolved loss_cost_eps > 0. Inert outside tangent_signed_flow.
OptReal gtopt:: Line:: loss_overflow_cost
Price [$/MWh] on the loss carried by this line's OVERFLOW tier, i.e. flow between loss_envelope and the flow cap tmax. Every overflow column (|f| ladder column, secant segment, λ breakpoint or the split overflow loss column of the tangent layout) is charged loss_overflow_cost per MWh of loss it adds above R·loss_envelope²/V². This is what stops the tier from acting as a free energy sink under negative bus prices: burning a MWh there costs loss_overflow_cost, so only an incentive above it can buy fictitious loss (the in-envelope residual ≤ R·env²/V² stays governed by loss_cost_eps / SOS2). A GENUINE overload pays the same price on its loss above the envelope — a marginal LMP spread of loss_overflow_cost · 2·R·|f|/V² across the line — which is the minimum any pure-LP guard must charge (see the formulation doc). Unset → model_options.loss_overflow_cost, itself defaulting to the case's effective demand_fail_cost (1000 $/MWh when unset; 1000 with a warning when it is 0); 0 disables the guard on this line. Inert when loss_envelope is unset or ≥ the flow cap.
OptName gtopt:: Line:: loss_pwl_layout
Segment-layout strategy for the PWL loss approximation. See LinePwlLayout for valid values: "uniform" (default, equal-width secant chords), "equal_error" (√-spaced minimax), "tangent" (outer approximation, future). Active only when line_losses_mode selects a PWL flavour. When unset, defaults to uniform — preserving pre-2026-05 behaviour.
OptInt gtopt:: Line:: loss_secant_segments
Number of L-secant segments for the tangent_signed_flow loss- upper-bound chord (issue #504). When L > 1 the single v ≥ |f| auxiliary column is replaced by L segment columns v_l ∈ [0, envelope/L] and the chord upper bound becomes the piecewise sum ℓ ≤ Σ chord_slope_l · v_l with per-segment slope (R/V²) · (envelope/L) · (2l − 1). Combined with loss_use_sos2 this yields a tight piecewise-linear upper bound on the convex quadratic loss curve, lowering worst-case overstatement from c·envelope²/4 (L=1 secant) to c·envelope²/(4·L²).
Per-line override beats model_options.loss_secant_segments. Unset → 1 (single-secant chord, current production behaviour). Inert outside tangent_signed_flow mode.
OptInt gtopt:: Line:: loss_segments
Number of piecewise-linear segments for quadratic losses (default: from Options)
OptBool gtopt:: Line:: loss_use_sos2
Enable SOS2 enforcement on the L secant-segment columns emitted when loss_secant_segments > 1 (issue #504). Without SOS2 the LP exploits the segment freedom to maximise the chord ceiling; with SOS2 at most two consecutive v_l are non-zero, forcing fill order v_1 → v_2 → … → v_L and making the chord piecewise-tight at every breakpoint b_l = l·w.
REQUIRES a MIP-capable LP backend (CPLEX, Gurobi, HiGHS ≥ 1.6); gtopt's CBC/CLP plugins do not currently expose SOS2 — the LP build raises a structured error if SOS2 is requested with an unsupporting backend so the misconfig surfaces at build time.
Per-line override beats model_options.loss_use_sos2. Unset → false (no SOS2 declaration; behaviour identical to the pre-#504 single-secant chord). Inert outside tangent_signed_flow mode or when loss_secant_segments ≤ 1.
OptTBRealFieldSched gtopt:: Line:: lossfactor
Lumped loss factor [p.u.] per-(stage, block).
OptReal gtopt:: Line:: max_overload_ratio
Overload headroom as a fraction of the normal threshold, used by overload_slack_bound = "ratio" (and the "thermal" fallback). Unset → model_options.max_overload_ratio (default 1.5).
OptTBRealFieldSched gtopt:: Line:: max_rating
PLEXOS Max Rating / Min Rating [MW]: normal rating (CEN's daily operational limit Lin_MaxRating.csv). Limit = min(flow, rating).
OptTBRealFieldSched gtopt:: Line:: min_rating
≤ 0 (B→A normal rating)
OptTBRealFieldSched gtopt:: Line:: outage_max_rating
PLEXOS Outage Max Rating / Outage Min Rating [MW]: the rating in blocks with units_out > 0 (maintenance derate). Never replaced by the DLR.
OptTBRealFieldSched gtopt:: Line:: outage_min_rating
≤ 0
OptTBRealFieldSched gtopt:: Line:: overload_max_rating
PLEXOS Overload Max Rating / Overload Min Rating [MW]: emergency rating. With a positive overload_penalty (limit_penalty) in the block it is the hard cap and the normal rating the soft threshold of the overload band; otherwise unused.
OptTBRealFieldSched gtopt:: Line:: overload_min_rating
≤ 0
OptTBRealFieldSched gtopt:: Line:: overload_penalty
Overload penalty above the soft thresholds [$/MWh] — per-(stage, block). Accepts a scalar (broadcasts), a 2-D nested array [[block, …], …], or a file-backed schedule. Per-block duration is factored in by the LP build (matches the convention of other cost coefficients). When zero or unset, no slack columns are emitted and tmax_normal_* are ignored.
OptName gtopt:: Line:: overload_slack_bound
Upper bound of the overload slack: "thermal" (min(hard − normal, max_overload_ratio × normal), the thermal headroom capped by the ratio; ratio only without a finite hard cap), "ratio" (max_overload_ratio × normal) or "unbounded". Unset → model_options.overload_slack_bound (default "thermal").
OptTRealFieldSched gtopt:: Line:: phase_shift_deg
Phase-shift angle [degrees]. Models a phase-shifting transformer (PST) by adding a constant angle offset φ to the Kirchhoff equality constraint: f = B_eff · (θ_a − θ_b − φ). Positive values reduce the natural power flow from bus_a to bus_b. Defaults to 0.0.
OptTRealFieldSched gtopt:: Line:: reactance
Series reactance for DC power flow [Ω] (p.u. when voltage is omitted). Susceptance: B = V² / X. Omit it for a DC link (HVDC, no Kirchhoff coupling). 0 or a value with |X/V²| below model_options.dc_line_reactance_threshold makes the line a zero-impedance tie that forces the two bus angles equal (θ_a − θ_b = φ), unless model_options.tiny_reactance_mode = "dc" (legacy: such lines are DC links).
OptTRealFieldSched gtopt:: Line:: resistance
Series resistance [Ω]. Use p.u. when voltage is omitted.
OptTBRealFieldSched gtopt:: Line:: security_limit_ab
Security / stability limit [MW]: voltage stability (ERST "Estabilidad de Tensión"), transient stability, N-1. Never replaced.
OptTRealFieldSched gtopt:: Line:: tap_ratio
Off-nominal tap ratio [p.u.]. For transformers only; ignored for plain lines. When set to a value other than 1.0 the effective susceptance of the branch in the DC power-flow (Kirchhoff) constraint is scaled by 1/tap_ratio, i.e. B_eff = V²/(tap_ratio · X). Defaults to 1.0 (nominal tap, no correction).
OptReal gtopt:: Line:: tap_ratio_min
Range of an optimised (on-load) tap ratio [p.u.] under network_model = "lindistflow": the LP picks t ∈ [tap_ratio_min, tap_ratio_max] per block through the exact linear change of variable y = w_a/t², w_a/tap_ratio_max² ≤ y ≤ w_a/tap_ratio_min². One bound unset → tap_ratio (or 1). Both unset → fixed tap_ratio. Ignored by the DC model.
OptTBRealFieldSched gtopt:: Line:: tcost
Variable transmission cost [$/MWh] — per-(stage, block). Accepts a scalar (broadcasts), a 2-D nested array, or a file-backed schedule.
OptTBRealFieldSched gtopt:: Line:: tmax_ab
Maximum power flow in A→B direction [MW]
OptTBRealFieldSched gtopt:: Line:: tmax_normal_ab
Soft (normal) flow threshold in the A→B direction [MW]. Same semantics as tmax_normal_ba for the A→B leg.
OptTBRealFieldSched gtopt:: Line:: tmax_normal_ba
Soft (normal) flow threshold in the B→A direction [MW]. When set and overload_penalty > 0, the LP allows flown up to tmax_ba (the hard cap, unchanged) but adds a per-MWh cost overload_penalty × max(0, flown − tmax_normal_ba) to the objective. Mirrors UC.jl's Normal flow limit (MW) and PLEXOS's Normal Rating paired with an overload penalty. When unset (or >= tmax_ba) the LP falls back to the pure hard-cap behavior.
OptTBRealFieldSched gtopt:: Line:: units_out
PLEXOS Units Out: units (circuits) out of service in the block. > 0 activates the outage_*_rating. Unset → 0.
OptBool gtopt:: Line:: use_line_losses
OptTRealFieldSched gtopt:: Line:: voltage
Nominal voltage level [kV]. Omit or set to 1.0 for per-unit mode.
OptTRealFieldSched gtopt:: Line:: overnight_capcost
Overnight investment cost per unit of capacity [$/MW]
OptTRealFieldSched gtopt:: Line:: wacc
Private discount rate of the annuity (WACC / hurdle rate) [p.u./year]
OptTRealFieldSched gtopt:: Line:: fixed_om_cost
Fixed O&M of the expansion capacity [$/unit-year], charged on the capacity built from this stage on, next to the annuity and with the same stage discounting. Unset → no fixed O&M.