oemof.solph package

Submodules

oemof.solph.linear_constraints module

The linear_contraints module contains the pyomo constraints wrapped in functions. These functions are used by the ‘_assembler- methods of the OptimizationModel()-class.

The module frequently uses the dictionaries I and O for the construction of constraints. I and O contain all components’ uids as dictionary keys and the relevant input input/output uids as dictionary items.

Illustrative Example:

Consider the following example of a chp-powerplant modeled with 4 entities (3 busses, 1 component) and their unique ids being stored in a list called uids:

>>> uids = ['bus_el', 'bus_th', 'bus_coal','pp_coal']
>>> I = {'pp_coal': 'bus_coal'}
>>> O = {'pp_coal': ['bus_el', 'bus_th']}
>>> print(I['pp_coal'])
bus_coal

In mathematical notation I, O can be seen as indexed index sets The elements of the sets are the uids of all components (index: e). The the inputs/outputs uids are the elements of the accessed set by the component index e. Generally the index e is the index for the uids-sets containing the uids of objects for which the constraints are build. For all mathematical constraints the following definitions hold:

Inputs: \mathcal{I}_e = \text{Input-uids of entity } e \in \mathcal{E}

Outputs: \mathcal{O}_e = \text{All output-uids of entity } e \in \mathcal{E}

Simon Hilpert (simon.hilpert@fh-flensburg.de)

oemof.solph.linear_constraints.add_bus_balance(model, block=None)[source]

Adds constraint for the input-ouput balance of bus objects.

The mathematical formulation for the balance is as follows:

\sum_{i \in \mathcal{I}_e} w_{i, e}(t) = \sum_{o \in O_e}     w_{e, o}(t), \qquad \forall e, \forall t

With e  \in \mathcal{E}_B, t \in \mathcal{T}

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_dispatch_source(model, block)[source]

Creates dispatchable source bounds/constraints.

First the maximum value for the output of the source will be set. Then a constraint is defined that determines the dispatch of the source. This dispatch can be used in the objective function to add cost for dispatch of sources.

The mathemathical formulation of the constraint is as follows:

w^{cut}_{e,o_e}(t) = V^{norm}_e(t) \cdot \overline{W}_{e,o_e} -     w_{e,o_e}(t),  \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped in the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{O}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_eta_total_chp_relation(model, block)[source]

Adds constraints for input-(output1,output2) relation as simple function for all objects in block.objs.

The mathematical formulation of the input-output relation of a simple transformer is as follows:

w_{i_e, e}(t) \cdot \eta^{total}_e =     w_{e, o_{e,1}}(t) + w_{e, o_{e,2}}(t), \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{IOO}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_fixed_source(model, block)[source]

Sets fixed source bounds and constraints for all objects in block.objs

The mathematical formulation is as follows:

w_{e,o_e}(t) = V^{norm}_e(t) \cdot \overline{W}_{e, o_e},      \qquad \forall e, \forall t

For investment for component:

w_{e, o}(t) \leq (\overline{W}_{e, o_e} + \overline{w}^{add}_{e_o})     \cdot V^{norm}_e(t), \qquad \forall e, \forall t

\overline{w}^{add}_{e_o}  \leq \overline{W}^{add}_{e_o},     \qquad \forall e

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{O}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_global_output_limit(model, block=None)[source]

Adds constraints to set limit for variables as sum over the total timehorizon for all objects in block.objs

The mathematical formulation is as follows:

\sum_{t \in \mathcal{T}} \sum_{o \in \mathcal{O}_e} w_{e, o}(t)     \leq \overline{O}^{global}_e, \qquad \forall e \in E

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally: \mathcal{E} \subset \{\mathcal{E}_{B},\mathcal{E}_{O}\}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_output_gradient_calc(model, block, grad_direc='both', idx=0)[source]

Add constraint to calculate the gradient between two timesteps (positive and negative)

The mathematical formulation for constraints are as follows:

Positive gradient:

