|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
"""Tests for Flows with NonConvex attribute |
|
4
|
|
|
|
|
5
|
|
|
SPDX-FileCopyrightText: Deutsches Zentrum für Luft- und Raumfahrt e.V. |
|
6
|
|
|
SPDX-FileCopyrightText: Patrik Schönfeldt |
|
7
|
|
|
|
|
8
|
|
|
SPDX-License-Identifier: MIT |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
from oemof import solph |
|
12
|
|
|
|
|
13
|
|
|
from . import _run_flow_model |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
def test_initial_status_off(): |
|
17
|
|
|
# negative costs but turned off initially |
|
18
|
|
|
flow = solph.flows.Flow( |
|
19
|
|
|
nominal_capacity=10, |
|
20
|
|
|
nonconvex=solph.NonConvex(initial_status=0, minimum_downtime=5), |
|
21
|
|
|
variable_costs=-1, |
|
22
|
|
|
) |
|
23
|
|
|
flow_result = _run_flow_model(flow) |
|
24
|
|
|
|
|
25
|
|
|
assert (flow_result["flow"][:-1] == 5 * [0] + 5 * [10]).all() |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
def test_maximum_shutdowns(): |
|
29
|
|
|
flow = solph.flows.Flow( |
|
30
|
|
|
nominal_capacity=10, |
|
31
|
|
|
min=0.5, |
|
32
|
|
|
nonconvex=solph.NonConvex(maximum_shutdowns=1), |
|
33
|
|
|
variable_costs=[1, -2, 1, 1, 1, -5, 1, 1, 1, -2], |
|
34
|
|
|
) |
|
35
|
|
|
flow_result = _run_flow_model(flow) |
|
36
|
|
|
|
|
37
|
|
|
assert list(flow_result["status"][:-1]) == [0, 1, 1, 1, 1, 1, 0, 0, 0, 1] |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
def test_maximum_startups(): |
|
41
|
|
|
flow = solph.flows.Flow( |
|
42
|
|
|
nominal_capacity=10, |
|
43
|
|
|
min=0.5, |
|
44
|
|
|
nonconvex=solph.NonConvex(maximum_startups=1), |
|
45
|
|
|
variable_costs=[1, -4, 1, 1, 1, -5, 1, 1, 5, -3], |
|
46
|
|
|
) |
|
47
|
|
|
flow_result = _run_flow_model(flow) |
|
48
|
|
|
|
|
49
|
|
|
assert list(flow_result["status"][:-1]) == [0, 1, 1, 1, 1, 1, 0, 0, 0, 0] |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
def test_initial_status_on(): |
|
53
|
|
|
# positive costs but turned on initially |
|
54
|
|
|
flow = solph.flows.Flow( |
|
55
|
|
|
nominal_capacity=10, |
|
56
|
|
|
min=0.5, |
|
57
|
|
|
nonconvex=solph.NonConvex(initial_status=1, minimum_uptime=3), |
|
58
|
|
|
variable_costs=1, |
|
59
|
|
|
) |
|
60
|
|
|
flow_result = _run_flow_model(flow) |
|
61
|
|
|
|
|
62
|
|
|
assert (flow_result["flow"][:-1] == 3 * [5] + 7 * [0]).all() |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
def test_activity_costs(): |
|
66
|
|
|
# activity costs higher then revenue for first time steps |
|
67
|
|
|
flow = solph.flows.Flow( |
|
68
|
|
|
nominal_capacity=10, |
|
69
|
|
|
min=0.1, |
|
70
|
|
|
max=[0.1] + [i * 0.1 for i in range(1, 10)], |
|
71
|
|
|
nonconvex=solph.NonConvex(activity_costs=9 * [1] + [10]), |
|
72
|
|
|
variable_costs=-0.45, |
|
73
|
|
|
) |
|
74
|
|
|
flow_result = _run_flow_model(flow)["flow"][:-1] |
|
75
|
|
|
|
|
76
|
|
|
assert (flow_result == [0, 0, 0, 3, 4, 5, 6, 7, 8, 0]).all() |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
def test_inactivity_costs(): |
|
80
|
|
|
# inactivity costs lower then running costs for middle time steps |
|
81
|
|
|
flow = solph.flows.Flow( |
|
82
|
|
|
nominal_capacity=10, |
|
83
|
|
|
min=[i * 0.1 for i in range(10)], |
|
84
|
|
|
nonconvex=solph.NonConvex(inactivity_costs=9 * [1] + [10]), |
|
85
|
|
|
variable_costs=0.45, |
|
86
|
|
|
) |
|
87
|
|
|
flow_result = _run_flow_model(flow)["flow"][:-1] |
|
88
|
|
|
|
|
89
|
|
|
assert (flow_result == [0, 1, 2, 0, 0, 0, 0, 0, 0, 9]).all() |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
View Code Duplication |
def test_startup_costs_start_off(): |
|
|
|
|
|
|
93
|
|
|
price_pattern = [1, 1, 1, -4, 1, 1, 1, -4, 1, 1] |
|
94
|
|
|
|
|
95
|
|
|
# startup costs higher then effect of shutting down |
|
96
|
|
|
flow = solph.flows.Flow( |
|
97
|
|
|
nominal_capacity=10, |
|
98
|
|
|
min=0.1, |
|
99
|
|
|
nonconvex=solph.NonConvex(startup_costs=5, initial_status=0), |
|
100
|
|
|
variable_costs=price_pattern, |
|
101
|
|
|
) |
|
102
|
|
|
flow_result = _run_flow_model(flow) |
|
103
|
|
|
|
|
104
|
|
|
assert (flow_result["flow"][:-1] == [0, 0, 0, 10, 1, 1, 1, 10, 0, 0]).all() |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
View Code Duplication |
def test_startup_costs_start_on(): |
|
|
|
|
|
|
108
|
|
|
price_pattern = [1, 1, 1, -4, 1, 1, 1, -4, 1, 1] |
|
109
|
|
|
|
|
110
|
|
|
# startup costs higher then effect of shutting down |
|
111
|
|
|
flow = solph.flows.Flow( |
|
112
|
|
|
nominal_capacity=10, |
|
113
|
|
|
min=0.1, |
|
114
|
|
|
nonconvex=solph.NonConvex(startup_costs=5, initial_status=1), |
|
115
|
|
|
variable_costs=price_pattern, |
|
116
|
|
|
) |
|
117
|
|
|
flow_result = _run_flow_model(flow) |
|
118
|
|
|
|
|
119
|
|
|
assert (flow_result["flow"][:-1] == [1, 1, 1, 10, 1, 1, 1, 10, 0, 0]).all() |
|
120
|
|
|
|
|
121
|
|
|
|
|
122
|
|
|
def test_shutdown_costs_start_on(): |
|
123
|
|
|
price_pattern = [1, 1, 1, -4, 1, 1, 1, -4, 1, 1] |
|
124
|
|
|
|
|
125
|
|
|
# shutdown costs higher then effect of shutting down |
|
126
|
|
|
flow = solph.flows.Flow( |
|
127
|
|
|
nominal_capacity=10, |
|
128
|
|
|
min=0.1, |
|
129
|
|
|
nonconvex=solph.NonConvex(shutdown_costs=5, initial_status=1), |
|
130
|
|
|
variable_costs=price_pattern, |
|
131
|
|
|
) |
|
132
|
|
|
flow_result = _run_flow_model(flow) |
|
133
|
|
|
|
|
134
|
|
|
assert (flow_result["flow"][:-1] == [1, 1, 1, 10, 1, 1, 1, 10, 1, 1]).all() |
|
135
|
|
|
|