Skip to content

flixopt.features

This module contains the features of the flixopt framework. Features extend the functionality of Elements.

Attributes

Classes

InvestmentModel

InvestmentModel(model: FlowSystemModel, label_of_element: str, parameters: InvestParameters, label_of_model: str | None = None)

Bases: Submodel

Mathematical model implementation for investment decisions.

Creates optimization variables and constraints for investment sizing decisions, supporting both binary and continuous sizing with comprehensive effect modeling.

Mathematical Formulation

See https://flixopt.github.io/flixopt/latest/user-guide/mathematical-notation/features/InvestParameters/

Parameters:

Name Type Description Default
model FlowSystemModel

The optimization model instance

required
label_of_element str

The label of the parent (Element). Used to construct the full label of the model.

required
parameters InvestParameters

The parameters of the feature model.

required
label_of_model str | None

The label of the model. This is needed to construct the full label of the model.

None

Attributes

size property
size: Variable

Investment size variable

invested property
invested: Variable | None

Binary investment decision variable

all_submodels property
all_submodels: list[Submodel]

Get all submodels including nested ones recursively.

variables_direct property
variables_direct: Variables

Variables of the model, excluding those of sub-models

constraints_direct property
constraints_direct: Constraints

Constraints of the model, excluding those of sub-models

constraints property
constraints: Constraints

All constraints of the model, including those of all sub-models

variables property
variables: Variables

All variables of the model, including those of all sub-models

Functions

add_submodels
add_submodels(submodel: Submodel, short_name: str = None) -> Submodel

Register a sub-model with the model

add_variables
add_variables(short_name: str = None, **kwargs) -> linopy.Variable

Create and register a variable in one step

add_constraints
add_constraints(expression, short_name: str = None, **kwargs) -> linopy.Constraint

Create and register a constraint in one step

register_variable
register_variable(variable: Variable, short_name: str = None) -> linopy.Variable

Register a variable with the model

register_constraint
register_constraint(constraint: Constraint, short_name: str = None) -> linopy.Constraint

Register a constraint with the model

get
get(name: str, default=None)

Get variable by short name, returning default if not found

StatusModel

StatusModel(model: FlowSystemModel, label_of_element: str, parameters: StatusParameters, status: Variable, previous_status: DataArray | None, label_of_model: str | None = None)

Bases: Submodel

Mathematical model implementation for binary status.

Creates optimization variables and constraints for binary status modeling, state transitions, duration tracking, and operational effects.

Mathematical Formulation

See https://flixopt.github.io/flixopt/latest/user-guide/mathematical-notation/features/StatusParameters/

This feature model is used to model the status (active/inactive) state of flow_rate(s). It does not matter if the flow_rates are bounded by a size variable or by a hard bound. The used bound here is the absolute highest/lowest bound!

Parameters:

Name Type Description Default
model FlowSystemModel

The optimization model instance

required
label_of_element str

The label of the parent (Element). Used to construct the full label of the model.

required
parameters StatusParameters

The parameters of the feature model.

required
status Variable

The variable that determines the active state

required
previous_status DataArray | None

The previous flow_rates

required
label_of_model str | None

The label of the model. This is needed to construct the full label of the model.

None

Attributes

active_hours property
active_hours: Variable

Total active hours variable

inactive property
inactive: Variable | None

Binary inactive state variable.

Note

Only created when downtime tracking is enabled (min_downtime or max_downtime set). For general use, prefer the expression 1 - status instead of this variable.

startup property
startup: Variable | None

Startup variable

shutdown property
shutdown: Variable | None

Shutdown variable

startup_count property
startup_count: Variable | None

Number of startups variable

uptime property
uptime: Variable | None

Consecutive active hours (uptime) variable

downtime property
downtime: Variable | None

Consecutive inactive hours (downtime) variable

all_submodels property
all_submodels: list[Submodel]

Get all submodels including nested ones recursively.

variables_direct property
variables_direct: Variables

Variables of the model, excluding those of sub-models

constraints_direct property
constraints_direct: Constraints

Constraints of the model, excluding those of sub-models