w_{e,o_{e,n}}(t) - w_{e, o_{e,n}}(t-1) \leq g^{pos}_{e_o}(t)    \qquad \forall e, \forall t / t=1

g^{pos}_{e_o}(t) \leq \overline{G}^{pos}_{e_o}, \qquad \forall e, \forall t

Negative gradient:

w_{e,o_{e,n}}(t-1) - w_{e,o_{e,n}}(t) \leq g^{neg}_{e_o}(t)    \qquad \forall e, \forall t / t=1

g^{neg}_{e_o}(t) \leq \overline{G}^{neg}_{e_o}, \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped in the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{C}.

n indicates the n-th output of component e (arg: idx)

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
  • grad_direc (string) – string defining the direction of the gradient constraint. (‘positive’, negative’, ‘both’)
oemof.solph.linear_constraints.add_simple_chp_relation(model, block)[source]

Adds constraint for output-output relation for all simple combined heat an power units in block.objs.

The mathematical formulation for the constraint is as follows:

\frac{w_{e, o_{e,1}}(t)}{\eta_{e, o_{e,1}}(t)} =     \frac{w_{e, o_{e,2}}(t)}{\eta_{e, o_{e,2}}(t)},     \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{IOO}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_simple_extraction_chp_relation(model, block)[source]

Adds constraints for power to heat relation and equivalent output for a simple extraction combined heat an power units. The constraints represent the PQ-region of the extraction unit and are set for all objects in block.objs

The mathematical formulation is as follows:

For Power/Heat ratio:

w_{e,o_{e,1}}(t) = w_{e, o_{e,2}}(t) \cdot \sigma_{e},     \qquad \forall e, \forall t

\sigma_{e} = \text{Power to heat ratio of entity } e

For euivalent power:

w_{i_e,e}(t) = \frac{w_{e,o_{e,1}}(t) + \beta_e \cdot     w_{e, o_{e,2}}(t)}{\eta_{i_e, o_{e,1}}}

\beta_e = \text{Power loss index of entity } e

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{IOO}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_simple_io_relation(model, block, idx=0)[source]

Adds constraints for input-output relation as simple function for all objects in block.objs.

The mathematical formulation of the input-output relation of a simple transformer is as follows:

w_{i_e, e}(t) \cdot \eta_{i,o_{e,n}} = w_{e, o_{e,n}}(t),     \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally \mathcal{E} \subset \{\mathcal{E}_{IO}, \mathcal{E}_{IOO}\}.

n indicates the n-th output of component e (arg: idx)

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
  • idx (integer) – Index to choose which output to select (from list of Outputs: O[e][idx])
oemof.solph.linear_constraints.add_storage_balance(model, block)[source]

Constraint to build the storage balance in every timestep

The mathematical formulation of the constraint is as follows:

l_e(t) = l_e(t-1) \cdot (1 - C^{loss}(e))     - \frac{w_{e,o_e}(t)}{\eta^{out}_e}     + w_{i_e,e}(t) \cdot \eta^{in}_e  \qquad \forall e, \forall t \in [2, t_{max}]

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped in the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{S}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_constraints.add_storage_charge_discharge_limits(model, block)[source]

Constraints that limit the discharge and charge power by the c-rate

Constraints are for investment models only.

The mathematical formulation for the constraints is as follows:

Discharge:

w_{e, o_e}(t) \leq (\overline{L}_e + \overline{l}^{add}_e)         \cdot C^{rate}_{o_e}
\qquad \forall e, \forall t

Charge:

w_{i_e, e}(t) \leq (\overline{L}_e + \overline{l}^{add}_e)         \cdot C^{rate}_{i_e}
\qquad \forall e, \forall t

oemof.solph.linear_constraints.add_two_inputs_one_output_relation(model, block)[source]

Adds constraint for the input-output relation of a post heating transformer with two input flows.

Then the amount of all input flows multiplied with their efficiency will be the output flow. The efficiency of the each will be calculated so that the sum of the efficiency of both flows might be greater than one.

