oemof.solph package¶
Submodules¶
oemof.solph.blocks module¶
Creating sets, variables, constraints and parts of the objective function for the specified groups.

class
oemof.solph.blocks.
BinaryFlow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
The following sets are created: (> see basic sets at
OperationalModel
) BINARY_FLOWS
 A set of flows with the attribute
binary
of typeoptions.Binary
.  MIN_FLOWS
 A subset of set BINARY_FLOWS with the attribute
min
greater than zero for at least one timestep in the simulation horizon.  STARTUP_FLOWS
 A subset of set BINARY_FLOWS with the attribute
startup_costs
being not None.  SHUTDOWN_FLOWS
 A subset of set BINARY_FLOWS with the attribute
shutdown_costs
being not None.
The following variable are created:
 Status variable (binary)
om.BinaryFLow.status
:  Variable indicating if flow is >= 0 indexed by FLOWS
 Startup variable (binary)
om.BinaryFlow.startup
:  Variable indicating startup of flow (component) indexed by STARTUP_FLOWS
 Shutdown variable (binary)
om.BinaryFlow.shutdown
:  Variable indicating shutdown of flow (component) indexed by SHUTDOWN_FLOWS
The following constraints are created:
 Minimum flow constraint
om.BinaryFlow.min[i,o,t]
 Maximum flow constraint
om.BinaryFlow.max[i,o,t]
 Startup constraint
om.BinaryFlow.startup_constr[i,o,t]
 Shutdown constraint
om.BinaryFlow.shutdown_constr[i,o,t]
The following parts of the objective function are created:
 If
binary.startup_costs
is set by the user:  If
binary.shutdown_costs
is set by the user:

class
oemof.solph.blocks.
Bus
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for all balanced buses.
The following constraints are build:
 Bus balance
om.Bus.balance[i, o, t]
 Bus balance

class
oemof.solph.blocks.
DiscreteFlow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
The following sets are created: (> see basic sets at
OperationalModel
) DISCRETE_FLOWS
 A set of flows with the attribute
discrete
of typeoptions.Discrete
.

class
oemof.solph.blocks.
Flow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Flow block with definitions for standard flows.
The following sets are created: (> see basic sets at
OperationalModel
) SUMMED_MAX_FLOWS
 A set of flows with the attribute
summed_max
being not None.  SUMMED_MIN_FLOWS
 A set of flows with the attribute
summed_min
being not None.  NEGATIVE_GRADIENT_FLOWS
 A set of flows with the attribute
negative_gradient
being not None.  POSITIVE_GRADIENT_FLOWS
 A set of flows with the attribute
positive_gradient
being not None
The following constraints are build:
 Flow max sum
om.Flow.summed_max[i, o]
 Flow min sum
om.Flow.summed_min[i, o]
 Negative gradient constraint
om.Flow.negative_gradient_constr[i, o]
:  Positive gradient constraint
om.Flow.positive_gradient_constr[i, o]
:
The following parts of the objective function are created:
 If
variable_costs
are set by the user:  Additionally, if
fixed_costs
are set by the user:
The expression can be accessed by
om.Flow.fixed_costs
and their value after optimization byom.Flow.fixed_costs()
. This works similar for variable costs with*.variable_costs
.

class
oemof.solph.blocks.
InvestmentFlow
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for all flows with
investment
being not None.The following sets are created: (> see basic sets at
OperationalModel
) FLOWS
 A set of flows with the attribute
invest
of typeoptions.Investment
.  FIXED_FLOWS
 A set of flow with the attribute
fixed
set to True  SUMMED_MAX_FLOWS
 A subset of set FLOWS with flows with the attribute
summed_max
being not None.  SUMMED_MIN_FLOWS
 A subset of set FLOWS with flows with the attribute
summed_min
being not None.  MIN_FLOWS
 A subset of FLOWS with flows having set a least minimum value for at least one timestep in the optimization model.
The following variables are created:
 invest
