fpowerkit 0.0.8__tar.gz → 0.0.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.1
2
+ Name: fpowerkit
3
+ Version: 0.0.10
4
+ Summary: A Distflow PDN solver based on Gurobi.
5
+ Author: fmy_xfk
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: feasytools>=0.0.18
13
+ Requires-Dist: gurobipy>=9.1.0
14
+
15
+ # FPowerKit 配电网运算组件
16
+ **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!
17
+
18
+ IEEE33和IEEE69节点的配网数据从公开渠道收集。除配网数据以外,本仓库代码均遵循LGPL3.0协议使用。
19
+
20
+ ## 简介
21
+ - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
22
+ - 包含电网的描述(含母线、发电机、线路等)和采用Gurobi的配电网DistFlow模型求解。
23
+ - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
24
+ - 内含IEEE 33节点配电网和IEEE 69节点配电网,可通过以下方式快速创建:
25
+ ```py
26
+ from fpowerkit import PDNCases
27
+ grid_obj33 = PDNCases.IEEE33()
28
+ grid_obj69 = PDNCases.IEEE69()
29
+ ```
30
+
31
+ ## 使用
32
+
33
+ 克隆本仓库,并输入以下命令开始仿真:
34
+
35
+ ```bash
36
+ python main.py -g cases/ieee33.grid.zip
37
+ ```
38
+
39
+ 请注意上述命令不适用于pip安装的版本。
40
+
41
+ `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
42
+
43
+ ```
44
+ G0 G1
45
+ | |
46
+ B0->B1->B2
47
+ | |
48
+ L1 L2
49
+ ```
50
+
51
+ 您也换成自己的配电网文件来求解,例如`python main.py -g path/to/your_zipfile.zip`
52
+
53
+ ## 配电网文件格式
54
+ 目前,我们提供了2种方式记录配电网的结构和负荷信息,分别为ZIP格式和XML格式,我们推荐使用XML格式记录数据,因为其更加灵活。以下是两种方式的说明链接:
55
+
56
+ [XML格式](docs/xml_file.md) (推荐!)
57
+
58
+ [ZIP格式](docs/zip_file.md)
@@ -0,0 +1,44 @@
1
+ # FPowerKit 配电网运算组件
2
+ **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!
3
+
4
+ IEEE33和IEEE69节点的配网数据从公开渠道收集。除配网数据以外,本仓库代码均遵循LGPL3.0协议使用。
5
+
6
+ ## 简介
7
+ - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
8
+ - 包含电网的描述(含母线、发电机、线路等)和采用Gurobi的配电网DistFlow模型求解。
9
+ - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
10
+ - 内含IEEE 33节点配电网和IEEE 69节点配电网,可通过以下方式快速创建:
11
+ ```py
12
+ from fpowerkit import PDNCases
13
+ grid_obj33 = PDNCases.IEEE33()
14
+ grid_obj69 = PDNCases.IEEE69()
15
+ ```
16
+
17
+ ## 使用
18
+
19
+ 克隆本仓库,并输入以下命令开始仿真:
20
+
21
+ ```bash
22
+ python main.py -g cases/ieee33.grid.zip
23
+ ```
24
+
25
+ 请注意上述命令不适用于pip安装的版本。
26
+
27
+ `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
28
+
29
+ ```
30
+ G0 G1
31
+ | |
32
+ B0->B1->B2
33
+ | |
34
+ L1 L2
35
+ ```
36
+
37
+ 您也换成自己的配电网文件来求解,例如`python main.py -g path/to/your_zipfile.zip`
38
+
39
+ ## 配电网文件格式
40
+ 目前,我们提供了2种方式记录配电网的结构和负荷信息,分别为ZIP格式和XML格式,我们推荐使用XML格式记录数据,因为其更加灵活。以下是两种方式的说明链接:
41
+
42
+ [XML格式](docs/xml_file.md) (推荐!)
43
+
44
+ [ZIP格式](docs/zip_file.md)
@@ -0,0 +1,350 @@
1
+ from feasytools import SegFunc
2
+ from .grid import GeneratorModel, Grid, Bus, Line, Generator
3
+
4
+ # IEEE33 kVA
5
+ _IEEE33_LOAD = [
6
+ (1,0,0),
7
+ (2,100.00,60.00),
8
+ (3,90.00,40.00),
9
+ (4,120.00,80.00),
10
+ (5,60.00,30.00),
11
+ (6,60.00,20.00),
12
+ (7,200.00,100.00),
13
+ (8,200.00,100.00),
14
+ (9,60.00,20.00),
15
+ (10,60.00,20.00),
16
+ (11,45.00,30.00),
17
+ (12,60.00,35.00),
18
+ (13,60.00,35.00),
19
+ (14,120.00,80.00),
20
+ (15,60.00,10.00),
21
+ (16,60.00,20.00),
22
+ (17,60.00,20.00),
23
+ (18,90.00,40.00),
24
+ (19,90.00,40.00),
25
+ (20,90.00,40.00),
26
+ (21,90.00,40.00),
27
+ (22,90.00,40.00),
28
+ (23,90.00,50.00),
29
+ (24,420.00,200.00),
30
+ (25,420.00,200.00),
31
+ (26,60.00,25.00),
32
+ (27,60.00,25.00),
33
+ (28,60.00,20.00),
34
+ (29,120.00,70.00),
35
+ (30,200.00,600.00),
36
+ (31,150.00,70.00),
37
+ (32,210.00,100.00),
38
+ (33,60.00,40.00)
39
+ ]
40
+
41
+ # IEEE69 kVA
42
+ _IEEE69_LOAD = [
43
+ (1, 0, 0),
44
+ (2, 0, 0),
45
+ (3, 0, 0),
46
+ (4, 0, 0),
47
+ (5, 0, 0),
48
+ (6, 2.6, 2.2),
49
+ (7, 40.4, 30),
50
+ (8, 75, 54),
51
+ (9, 30, 22),
52
+ (10, 28, 19),
53
+ (11, 145, 104),
54
+ (12, 145, 104),
55
+ (13, 8, 5.5),
56
+ (14, 8, 5.5),
57
+ (15, 0, 0, 0),
58
+ (16, 45.5, 30),
59
+ (17, 60, 35),
60
+ (18, 60, 35),
61
+ (19, 0, 0, 0),
62
+ (20, 1, 0.6),
63
+ (21, 114, 81),
64
+ (22, 5.5, 3.5),
65
+ (23, 0, 0, 0),
66
+ (24, 28, 20),
67
+ (25, 0, 0, 0),
68
+ (26, 14, 10),
69
+ (27, 14, 10),
70
+ (28, 26, 18.6),
71
+ (29, 26, 18.6),
72
+ (30, 0, 0, 0),
73
+ (31, 0, 0, 0),
74
+ (32, 0, 0, 0),
75
+ (33, 14, 10),
76
+ (34, 19.5, 14),
77
+ (35, 6, 4),
78
+ (36, 0, 0, 0),
79
+ (37, 79, 56.4),
80
+ (38, 384.7, 274.5),
81
+ (39, 384.7, 274.5),
82
+ (40, 40.5, 28.3),
83
+ (41, 3.6, 3.7),
84
+ (42, 4.35, 3.5),
85
+ (43, 26.4, 19),
86
+ (44, 24, 17.2),
87
+ (45, 0, 0, 0),
88
+ (46, 0, 0, 0),
89
+ (47, 0, 0, 0),
90
+ (48, 100, 72),
91
+ (49, 0, 0, 0),
92
+ (50, 1244, 888),
93
+ (51, 32, 23),
94
+ (52, 0, 0, 0),
95
+ (53, 227, 162),
96
+ (54, 59, 42),
97
+ (55, 18, 13),
98
+ (56, 18, 13),
99
+ (57, 28, 20),
100
+ (58, 28, 20),
101
+ (59, 26, 18.55),
102
+ (60, 26, 18.55),
103
+ (61, 0, 0, 0),
104
+ (62, 24, 17),
105
+ (63, 24, 17),
106
+ (64, 1.2, 1),
107
+ (65, 0, 0, 0),
108
+ (66, 6, 4.3),
109
+ (67, 0, 0, 0),
110
+ (68, 39.22, 26.3),
111
+ (69, 39.22, 26.3),
112
+ ]
113
+
114
+ _DEFAULT_LOAD_SCALE = [
115
+ (0*3600, 0.7),
116
+ (1*3600, 0.65),
117
+ (2*3600, 0.625),
118
+ (3*3600, 0.625),
119
+ (4*3600, 0.625),
120
+ (5*3600, 0.6),
121
+ (6*3600, 0.725),
122
+ (7*3600, 0.9),
123
+ (8*3600, 1.15),
124
+ (9*3600, 1.6),
125
+ (10*3600, 2.025),
126
+ (11*3600, 2.2),
127
+ (12*3600, 2.25),
128
+ (13*3600, 1.8),
129
+ (14*3600, 1.0),
130
+ (15*3600, 1.725),
131
+ (16*3600, 1.975),
132
+ (17*3600, 2.3),
133
+ (18*3600, 2.425),
134
+ (19*3600, 2.5),
135
+ (20*3600, 1.95),
136
+ (21*3600, 1.4),
137
+ (22*3600, 1.0),
138
+ (23*3600, 0.8),
139
+ ]
140
+
141
+ _IEEE33_LINE = [
142
+ (1,1,2,0.0922,0.047),
143
+ (2,2,3,0.493,0.2511),
144
+ (3,3,4,0.366,0.1864),
145
+ (4,4,5,0.3811,0.1941),
146
+ (5,5,6,0.819,0.707),
147
+ (6,6,7,0.1872,0.6188),
148
+ (7,7,8,0.7114,0.2351),
149
+ (8,8,9,1.03,0.74),
150
+ (9,9,10,1.044,0.74),
151
+ (10,10,11,0.1966,0.065),
152
+ (11,11,12,0.3744,0.1238),
153
+ (12,12,13,1.468,1.155),
154
+ (13,13,14,0.5416,0.7129),
155
+ (14,14,15,0.591,0.526),
156
+ (15,15,16,0.7463,0.545),
157
+ (16,16,17,1.289,1.721),
158
+ (17,17,18,0.732,0.574),
159
+ (18,2,19,0.164,0.1565),
160
+ (19,19,20,1.5042,1.3554),
161
+ (20,20,21,0.4095,0.4784),
162
+ (21,21,22,0.7089,0.9373),
163
+ (22,3,23,0.4512,0.3083),
164
+ (23,23,24,0.898,0.7091),
165
+ (24,24,25,0.896,0.7011),
166
+ (25,6,26,0.203,0.1034),
167
+ (26,26,27,0.2842,0.1447),
168
+ (27,27,28,1.059,0.9337),
169
+ (28,28,29,0.8042,0.7006),
170
+ (29,29,30,0.5075,0.2585),
171
+ (30,30,31,0.9744,0.963),
172
+ (31,31,32,0.3105,0.3619),
173
+ (32,32,33,0.341,0.5302),
174
+ ]
175
+
176
+ _IEEE69_LINE = [
177
+ (1, 1, 2, 0.0005, 0.0012),
178
+ (2, 2, 3, 0.0005, 0.0012),
179
+ (3, 3, 4, 0.0015, 0.0036),
180
+ (4, 4, 5, 0.0251, 0.0294),
181
+ (5, 5, 6, 0.366, 0.1864),
182
+ (6, 6, 7, 0.3811, 0.1941),
183
+ (7, 7, 8, 0.0922, 0.047),
184
+ (8, 8, 9, 0.0493, 0.0251),
185
+ (9, 9, 10, 0.819, 0.2707),
186
+ (10, 10, 11, 0.1872, 0.0619),
187
+ (11, 11, 12, 0.7114, 0.2351),
188
+ (12, 12, 13, 1.03, 0.34),
189
+ (13, 13, 14, 1.044, 0.345),
190
+ (14, 14, 15, 1.058, 0.3496),
191
+ (15, 15, 16, 0.1966, 0.065),
192
+ (16, 16, 17, 0.3744, 0.1238),
193
+ (17, 17, 18, 0.0047, 0.0016),
194
+ (18, 18, 19, 0.3267, 0.1083),
195
+ (19, 19, 20, 0.2106, 0.0696),
196
+ (20, 20, 21, 0.3416, 0.1129),
197
+ (21, 21, 22, 0.014, 0.0046),
198
+ (22, 22, 23, 0.1591, 0.0526),
199
+ (23, 23, 24, 0.3463, 0.1145),
200
+ (24, 24, 25, 0.7488, 0.2475),
201
+ (25, 25, 26, 0.3089, 0.1021),
202
+ (26, 26, 27, 0.1732, 0.0572),
203
+ (27, 3, 28, 0.0044, 0.0108),
204
+ (28, 28, 29, 0.064, 0.1565),
205
+ (29, 29, 30, 0.3978, 0.1315),
206
+ (30, 30, 31, 0.0702, 0.0232),
207
+ (31, 31, 32, 0.351, 0.116),
208
+ (32, 32, 33, 0.839, 0.2816),
209
+ (33, 33, 34, 1.708, 0.5646),
210
+ (34, 34, 35, 1.474, 0.4873),
211
+ (35, 4, 36, 0.0034, 0.0084),
212
+ (36, 36, 37, 0.0851, 0.2083),
213
+ (37, 37, 38, 0.2898, 0.7091),
214
+ (38, 38, 39, 0.0822, 0.2011),
215
+ (39, 8, 40, 0.0928, 0.0473),
216
+ (40, 40, 41, 0.3319, 0.1114),
217
+ (41, 9, 42, 0.174, 0.0886),
218
+ (42, 42, 43, 0.203, 0.1034),
219
+ (43, 43, 44, 0.2842, 0.1447),
220
+ (44, 44, 45, 0.2813, 0.1433),
221
+ (45, 45, 46, 1.59, 0.5337),
222
+ (46, 46, 47, 0.7837, 0.263),
223
+ (47, 47, 48, 0.3042, 0.1006),
224
+ (48, 48, 49, 0.3861, 0.1172),
225
+ (49, 49, 50, 0.5075, 0.2585),
226
+ (50, 50, 51, 0.0974, 0.0496),
227
+ (51, 51, 52, 0.145, 0.0738),
228
+ (52, 52, 53, 0.7105, 0.3619),
229
+ (53, 53, 54, 1.041, 0.5302),
230
+ (54, 11, 55, 0.2012, 0.0611),
231
+ (55, 55, 56, 0.0047, 0.0014),
232
+ (56, 12, 57, 0.7394, 0.2444),
233
+ (57, 57, 58, 0.0047, 0.0016),
234
+ (58, 3, 59, 0.0044, 0.0108),
235
+ (59, 59, 60, 0.064, 0.1565),
236
+ (60, 60, 61, 0.1053, 0.123),
237
+ (61, 61, 62, 0.0304, 0.0355),
238
+ (62, 62, 63, 0.0018, 0.0021),
239
+ (63, 63, 64, 0.7283, 0.8509),
240
+ (64, 64, 65, 0.31, 0.3623),
241
+ (65, 65, 66, 0.041, 0.0478),
242
+ (66, 66, 67, 0.0092, 0.0116),
243
+ (67, 67, 68, 0.1089, 0.1373),
244
+ (68, 68, 69, 0.0009, 0.0012),
245
+ (69, 11, 66, 0.5, 0.5),
246
+ (70, 13, 21, 0.5, 0.5),
247
+ (71, 15, 69, 1, 0.5),
248
+ (72, 39, 48, 2, 1),
249
+ (73, 27, 54, 1, 0.5),
250
+ ]
251
+
252
+ _DEFAULT_GEN_POS = [1,2,3,6,8]
253
+
254
+ _DEFAULT_GENERATOR = GeneratorModel(0, 30, -30, 30, 0.0001, 0.3, 10)
255
+
256
+ def _create_load(s:float, scales:'list[tuple[int, float]]'):
257
+ return SegFunc([(p[0],p[1]*s) for p in scales])
258
+
259
+ def _get_buses(
260
+ Sb_KVA:float, grid_repeat:int,
261
+ LOAD:'list[tuple[int,float,float]]',
262
+ changeable_load:bool,
263
+ load_fluctuation:'list[tuple[int,float]]',
264
+ load_repeat:int,
265
+ load_period:int,
266
+ ):
267
+ if changeable_load:
268
+ if len(load_fluctuation) == 0:
269
+ for i in range(load_repeat):
270
+ for j in range(24):
271
+ load_fluctuation.append((_DEFAULT_LOAD_SCALE[j][0] + 86400 * i, _DEFAULT_LOAD_SCALE[j][1]))
272
+ else:
273
+ ls = load_fluctuation
274
+ load_fluctuation = []
275
+ for i in range(load_repeat):
276
+ for j in range(24):
277
+ load_fluctuation.append((ls[j][0] + load_period * i, ls[j][1]))
278
+ if grid_repeat == 1:
279
+ B = [Bus("B"+str(p[0]), _create_load(p[1]/Sb_KVA,load_fluctuation),
280
+ _create_load(p[2]/Sb_KVA,load_fluctuation)) for p in LOAD]
281
+ else:
282
+ B = []
283
+ for i in range(grid_repeat):
284
+ B.extend([Bus(f"B{i}_{p[0]}", _create_load(p[1]/Sb_KVA,load_fluctuation),
285
+ _create_load(p[2]/Sb_KVA,load_fluctuation)) for p in LOAD])
286
+ else:
287
+ if grid_repeat == 1:
288
+ B = [Bus("B"+str(p[0]), p[1]/Sb_KVA, p[2]/Sb_KVA) for p in LOAD]
289
+ else:
290
+ B = []
291
+ for i in range(grid_repeat):
292
+ B.extend([Bus(f"B{i}_{p[0]}", p[1]/Sb_KVA, p[2]/Sb_KVA) for p in LOAD])
293
+ return B
294
+
295
+ def _get_lines(Zb:float, LINE:'list[tuple[int,int,int,float,float]]', grid_repeat:int):
296
+ if grid_repeat == 1:
297
+ L = [Line("L"+str(p[0]), "B"+str(p[1]), "B"+str(p[2]), p[3]/Zb, p[4]/Zb) for p in LINE]
298
+ else:
299
+ L = []
300
+ for i in range(grid_repeat):
301
+ L.extend([Line(f"L{i}_{p[0]}", f"B{i}_{p[1]}", f"B{i}_{p[2]}", p[3]/Zb, p[4]/Zb) for p in LINE])
302
+ return L
303
+
304
+ def _get_gens(default_gen:GeneratorModel, gen_pos:'list[int]', grid_repeat:int):
305
+ if grid_repeat == 1:
306
+ G = [default_gen.toGenerator("G"+p, "B"+p) for p in map(str,gen_pos)]
307
+ else:
308
+ G = []
309
+ for i in range(grid_repeat):
310
+ G.extend([default_gen.toGenerator(f"G{i}_{p}", f"B{i}_{p}") for p in gen_pos])
311
+ return G
312
+
313
+ class PDNCases:
314
+ @staticmethod
315
+ def IEEE33(
316
+ Ub_kV:float=10.0,
317
+ Sb_MVA:float=0.25,
318
+ gen_pos:'list[int]'=_DEFAULT_GEN_POS,
319
+ default_gen:GeneratorModel=_DEFAULT_GENERATOR,
320
+ grid_repeat:int = 1,
321
+ changeable_load:bool = False,
322
+ load_fluctuation:'list[tuple[int, float]]' = [],
323
+ load_repeat:int = 8,
324
+ load_period:int = 86400
325
+ ):
326
+ '''IEEE 33-bus distribution network'''
327
+ return Grid(Sb_MVA, Ub_kV,
328
+ _get_buses(Sb_MVA*1000, grid_repeat, _IEEE33_LOAD, changeable_load, load_fluctuation, load_repeat, load_period),
329
+ _get_lines(Ub_kV**2/Sb_MVA, _IEEE33_LINE, grid_repeat),
330
+ _get_gens(default_gen, gen_pos, grid_repeat)
331
+ )
332
+
333
+ @staticmethod
334
+ def IEEE69(
335
+ Ub_kV:float=10.0,
336
+ Sb_MVA:float=0.25,
337
+ gen_pos:'list[int]'=_DEFAULT_GEN_POS,
338
+ default_gen:GeneratorModel=_DEFAULT_GENERATOR,
339
+ grid_repeat:int = 1,
340
+ changeable_load:bool = False,
341
+ load_fluctuation:'list[tuple[int, float]]' = [],
342
+ load_repeat:int = 8,
343
+ load_period:int = 86400
344
+ ):
345
+ '''IEEE 69-bus distribution network'''
346
+ return Grid(Sb_MVA, Ub_kV,
347
+ _get_buses(Sb_MVA*1000, grid_repeat, _IEEE69_LOAD, changeable_load, load_fluctuation, load_repeat, load_period),
348
+ _get_lines(Ub_kV**2/Sb_MVA, _IEEE69_LINE, grid_repeat),
349
+ _get_gens(default_gen, gen_pos, grid_repeat)
350
+ )
@@ -6,6 +6,7 @@ from typing import Any, TextIO, Iterable, Optional, Union
6
6
  from xml.etree.ElementTree import Element, ElementTree