constraints property
constraints: Constraints

All constraints of the model, including those of all sub-models

variables property
variables: Variables

All variables of the model, including those of all sub-models

Functions

add_submodels
add_submodels(submodel: Submodel, short_name: str = None) -> Submodel

Register a sub-model with the model

add_variables
add_variables(short_name: str = None, **kwargs) -> linopy.Variable

Create and register a variable in one step

add_constraints
add_constraints(expression, short_name: str = None, **kwargs) -> linopy.Constraint

Create and register a constraint in one step

register_variable
register_variable(variable: Variable, short_name: str = None) -> linopy.Variable

Register a variable with the model

register_constraint
register_constraint(constraint: Constraint, short_name: str = None) -> linopy.Constraint

Register a constraint with the model

get
get(name: str, default=None)

Get variable by short name, returning default if not found

PieceModel

PieceModel(model: FlowSystemModel, label_of_element: str, label_of_model: str, dims: Collection[FlowSystemDimensions] | None)

Bases: Submodel

Class for modeling a linear piece of one or more variables in parallel

Attributes

all_submodels property
all_submodels: list[Submodel]

Get all submodels including nested ones recursively.

variables_direct property
variables_direct: Variables

Variables of the model, excluding those of sub-models

constraints_direct property
constraints_direct: Constraints

Constraints of the model, excluding those of sub-models

constraints property
constraints: Constraints

All constraints of the model, including those of all sub-models

variables property
variables: Variables

All variables of the model, including those of all sub-models

Functions

add_submodels
add_submodels(submodel: Submodel, short_name: str = None) -> Submodel

Register a sub-model with the model

add_variables
add_variables(short_name: str = None, **kwargs) -> linopy.Variable

Create and register a variable in one step

add_constraints
add_constraints(expression, short_name: str = None, **kwargs) -> linopy.Constraint

Create and register a constraint in one step

register_variable
register_variable(variable: Variable, short_name: str = None) -> linopy.Variable

Register a variable with the model

register_constraint
register_constraint(constraint: Constraint, short_name: str = None) -> linopy.Constraint

Register a constraint with the model

get
get(name: str, default=None)

Get variable by short name, returning default if not found

PiecewiseModel

PiecewiseModel(model: FlowSystemModel, label_of_element: str, label_of_model: str, piecewise_variables: dict[str, Piecewise], zero_point: bool | Variable | None, dims: Collection[FlowSystemDimensions] | None)

Bases: Submodel

Mathematical model implementation for piecewise linear approximations.

Creates optimization variables and constraints for piecewise linear relationships, including lambda variables, piece activation binaries, and coupling constraints.

Mathematical Formulation

See https://flixopt.github.io/flixopt/latest/user-guide/mathematical-notation/features/Piecewise/

Modeling a Piecewise relation between miultiple variables. The relation is defined by a list of Pieces, which are assigned to the variables. Each Piece is a tuple of (start, end).

Parameters:

Name Type Description Default
model FlowSystemModel

The FlowSystemModel that is used to create the model.

required
label_of_element str

The label of the parent (Element). Used to construct the full label of the model.

required
label_of_model str

The label of the model. Used to construct the full label of the model.

required
piecewise_variables dict[str, Piecewise]

The variables to which the Pieces are assigned.

required
zero_point bool | Variable | None

A variable that can be used to define a zero point for the Piecewise relation. If None or False, no zero point is defined.

required
dims Collection[FlowSystemDimensions] | None

The dimensions used for variable creation. If None, all dimensions are used.

required

Attributes

all_submodels property
all_submodels: list[Submodel]

Get all submodels including nested ones recursively.

variables_direct property
variables_direct: Variables

Variables of the model, excluding those of sub-models

constraints_direct property
constraints_direct: Constraints

Constraints of the model, excluding those of sub-models

constraints property
constraints: Constraints

All constraints of the model, including those of all sub-models

variables property
variables: Variables

All variables of the model, including those of all sub-models

Functions

add_submodels
add_submodels(submodel: Submodel, short_name: str = None) -> Submodel

Register a sub-model with the model

