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

This feature model is used to model the investment of a variable. It applies the corresponding bounds to the variable and the on/off state of the variable.

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

OnOffModel

OnOffModel(model: FlowSystemModel, label_of_element: str, parameters: OnOffParameters, on_variable: Variable, previous_states: TemporalData | None, label_of_model: str | None = None)

Bases: Submodel

OnOff model using factory patterns

This feature model is used to model the on/off state of flow_rate(s). It does not matter of 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 OnOffParameters

The parameters of the feature model.

required
on_variable Variable

The variable that determines the on state

required
previous_states TemporalData | 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

on_hours_total property
on_hours_total: Variable

Total on hours variable

off property
off: Variable | None

Binary off state variable

switch_on property
switch_on: Variable | None

Switch on variable

switch_off property
switch_off: Variable | None

Switch off variable

switch_on_nr property
switch_on_nr: Variable | None

Number of switch-ons variable

consecutive_on_hours property
consecutive_on_hours: Variable | None

Consecutive on hours variable

consecutive_off_hours property
consecutive_off_hours: Variable | None

Consecutive off hours 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: 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: FlowSystemDimensions | None)

Bases: Submodel

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 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

ShareAllocationModel

ShareAllocationModel(model: FlowSystemModel, dims: list[FlowSystemDimensions], label_of_element: str | None = None, label_of_model: str | None = None, total_max: Scalar | None = None, total_min: Scalar | None = None, max_per_hour: TemporalData | None = None, min_per_hour: TemporalData | 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