The mathematical formulation for the constraint is as follows:

w_{e,i_{e,1}}(t)\cdot\eta_{e,i_{e,1}}(t)+w_{e,i_{e,2}}(t)\cdot
\eta_{e,i_{e,2}}(t)=w_{e,o_{e}},\qquad\forall e,\forall t\qquad\qquad

w_{e,i_{e,1}}(t)=w_{e,i_{e,2}}(t)\cdot f(t),\quad\forall e,\forall t
\qquad\\

With e\in\mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally: \mathcal{E} \subset \mathcal{E}_{IIO}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class

oemof.solph.linear_mixed_integer_constraints module

The module contains linear mixed integer constraints.

@author: Simon Hilpert (simon.hilpert@fh-flensburg.de)

oemof.solph.linear_mixed_integer_constraints.add_minimum_downtime(model, block)[source]

Adds minimum downtime constraints for for components grouped inside block.objs.

The mathematical formulation for constraints is as follows:

(y_e(t-1)-y_e(t)) \cdot T^{min,off}_e \leq T^{min,off}_e -      \sum_{\gamma=0}^{T^{min,off}_e-1} y_e(t+\gamma)       \qquad \forall e, \forall t \in [2, t_{max}-t_{min,off}]

Extra constraints for last timesteps:

(y_e(t-1)-y_e(t)) \cdot T^{min,off}_e \leq T^{min,off}_e -      \sum_{\gamma=0}^{t_{max}-t} y_e(t+\gamma)       \qquad \forall e, \forall t \in [t_{max}-t_{min,off}, t_{max}]

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_mixed_integer_constraints.add_minimum_uptime(model, block)[source]

Adds minimum uptime constraints for for components in block

The mathematical formulation for constraints is as follows:

(y_e(t) - y_e(t-1)) \cdot T^{min,on}_e \leq       \sum_{\gamma=0}^{T^{min,on}_e-1} y_e(t+\gamma)       \qquad \forall e, \forall t \in [2, t_{max}-t_{min,on}]

Extra constraint for the last timesteps:

(y_e(t) - y_e(t-1)) \cdot T^{min,on}_e \leq        \sum_{\gamma=0}^{t_{max}-t} y_e(t+\gamma)        \qquad \forall e, \forall t \in [t_{max}-t_{min,on}, t_{max}]

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_mixed_integer_constraints.add_output_gradient_constraints(model, block, grad_direc='both')[source]

Creates constraints to model the output gradient for milp-models.

If gradient direction is positive:

w_{e,o_{e,1}}(t) - w_{e,o_{e,1}}(t-1) \leq \overline{G}^{pos}_{e_{o,1}} +     \underline{W}_{e, o_{e,1}} \cdot (1 - y_e(t))

If gradient direction is negative:

w_{e,o_{e,1}}(t-1) - w_{e,o_{e,1}}(t) \leq \overline{G}^{neg}_{e_{o,1}} +     \underline{W}_{e, o_{e,1}} \cdot (1 - y_{e}(t-1))

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
  • grad_direc (string) – direction of gradient (“both”, “positive”, “negative”)

References

[1]M. Steck (2012): “Entwicklung und Bewertung von Algorithmen zur Einsatzplanerstelleung virtueller Kraftwerke”, PhD-Thesis, TU Munich, p.38
oemof.solph.linear_mixed_integer_constraints.add_shutdown_constraints(model, block)[source]

Creates constraints to model the shut down of a component.

The mathematical formulation for the constraint is as follows:

y_e(t-1) - y_e(t) \leq z^{stop}_e(t), \qquad     \forall e, \forall t

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_mixed_integer_constraints.add_startup_constraints(model, block)[source]

Creates constraints to model the start up of a components.

The mathematical formulation of constraint is as follows:

y_e(t) - y_e(t-1) \leq z^{start}_e(t), \qquad         \forall e, \forall t

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_mixed_integer_constraints.add_variable_linear_eta_relation(model, block)[source]

Adds constraint for input-output relation for all units with variable efficiency grouped in block.objs.

The mathematical formulation for the constraint is as follows:

w_{i_e, e}(t) = y_e(t) \cdot c_1 + c_2 \cdot w_{e, o_{e,1}}(t),     \qquad \forall e, \forall t

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
oemof.solph.linear_mixed_integer_constraints.maximum_starts_per_period(model, block, period=24)[source]
Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data. Bounds are altered at model attributes (variables) of model
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
  • period (array like) – length of period
oemof.solph.linear_mixed_integer_constraints.set_bounds(model, block, side='output')[source]

Set upper and lower bounds via constraints.

The bounds are set with constraints using the binary status variable of the components. The mathematical formulation is as follows:

If side is output:

w_{e, o_{e,1}}(t) \leq \overline{W}_{e, o_{e,1}} \cdot y_e(t),     \qquad \forall e, \forall t

w_{e, o_{e,1}}(t) \geq \underline{W}_{e, o_{e,1}} \cdot y_e(t),     \qquad \forall e, \forall t

If side is input:

w_{i_e, e}(t) \leq \overline{W}_{i_e, e} \cdot y_e(t),     \qquad \forall e, \forall t

w_{i_e, e}(t) \geq \underline{W}_{i_e, e} \cdot y_e(t),     \qquad \forall e, \forall t

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data. Bounds are altered at model attributes (variables) of model
  • block (SimpleBlock()) – block to group all constraints and variables etc., block corresponds to one oemof base class
  • side (string) – string to select on which side the bounds should be set (ìnput, output)

oemof.solph.objective_expressions module

The module contains different objective expression terms.

@author: Simon Hilpert (simon.hilpert@fh-flensburg.de)

oemof.solph.objective_expressions.add_capex(model, block, ref='output')[source]

Add capital expenditure to linear objective.

If reference is output (e.g. powerplants):

If reference is capacity (e.g. storages):

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • ref (string) – string to check if capex is referred to capacity (storage) or output (e.g. powerplant)
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_curtailment_costs(model, block=None)[source]

Cost term for dispatchable sources in linear objective.

\sum_e \sum_ t w^{cut}_e(t) \cdot C^{cut}_e

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_excess_slack_costs(model, block=None)[source]

Artificial cost term for excess slack variables.

\sum_e \sum_t EXCESS_e(t) \cdot C^{excess}_e

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock() block : SimpleBlock()) – block to group all objects corresponding to one oemof base class
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_input_costs(model, block)[source]

Adds costs for usage of input (fuel, elec, etc. ) if not included in opex

\sum_e \sum_t w_{i_e, e}(t) \cdot C_{i_e, e}(t)

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_opex_fix(model, block, ref=None)[source]

Fixed operation expenditure term for linear objective function.

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • ref (string) – string to check if capex is referred to capacity (storage) or output (e.g. powerplant)
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_opex_var(model, block, ref='output', idx=0)[source]

Variable operation expenditure term for linear objective function.

If reference of opex is output:

\sum_e \sum_t w_{e, o_{e,1}}(t) \cdot C_{e, o_{e,1}}(t)

If reference of opex is input:

\sum_e \sum_t w_{i_e,e}(t) \cdot C_{i_e, e}(t)

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • ref (string) – Reference side on which opex are based on (e.g. powerplant MWhth -> input or MWhel -> output)
  • idx (int) – Index to select output/input of list of inputs/ouputs if multiple i/o exist
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_ramping_costs(model, block, grad_direc='positive')[source]

Add gradient costs for components to linear objective expression.

\sum_e \sum_t g^{pos}_e(t) \cdot C^{g,neg}_e

\sum_e \sum_t g^{neg}_e(t) \cdot C^{g,pos}_e

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • grad_direc (string) – direction of gradient for which the costs are added to the objective expression
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_revenues(model, block, ref='output', idx=0)[source]

Revenue term for linear objective function.

