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

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 If defining_bounds are given, creates sufficient lower bounds

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

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

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

Parameters:

Name Type Description Default
previous_values List[Optional[NumericData]]

List of previous values of the defining variables. In Range [0, inf] or None (ignored)

required
epsilon float

Tolerance for equality to determine "off" state, default is 1e-5.

1e-05

Returns:

Type Description
ndarray

A binary array (0 and 1) indicating the previous on/off states of the variables.

ndarray

Returns array([0]) if no previous values are available.

compute_consecutive_duration staticmethod
compute_consecutive_duration(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.

hours_per_timestep is handled in a way, that maximizes compatability. Its length must only be as long as the last consecutive duration in binary_values.

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.

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

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, label: str, piecewise_variables: Dict[str, Piecewise], zero_point: Optional[Union[bool, Variable]], as_time_series: bool)

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.

required
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