-
Notifications
You must be signed in to change notification settings - Fork 465
/
test_cost_consistency.py
170 lines (138 loc) · 5.42 KB
/
test_cost_consistency.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import pandapower as pp
import pytest
from numpy import array, isclose
@pytest.fixture()
def base_net():
net = pp.create_empty_network()
pp.create_bus(net, vn_kv=10)
pp.create_bus(net, vn_kv=10)
pp.create_ext_grid(net, 0)
pp.create_load(net, 1, p_mw=0.2, controllable=False)
pp.create_line_from_parameters(net, 0, 1, 50, name="line", r_ohm_per_km=0.876,
c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876,
max_loading_percent=100 * 690)
pp.runpp(net)
return net
def test_contingency_sgen(base_net):
net = base_net
pp.create_sgen(net, 1, p_mw=0.1, q_mvar=0, controllable=True, min_p_mw=0.005, max_p_mw=0.150,
max_q_mvar=0.05, min_q_mvar=-0.05)
# pwl costs
# maximize the sgen feed in by using a positive cost slope
# using a slope of 1
# | /
# | /
# | /
# |/
#-------------------------------------------
# p_min_mw /|
# / |
# / |
pwl = pp.create_pwl_cost(net, 0, "sgen", [[0, net.sgen.max_p_mw.at[0], 1]])
pp.runopp(net)
assert isclose(net.res_cost, net.res_sgen.p_mw.at[0], atol=1e-3)
# minimize the sgen feed in by using a positive cost slope
# using a slope of 1
# \ |
# \ |
# \ |
# \|
#-------------------------------------------
# p_min_mw |\
# | \
# | \
net.pwl_cost.points.loc[pwl] = [(0, net.sgen.max_p_mw.at[0], -1)]
pp.runopp(net)
assert isclose(net.res_cost, -net.res_sgen.p_mw.at[0], atol=1e-4)
net.pwl_cost.drop(0, inplace=True)
# first using a positive slope as in the case above
pp.create_poly_cost(net, 0, "sgen", cp1_eur_per_mw=1.)
pp.runopp(net)
assert isclose(net.res_cost, net.res_sgen.p_mw.at[0], atol=1e-3)
# negative slope as in the case above
net.poly_cost.cp1_eur_per_mw.at[0] *= -1
pp.runopp(net)
assert isclose(net.res_cost, -net.res_sgen.p_mw.at[0], atol=1e-4)
def test_contingency_load(base_net):
net = base_net
pp.create_gen(net, 1, p_mw=0.1, vm_pu = 1.05, controllable=True, min_p_mw=0.005, max_p_mw=0.150,
max_q_mvar=0.05, min_q_mvar=-0.05)
# pwl costs
# maximize the sgen feed in by using a positive cost slope
# using a slope of 1
# | /
# | /
# | /
# |/
#-------------------------------------------
# p_min_mw /|
# / |
# / |
pp.create_pwl_cost(net, 0, "gen",[[0, net.gen.max_p_mw.at[0], 1]])
pp.runopp(net)
assert isclose(net.res_cost, net.res_gen.p_mw.at[0], atol=1e-3)
# minimize the sgen feed in by using a positive cost slope
# using a slope of 1
# \ |
# \ |
# \ |
# \|
#-------------------------------------------
# p_min_mw |\
# | \
# | \
net.pwl_cost.points.iloc[0] = [(0, net.gen.max_p_mw.at[0], -1)]
pp.runopp(net)
assert isclose(net.res_cost, -net.res_gen.p_mw.at[0], atol=1e-3)
net.pwl_cost.drop(0, inplace=True)
# first using a positive slope as in the case above
pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=1)
pp.runopp(net)
assert isclose(net.res_cost, net.res_gen.p_mw.at[0], atol=1e-3)
# negative slope as in the case above
net.poly_cost.cp1_eur_per_mw.at[0] *= -1
pp.runopp(net)
assert isclose(net.res_cost, -net.res_gen.p_mw.at[0], atol=1e-3)
def test_contingency_gen(base_net):
net = base_net
pp.create_gen(net, 1, p_mw=0.1, vm_pu = 1.05, controllable=True, min_p_mw=0.005, max_p_mw=0.150,
max_q_mvar=0.05, min_q_mvar=-0.05)
# pwl costs
# maximize the sgen feed in by using a positive cost slope
# using a slope of 1
# | /
# | /
# | /
# |/
#-------------------------------------------
# p_min_mw /|
# / |
# / |
pp.create_pwl_cost(net, 0, "gen", [[0, net.gen.max_p_mw.at[0], 1]])
pp.runopp(net)
assert isclose(net.res_cost, net.res_gen.p_mw.at[0], atol=1e-3)
# minimize the sgen feed in by using a positive cost slope
# using a slope of 1
# \ |
# \ |
# \ |
# \|
#-------------------------------------------
# p_min_mw |\
# | \
# | \
net.pwl_cost.points.iloc[0] = [(0, net.gen.max_p_mw.at[0], -1)]
pp.runopp(net)
assert isclose(net.res_cost, -net.res_gen.p_mw.at[0], atol=1e-3)
net.pwl_cost.drop(0, inplace=True)
# first using a positive slope as in the case above
# pp.create_pwl_cost(net, 0, "gen", array([1, 0]))
pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=1)
pp.runopp(net)
assert isclose(net.res_cost, net.res_gen.p_mw.at[0], atol=1e-3)
# negative slope as in the case above
net.poly_cost.cp1_eur_per_mw *= -1
pp.runopp(net)
assert isclose(net.res_cost, -net.res_gen.p_mw.at[0], atol=1e-3)
if __name__ == "__main__":
pytest.main(['-s', __file__])