Passed
Pull Request — dev (#850)
by Uwe
01:35
created

min_max_runtimes   A

Complexity

Total Complexity 0

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 50
dl 0
loc 101
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
3
"""
4
General description
5
-------------------
6
Example that illustrates how to model min and max runtimes.
7
8
Installation requirements
9
-------------------------
10
11
This example requires oemof.solph (v0.5.x), install by:
12
13
    pip install oemof.solph[examples]
14
15
16
License
17
-------
18
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_
19
20
"""
21
from matplotlib import pyplot as plt
22
from oemof.network.network import Node
23
24
from oemof import solph
25
26
# Create demand data
27
demand_el = [0] * 24
28
for n in [10, 15, 19]:
29
    demand_el[n] = 1
30
31
# create an energy system
32
idx = solph.create_time_index(2017, number=24)
33
es = solph.EnergySystem(timeindex=idx, infer_last_interval=False)
34
Node.registry = es
35
36
# power bus and components
37
bel = solph.Bus(label="bel")
38
39
demand_el = solph.components.Sink(
40
    label="demand_el",
41
    inputs={bel: solph.Flow(fix=demand_el, nominal_value=10)},
42
)
43
44
dummy_el = solph.components.Sink(
45
    label="dummy_el", inputs={bel: solph.Flow(variable_costs=10)}
46
)
47
48
pp1 = solph.components.Source(
49
    label="plant_min_down_constraints",
50
    outputs={
51
        bel: solph.Flow(
52
            nominal_value=10,
53
            min=0.5,
54
            max=1.0,
55
            variable_costs=10,
56
            nonconvex=solph.NonConvex(minimum_downtime=4, initial_status=0),
57
        )
58
    },
59
)
60
61
pp2 = solph.components.Source(
62
    label="plant_min_up_constraints",
63
    outputs={
64
        bel: solph.Flow(
65
            nominal_value=10,
66
            min=0.5,
67
            max=1.0,
68
            variable_costs=10,
69
            nonconvex=solph.NonConvex(minimum_uptime=2, initial_status=1),
70
        )
71
    },
72
)
73
74
# create an optimization problem and solve it
75
om = solph.Model(es)
76
77
# debugging
78
# om.write('problem.lp', io_options={'symbolic_solver_labels': True})
79
80
# solve model
81
om.solve(solver="cbc", solve_kwargs={"tee": True})
82
83
# create result object
84
results = solph.processing.results(om)
85
86
# plot data
87
data = solph.views.node(results, "bel")["sequences"]
88
data[[(("bel", "demand_el"), "flow"), (("bel", "dummy_el"), "flow")]] *= -1
89
exclude = ["dummy_el", "status"]
90
columns = [
91
    c for c in data.columns if not any(s in c[0] or s in c[1] for s in exclude)
92
]
93
data = data[columns]
94
fig, ax = plt.subplots(figsize=(10, 5))
95
data.plot(ax=ax, kind="line", drawstyle="steps-post", grid=True, rot=0)
96
ax.set_xlabel("Hour")
97
ax.set_ylabel("P [MW]")
98
plt.legend(loc="upper center", bbox_to_anchor=(0.5, 1.3), ncol=1)
99
fig.subplots_adjust(top=0.8)
100
plt.show()
101