\sum_e \sum_t w_{e, o_{e,1}}(t) \cdot R_{e, o_{e,1}}(t)

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • ref (string) – Reference side for revnues (‘output’ or ‘input’ Note: ‘input’ not defined)
  • idx (integer) – Integer indicating which output from list to select if entity has multiple outputs
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_shortage_slack_costs(model, block=None)[source]

Artificial cost term for shortage slack variables.

\sum_e \sum_t SHORTAGE_e(t) \cdot C^{shortage}_e

With e  \in E and E beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_shutdown_costs(model, block)[source]

Adds shutdown costs for components to objective expression

\sum_{e} \sum_t z^{stop}_e(t) \cdot C^{stop}_e

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
Returns:

Return type:

Expression

oemof.solph.objective_expressions.add_startup_costs(model, block)[source]

Adds startup costs for components to objective expression

\sum_{e} \sum_{t} z^{start}_e(t) \cdot C^{start}_e

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
Returns:

Return type:

Expression

oemof.solph.objective_expressions.linearized_invest_costs(model, block, ref)[source]

This functionality add linearized costs with sos2-constraint.

The capex attribute of objects in ‘block.objs’- needs to be a list of tuples with interpolation points. Every first element is the absolut value of investment for the corresponding size of investment in the second element of the tuple.

e.g. capex = [(10, 20), (20, 15),..]

Parameters:
  • model (OptimizationModel() instance) –
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • ref (string) – string to check if capex is referred to capacity (storage) or output (e.g. powerplant)

oemof.solph.optimization_model module

@contact Simon Hilpert (simon.hilpert@fh-flensburg.de)

class oemof.solph.optimization_model.OptimizationModel(energysystem, loglevel=20)[source]

Bases: pyomo.core.base.PyomoModel.ConcreteModel

Create Pyomo model of the energy system.

Parameters:
  • entities (list with all entity objects) –
  • timesteps (list with all timesteps as integer values) –
  • options (nested dictionary with options to set.) –
build_bus_constraints(bbt)[source]
build_component_constraints(cbt)[source]
default_assembler(block)[source]

Method for setting optimization model objects for blocks

Parameters:
  • self (OptimizationModel() instance) –
  • block (SimpleBlock()) –
edges(components)[source]

Method that creates a list with all edges for the objects in components.

Parameters:
  • self
  • components (list of component objects) –
Returns:

edges

Return type:

list with tupels that represent the edges

objective_assembler(objective_options)[source]

calls functions to add predefined objective functions

Parameters:
  • self (OptimizationModel() instance) –
  • objective_options (dict) – dictionary with infos about objects. key “function” hold function to build objective
results()[source]

Returns a nested dictionary of the results of this optimization model.

The dictionary is keyed by the Entities of the optimization model, that is om.results()[s][t] holds the time series representing values attached to the edge (i.e. the flow) from s to t, where s and t are instances of Entity.

Time series belonging only to one object, like e.g. shadow prices of commodities on a certain Bus, dispatch values of a DispatchSource or storage values of a Storage are treated as belonging to an edge looping from the object to itself. This means they can be accessed via om.results()[object][object].

Object attributes holding optimization results, like e.g. add_cap for storage objects, can be accessed like this:

om.results()[s].add_cap()

where s is a storage object.

The value of the objective function is stored under the om.results().objective attribute.

Note that the optimization model has to be solved prior to invoking this method.

solve(**kwargs)[source]

Method that takes care of the communication with the solver to solve the optimization model.

Parameters:
  • self (pyomo.ConcreteModel() object) –
  • **kwargs (keywords) – Possible keys can be set see below
  • string (solver) – solver to be used e.g. “glpk”,”gurobi”,”cplex”
  • debug (boolean) – If True model is solved in debug mode. lp-file is written.
  • duals (boolean) – If True, duals and reduced costs are imported from the solver results
  • verbose (boolean) – If True informations are printed
  • solver_io (string) – pyomo solver interface file format: “lp”,”python”,”nl”, etc.
  • solve_kwargs (dict) – Other arguments for the pyomo.opt.SolverFactory.solve() method Example : {“solver_io”:”lp”}
  • solver_cmdline_options (dict) – Dictionary with command line options for solver Examples: {“mipgap”:”0.01”} results in “–mipgap 0.01” {“interior”:” “} results in “–interior”