7
7
  from feasytools import TimeFunc, SegFunc, ConstFunc, makeFunc
8
8
  from gurobipy import Model, GRB, quicksum, Var, Constr
9
+ from copy import deepcopy
9
10
 
10
11
  FloatVar = Optional[float]
11
12
  FloatLike = Union[int, float, TimeFunc, 'list[tuple[int, float]]']
@@ -264,6 +265,54 @@ class Line:
264
265
  "X": str(self.X),
265
266
  })
266
267
 
268
+ class GeneratorModel:
269
+ Pmin: TimeFunc #pu
270
+ Pmax: TimeFunc #pu
271
+ Qmin: TimeFunc #pu
272
+ Qmax: TimeFunc #pu
273
+ CostA: TimeFunc #$/(pu Power·h)**2
274
+ CostB: TimeFunc #$/pu Power·h
275
+ CostC: TimeFunc #$
276
+ def __init__(self, pmin_pu: FloatLike, pmax_pu: FloatLike, qmin_pu: FloatLike, qmax_pu: FloatLike,
277
+ costA: FloatLike, costB: FloatLike, costC: FloatLike):
278
+ '''
279
+ Initialize
280
+ pmin_pu: Minimal active power output, pu
281
+ pmax_pu: Maximal active power output, pu
282
+ qmin_pu: Minimal reactive power output, pu
283
+ qmax_pu: Maximal reactive power output, pu
284
+ costA: Secondary cost, $/(pu Power·h)**2
285
+ costB: Primary cost, $/pu Power·h
286
+ costC: Fixed cost, $
287
+ '''
288
+ self.Pmin = _float2func(pmin_pu)
289
+ self.Pmax = _float2func(pmax_pu)
290
+ self.Qmin = _float2func(qmin_pu)
291
+ self.Qmax = _float2func(qmax_pu)
292
+ self.CostA = _float2func(costA)
293
+ self.CostB = _float2func(costB)
294
+ self.CostC = _float2func(costC)
295
+
296
+ def toGenerator(self, id:str, busid:str):
297
+ return Generator(id, busid,
298
+ deepcopy(self.Pmin), deepcopy(self.Pmax),
299
+ deepcopy(self.Qmin), deepcopy(self.Qmax),
300
+ deepcopy(self.CostA), deepcopy(self.CostB),
301
+ deepcopy(self.CostC)
302
+ )
303
+
304
+ @staticmethod
305
+ def fromXML(node: 'Element', Sb_MVA: float, Ub_kV: float):
306
+ pmin = _readFloatLike(node.find("Pmin"), Sb_MVA, Ub_kV)
307
+ pmax = _readFloatLike(node.find("Pmax"), Sb_MVA, Ub_kV)
308
+ qmin = _readFloatLike(node.find("Qmin"), Sb_MVA, Ub_kV)
309
+ qmax = _readFloatLike(node.find("Qmax"), Sb_MVA, Ub_kV)
310
+ ca = _readFloatLike(node.find("CostA"), Sb_MVA, Ub_kV)
311
+ cb = _readFloatLike(node.find("CostB"), Sb_MVA, Ub_kV)
312
+ cc = _readFloatLike(node.find("CostC"), Sb_MVA, Ub_kV)
313
+ return GeneratorModel(pmin, pmax, qmin, qmax, ca, cb, cc)
314
+
315
+
267
316
  class Generator:
