fpowerkit 0.0.6__tar.gz → 0.0.8__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -13,7 +13,10 @@ Requires-Dist: feasytools>=0.0.18
13
13
  Requires-Dist: gurobipy>=9.1.0
14
14
 
15
15
  # FPowerKit 配电网运算组件
16
- - 依赖于feasytools和gurobipy: `pip install feasytools,gurobipy`(请自行安装Gurobi并申请许可证)
16
+ **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!(但不包括IEEE33等内置模型)
17
+
18
+ ## 简介
19
+ - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
17
20
  - 包含电网的描述(含母线、发电机、线路等)和基于gurobipy的配电网求解
18
21
  - 内含IEEE 33节点配电网DistFlow模型
19
22
  - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
@@ -1,5 +1,8 @@
1
1
  # FPowerKit 配电网运算组件
2
- - 依赖于feasytools和gurobipy: `pip install feasytools,gurobipy`(请自行安装Gurobi并申请许可证)
2
+ **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!(但不包括IEEE33等内置模型)
3
+
4
+ ## 简介
5
+ - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
3
6
  - 包含电网的描述(含母线、发电机、线路等)和基于gurobipy的配电网求解
4
7
  - 内含IEEE 33节点配电网DistFlow模型
5
8
  - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
@@ -0,0 +1,2 @@
1
+ from .grid import *
2
+ from .cases import PDNCases
@@ -0,0 +1,378 @@
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,4 +1,5 @@
1
1
  from enum import IntEnum
2
+ from pathlib import Path
2
3
  import zipfile
3
4
  from io import BytesIO, TextIOWrapper
4
5
  from typing import Any, TextIO, Iterable, Optional, Union
@@ -395,6 +396,7 @@ class GridSolveResult(IntEnum):
395
396
  Failed = 0
396
397
  OK = 1
397
398
  OKwithoutVICons = 2
399
+ SubOKwithoutVICons = 3
398
400
 
399
401
  class Grid:
400
402
  Sb: float #MVA
@@ -447,6 +449,10 @@ class Grid:
447
449
  assert gen.BusID in self._bnames
448
450
  self._gatb[gen.BusID].append(gen)
449
451
  self.__holdShadowPrice = holdShadowPrice
452
+ self.__saveto:str = ""
453
+
454
+ def SetErrorSaveTo(self, path:str = ""):
455
+ self.__saveto = path
450
456
 
451
457
  def AddGen(self, g: Generator):
452
458
  self._gens[g.ID] = g
@@ -580,6 +586,12 @@ class Grid:
580
586
  raise ValueError(f"Invalid power unit: {gens_unit}")
581
587
  return Grid(Sb, Ub, buses, lines, gens, holdShadowPrice)
582
588
 
589
+ def savePQofBus(self, file_name: str, t:int):
590
+ with open(file_name, "w") as fp:
591
+ fp.write("Bus,Pd,Qd\n")
592
+ for bus in self.Buses:
593
+ fp.write(f"{bus.ID},{bus.Pd(t)},{bus.Qd(t)}\n")
594
+
583
595
  def loadPQofBus(self, file_name: str):
584
596
  with open(file_name) as fp:
585
597
  for ln in fp.readlines()[1:]:
@@ -587,9 +599,28 @@ class Grid:
587
599
  self.Bus(bn).Pd = ConstFunc(float(p) / self.Sb)
588
600
  self.Bus(bn).Qd = ConstFunc(float(q) / self.Sb)
589
601
 