Returns:

self

Return type:

solved pyomo.ConcreteModel() instance

update_objective(objective_options=None)[source]

Updates the objective function with new parameters from entities

Parameters:
  • self (OptimizationModel() instance) –
  • objective_options (dict) – dictionary with infos about objects. key “function” hold function to build objective
write_lp_file(path=None, filename='problem.lp')[source]
oemof.solph.optimization_model.assembler(e, om, block)[source]
Assemblers are the functions adding constraints to an optimization
model for a set of objects.

This is the most general form of assembler function, called only if no other, more specific assemblers have been found. Since we don’t know what to do in this case, we can only throw a TypeError.

Parameters:
  • entity (An object. Only used to figure out which assembler function to call) – by dispatching on its type. Not used otherwise. It’s a good idea to set this to None if the function is called directly via assembler.registry.
  • om (The optimization model. Should be an instance of) – pyomo.ConcreteModel.
  • block (A pyomo block.) –
Returns:

om – bus balances.

Return type:

The optimization model passed in as an argument, with additional

oemof.solph.predefined_objectives module

This module contains predefined objectives that can be used to model energy systems.

@author: Simon Hilpert (simon.hilpert@fh-flensburg.de)

oemof.solph.predefined_objectives.minimize_cost(self, cost_objects=None, revenue_objects=None)[source]

Builds objective function that minimises the total costs.

Costs included are:
opex_var, opex_fix, curtailment_costs (dispatch sources), annualised capex (investment components)
Parameters:
  • self (pyomo model instance) –
  • cost_blocks (array like) – list containing classes of objects that are included in cost terms of objective function
  • revenue_blocks (array like) – list containing classes of objects that are included in revenue terms of objective function

oemof.solph.pyomo_fastbuild module

@author: Simon Hilpert

oemof.solph.pyomo_fastbuild.l_constraint(model, name, constraints, *args)[source]

A replacement for pyomo’s Constraint that quickly builds linear constraints.

Instead of: model.constraint_name = Constraint(index1,index2,...,rule=f)

Call: l_constraint(model, constraint_name, constraints, index1, index2,...)

This is a copy of the code from the python module pypsa. Thanks to Tom Brown / Jonas Hoersch for implementing it!

Parameters:
  • model (pyomo.ConcreteModel() / SimpleBlock() instance) – pyomo model or block with constructed components
  • name (string) – Name of constraint to be constructed
  • constraints (dict) –

    Constraints is a dictionary of constraints of the form:

    constraints[i] = [[(coeff1, var1), (coeff2, var2),...], sense,
    constant_term]

    sense is one of “==”,”<=”,”>=”.

    constant_term is constant rhs of equation

    I.e. variable coefficients are stored as a list of tuples.

  • *args – arguments passed to the pyomo.Constraint() class.
oemof.solph.pyomo_fastbuild.mutate_variable(var=None, value=None, bounds=(0, None), fix=False, index=None)[source]

Mutates existing pyomo variable, could be used to extend an emtpy Var() object or an existing indexed pyomo variable. It’s possible to overwrite information for existing indices.

Parameters:
  • var (pyomo.core.base.var.Var() object) – pyomo variable to be extended
  • value (list) – values of variable in list
  • bounds (list) – lower and upper bounds of variable as tuples in list
  • index (type of var._index elements (most likely tuple)) – list of indices for extension (Warning: if existing indices are used, data for for these indices will be overwritten.)
  • fix (list) – list with boolean elements, if true, variable value is fixed, i.e. converted to parameter in opt-problem

Example

extend_variable(om.w, value=[10], bounds=[(0,10)], fix=[True],
index=[(‘bel’,’sink’,155)])

oemof.solph.variables module

Module contains variable definitions and constraint to bound variables (e.g. for investement).

