fluxopt.constraints.status
¶
Status (on/off) constraint helpers.
Module-level functions that add binary status tracking constraints to a linopy Model. Used by FlowSystem to build status features.
Functions:
| Name | Description |
|---|---|
compute_previous_duration |
Compute consecutive duration of target_state at end of previous_status. |
add_duration_tracking |
Add consecutive duration tracking for a binary state variable. |
add_switch_transitions |
Add startup/shutdown transition constraints. |
compute_previous_duration
¶
compute_previous_duration(
previous_status: DataArray, target_state: int, dt: DataArray | float
) -> float
Compute consecutive duration of target_state at end of previous_status.
Walks backward through previous_status counting timesteps that match the target state, then multiplies by timestep duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DataArray
|
Previous status values (time dimension). |
required |
|
int
|
1 for active (uptime), 0 for inactive (downtime). |
required |
|
DataArray | float
|
Duration per timestep (scalar or DataArray). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total duration in target state at end of previous period. |
Source code in src/fluxopt/constraints/status.py
add_duration_tracking
¶
add_duration_tracking(
m: Model,
state: Variable | LinearExpression,
dt: DataArray,
*,
name: str,
element_dim: str = 'flow',
dim: str = 'time',
minimum: DataArray | None = None,
maximum: DataArray | None = None,
previous: DataArray | None = None,
) -> Variable
Add consecutive duration tracking for a binary state variable.
Uses Big-M formulation to track how long each element has been continuously in the given state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Model
|
Linopy model to add constraints to. |
required |
|
Variable | LinearExpression
|
Binary state variable with (element_dim, time) dims. |
required |
|
DataArray
|
Timestep durations (time,). |
required |
|
str
|
Base name for created variables and constraints. |
required |
|
str
|
Element dimension name in state. |
'flow'
|
|
str
|
Temporal dimension name. |
'time'
|
|
DataArray | None
|
Minimum duration per element. NaN = no constraint. |
None
|
|
DataArray | None
|
Maximum duration per element. NaN = no constraint. |
None
|
|
DataArray | None
|
Previous duration per element. NaN = no previous. |
None
|
Returns:
| Type | Description |
|---|---|
Variable
|
Duration variable with same dims as state. |
Source code in src/fluxopt/constraints/status.py
add_switch_transitions
¶
add_switch_transitions(
m: Model,
status: Variable,
startup: Variable,
shutdown: Variable,
*,
name: str,
element_dim: str = 'flow',
dim: str = 'time',
previous_state: DataArray | None = None,
) -> None
Add startup/shutdown transition constraints.
Links status changes to startup and shutdown indicator variables:
startup[t] - shutdown[t] == status[t] - status[t-1].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Model
|
Linopy model. |
required |
|
Variable
|
Binary on/off variable. |
required |
|
Variable
|
Binary startup indicator variable. |
required |
|
Variable
|
Binary shutdown indicator variable. |
required |
|
str
|
Base name for constraints. |
required |
|
str
|
Element dimension name in status. |
'flow'
|
|
str
|
Temporal dimension name. |
'time'
|
|
DataArray | None
|
Previous on/off per element (pre-filtered, no NaN). |
None
|