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_el'
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:
Outputs:
As components may have multiple outputs they are grouped in subsets. The order is given by the order of outputs inside the attribute outputs of the entitiy.
Entities:
Timesteps:
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:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all outputs of entitiy (bus)
.
beeing the set of all inputs of entitiy (bus)
.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
-
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:
With
and
beeing the set of unique ids for all entities grouped in the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
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:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
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:
For investment for component:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all outputs of entitiy (component)
. ———- model : OptimizationModel() instance
An object to be solved containing all Variables, Constraints, Data.block : SimpleBlock()
-
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:
With
and
beeing the set of unique ids for all entities grouped in the attribute block.objs.
beeing the set of all outputs of entitiy
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
oemof.solph.linear_constraints.
add_output_gradient_calc
(model, block, grad_direc='both')[source]¶ Add constraint to calculate the gradient between two timesteps (positive and negative)
The mathematical formulation for constraints are as follows:
Positive gradient:
Negative gradient:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
- 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:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all second outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
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:
For euivalent power:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all second outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
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:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
- 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:With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
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:
Charge:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
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:
Extra constraints for last timesteps:
With
and
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.
- block (SimpleBlock()) –
-
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:
Extra constraint for the last timesteps:
With
and
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.
- block (SimpleBlock()) –
-
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:
If gradient direction is negative:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
- 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:
With
and
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.
- block (SimpleBlock()) –
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_startup_constraints
(model, block)[source]¶ Creates constraints to model the start up of a components.
The mathematical formulation of constraint is as follows:
With
and
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.
- block (SimpleBlock()) –
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_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:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
-
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:
If side is input:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
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()) –
- 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):
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- ref (string) – string to check if capex is referred to capacity (storage) or output (e.g. powerplant)
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_curtailment_costs
(model, block=None)[source]¶ Cost term for dispatchable sources in linear objective.
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_excess_slack_costs
(model, block=None)[source]¶ Artificial cost term for excess slack variables.
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- Returns –
- --------- –
- 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
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_opex_fix
(model, block, ref=None)[source]¶ Fixed operation expenditure term for linear objective function.
If reference is output (e.g. powerplants):
If reference is capacity (e.g. storages):
If investment:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- ref (string) – string to check if capex is referred to capacity (storage) or output (e.g. powerplant)
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_opex_var
(model, block, ref='output')[source]¶ Variable operation expenditure term for linear objective function.
If reference of opex is output:
If reference of opex is input:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data.
- block (SimpleBlock()) –
- ref (string) – Reference side on which opex are based on (e.g. powerplant MWhth -> input or MWhel -> output)
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_ramping_costs
(model, block, grad_direc='positive')[source]¶ Add gradient costs for components to linear objective expression.
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- grad_direc (string) – direction of gradient for which the costs are added to the objective expression
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_revenues
(model, block, ref='output')[source]¶ Revenue term for linear objective function.
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_shortage_slack_costs
(model, block=None)[source]¶ Artificial cost term for shortage slack variables.
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_shutdown_costs
(model, block)[source]¶ Adds shutdown costs for components to objective expression
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- Returns –
- --------- –
- Expression –
-
oemof.solph.objective_expressions.
add_startup_costs
(model, block)[source]¶ Adds startup costs for components to objective expression
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
Parameters: - model (OptimizationModel() instance) –
- block (SimpleBlock()) –
- Returns –
- --------- –
- Expression –
oemof.solph.optimization_model module¶
@contact Simon Hilpert (simon.hilpert@fh-flensburg.de)
-
class
oemof.solph.optimization_model.
OptimizationModel
(energysystem)[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.) –
-
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
-
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 isom.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 ofEntity
.Time series belonging only to one object, like e.g. shadow prices of commodities on a certain
Bus
, dispatch values of aDispatchSource
or storage values of aStorage
are treated as belonging to an edge looping from the object to itself. This means they can be accessed viaom.results()[object][object]
.Note that the optimization model has to be solved prior to invoking this method.
-
solve
(solver='glpk', solver_io='lp', debug=False, duals=False, **kwargs)[source]¶ Method that takes care of the communication with the solver to solve the optimization model
Parameters: - self (pyomo.ConcreteModel) –
- str (solver_io) –
- str –
- or interface) 'lp','nl','python' ((file) –
- **kwargs (other arguments for the pyomo.opt.SolverFactory.solve()) –
- method –
Returns: self
Return type: solved pyomo.ConcreteModel() instance
-
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.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. If an invest model is used an additional optimization variable indexed by the edges is created to handle “flexible” upper bounds of the edge variable by using an additional constraint. The following variables are created: Variables for all the edges, variables for the state of charge of storages. (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’),...]
Returns: - The variables are added as a attribute to the optimization model object
- model.
-
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
With investment:
If side is input:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all first outputs of entitiy (component)
.
beeing the set of all inputs of entitiy (component)
.
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:
With
and
beeing the set of unique ids for all entities grouped inside the attribute block.objs.
beeing the set of all inputs of entitiy (component)
.
Parameters: - model (OptimizationModel() instance) – An object to be solved containing all Variables, Constraints, Data Attributes are altered of the model
- block (SimpeBlock()) –
-
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 (SimpeBlock()) –
- outagetype (string) – Type 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 is off
- 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:
If investment:
With
and
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 Bounds are altered at model attributes (variables) of model
- block (SimpleBlock()) –
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.