@author: Simon Hilpert (simon.hilpert@fh-flensburg.de)

oemof.solph.variables.add_binary(model, block, relaxed=False)[source]

Creates all status variables (binary) for block.objs

Status variable indicates if a unit is turned on or off. E.g. if a transformer is switched on/off -> y=1/0

Parameters:
  • model (pyomo.ConcreteModel()) – A pyomo-object to be solved containing all Variables, Constraints, Data Variables are added as attributes to the model
  • objs (array_like (list)) – all components for which the status variable is created
  • relaxed (boolean) – If True “binary” variables will be created as continuous variables with bounds of 0 and 1.
oemof.solph.variables.add_continuous(model, edges)[source]

Adds all variables corresponding to the edges of the bi-partite graph for all timesteps.

The function uses the pyomo class Var() to create the optimization variables. As index-sets the provided edges of the graph (in general all edges) and the defined timesteps are used. The following variables are created: Variables for all the edges (If specific components such as disptach sources and storages exist.)

Parameters:
  • model (OptimizationModel() instance) – A object to be solved containing all Variables, Constraints, Data Variables are added as attributes to the model
  • edges (array_like (list)) – edges will be a list containing tuples representing the directed edges of the graph by using unique ids of components and buses. e.g. [(‘coal’, ‘pp_coal’), (‘pp_coal’, ‘b_el’),...]
oemof.solph.variables.set_bounds(model, block, side='output')[source]

Sets bounds for variables that represent the weight of the edges of the graph if investment models are calculated.

For investment models upper and lower bounds will be modeled via additional constraints. The mathematical description for the constraint is as follows:

If side is output

w_{e, o_{e,1}}(t) \leq \overline{W}_{e, o_{e,1}} \qquad     \forall e, \forall t

With investment:

w_{e, o_{e,1}}(t) \leq \overline{W}_{e, o_{e,1}} +     \overline{w}^{add}_{o_e}, \qquad \forall e, \forall t

If side is input:

w_{i_{e}, e}(t) \leq \overline{W}_{i_{e}, e} \qquad     \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data Constraints are added as attributes to the model
  • block (SimpleBlock()) –
  • side (string) – Side of component for which the bounds are set (‘input’ or ‘output’)
oemof.solph.variables.set_fixed_sink_value(model, block)[source]

Setting a value und fixes the variable of input.

The mathematical formulation is as follows:

w_{i_e, e}(t) = V_e(t), \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally \mathcal{E} \subset \mathcal{E}_{I}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data Attributes are altered of the model
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
oemof.solph.variables.set_outages(model, block, outagetype='period', side='output')[source]

Fixes component input/output to zeros for modeling outages.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class
  • outagetype (string) – String indicates how to model outages of component. If outages is scalar ‘period’ yield one timeblock where component is off, while ‘random_days’ will sample random days over the timehorizon where component will forced to be offline.
  • side (string) – Side of component to fix to zero: ‘output’, ‘input’.
oemof.solph.variables.set_storage_cap_bounds(model, block)[source]

Alters/sets upper and lower bounds for variables that represent the absolut state of charge e.g. filling level of a storage component.

For investment models upper and lower bounds will be modeled via additional constraints. The mathematical description for the constraint is as follows:

\underline{L}_e \leq l_e(t) \leq \overline{L}_e,     \qquad \forall e, \forall t

If investment:

l_e(t)  \leq \overline{L}_e + \overline{l}^{add}_e,     \qquad \forall e, \forall t

With e  \in \mathcal{E} and \mathcal{E} beeing the set of unique ids for all entities grouped inside the attribute block.objs.

Additionally \mathcal{E} \subset \mathcal{E}_{S}.

Parameters:
  • model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data Bounds are altered at model attributes (variables) of model
  • block (SimpleBlock()) – block to group all objects corresponding to one oemof base class

Module contents

The solph-package contains funtionalities for creating and solving an optimizaton problem. The problem is created from oemof base classes. Solph depend on pyomo.