om.InvestmentFlow.invest[i, o]
 Value of the investment variable (i.e. equivalent to the nominal value of the flows after optimization (indexed by FLOWS)
The following constraints are build:
 Actual value constraint for fixed invest flows
om.InvestmentFlow.fixed[i, o, t]
 Lower bound (min) constraint for invest flows
om.InvestmentFlow.min[i, o, t]
 Upper bound (max) constraint for invest flows
om.InvestmentFlow.max[i, o, t]
 Flow max sum for invest flow
om.InvestmentFlow.summed_max[i, o]
 Flow min sum for invest flow
om.InvestmentFlow.summed_min[i, o]
The following parts of the objective function are created:
 Equivalent periodical costs (epc) expression
om.InvestmentFlow.investment_costs
:  Additionally, if
fixed_costs
are set by the user:
The expression can be accessed by
om.InvestmentFlow.fixed_costs
and their value after optimization byom.InvestmentFlow.fixed_costs()
. This works similar for variable costs with*.variable_costs
etc.

class
oemof.solph.blocks.
InvestmentStorage
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Storage with an
Investment
object.The following sets are created: (> see basic sets at
OperationalModel
) INVESTSTORAGES
 A set with all storages containing an Investment object.
 INITIAL_CAPACITY
 A subset of the set INVESTSTORAGES where elements of the set have an initial_capacity attribute.
 MIN_INVESTSTORAGES
 A subset of INVESTSTORAGES where elements of the set have an capacity_min attribute greater than zero for at least one time step.
The following variables are created:
 capacity
om.InvestmentStorage.capacity[n, t]
 Level of the storage (indexed by STORAGES and TIMESTEPS)
 invest
om.InvestmentStorage.invest[n, t]
 Nominal capacity of the storage (indexed by STORAGES)
The following constraints are build:
 Storage balance
 Initial capacity of
network.Storage
 Connect the invest variables of the storage and the input flow.
 Connect the invest variables of the storage and the output flow.
 Maximal capacity
om.InvestmentStorage.max_capacity[n, t]
 Minimal capacity
om.InvestmentStorage.min_capacity[n, t]
The following parts of the objective function are created:
 Equivalent periodical costs (investment costs):
 Additionally, if fixed costs are set by the user:
The expression can be accessed by
om.InvestStorages.fixed_costs
and their value after optimization byom.InvestStorages.fixed_costs()
. This works similar for investment costs with*.investment_costs
.

class
oemof.solph.blocks.
LinearTransformer
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Block for the linear relation of nodes with type class:.LinearTransformer
The following constraints are created:
 Linear relation
om.LinearTransformer.relation[i,o,t]
 Linear relation

class
oemof.solph.blocks.
Storage
(*args, **kwargs)[source]¶ Bases:
pyomo.core.base.block.SimpleBlock
Storages (no investment)
The following sets are created: (> see basic sets at
OperationalModel
) STORAGES
 A set with all
Storage
objects (and no attr:investement of typeInvestment
)
The following variables are created:
 capacity
 Capacity (level) for every storage and timestep. The value for the capacity at the beginning is set by the parameter initial_capacity or not set if initial_capacity is None. The variable of storage s and timestep t can be accessed by: om.Storage.capacity[s, t]
The following constraints are created:
 Storage balance
om.Storage.balance[n, t]
The following parts of the objective function are created:
 If
fixed_costs
is set by the user:
The fixed costs expression can be accessed by om.Storage.fixed_costs and their value after optimization by: om.Storage.fixed_costs().
oemof.solph.groupings module¶
list: Groupings needed on an energy system for it to work with solph.
 TODO: Maybe move this to the module docstring? It should be somewhere prominent
 so solph user’s immediately see that they need to use
GROUPINGS
when they want to create an energy system for use with solph.
If you want to use solph on an energy system, you need to create it with these groupings specified like this:
from oemof.network import EnergySystem import solph
energy_system = EnergySystem(groupings=solph.GROUPINGS)

oemof.solph.groupings.
constraint_grouping
(node)[source]¶ Grouping function for constraints.
This function can be passed in a list to
groupings
ofoemof.solph.network.EnergySystem
.
oemof.solph.models module¶

class
oemof.solph.models.
ExpansionModel
[source]¶ Bases:
pyomo.core.base.PyomoModel.ConcreteModel
An energy system model for optimized capacity expansion.

class
oemof.solph.models.
OperationalModel
(es, **kwargs)[source]¶ Bases:
pyomo.core.base.PyomoModel.ConcreteModel
An energy system model for operational simulation with optimized dispatch.
The following sets are created:
 NODES
 A set with all nodes of the given energy system.
 TIMESTEPS
 A set with all time steps of the given time horizon.
Parameters:  es (EnergySystem object) – Object that holds the nodes of an oemof energy system graph
 constraint_groups (list) – Solph looks for these groups in the given energy system and uses them
to create the constraints of the optimization problem.
Defaults to
OperationalModel.CONSTRAINTS
 timeindex (pandas DatetimeIndex) – The timeindex will be used to calculate the timesteps the timeincrement for the optimization model.
 timesteps (sequence (optional)) – Timesteps used in the optimization model. If provided as list or pandas.DatetimeIndex the sequence will be used to index the time dependent variables, constraints etc. If not provided we will try to compute this sequence from attr:timeindex.
 timeincrement (float or list of floats (optional)) – Timeincrement used in constraints and objective expressions. If type is ‘float’, internally will be converted to solph.plumbing.Sequence() object for time dependent timeincrement. If a list is provided this list will be taken. Default is calculated from timeindex if provided.
 following sets are created (**The) –
 NODES – A set with all oemof nodes.
 TIMESTEPS – A set with all timesteps for the optimization problem.
 FLOWS – A 2 dimensional set with all flows. Index: (source, target)
 NEGATIVE_GRADIENT_FLOWS – A subset of set FLOWS with all flows where attribute negative_gradient is set.
 POSITIVE_GRADIENT_FLOWS – A subset of set FLOWS with all flows where attribute positive_gradient is set.
 following variables are created (**The) –
 flow – Flow from source to target indexed by FLOWS, TIMESTEPS. Note: Bounds of this variable are set depending on attributes of the corresponding flow object.
 negative_flow_gradient – Difference of a flow in consecutive timesteps if flow is reduced indexed by NEGATIVE_GRADIENT_FLOWS, TIMESTEPS.
 positive_flow_gradient – Difference of a flow in consecutive timesteps if flow is increased indexed by NEGATIVE_GRADIENT_FLOWS, TIMESTEPS.

CONSTRAINT_GROUPS
= [<class 'oemof.solph.blocks.Bus'>, <class 'oemof.solph.blocks.LinearTransformer'>, <class 'oemof.solph.blocks.Storage'>, <class 'oemof.solph.blocks.InvestmentFlow'>, <class 'oemof.solph.blocks.InvestmentStorage'>, <class 'oemof.solph.blocks.Flow'>, <class 'oemof.solph.blocks.BinaryFlow'>, <class 'oemof.solph.blocks.DiscreteFlow'>]¶

receive_duals
()[source]¶ Method sets solver suffix to extract information about dual variables from solver. Shadow prices (duals) and reduced costs (rc) are set as attributes of the model.

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]
.Other result from the optimization model can be accessed like attributes of the flow, e.g. the invest variable for capacity of the storage ‘stor’ can be accessed like:
om.results()[stor][stor].invest
attributeFor the investment flow of a ‘transformer’ trsf to the bus ‘bel’ this can be accessed with:
om.results()[trsf][bel].invest
attributeThe 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
(solver='glpk', solver_io='lp', **kwargs)[source]¶ Takes care of communication with solver to solve the model.
Parameters:  solver (string) – solver to be used e.g. “glpk”,”gurobi”,”cplex”
 solver_io (string) – pyomo solver interface file format: “lp”,”python”,”nl”, etc.
 **kwargs (keyword arguments) – Possible keys can be set see below:
