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: SystemModel,
    label_of_element: str,
    parameters: InvestParameters,
    defining_variable: [Variable],
    relative_bounds_of_defining_variable: Tuple[NumericData, NumericData],
    label: Optional[str] = None,
    on_variable: Optional[Variable] = None,
)

Bases: Model

Class for modeling an investment

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

StateModel

StateModel(
    model: SystemModel,
    label_of_element: str,
    defining_variables: List[Variable],
    defining_bounds: List[Tuple[NumericData, NumericData]],
    previous_values: List[Optional[NumericData]] = None,
    use_off: bool = True,
    on_hours_total_min: Optional[NumericData] = 0,
    on_hours_total_max: Optional[NumericData] = None,
    effects_per_running_hour: Dict[str, NumericData] = None,
    label: Optional[str] = None,
)

Bases: Model

Handles basic on/off binary states for defining variables

Models binary state variables based on a continous variable.

Parameters:

Name Type Description Default
model SystemModel

The SystemModel 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
defining_variables List[Variable]

List of Variables that are used to define the state

required
defining_bounds List[Tuple[NumericData, NumericData]]

List of Tuples, defining the absolute bounds of each defining variable

required
previous_values List[Optional[NumericData]]

List of previous values of the defining variables

None
use_off bool

Whether to use the off state or not

True
on_hours_total_min Optional[NumericData]

min. overall sum of operating hours.

0
on_hours_total_max Optional[NumericData]

max. overall sum of operating hours.

None
effects_per_running_hour Dict[str, NumericData]

Costs per operating hours

None
label Optional[str]

Label of the OnOffModel

None

Attributes

previous_states property
previous_states: ndarray

Computes the previous states {0, 1} of defining variables as a binary array from their previous values.

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

compute_previous_states staticmethod
compute_previous_states(
    previous_values: List[NumericData], epsilon: float = 1e-05
) -> np.ndarray

Computes the previous states {0, 1} of defining variables as a binary array from their previous values.

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

SwitchStateModel

SwitchStateModel(
    model: SystemModel,
    label_of_element: str,
    state_variable: Variable,
    previous_state=0,
    switch_on_max: Optional[Scalar] = None,
    label: Optional[str] = None,
)

Bases: Model

Handles switch on/off transitions

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

do_modeling
do_modeling()

Create switch variables and constraints

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

ConsecutiveStateModel

ConsecutiveStateModel(
    model: SystemModel,
    label_of_element: str,
    state_variable: Variable,
    minimum_duration: Optional[NumericData] = None,
    maximum_duration: Optional[NumericData] = None,
    previous_states: Optional[NumericData] = None,
    label: Optional[str] = None,
)

Bases: Model

Handles tracking consecutive durations in a state

Model and constraint the consecutive duration of a state variable.

Parameters:

Name Type Description Default
model SystemModel

The SystemModel 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
state_variable Variable

The state variable that is used to model the duration. state = {0, 1}

required
minimum_duration Optional[NumericData]

The minimum duration of the state variable.

None
maximum_duration Optional[NumericData]

The maximum duration of the state variable.

None
previous_states Optional[NumericData]

The previous states of the state variable.

None
label Optional[str]

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

None

Attributes

previous_duration property
previous_duration: Scalar

Computes the previous duration of the state variable

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

do_modeling
do_modeling()

Create consecutive duration variables and constraints

compute_consecutive_hours_in_state staticmethod
compute_consecutive_hours_in_state(
    binary_values: NumericData, hours_per_timestep: Union[int, float, ndarray]
) -> Scalar

Computes the final consecutive duration in state 'on' (=1) in hours, from a binary array.

Parameters:

Name Type Description Default
binary_values NumericData

An int or 1D binary array containing only 0s and 1s.

required
hours_per_timestep Union[int, float, ndarray]

The duration of each timestep in hours. If a scalar is provided, it is used for all timesteps. If an array is provided, it must be as long as the last consecutive duration in binary_values.

required

Returns:

Type Description
Scalar

The duration of the binary variable in hours.