add_variables
add_variables(short_name: str = None, **kwargs) -> linopy.Variable

Create and register a variable in one step

add_constraints
add_constraints(expression, short_name: str = None, **kwargs) -> linopy.Constraint

Create and register a constraint in one step

register_variable
register_variable(variable: Variable, short_name: str = None) -> linopy.Variable

Register a variable with the model

register_constraint
register_constraint(constraint: Constraint, short_name: str = None) -> linopy.Constraint

Register a constraint with the model

get
get(name: str, default=None)

Get variable by short name, returning default if not found

PiecewiseEffectsModel

PiecewiseEffectsModel(model: FlowSystemModel, label_of_element: str, label_of_model: str, piecewise_origin: tuple[str, Piecewise], piecewise_shares: dict[str, Piecewise], zero_point: bool | Variable | None)

Bases: Submodel

Attributes

all_submodels property
all_submodels: list[Submodel]

Get all submodels including nested ones recursively.

variables_direct property
variables_direct: Variables

Variables of the model, excluding those of sub-models

constraints_direct property
constraints_direct: Constraints

Constraints of the model, excluding those of sub-models

constraints property
constraints: Constraints

All constraints of the model, including those of all sub-models

variables property
variables: Variables

All variables of the model, including those of all sub-models

Functions

add_submodels
add_submodels(submodel: Submodel, short_name: str = None) -> Submodel

Register a sub-model with the model

add_variables
add_variables(short_name: str = None, **kwargs) -> linopy.Variable

Create and register a variable in one step

add_constraints
add_constraints(expression, short_name: str = None, **kwargs) -> linopy.Constraint

Create and register a constraint in one step

register_variable
register_variable(variable: Variable, short_name: str = None) -> linopy.Variable

Register a variable with the model

register_constraint
register_constraint(constraint: Constraint, short_name: str = None) -> linopy.Constraint

Register a constraint with the model

get
get(name: str, default=None)

Get variable by short name, returning default if not found

ShareAllocationModel

ShareAllocationModel(model: FlowSystemModel, dims: list[FlowSystemDimensions], label_of_element: str | None = None, label_of_model: str | None = None, total_max: Numeric_PS | None = None, total_min: Numeric_PS | None = None, max_per_hour: Numeric_TPS | None = None, min_per_hour: Numeric_TPS | None = None)

Bases: Submodel

Attributes

all_submodels property
all_submodels: list[Submodel]

Get all submodels including nested ones recursively.

variables_direct property
variables_direct: Variables

Variables of the model, excluding those of sub-models

constraints_direct property
constraints_direct: Constraints

Constraints of the model, excluding those of sub-models

constraints property
constraints: Constraints

All constraints of the model, including those of all sub-models

variables property
variables: Variables

All variables of the model, including those of all sub-models

Functions

add_share
add_share(name: str, expression: LinearExpression, dims: list[FlowSystemDimensions] | None = None)

Add a share to the share allocation model. If the share already exists, the expression is added to the existing share. The expression is added to the right hand side (rhs) of the constraint. The variable representing the total share is on the left hand side (lhs) of the constraint. var_total = sum(expressions)

Parameters:

Name Type Description Default
name str

The name of the share.

required
expression LinearExpression

The expression of the share. Added to the right hand side of the constraint.

required
dims list[FlowSystemDimensions] | None

The dimensions of the share. Defaults to all dimensions. Dims are ordered automatically

None
add_submodels
add_submodels(submodel: Submodel, short_name: str = None) -> Submodel

Register a sub-model with the model

add_variables
add_variables(short_name: str = None, **kwargs) -> linopy.Variable

Create and register a variable in one step

add_constraints
add_constraints(expression, short_name: str = None, **kwargs) -> linopy.Constraint

Create and register a constraint in one step

register_variable
register_variable(variable: Variable, short_name: str = None) -> linopy.Variable

Register a variable with the model

register_constraint
register_constraint(constraint: Constraint, short_name: str = None) -> linopy.Constraint

Register a constraint with the model

get
get(name: str, default=None)

Get variable by short name, returning default if not found