590
- def solve(self, _t: int, /, *, max_v_pu:float = 1.1, min_v_pu: float = 0.9, max_I_kA: float = 0.866,
591
- source_buses:'list[BusID]' = [], source_bus_V_pu:float = 1.0) -> 'tuple[GridSolveResult, float]':
592
- '''Get the best result at time _t, return a tuple: (success?, optimal objective value)'''
602
+ def solve(self, _t: int, /, *, max_v_pu: float = 1.1, min_v_pu: float = 0.9, max_I_kA: float = 0.866,
603
+ source_buses:'list[BusID]' = [], source_bus_V_pu:float = 1.0, timeout_s:float = 1) -> 'tuple[GridSolveResult, float]':
604
+ '''Get the best result at time _t, return a tuple: (result status, optimal objective value)'''
605
+ ok, val = self.__solve(_t, max_v_pu, min_v_pu, max_I_kA, source_buses, source_bus_V_pu, timeout_s)
606
+ if ok == GRB.Status.OPTIMAL:
607
+ return GridSolveResult.OK, val
608
+ else:
609
+ ok, val = self.__solve(_t, float("inf"), 0, float("inf"), source_buses, source_bus_V_pu, timeout_s)
610
+ if ok == GRB.Status.OPTIMAL:
611
+ return GridSolveResult.OKwithoutVICons, val
612
+ elif ok == GRB.Status.SUBOPTIMAL:
613
+ return GridSolveResult.SubOKwithoutVICons, val
614
+ else:
615
+ print(f"Failed to solve at time {_t}: {ok}")
616
+ if self.__saveto != "":
617
+ p = Path(self.__saveto)
618
+ p.mkdir(parents=True, exist_ok=True)
619
+ self.savePQofBus(str(p/f"{_t}_load.csv"), _t)
620
+ return GridSolveResult.Failed, val
621
+
622
+ def __solve(self, _t: int, max_v_pu:float, min_v_pu: float, max_I_kA: float,
623
+ source_buses:'list[BusID]', source_bus_V_pu:float, timeout_s:float) -> 'tuple[int, float]':
593
624
  model = Model("model")
594
625
  max_v = max_v_pu ** 2
595
626
  min_v = min_v_pu ** 2
@@ -646,18 +677,13 @@ class Grid:
646
677
  model.setObjective(
647
678
  quicksum(g.CostA(_t) * pg0[g.ID] ** 2 + g.CostB(_t) * pg0[g.ID] + g.CostC(_t) for g in self.Gens),
648
679
  GRB.MINIMIZE)
649
- model.setParam('OutputFlag', 0)
650
- model.setParam('QCPDual', 1)
680
+ model.setParam(GRB.Param.OutputFlag, 0)
681
+ model.setParam(GRB.Param.QCPDual, 1)
682
+ model.setParam(GRB.Param.TimeLimit, timeout_s)
651
683
  model.update()
652
684
  model.optimize()
653
685
  if model.Status != GRB.Status.OPTIMAL:
654
- # Remove VI constraints and try again
655
- state, val = self.solve(_t, max_v_pu=float("inf"), min_v_pu=0, max_I_kA=float("inf"),
656
- source_buses=source_buses,source_bus_V_pu=source_bus_V_pu)
657
- if state == GridSolveResult.OK:
658
- return GridSolveResult.OKwithoutVICons, val
659
- else:
660
- return GridSolveResult.Failed, val
686
+ return model.Status, -1
661
687
 
662
688
  for bus in self.Buses:
663
689
  j = bus.ID
@@ -679,4 +705,4 @@ class Grid:
679
705
  gen.P = pg0[j].X
680
706
  gen.Q = qg0[j].X
681
707
 
682
- return GridSolveResult.OK, model.ObjVal
708
+ return model.Status, model.ObjVal
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -13,7 +13,10 @@ Requires-Dist: feasytools>=0.0.18
13
13
  Requires-Dist: gurobipy>=9.1.0
14
14
 
15
15
  # FPowerKit 配电网运算组件
16
- - 依赖于feasytools和gurobipy: `pip install feasytools,gurobipy`(请自行安装Gurobi并申请许可证)
16
+ **本仓库已上线PyPI**,您可以通过`pip install fpowerkit`直接以Python包的形式安装使用本仓库的代码!(但不包括IEEE33等内置模型)
17
+
18
+ ## 简介
19
+ - 依赖于feasytools和gurobipy: `pip install feasytools gurobipy`(请自行安装Gurobi并申请许可证)
17
20
  - 包含电网的描述(含母线、发电机、线路等)和基于gurobipy的配电网求解
18
21
  - 内含IEEE 33节点配电网DistFlow模型
19
22
  - 优化目标为“发电成本最小”。发电成本模型为二次函数$f(x)=ax^2+bx+c$。
@@ -2,6 +2,7 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  fpowerkit/__init__.py
5
+ fpowerkit/cases.py
5
6
  fpowerkit/grid.py
6
7
  fpowerkit.egg-info/PKG-INFO
7
8
  fpowerkit.egg-info/SOURCES.txt
@@ -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.6",
8
+ version="0.0.8",
9
9
  author="fmy_xfk",
10
10
  packages=find_packages(),
11
11
  description="A Distflow PDN solver based on Gurobi.",
@@ -1 +0,0 @@
1
- from .grid import *
File without changes
File without changes