Other Parameters:  solve_kwargs (dict) – Other arguments for the pyomo.opt.SolverFactory.solve() method Example : {“tee”:True}
 cmdline_options (dict) – Dictionary with command line options for solver e.g. {“mipgap”:”0.01”} results in “–mipgap 0.01” {“interior”:” “} results in “–interior” Gurobi solver takes numeric parameter values such as {“method”: 2}
oemof.solph.network module¶

class
oemof.solph.network.
Bus
(*args, **kwargs)[source]¶ Bases:
oemof.network.Bus
A balance object. Every node has to be connected to Bus.
Notes
 The following sets, variables, constraints and objective parts are created

class
oemof.solph.network.
EnergySystem
(**kwargs)[source]¶ Bases:
oemof.energy_system.EnergySystem
Solph EnergySystem class

class
oemof.solph.network.
Flow
(**kwargs)[source]¶ Bases:
object
Define a flow between two nodes. Note: Some attributes can only take numeric scalar as some may either take scalar or sequences (arraylike). If for latter a scalar is passed, this will be internally converted to a sequence.
Parameters:  nominal_value (numeric) – The nominal value of the flow.
 min (numeric (sequence or scalar)) – Normed minimum value of the flow. The flow absolute maximum will be
calculated by multiplying
nominal_value
withmin
 max (numeric (sequence or scalar)) – Nominal maximum value of the flow. (see.
min
)  actual_value (numeric (sequence or scalar)) – Specific value for the flow variable. Will be multiplied with the
nominal_value to get the absolute value. If fixed is True the flow
variable will be fixed to actual_value *
nominal_value
.  positive_gradient (numeric (sequence or scalar)) – The normed maximal positive difference (flow[t1] < flow[t]) of two consecutive flow values.
 negative_gradient (numeric (sequence or scalar)) – The normed maximum negative difference (from[t1] > flow[t]) of two consecutive timesteps.
 summed_max (numeric) – Specific maximum value summed over all timesteps. Will be multiplied with the nominal_value to get the absolute limit.
 summed_min (numeric) – see above
 variable_costs (numeric (sequence or scalar)) – The costs associated with one unit of the flow.
 fixed_costs (numeric (sequence or scalar)) – The costs associated with the absolute nominal_value of the flow.
 fixed (boolean) – Boolean value indicating if a flow is fixed during the optimization