Raises

TypeError If the length of binary_values and dt_in_hours is not equal, but None is a scalar.

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

OnOffModel

OnOffModel(
    model: SystemModel,
    on_off_parameters: OnOffParameters,
    label_of_element: str,
    defining_variables: List[Variable],
    defining_bounds: List[Tuple[NumericData, NumericData]],
    previous_values: List[Optional[NumericData]],
    label: Optional[str] = None,
)

Bases: Model

Class for modeling the on and off state of a variable Uses component models to create a modular implementation

Constructor for OnOffModel

Parameters:

Name Type Description Default
model SystemModel

Reference to the SystemModel

required
on_off_parameters OnOffParameters

Parameters for the OnOffModel

required
label_of_element str

Label of the Parent

required
defining_variables List[Variable]

List of Variables that are used to define the OnOffModel

required
defining_bounds List[Tuple[NumericData, NumericData]]

List of Tuples, defining the absolute bounds of each defining variable

required
previous_values List[Optional[NumericData]]

List of previous values of the defining variables

required
label Optional[str]

Label of the OnOffModel

None

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

do_modeling
do_modeling()

Create all variables and constraints for the OnOffModel

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

PieceModel

PieceModel(
    model: SystemModel,
    label_of_element: str,
    label: str,
    as_time_series: bool = True,
)

Bases: Model

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

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

PiecewiseModel

PiecewiseModel(
    model: SystemModel,
    label_of_element: str,
    piecewise_variables: Dict[str, Piecewise],
    zero_point: Optional[Union[bool, Variable]],
    as_time_series: bool,
    label: str = '',
)

Bases: Model

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 SystemModel

The SystemModel 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 str

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

''
piecewise_variables Dict[str, Piecewise]

The variables to which the Pieces are assigned.

required
zero_point Optional[Union[bool, Variable]]

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

Whether the Piecewise relation is defined for a TimeSeries or a single variable.

required

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

ShareAllocationModel

ShareAllocationModel(
    model: SystemModel,
    shares_are_time_series: bool,
    label_of_element: Optional[str] = None,
    label: Optional[str] = None,
    label_full: Optional[str] = None,
    total_max: Optional[Scalar] = None,
    total_min: Optional[Scalar] = None,
    max_per_hour: Optional[NumericData] = None,
    min_per_hour: Optional[NumericData] = None,
)

Bases: Model

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

add_share
add_share(name: str, expression: LinearExpression)

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
add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None

PreventSimultaneousUsageModel

PreventSimultaneousUsageModel(
    model: SystemModel,
    variables: List[Variable],
    label_of_element: str,
    label: str = 'PreventSimultaneousUsage',
)

Bases: Model

Prevents multiple Multiple Binary variables from being 1 at the same time

Only 'classic type is modeled for now (# "classic" -> alle Flows brauchen Binärvariable:) In 'new', the binary Variables need to be forced beforehand, which is not that straight forward... --> TODO maybe

"new":

eq: flow_1.on(t) + flow_2.on(t) + .. + flow_i.val(t)/flow_i.max <= 1 (1 Flow ohne Binärvariable!)

Anmerkung: Patrick Schönfeld (oemof, custom/link.py) macht bei 2 Flows ohne Binärvariable dies:

1) bin + flow1/flow1_max <= 1

2) bin - flow2/flow2_max >= 0

3) geht nur, wenn alle flow.min >= 0

--> könnte man auch umsetzen (statt force_on_variable() für die Flows, aber sollte aufs selbe wie "new" kommen)

Attributes

label_full property
label_full: str

Used to construct the names of variables and constraints

Functions

add
add(
    item: Union[Variable, Constraint, Model], short_name: Optional[str] = None
) -> Union[linopy.Variable, linopy.Constraint, Model]

Add a variable, constraint or sub-model to the model

Parameters:

Name Type Description Default
item Union[Variable, Constraint, Model]

The variable, constraint or sub-model to add to the model

required
short_name Optional[str]

The short name of the variable, constraint or sub-model. If not provided, the full name is used.

None