268
317
  ID: str
269
318
  BusID: str
@@ -304,7 +353,6 @@ class Generator:
304
353
  self.CostC = _float2func(costC)
305
354
  self.CostShadow = None
306
355
 
307
-
308
356
  def __repr__(self) -> str:
309
357
  return (f"Generator(id='{self.ID}', busid='{self.BusID}', P={self.P}, Q={self.Q}, " +
310
358
  f"pmin_pu={self.Pmin}, pmax_pu={self.Pmax}, qmin_pu={self.Qmin}, qmax_pu={self.Qmax}, " +
@@ -500,7 +548,7 @@ class Grid:
500
548
  b = '\n '.join(map(str, self._buses.values()))
501
549
  l = '\n '.join(map(str, self._lines.values()))
502
550
  g = '\n '.join(map(str, self._gens.values()))
503
- return f"Buses:\n {b}\nLines:\n {l}\nGenerators:\n {g}"
551
+ return f"Ub={self.Ub}kV, Sb={self.Sb_MVA}MVA\nBuses:\n {b}\nLines:\n {l}\nGenerators:\n {g}"
504
552
 
505
553
  def __str__(self):
506
554
  return repr(self)
@@ -509,7 +557,7 @@ class Grid:
509
557
  b = '\n '.join(v.str_t(_t) for v in self._buses.values())
510
558
  l = '\n '.join(v.str_t(_t) for v in self._lines.values())
511
559
  g = '\n '.join(v.str_t(_t) for v in self._gens.values())
512
- return f"At time {_t}:\nBuses:\n {b}\nLines:\n {l}\nGenerators:\n {g}"
560
+ return f"Ub={self.Ub}kV, Sb={self.Sb_MVA}MVA\nAt time {_t}:\nBuses:\n {b}\nLines:\n {l}\nGenerators:\n {g}"
513
561
 
514
562
  @staticmethod
515
563
  def fromFile(file_name:str, holdShadowPrice: bool = False):
@@ -523,6 +571,7 @@ class Grid:
523
571
  @staticmethod
524
572
  def fromFileXML(xml_name: str, holdShadowPrice: bool = False):
525
573
  rt = ElementTree(file=xml_name).getroot()
574
+ # Read base values
526
575
  Sb, unit = _readVal(rt.attrib["Sb"])
527
576
  if unit == "MVA": pass
528
577
  elif unit == "kVA": Sb /= 1000
@@ -530,16 +579,49 @@ class Grid:
530
579
  Ub, unit = _readVal(rt.attrib["Ub"])
531
580
  if unit == "kV": pass
532
581
  else: raise ValueError(f"Invalid base value unit: {unit}")
533
- buses = []
534
- lines = []
535
- gens = []
582
+ #Read grid model
583
+ bm = rt.attrib.get("model","")
584
+ if bm != "": # No base model
585
+ try:
586
+ grpt = int(rt.attrib.get("grid-repeat","1"))
587
+ lrpt = int(rt.attrib.get("load-repeat","1"))
588
+ fixed = rt.attrib.get("fixed-load","") == "true"
589
+ except:
590
+ raise ValueError("Invalid grid-repeat or load-repeat or fixed-load")
591
+ from .cases import _get_buses, _get_lines, _get_gens, _DEFAULT_LOAD_SCALE, _DEFAULT_GENERATOR, _DEFAULT_GEN_POS
592
+ if bm.lower() == "ieee33":
593
+ from .cases import _IEEE33_LOAD, _IEEE33_LINE
594
+ buses:list[Bus] = _get_buses(Sb * 1000, grpt, _IEEE33_LOAD, not fixed, _DEFAULT_LOAD_SCALE, lrpt, 86400)
595
+ lines:list[Line] = _get_lines(Ub * Ub / Sb, _IEEE33_LINE, grpt)
596
+ gens:list[Generator] = _get_gens(_DEFAULT_GENERATOR, _DEFAULT_GEN_POS, grpt)
597
+ elif bm.lower() == "ieee69":
598
+ from .cases import _IEEE69_LOAD, _IEEE69_LINE
599
+ buses:list[Bus] = _get_buses(Sb * 1000, grpt, _IEEE69_LOAD, not fixed, _DEFAULT_LOAD_SCALE, lrpt, 86400)
600
+ lines:list[Line] = _get_lines(Ub * Ub / Sb, _IEEE69_LINE, grpt)
601
+ gens:list[Generator] = _get_gens(_DEFAULT_GENERATOR, _DEFAULT_GEN_POS, grpt)
602
+ else:
603
+ raise ValueError(f"Undefined base model: {bm}")
604
+ else:
605
+ buses:list[Bus] = []
606
+ lines:list[Line] = []
607
+ gens:list[Generator] = []
608
+ #Read buses, lines and generators
609
+
610
+ gen_models:dict[str, GeneratorModel] = {}
536
611
  for e in rt:
537
612
  if e.tag == "bus":
538
613
  buses.append(Bus.fromXML(e, Sb, Ub))
539
614
  elif e.tag == "line":
540
615
  lines.append(Line.fromXML(e, Ub * Ub / Sb))
541
616
  elif e.tag == "gen" or e.tag == "generator":
542
- gens.append(Generator.fromXML(e, Sb, Ub))
617
+ bm = e.attrib.get("model","")
618
+ if bm == "": # No base model
619
+ gens.append(Generator.fromXML(e, Sb, Ub))
620
+ else:
621
+ if bm not in gen_models: raise ValueError(f"Undefined generator model: {bm}")
622
+ gens.append(gen_models[bm].toGenerator(e.attrib["ID"], e.attrib["Bus"]))
623
+ elif e.tag == "genmodel" or e.tag == "generatormodel":
624
+ gen_models[e.attrib["name"]] = GeneratorModel.fromXML(e, Sb, Ub)
543
625
  else:
544
626
  raise ValueError(f"Unknown XML node: {e.tag}")
545
627
  return Grid(Sb, Ub, buses, lines, gens, holdShadowPrice)
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.1
2
+ Name: fpowerkit
3
+ Version: 0.0.10
4
+ Summary: A Distflow PDN solver based on Gurobi.
5
+ Author: fmy_xfk
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: feasytools>=0.0.18
13
+ Requires-Dist: gurobipy>=9.1.0
14
+
15
+ # FPowerKit 配电网运算组件
16
+ **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!
17
+
18
+ IEEE33和IEEE69节点的配网数据从公开渠道收集。除配网数据以外,本仓库代码均遵循LGPL3.0协议使用。
19
+
20
+ ## 简介
21
+ - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
22
+ - 包含电网的描述(含母线、发电机、线路等)和采用Gurobi的配电网DistFlow模型求解。
23
+ - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
24
+ - 内含IEEE 33节点配电网和IEEE 69节点配电网,可通过以下方式快速创建:
25
+ ```py
26
+ from fpowerkit import PDNCases
27
+ grid_obj33 = PDNCases.IEEE33()
28
+ grid_obj69 = PDNCases.IEEE69()
29
+ ```
30
+
31
+ ## 使用
32
+
33
+ 克隆本仓库,并输入以下命令开始仿真:
34
+
35
+ ```bash
36
+ python main.py -g cases/ieee33.grid.zip
37
+ ```
38
+
39
+ 请注意上述命令不适用于pip安装的版本。
40
+
41
+ `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
42
+
43
+ ```
44
+ G0 G1
45
+ | |
46
+ B0->B1->B2
47
+ | |
48
+ L1 L2
49
+ ```
50
+
51
+ 您也换成自己的配电网文件来求解,例如`python main.py -g path/to/your_zipfile.zip`
52
+
53
+ ## 配电网文件格式
54
+ 目前,我们提供了2种方式记录配电网的结构和负荷信息,分别为ZIP格式和XML格式,我们推荐使用XML格式记录数据,因为其更加灵活。以下是两种方式的说明链接:
55
+
56
+ [XML格式](docs/xml_file.md) (推荐!)
57
+
58
+ [ZIP格式](docs/zip_file.md)
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf8") as f:
5
5
 
6
6
  setup(
7
7
  name="fpowerkit",
8
- version="0.0.8",
8
+ version="0.0.10",
9
9
  author="fmy_xfk",
10
10
  packages=find_packages(),
11
11
  description="A Distflow PDN solver based on Gurobi.",
fpowerkit-0.0.8/PKG-INFO DELETED
@@ -1,106 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: fpowerkit
3
- Version: 0.0.8
4
- Summary: A Distflow PDN solver based on Gurobi.
5
- Author: fmy_xfk
6
- Classifier: Programming Language :: Python :: 3
7
- Classifier: License :: OSI Approved :: MIT License
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: feasytools>=0.0.18
13
- Requires-Dist: gurobipy>=9.1.0
14
-
15
- # FPowerKit 配电网运算组件
16
- **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!(但不包括IEEE33等内置模型)
17
-
18
- ## 简介
19
- - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
20
- - 包含电网的描述(含母线、发电机、线路等)和基于gurobipy的配电网求解
21
- - 内含IEEE 33节点配电网DistFlow模型
22
- - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
23
-
24
- ## 使用
25
-
26
- 输入以下命令开始仿真:
27
- ```bash
28
- python main.py -g cases/ieee33.grid.zip
29
- ```
30
- `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
31
-
32
- ```
33
- G0 G1
34
- | |
35
- B0->B1->B2
36
- | |
37
- L1 L2
38
- ```
39
-
40
- 您也换成自己的`.zip`文件来仿真,例如`python main.py -g path/to/your_zipfile.zip`
41
-
42
- ## 文件格式
43
- 若要配置您自己的`.zip`文件来仿真,您需要确保该zip压缩文件**有且仅有**如下文件(区分大小写),不能包含任何文件夹:
44
- ```
45
- <your_file>.zip
46
- info.txt
47
- buses.csv
48
- lines.csv
49
- gens.csv
50
- ```
51
-
52
- 具体范例参见`PowerKit/cases/nodes3.zip`。
53
-
54
- #### info.txt
55
- 该文件示例如下:
56
-
57
- ```
58
- S_base_MVA: 10
59
- U_base_kV: 10
60
- buses_loop: 86400, 8
61
- buses_unit: MVA
62
- lines_unit: ohm
63
- gens_unit: MVA
64
- ```
65
-
66
- `S_base_MVA`表示复功率标幺值,单位为MVA;
67
- `U_base_kV`表示电压标幺值,单位为kV;
68
- `buses_loop`表示buses.csv中功率的循环周期(秒)和循环次数;
69
- `buses_unit`表示buses.csv中功率值的单位,可选pu(标幺值),kVA,MVA;
70
- `lines_unit`表示lines.csv中功率值的单位,可选pu(标幺值),ohm;
71
- `gens_unit`表示gens.csv中功率值的单位,可选pu(标幺值),kVA,MVA;
72
-
73
- #### buses.csv
74
- 该文件示例如下:
75
-
76
- ```
77
- time,0
78
- B0,0|0
79
- B1,10.2|3.2
80
- B2,3.8|0.7
81
- ```
82
-
83
- 首行表示时间线,内容用英文逗号分隔。第1个内容必定是小写`time`,从第2个内容开始为整数,表示从这一**秒**开始的负载功率;
84
- 从第2行开始,每行的第1个内容表示母线名称,从第二个内容开始表示复功率,以`有功功率|无功功率`的形式出现,单位为`info.txt`中的指定值。
85
-
86
- #### gens.csv
87
- 该文件示例如下:
88
-
89
- ```
90
- time,0
91
- G0|B0|0.002|0.3|5,0|100|-100|100
92
- G1|B1|0.0025|0.4|15,0|100|-100|100
93
- ```
94
-
95
- 首行表示时间线,内容用英文逗号分隔。第1个内容必定是小写`time`,从第2个内容开始为整数,表示从这一**秒**开始的发电功率最值;
96
- 从第2行开始,每行的第1个内容为`发电机ID|所在母线|成本系数a|成本系数b|成本系数c`,从第二个内容开始表示发电功率最值,以`最小有功功率|最大有功功率|最小无功功率|最大无功功率`的形式出现,单位为`info.txt`中的指定值。
97
-
98
- #### lines.csv
99
- 该文件示例如下:
100
- ```
101
- id,fBus,tBus,R,X
102
- L0-1,B0,B1,0.08,0.2
103
- L1-2,B1,B2,0.06,0.12
104
- ```
105
- 首行内容必须是`id,fBus,tBus,R,X`,区分大小写;
106
- 从第2行开始,每行的内容为`线路名称,起始母线,终止母线,线路电阻,线路电抗`。请注意线路功率的正方向为“起始母线->终止母线”,填反有可能需要在仿真时修改边界条件。
fpowerkit-0.0.8/README.md DELETED
@@ -1,92 +0,0 @@
1
- # FPowerKit 配电网运算组件
2
- **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!(但不包括IEEE33等内置模型)
3
-
4
- ## 简介
5
- - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
6
- - 包含电网的描述(含母线、发电机、线路等)和基于gurobipy的配电网求解
7
- - 内含IEEE 33节点配电网DistFlow模型
8
- - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
9
-
10
- ## 使用
11
-
12
- 输入以下命令开始仿真:
13
- ```bash
14
- python main.py -g cases/ieee33.grid.zip
15
- ```
16
- `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
17
-
18
- ```
19
- G0 G1
20
- | |
21
- B0->B1->B2
22
- | |
23
- L1 L2
24
- ```
25
-
26
- 您也换成自己的`.zip`文件来仿真,例如`python main.py -g path/to/your_zipfile.zip`
27
-
28
- ## 文件格式
29
- 若要配置您自己的`.zip`文件来仿真,您需要确保该zip压缩文件**有且仅有**如下文件(区分大小写),不能包含任何文件夹:
30
- ```
31
- <your_file>.zip
32
- info.txt
33
- buses.csv
34
- lines.csv
35
- gens.csv
36
- ```
37
-
38
- 具体范例参见`PowerKit/cases/nodes3.zip`。
39
-
40
- #### info.txt
41
- 该文件示例如下:
42
-
43
- ```
44
- S_base_MVA: 10
45
- U_base_kV: 10
46
- buses_loop: 86400, 8
47
- buses_unit: MVA
48
- lines_unit: ohm
49
- gens_unit: MVA
50
- ```
51
-
52
- `S_base_MVA`表示复功率标幺值,单位为MVA;
53
- `U_base_kV`表示电压标幺值,单位为kV;
54
- `buses_loop`表示buses.csv中功率的循环周期(秒)和循环次数;
55
- `buses_unit`表示buses.csv中功率值的单位,可选pu(标幺值),kVA,MVA;
56
- `lines_unit`表示lines.csv中功率值的单位,可选pu(标幺值),ohm;
57
- `gens_unit`表示gens.csv中功率值的单位,可选pu(标幺值),kVA,MVA;
58
-
59
- #### buses.csv
60
- 该文件示例如下:
61
-
62
- ```
63
- time,0
64
- B0,0|0
65
- B1,10.2|3.2
66
- B2,3.8|0.7
67
- ```
68
-
69
- 首行表示时间线,内容用英文逗号分隔。第1个内容必定是小写`time`,从第2个内容开始为整数,表示从这一**秒**开始的负载功率;
70
- 从第2行开始,每行的第1个内容表示母线名称,从第二个内容开始表示复功率,以`有功功率|无功功率`的形式出现,单位为`info.txt`中的指定值。
71
-
72
- #### gens.csv
73
- 该文件示例如下:
74
-
75
- ```
76
- time,0
77
- G0|B0|0.002|0.3|5,0|100|-100|100
78
- G1|B1|0.0025|0.4|15,0|100|-100|100
79
- ```
80
-
81
- 首行表示时间线,内容用英文逗号分隔。第1个内容必定是小写`time`,从第2个内容开始为整数,表示从这一**秒**开始的发电功率最值;
82
- 从第2行开始,每行的第1个内容为`发电机ID|所在母线|成本系数a|成本系数b|成本系数c`,从第二个内容开始表示发电功率最值,以`最小有功功率|最大有功功率|最小无功功率|最大无功功率`的形式出现,单位为`info.txt`中的指定值。
83
-
84
- #### lines.csv
85
- 该文件示例如下:
86
- ```
87
- id,fBus,tBus,R,X
88
- L0-1,B0,B1,0.08,0.2
89
- L1-2,B1,B2,0.06,0.12
90
- ```
91
- 首行内容必须是`id,fBus,tBus,R,X`,区分大小写;
92
- 从第2行开始,每行的内容为`线路名称,起始母线,终止母线,线路电阻,线路电抗`。请注意线路功率的正方向为“起始母线->终止母线”,填反有可能需要在仿真时修改边界条件。
@@ -1,378 +0,0 @@
1
- from feasytools import SegFunc
2
- from .grid import Grid, Bus, Line, Generator
3
-
4
- # IEEE33 kVA
5
- _IEEE33_LOAD = [
6
- (1,0,0),
7
- (2,100.00,60.00),
8
- (3,90.00,40.00),
9
- (4,120.00,80.00),
10
- (5,60.00,30.00),
11
- (6,60.00,20.00),
12
- (7,200.00,100.00),
13
- (8,200.00,100.00),
14
- (9,60.00,20.00),
15
- (10,60.00,20.00),
16
- (11,45.00,30.00),
17
- (12,60.00,35.00),
18
- (13,60.00,35.00),
19
- (14,120.00,80.00),
20
- (15,60.00,10.00),
21
- (16,60.00,20.00),
22
- (17,60.00,20.00),
23
- (18,90.00,40.00),
24
- (19,90.00,40.00),
25
- (20,90.00,40.00),
26
- (21,90.00,40.00),
27
- (22,90.00,40.00),
28
- (23,90.00,50.00),
29
- (24,420.00,200.00),
30
- (25,420.00,200.00),
31
- (26,60.00,25.00),
32
- (27,60.00,25.00),
33
- (28,60.00,20.00),
34
- (29,120.00,70.00),
35
- (30,200.00,600.00),
36
- (31,150.00,70.00),
37
- (32,210.00,100.00),
38
- (33,60.00,40.00)
39
- ]
40
-
41
- # IEEE69 kVA
42
- _IEEE69_LOAD = [
43
- [1, 0, 0],
44
- [2, 0, 0],
45
- [3, 0, 0],
46
- [4, 0, 0],
47
- [5, 0, 0],
48
- [6, 2.6, 2.2],
49
- [7, 40.4, 30],
50
- [8, 75, 54],
51
- [9, 30, 22],
52
- [10, 28, 19],
53
- [11, 145, 104],
54
- [12, 145, 104],
55
- [13, 8, 5.5],
56
- [14, 8, 5.5],
57
- [15, 0, 0, 0],
58
- [16, 45.5, 30],
59
- [17, 60, 35],
60
- [18, 60, 35],
61
- [19, 0, 0, 0],
62
- [20, 1, 0.6],
63
- [21, 114, 81],
64
- [22, 5.5, 3.5],
65
- [23, 0, 0, 0],
66
- [24, 28, 20],
67
- [25, 0, 0, 0],
68
- [26, 14, 10],
69
- [27, 14, 10],
70
- [28, 26, 18.6],
71
- [29, 26, 18.6],
72
- [30, 0, 0, 0],
73
- [31, 0, 0, 0],
74
- [32, 0, 0, 0],
75
- [33, 14, 10],
76
- [34, 19.5, 14],
77
- [35, 6, 4],
78
- [36, 0, 0, 0],
79
- [37, 79, 56.4],
80
- [38, 384.7, 274.5],
81
- [39, 384.7, 274.5],
82
- [40, 40.5, 28.3],
83
- [41, 3.6, 3.7],
84
- [42, 4.35, 3.5],
85
- [43, 26.4, 19],
86
- [44, 24, 17.2],
87
- [45, 0, 0, 0],
88
- [46, 0, 0, 0],
89
- [47, 0, 0, 0],
90
- [48, 100, 72],
91
- [49, 0, 0, 0],
92
- [50, 1244, 888],
93
- [51, 32, 23],
94
- [52, 0, 0, 0],
95
- [53, 227, 162],
96
- [54, 59, 42],
97
- [55, 18, 13],
98
- [56, 18, 13],
99
- [57, 28, 20],
100
- [58, 28, 20],
101
- [59, 26, 18.55],
102
- [60, 26, 18.55],
103
- [61, 0, 0, 0],
104
- [62, 24, 17],
105
- [63, 24, 17],
106
- [64, 1.2, 1],
107
- [65, 0, 0, 0],
108
- [66, 6, 4.3],
109
- [67, 0, 0, 0],
110
- [68, 39.22, 26.3],
111
- [69, 39.22, 26.3],
112
- ]
113
-
114
- _DEFAULT_LOAD_SCALE = [
115
- (0*3600, 0.7),
116
- (1*3600, 0.65),
117
- (2*3600, 0.625),
118
- (3*3600, 0.625),
119
- (4*3600, 0.625),
120
- (5*3600, 0.6),
121
- (6*3600, 0.725),
122
- (7*3600, 0.9),
123
- (8*3600, 1.15),
124
- (9*3600, 1.6),
125
- (10*3600, 2.025),
126
- (11*3600, 2.2),
127
- (12*3600, 2.25),
128
- (13*3600, 1.8),
129
- (14*3600, 1.0),
130
- (15*3600, 1.725),
131
- (16*3600, 1.975),
132
- (17*3600, 2.3),
133
- (18*3600, 2.425),
134
- (19*3600, 2.5),
135
- (20*3600, 1.95),
136
- (21*3600, 1.4),
137
- (22*3600, 1.0),
138
- (23*3600, 0.8),
139
- ]
140
-
141
- _IEEE33_LINE = [
142
- (1,1,2,0.0922,0.047),
143
- (2,2,3,0.493,0.2511),
144
- (3,3,4,0.366,0.1864),
145
- (4,4,5,0.3811,0.1941),
146
- (5,5,6,0.819,0.707),
147
- (6,6,7,0.1872,0.6188),
148
- (7,7,8,0.7114,0.2351),
149
- (8,8,9,1.03,0.74),
150
- (9,9,10,1.044,0.74),
151
- (10,10,11,0.1966,0.065),
152
- (11,11,12,0.3744,0.1238),
153
- (12,12,13,1.468,1.155),
154
- (13,13,14,0.5416,0.7129),
155
- (14,14,15,0.591,0.526),
156
- (15,15,16,0.7463,0.545),
157
- (16,16,17,1.289,1.721),
158
- (17,17,18,0.732,0.574),
159
- (18,2,19,0.164,0.1565),
160
- (19,19,20,1.5042,1.3554),
161
- (20,20,21,0.4095,0.4784),
162
- (21,21,22,0.7089,0.9373),
163
- (22,3,23,0.4512,0.3083),
164
- (23,23,24,0.898,0.7091),
165
- (24,24,25,0.896,0.7011),
166
- (25,6,26,0.203,0.1034),
167
- (26,26,27,0.2842,0.1447),
168
- (27,27,28,1.059,0.9337),
169
- (28,28,29,0.8042,0.7006),
170
- (29,29,30,0.5075,0.2585),
171
- (30,30,31,0.9744,0.963),
172
- (31,31,32,0.3105,0.3619),
173
- (32,32,33,0.341,0.5302),
174
- ]
175
-
176
- _IEEE69_LINE = [
177
- [1, 1, 2, 0.0005, 0.0012],
178
- [2, 2, 3, 0.0005, 0.0012],
179
- [3, 3, 4, 0.0015, 0.0036],
180
- [4, 4, 5, 0.0251, 0.0294],
181
- [5, 5, 6, 0.366, 0.1864],
182
- [6, 6, 7, 0.3811, 0.1941],
183
- [7, 7, 8, 0.0922, 0.047],
184
- [8, 8, 9, 0.0493, 0.0251],
185
- [9, 9, 10, 0.819, 0.2707],
186
- [10, 10, 11, 0.1872, 0.0619],
187
- [11, 11, 12, 0.7114, 0.2351],
188
- [12, 12, 13, 1.03, 0.34],
189
- [13, 13, 14, 1.044, 0.345],
190
- [14, 14, 15, 1.058, 0.3496],
191
- [15, 15, 16, 0.1966, 0.065],
192
- [16, 16, 17, 0.3744, 0.1238],
193
- [17, 17, 18, 0.0047, 0.0016],
194
- [18, 18, 19, 0.3267, 0.1083],
195
- [19, 19, 20, 0.2106, 0.0696],
196
- [20, 20, 21, 0.3416, 0.1129],
197
- [21, 21, 22, 0.014, 0.0046],
198
- [22, 22, 23, 0.1591, 0.0526],
199
- [23, 23, 24, 0.3463, 0.1145],
200
- [24, 24, 25, 0.7488, 0.2475],
201
- [25, 25, 26, 0.3089, 0.1021],
202
- [26, 26, 27, 0.1732, 0.0572],
203
- [27, 3, 28, 0.0044, 0.0108],
204
- [28, 28, 29, 0.064, 0.1565],
205
- [29, 29, 30, 0.3978, 0.1315],
206
- [30, 30, 31, 0.0702, 0.0232],
207
- [31, 31, 32, 0.351, 0.116],
208
- [32, 32, 33, 0.839, 0.2816],
209
- [33, 33, 34, 1.708, 0.5646],
210
- [34, 34, 35, 1.474, 0.4873],
211
- [35, 4, 36, 0.0034, 0.0084],
212
- [36, 36, 37, 0.0851, 0.2083],
213
- [37, 37, 38, 0.2898, 0.7091],
214
- [38, 38, 39, 0.0822, 0.2011],
215
- [39, 8, 40, 0.0928, 0.0473],
216
- [40, 40, 41, 0.3319, 0.1114],
217
- [41, 9, 42, 0.174, 0.0886],
218
- [42, 42, 43, 0.203, 0.1034],
219
- [43, 43, 44, 0.2842, 0.1447],
220
- [44, 44, 45, 0.2813, 0.1433],
221
- [45, 45, 46, 1.59, 0.5337],
222
- [46, 46, 47, 0.7837, 0.263],
223
- [47, 47, 48, 0.3042, 0.1006],
224
- [48, 48, 49, 0.3861, 0.1172],
225
- [49, 49, 50, 0.5075, 0.2585],
226
- [50, 50, 51, 0.0974, 0.0496],
227
- [51, 51, 52, 0.145, 0.0738],
228
- [52, 52, 53, 0.7105, 0.3619],
229
- [53, 53, 54, 1.041, 0.5302],
230
- [54, 11, 55, 0.2012, 0.0611],
231
- [55, 55, 56, 0.0047, 0.0014],
232
- [56, 12, 57, 0.7394, 0.2444],
233
- [57, 57, 58, 0.0047, 0.0016],
234
- [58, 3, 59, 0.0044, 0.0108],
235
- [59, 59, 60, 0.064, 0.1565],
236
- [60, 60, 61, 0.1053, 0.123],
237
- [61, 61, 62, 0.0304, 0.0355],
238
- [62, 62, 63, 0.0018, 0.0021],
239
- [63, 63, 64, 0.7283, 0.8509],
240
- [64, 64, 65, 0.31, 0.3623],
241
- [65, 65, 66, 0.041, 0.0478],
242
- [66, 66, 67, 0.0092, 0.0116],
243
- [67, 67, 68, 0.1089, 0.1373],
244
- [68, 68, 69, 0.0009, 0.0012],
245
- [69, 11, 66, 0.5, 0.5],
246
- [70, 13, 21, 0.5, 0.5],
247
- [71, 15, 69, 1, 0.5],
248
- [72, 39, 48, 2, 1],
249
- [73, 27, 54, 1, 0.5],
250
- ]
251
-
252
- _DEFAULT_GEN_POS = [1,2,3,6,8]
253
-
254
- def _create_load(s:float, scales:'list[tuple[int, float]]'):
255
- return SegFunc([(p[0],p[1]*s) for p in scales])
256
-
257
- class PDNCases:
258
- @staticmethod
259
- def IEEE33(
260
- Ub_kV:float=10.0,
261
- Sb_MVA:float=0.25,
262
- default_costA_dollar_per_kWh2:float=0.0001,
263
- default_costB_dollar_per_kWh:float=0.3,
264
- default_costC_dollar:float=10,
265
- default_gen_pmin_MW:float=0,
266
- default_gen_pmax_MW:float=30,
267
- default_gen_qmin_Mvar:float=-30,
268
- default_gen_qmax_Mvar:float=30,
269
- grid_repeat:int = 1,
270
- changeable_load:bool = False,
271
- load_fluctuation:'list[tuple[int, float]]' = [],
272
- load_repeat:int = 8
273
- ):
274
- '''IEEE 33-bus distribution network'''
275
- return PDNCases.__ieee(
276
- 33, Ub_kV, Sb_MVA, default_costA_dollar_per_kWh2, default_costB_dollar_per_kWh, default_costC_dollar,
277
- default_gen_pmin_MW, default_gen_pmax_MW, default_gen_qmin_Mvar, default_gen_qmax_Mvar,
278
- grid_repeat, changeable_load, load_fluctuation, load_repeat
279
- )
280
-
281
- @staticmethod
282
- def IEEE69(
283
- Ub_kV:float=10.0,
284
- Sb_MVA:float=0.25,
285
- default_costA_dollar_per_kWh2:float=0.0001,
286
- default_costB_dollar_per_kWh:float=0.3,
287
- default_costC_dollar:float=10,
288
- default_gen_pmin_MW:float=0,
289
- default_gen_pmax_MW:float=30,
290
- default_gen_qmin_Mvar:float=-30,
291
- default_gen_qmax_Mvar:float=30,
292
- grid_repeat:int = 1,
293
- changeable_load:bool = False,
294
- load_fluctuation:'list[tuple[int, float]]' = [],
295
- load_repeat:int = 8
296
- ):
297
- '''IEEE 69-bus distribution network'''
298
- return PDNCases.__ieee(
299
- 69, Ub_kV, Sb_MVA, default_costA_dollar_per_kWh2, default_costB_dollar_per_kWh, default_costC_dollar,
300
- default_gen_pmin_MW, default_gen_pmax_MW, default_gen_qmin_Mvar, default_gen_qmax_Mvar,
301
- grid_repeat, changeable_load, load_fluctuation, load_repeat
302
- )
303
-
304
- @staticmethod
305
- def __ieee(
306
- case:int,
307
- Ub_kV:float=10.0,
308
- Sb_MVA:float=0.25,
309
- default_costA_dollar_per_kWh2:float=0.0001,
310
- default_costB_dollar_per_kWh:float=0.3,
311
- default_costC_dollar:float=10,
312
- default_gen_pmin_MW:float=0,
313
- default_gen_pmax_MW:float=30,
314
- default_gen_qmin_Mvar:float=-30,
315
- default_gen_qmax_Mvar:float=30,
316
- grid_repeat:int = 1,
317
- changeable_load:bool = False,
318
- load_fluctuation:'list[tuple[int, float]]' = [],
319
- load_repeat:int = 8
320
- ):
321
- Ub = Ub_kV
322
- Sb = Sb_MVA
323
- Sb_KVA = Sb * 1000
324
- Zb = Ub**2/Sb
325
- G_pars = [
326
- default_gen_pmin_MW/Sb, default_gen_pmax_MW/Sb,
327
- default_gen_qmin_Mvar/Sb, default_gen_qmax_Mvar/Sb,
328
- default_costA_dollar_per_kWh2 * Sb_KVA * Sb_KVA,
329
- default_costB_dollar_per_kWh * Sb_KVA,
330
- default_costC_dollar
331
- ]
332
- if case == 33:
333
- LOAD = _IEEE33_LOAD
334
- LINE = _IEEE33_LINE
335
- elif case == 69:
336
- LOAD = _IEEE69_LOAD
337
- LINE = _IEEE69_LINE
338
- else:
339
- raise ValueError("case should be 33 or 69.")
340
- if grid_repeat == 1:
341
- L = [Line("L"+str(p[0]), "B"+str(p[1]), "B"+str(p[2]), p[3]/Zb, p[4]/Zb) for p in LINE]
342
- G = [Generator("G"+p, "B"+p, *G_pars) for p in map(str,_DEFAULT_GEN_POS)]
343
- else:
344
- L = []
345
- G = []
346
- for i in range(grid_repeat):
347
- L.extend([Line(f"L{i}_{p[0]}", f"B{i}_{p[1]}", f"B{i}_{p[2]}", p[3]/Zb, p[4]/Zb) for p in LINE])
348
- G.extend([Generator(
349
- f"G{i}_{p}", f"B{i}_{p}",
350
- default_gen_pmin_MW/Sb, default_gen_pmax_MW/Sb,
351
- default_gen_qmin_Mvar/Sb, default_gen_qmax_Mvar/Sb,
352
- default_costA_dollar_per_kWh2,
353
- default_costB_dollar_per_kWh,
354
- default_costC_dollar
355
- ) for p in _DEFAULT_GEN_POS])
356
-
357
- if changeable_load:
358
- if len(load_fluctuation) == 0:
359
- for i in range(load_repeat):
360
- for j in range(24):
361
- load_fluctuation.append((_DEFAULT_LOAD_SCALE[j][0] + 86400 * i, _DEFAULT_LOAD_SCALE[j][1]))
362
- if grid_repeat == 1:
363
- B = [Bus("B"+str(p[0]), _create_load(p[1]/Sb_KVA,load_fluctuation),
364
- _create_load(p[2]/Sb_KVA,load_fluctuation)) for p in LOAD]
365
- else:
366
- B = []
367
- for i in range(grid_repeat):
368
- B.extend([Bus(f"B{i}_{p[0]}", _create_load(p[1]/Sb_KVA,load_fluctuation),
369
- _create_load(p[2]/Sb_KVA,load_fluctuation)) for p in LOAD])
370
- else:
371
- if grid_repeat == 1:
372
- B = [Bus("B"+str(p[0]), p[1]/Sb_KVA, p[2]/Sb_KVA) for p in LOAD]
373
- else:
374
- B = []
375
- for i in range(grid_repeat):
376
- B.extend([Bus(f"B{i}_{p[0]}", p[1]/Sb_KVA, p[2]/Sb_KVA) for p in LOAD])
377
- return Grid(Sb,Ub,B,L,G)
378
-
@@ -1,106 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: fpowerkit
3
- Version: 0.0.8
4
- Summary: A Distflow PDN solver based on Gurobi.
5
- Author: fmy_xfk
6
- Classifier: Programming Language :: Python :: 3
7
- Classifier: License :: OSI Approved :: MIT License
8
- Classifier: Operating System :: OS Independent
9
- Requires-Python: >=3.8
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Requires-Dist: feasytools>=0.0.18
13
- Requires-Dist: gurobipy>=9.1.0
14
-
15
- # FPowerKit 配电网运算组件
16
- **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!(但不包括IEEE33等内置模型)
17
-
18
- ## 简介
19
- - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
20
- - 包含电网的描述(含母线、发电机、线路等)和基于gurobipy的配电网求解
21
- - 内含IEEE 33节点配电网DistFlow模型
22
- - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
23
-
24
- ## 使用
25
-
26
- 输入以下命令开始仿真:
27
- ```bash
28
- python main.py -g cases/ieee33.grid.zip
29
- ```
30
- `ieee33`描述了IEEE 33节点配电网模型。换成`nodes3`则是一个极简版3节点辐射形配电网模型,结构如下:
31
-
32
- ```
33
- G0 G1
34
- | |
35
- B0->B1->B2
36
- | |
37
- L1 L2
38
- ```
39
-
40
- 您也换成自己的`.zip`文件来仿真,例如`python main.py -g path/to/your_zipfile.zip`
41
-
42
- ## 文件格式
43
- 若要配置您自己的`.zip`文件来仿真,您需要确保该zip压缩文件**有且仅有**如下文件(区分大小写),不能包含任何文件夹:
44
- ```
45
- <your_file>.zip
46
- info.txt
47
- buses.csv
48
- lines.csv
49
- gens.csv
50
- ```
51
-
52
- 具体范例参见`PowerKit/cases/nodes3.zip`。
53
-
54
- #### info.txt
55
- 该文件示例如下:
56
-
57
- ```
58
- S_base_MVA: 10
59
- U_base_kV: 10
60
- buses_loop: 86400, 8
61
- buses_unit: MVA
62
- lines_unit: ohm
63
- gens_unit: MVA
64
- ```
65
-
66
- `S_base_MVA`表示复功率标幺值,单位为MVA;
67
- `U_base_kV`表示电压标幺值,单位为kV;
68
- `buses_loop`表示buses.csv中功率的循环周期(秒)和循环次数;
69
- `buses_unit`表示buses.csv中功率值的单位,可选pu(标幺值),kVA,MVA;
70
- `lines_unit`表示lines.csv中功率值的单位,可选pu(标幺值),ohm;
71
- `gens_unit`表示gens.csv中功率值的单位,可选pu(标幺值),kVA,MVA;
72
-
73
- #### buses.csv
74
- 该文件示例如下:
75
-
76
- ```
77
- time,0
78
- B0,0|0
79
- B1,10.2|3.2
80
- B2,3.8|0.7
81
- ```
82
-
83
- 首行表示时间线,内容用英文逗号分隔。第1个内容必定是小写`time`,从第2个内容开始为整数,表示从这一**秒**开始的负载功率;
84
- 从第2行开始,每行的第1个内容表示母线名称,从第二个内容开始表示复功率,以`有功功率|无功功率`的形式出现,单位为`info.txt`中的指定值。
85
-
86
- #### gens.csv
87
- 该文件示例如下:
88
-
89
- ```
90
- time,0
91
- G0|B0|0.002|0.3|5,0|100|-100|100
92
- G1|B1|0.0025|0.4|15,0|100|-100|100
93
- ```
94
-
95
- 首行表示时间线,内容用英文逗号分隔。第1个内容必定是小写`time`,从第2个内容开始为整数,表示从这一**秒**开始的发电功率最值;
96
- 从第2行开始,每行的第1个内容为`发电机ID|所在母线|成本系数a|成本系数b|成本系数c`,从第二个内容开始表示发电功率最值,以`最小有功功率|最大有功功率|最小无功功率|最大无功功率`的形式出现,单位为`info.txt`中的指定值。
97
-
98
- #### lines.csv
99
- 该文件示例如下:
100
- ```
101
- id,fBus,tBus,R,X
102
- L0-1,B0,B1,0.08,0.2
103
- L1-2,B1,B2,0.06,0.12
104
- ```
105
- 首行内容必须是`id,fBus,tBus,R,X`,区分大小写;
106
- 从第2行开始,每行的内容为`线路名称,起始母线,终止母线,线路电阻,线路电抗`。请注意线路功率的正方向为“起始母线->终止母线”,填反有可能需要在仿真时修改边界条件。
File without changes
File without changes