problem to its exante set value. Used in combination with the
actual_value
.  investment (
oemof.solph.options.Investment
object) – Object indicating if a nominal_value of the flow is determined by the optimization problem. Note: This will refer all attributes to an investment variable instead of to the nominal_value. The nominal_value should not be set (or set to None) if an investment object is used.
Notes
 The following sets, variables, constraints and objective parts are created
Flow
InvestmentFlow
(additionally if Investment object is present)
Examples
Creating a fixed flow object:
>>> f = Flow(actual_value=[10, 4, 4], fixed=True, variable_costs=5) >>> f.variable_costs[2] 5 >>> f.actual_value[2] 4
Creating a flow object with timedepended lower and upper bounds:
>>> f1 = Flow(min=[0.2, 0.3], max=0.99, nominal_value=100) >>> f1.max[1] 0.99

class
oemof.solph.network.
LinearTransformer
(*args, **kwargs)[source]¶ Bases:
oemof.network.Transformer
A Linear Transformer object.
Parameters: conversion_factors (dict) – Dictionary containing conversion factors for conversion of inflow to specified outflow. Keys are output bus objects. The dictionary values can either be a scalar or a sequence with length of time horizon for simulation. Examples
Defining an linear transformer:
>>> bel = Bus() >>> bth = Bus() >>> trsf = LinearTransformer(conversion_factors={bel: 0.4, ... bth: [1, 2, 3]}) >>> trsf.conversion_factors[bel][3] 0.4
Notes
 The following sets, variables, constraints and objective parts are created

class
oemof.solph.network.
Sink
(*args, **kwargs)[source]¶ Bases:
oemof.network.Sink
An object with one input flow.

class
oemof.solph.network.
Source
(*args, **kwargs)[source]¶ Bases:
oemof.network.Source
An object with one output flow.

class
oemof.solph.network.
Storage
(*args, **kwargs)[source]¶ Bases:
oemof.network.Transformer
Parameters:  nominal_capacity (numeric) – Absolute nominal capacity of the storage
 nominal_input_capacity_ratio (numeric) – Ratio between the nominal inflow of the storage and its capacity.
 nominal_output_capacity_ratio (numeric) – Ratio between the nominal outflow of the storage and its capacity. Note: This ratio is used to create the Flow object for the outflow and set its nominal value of the storage in the constructor.
 nominal_input_capacity_ratio – see: nominal_output_capacity_ratio
 initial_capacity (numeric) – The capacity of the storage in the first (and last) timestep of optimization.
 capacity_loss (numeric (sequence or scalar)) – The relative loss of the storage capacity from between two consecutive timesteps.
 inflow_conversion_factor (numeric (sequence or scalar)) – The relative conversion factor, i.e. efficiency associated with the inflow of the storage.
 outflow_conversion_factor (numeric (sequence or scalar)) – see: inflow_conversion_factor
 capacity_min (numeric (sequence or scalar)) – The nominal minimum capacity of the storage as fraction of the nominal capacity (between 0 and 1, default: 0). To set different values in every timestep use a sequence.
 capacity_max (numeric (sequence or scalar)) – see: capacity_min
 investment (
oemof.solph.options.Investment
object) – Object indicating if a nominal_value of the flow is determined by the optimization problem. Note: This will refer all attributes to an investment variable instead of to the nominal_capacity. The nominal_capacity should not be set (or set to None) if an investment object is used.
Notes
 The following sets, variables, constraints and objective parts are created
Storage
(if no Investment object present)InvestmentStorage
(if Investment object present)
oemof.solph.options module¶
Optional classes to be added to a network class.

class
oemof.solph.options.
BinaryFlow
(**kwargs)[source]¶ Bases:
object
Parameters:  startup_costs (numeric) – Costs associated with a start of the flow (representing a unit).
 shutdown_costs (numeric) – Costs associated with the shutdown of the flow (representing a until).
 minimum_uptime (numeric) – Minimum time that a flow must be greater then its minimum flow after startup.
 minimum_downtime (numeric) – Minimum time a flow is forced to zero after shutting down.
 initial_status (numeric (0 or 1)) – Integer value indicating the status of the flow in the first time step (0 = off, 1 = on).

class
oemof.solph.options.
DiscreteFlow
(**kwargs)[source]¶ Bases:
object
Parameters: integers (boolean) – Specify domain of flow variable: If True, flow is force to integer values.

class
oemof.solph.options.
Investment
(maximum=inf, ep_costs=0)[source]¶ Bases:
object
Parameters:  maximum (float) – Maximum of the additional invested capacity
 ep_costs (float) – Equivalent periodical costs for the investment, if period is one year these costs are equal to the equivalent annual costs.
oemof.solph.plumbing module¶

oemof.solph.plumbing.
NodesFromCSV
(file_nodes_flows, file_nodes_flows_sequences, delimiter=', ', additional_classes={}, additional_seq_attributes=[])[source]¶ Creates nodes with their respective flows and sequences from a predefined CSV structure. An example has been provided in the development examples
Parameters:  file_nodes_flows (string with name of CSV file of nodes and flows) –
 file_nodes_flows_sequences (string with name of CSV file of sequences) –
 delimiter (delimiter of CSV file) –
 additional_classes (dictionary with additional classes to be used in csv) – of type {‘MyClass1’: MyClass1, ...}
 additional_seq_attributes (list of strings with attributes that have to be) – of type ‘solph sequence’

oemof.solph.plumbing.
Sequence
(sequence_or_scalar)[source]¶ Tests if an object is sequence (except string) or scalar and returns a the original sequence if object is a sequence and a ‘emulated’ sequence object of class _Sequence if object is a scalar or string.
Parameters: sequence_or_scalar (arraylike or scalar (None, int, etc.)) – Examples
>>> Sequence([1,2]) [1, 2]
>>> x = Sequence(10) >>> x[0] 10
>>> x[10] 10 >>> print(x) [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]