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

activity_costs   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 40
dl 0
loc 108
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A main() 0 65 1
1
# -*- coding: utf-8 -*-
2
3
"""
4
General description
5
-------------------
6
7
This example illustrates the effect of activity_costs.
8
9
There are the following components:
10
11
    - demand_heat: heat demand (constant, for the sake of simplicity)
12
    - fireplace: wood firing, burns "for free" if somebody is around
13
    - boiler: gas firing, consumes (paid) gas
14
15
Notice that activity_costs is an attribute to NonConvex.
16
This is because it relies on the activity status of a component
17
which is only available for nonconvex flows.
18
19
20
Installation requirements
21
-------------------------
22
This example requires oemof.solph (v0.5.x), install by:
23
24
    pip install oemof.solph[examples]
25
26
License
27
-------
28
`MIT license <https://github.com/oemof/oemof-solph/blob/dev/LICENSE>`_
29
30
"""
31
32
import matplotlib.pyplot as plt
33
import numpy as np
34
import pandas as pd
35
36
from oemof import solph
37
38
39
def main():
40
    ##########################################################################
41
    # Calculate parameters and initialize the energy system and
42
    ##########################################################################
43
    periods = 24
44
    time = pd.date_range("1/1/2018", periods=periods, freq="H")
45
46
    demand_heat = np.full(periods, 5)
47
    demand_heat[:4] = 0
48
    demand_heat[4:18] = 4
49
50
    activity_costs = np.full(periods, 5)
51
    activity_costs[18:] = 0
52
53
    es = solph.EnergySystem(timeindex=time)
54
55
    b_heat = solph.Bus(label="b_heat")
56
57
    es.add(b_heat)
58
59
    sink_heat = solph.components.Sink(
60
        label="demand",
61
        inputs={b_heat: solph.Flow(fix=demand_heat, nominal_value=1)},
62
    )
63
64
    fireplace = solph.components.Source(
65
        label="fireplace",
66
        outputs={
67
            b_heat: solph.Flow(
68
                nominal_value=3,
69
                variable_costs=0,
70
                nonconvex=solph.NonConvex(activity_costs=activity_costs),
71
            )
72
        },
73
    )
74
75
    boiler = solph.components.Source(
76
        label="boiler",
77
        outputs={b_heat: solph.Flow(nominal_value=10, variable_costs=1)},
78
    )
79
80
    es.add(sink_heat, fireplace, boiler)
81
82
    ##########################################################################
83
    # Optimise the energy system
84
    ##########################################################################
85
86
    # create an optimization problem and solve it
87
    om = solph.Model(es)
88
89
    # solve model
90
    om.solve(solver="cbc", solve_kwargs={"tee": True})
91
92
    ##########################################################################
93
    # Check and plot the results
94
    ##########################################################################
95
96
    results = solph.processing.results(om)
97
98
    # plot data
99
    data = solph.views.node(results, "b_heat")["sequences"]
100
    ax = data.plot(kind="line", drawstyle="steps-post", grid=True, rot=0)
101
    ax.set_xlabel("Time")
102
    ax.set_ylabel("Heat (arb. units)")
103
    plt.show()
104
105
106
if __name__ == "__main__":
107
    main()
108