Created
June 14, 2020 08:11
-
-
Save nesnoj/9c31238f104836734aa62bdaf65c99ae to your computer and use it in GitHub Desktop.
Minimal example for line invest, based upon example from oemof-examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original example: https://github.com/oemof/oemof-examples/blob/master/oemof_examples/oemof.solph/v0.3.x/electrical/transshipment.py | |
import pandas as pd | |
# solph imports | |
from oemof.solph import (EnergySystem, Model, Bus, Flow, Source, Sink, | |
custom, Investment) | |
from oemof.outputlib import processing, views | |
from oemof.graph import create_nx_graph | |
datetimeindex = pd.date_range('1/1/2017', periods=2, freq='H') | |
es = EnergySystem(timeindex=datetimeindex) | |
b_0 = Bus(label='b_0') | |
b_1 = Bus(label='b_1') | |
es.add(b_0, b_1) | |
es.add(custom.Link(label="line_0", | |
inputs={ | |
b_0: Flow(), b_1: Flow()}, | |
outputs={ | |
b_1: Flow(investment=Investment(ep_costs=100, existing=50)), | |
b_0: Flow(investment=Investment(ep_costs=100, existing=50))}, | |
conversion_factors={ | |
(b_0, b_1): 1, (b_1, b_0): 1})) | |
es.add(Source(label="gen_0", outputs={ | |
b_0: Flow(nominal_value=300, | |
actual_value=[1, 0], | |
variable_costs=50, | |
fixed=True)})) | |
es.add(Sink(label="load_0", inputs={ | |
b_1: Flow(nominal_value=300, | |
actual_value=[1, 0], | |
fixed=True)})) | |
es.add(Source(label="gen_1", outputs={ | |
b_1: Flow(nominal_value=200, | |
actual_value=[0, 1], | |
variable_costs=50, | |
fixed=True)})) | |
es.add(Sink(label="load_1", inputs={ | |
b_0: Flow(nominal_value=200, | |
actual_value=[0, 1], | |
fixed=True)})) | |
m = Model(energysystem=es) | |
# m.write('transshipment.lp', io_options={'symbolic_solver_labels': True}) | |
m.solve(solver='cbc', | |
solve_kwargs={'tee': True, 'keepfiles': False}) | |
m.results() | |
results = processing.results(m) | |
print(views.node(results, 'line_0')) | |
views.node(results, 'line_0')['sequences'].plot(kind='bar') | |
# look at constraints of Links in the pyomo model LinkBlock | |
m.LinkBlock.pprint() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment