fpowerkit 0.1.4__tar.gz → 0.1.6__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.
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/PKG-INFO +9 -2
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/README.md +2 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/grid.py +2 -2
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/solbase.py +2 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/soldist.py +40 -19
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit.egg-info/PKG-INFO +9 -2
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/setup.py +1 -1
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/LICENSE +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/__init__.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/bus.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/cases.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/ess.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/gen.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/line.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/pvwind.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/soldss.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/solnt.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit/utils.py +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit.egg-info/SOURCES.txt +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit.egg-info/dependency_links.txt +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit.egg-info/requires.txt +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/fpowerkit.egg-info/top_level.txt +0 -0
- {fpowerkit-0.1.4 → fpowerkit-0.1.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: fpowerkit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: A Distflow PDN solver based on Gurobi.
|
|
5
5
|
Author: fmy_xfk
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -12,6 +12,13 @@ License-File: LICENSE
|
|
|
12
12
|
Requires-Dist: feasytools>=0.0.21
|
|
13
13
|
Requires-Dist: gurobipy>=9.1.0
|
|
14
14
|
Requires-Dist: numpy>=1.20.0
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: requires-dist
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
15
22
|
|
|
16
23
|
# FPowerKit - A power distribution network calculation component
|
|
17
24
|
|
|
@@ -234,9 +234,9 @@ class Grid:
|
|
|
234
234
|
l = self._lines.get(line_id)
|
|
235
235
|
if not l: raise ValueError(f"Invalid line name: {line_id}")
|
|
236
236
|
if l.tBus == new_bus_id: return
|
|
237
|
-
self.
|
|
237
|
+
self._ladjtb[l.tBus].remove(l)
|
|
238
238
|
l._tBus = new_bus_id
|
|
239
|
-
self.
|
|
239
|
+
self._ladjtb[l.tBus].append(l)
|
|
240
240
|
|
|
241
241
|
def ChangeLineID(self, old_id: str, new_id: str):
|
|
242
242
|
if old_id == new_id: return
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from enum import IntEnum
|
|
3
|
+
from pathlib import Path
|
|
3
4
|
from .grid import *
|
|
4
5
|
|
|
5
6
|
DEFAULT_SAVETO = "./fpowerkit_logs/"
|
|
@@ -21,6 +22,7 @@ class SolverBase(ABC):
|
|
|
21
22
|
|
|
22
23
|
def SetErrorSaveTo(self, path:str = DEFAULT_SAVETO):
|
|
23
24
|
self.saveto = path
|
|
25
|
+
Path(path).mkdir(parents=True, exist_ok = True)
|
|
24
26
|
|
|
25
27
|
@abstractmethod
|
|
26
28
|
def solve(self, grid:Grid, _t:int, /, **kwargs):
|
|
@@ -67,12 +67,17 @@ class IslandResult(IntEnum):
|
|
|
67
67
|
|
|
68
68
|
class DistFlowSolver(SolverBase):
|
|
69
69
|
'''DistFlow solver'''
|
|
70
|
-
def __init__(self, grid:Grid, eps:float = 1e-6, default_saveto:str = DEFAULT_SAVETO, /,
|
|
70
|
+
def __init__(self, grid:Grid, eps:float = 1e-6, default_saveto:str = DEFAULT_SAVETO, /,
|
|
71
|
+
*, mlrp:float = 0.5, secondary_cost:bool = True):
|
|
71
72
|
'''
|
|
72
73
|
Initialize
|
|
73
74
|
grid: Grid object
|
|
74
75
|
default_saveto: Default path to save the results
|
|
75
76
|
mlrp: Maximum proportion of load reduction
|
|
77
|
+
secondary_cost: Whether to include the secondary cost.
|
|
78
|
+
If False, the cost is calculated as CostB * Pg + CostC;
|
|
79
|
+
If True, the cost is calculated as CostA * Pg^2 + CostB * Pg + CostC,
|
|
80
|
+
which is likely to induce numerical instability.
|
|
76
81
|
'''
|
|
77
82
|
super().__init__(grid, eps, default_saveto)
|
|
78
83
|
self._decb:dict[BusID, LoadReduceModule] = {}
|
|
@@ -80,6 +85,7 @@ class DistFlowSolver(SolverBase):
|
|
|
80
85
|
self._mlrp = mlrp
|
|
81
86
|
self._oflines:set[LineID] = set()
|
|
82
87
|
self._ofbuses:set[BusID] = set()
|
|
88
|
+
self._sec_cost = secondary_cost
|
|
83
89
|
self.UpdateGrid()
|
|
84
90
|
|
|
85
91
|
@property
|
|
@@ -95,6 +101,7 @@ class DistFlowSolver(SolverBase):
|
|
|
95
101
|
_Island(self.grid, il, self._oflines) for il in self.__detect_islands(cut_overflow_lines)
|
|
96
102
|
)
|
|
97
103
|
self._island_res = [(IslandResult.Undefined, -1.0) for _ in range(len(self._islands))]
|
|
104
|
+
self.__il_relax = [False] * len(self._islands)
|
|
98
105
|
|
|
99
106
|
def __detect_islands(self, cutofl:bool):
|
|
100
107
|
'''Detect islands'''
|
|
@@ -163,11 +170,16 @@ class DistFlowSolver(SolverBase):
|
|
|
163
170
|
allFail = True
|
|
164
171
|
val = 0
|
|
165
172
|
for i, il in enumerate(self._islands):
|
|
166
|
-
self.
|
|
173
|
+
relax = self.__il_relax[i]
|
|
174
|
+
self._island_res[i] = self.__solve(_t, il, timeout_s, relax, relax)
|
|
175
|
+
if self._island_res[i][0] == IslandResult.Failed:
|
|
176
|
+
self.__il_relax[i] = True
|
|
177
|
+
self._island_res[i] = self.__solve(_t, il, timeout_s, True, True)
|
|
167
178
|
if self._island_res[i][0] != IslandResult.Failed:
|
|
168
179
|
allFail = False
|
|
169
180
|
val += self._island_res[i][1]
|
|
170
181
|
if self._island_res[i][0] != IslandResult.OK: allOK = False
|
|
182
|
+
if self._island_res[i][0] == IslandResult.OverFlow: self.__il_relax[i] = False
|
|
171
183
|
if allOK:
|
|
172
184
|
return GridSolveResult.OK, val
|
|
173
185
|
elif allFail:
|
|
@@ -180,7 +192,7 @@ class DistFlowSolver(SolverBase):
|
|
|
180
192
|
else:
|
|
181
193
|
return GridSolveResult.PartialOK, val
|
|
182
194
|
|
|
183
|
-
def __solve(self, _t: int, island:_Island, timeout_s:float) -> 'tuple[IslandResult, float]':
|
|
195
|
+
def __solve(self, _t: int, island:_Island, timeout_s:float, relaxV:bool, relaxI:bool, clear_results:bool=False) -> 'tuple[IslandResult, float]':
|
|
184
196
|
model = Model("model")
|
|
185
197
|
|
|
186
198
|
''' ---------Variables----------
|
|
@@ -235,11 +247,11 @@ class DistFlowSolver(SolverBase):
|
|
|
235
247
|
p, q = e.GetLoad(_t, island.grid.ChargePrice(_t), island.grid.DischargePrice(_t))
|
|
236
248
|
e.P = p
|
|
237
249
|
if p > 0:
|
|
238
|
-
|
|
239
|
-
|
|
250
|
+
pd[e.BusID] += p
|
|
251
|
+
qd[e.BusID] += q
|
|
240
252
|
elif p < 0:
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
pg[e.BusID].append(-p)
|
|
254
|
+
qg[e.BusID].append(-q)
|
|
243
255
|
|
|
244
256
|
# Create BUS vars
|
|
245
257
|
v = {bID: model.addVar(name=f"v_{bID}", vtype='C') for bID in island.Buses}
|
|
@@ -249,18 +261,24 @@ class DistFlowSolver(SolverBase):
|
|
|
249
261
|
if b.FixedV:
|
|
250
262
|
assert b.V is not None, f"Bus {bid} has fixed voltage but not set"
|
|
251
263
|
model.addConstr(v[bid] == b.V ** 2)
|
|
252
|
-
|
|
264
|
+
elif relaxV:
|
|
253
265
|
dvmin[bid] = model.addVar(name=f"dvmin_{bid}", vtype='C', lb=0)
|
|
254
266
|
dvmax[bid] = model.addVar(name=f"dvmax_{bid}", vtype='C', lb=0)
|
|
255
267
|
model.addConstr(v[bid] >= b.MinV ** 2 - dvmin[bid])
|
|
256
268
|
model.addConstr(v[bid] <= b.MaxV ** 2 + dvmax[bid])
|
|
269
|
+
else:
|
|
270
|
+
model.addConstr(v[bid] >= b.MinV ** 2)
|
|
271
|
+
model.addConstr(v[bid] <= b.MaxV ** 2)
|
|
257
272
|
|
|
258
273
|
# Create Line vars
|
|
259
274
|
dlmax:dict[str, Var] = {}
|
|
260
275
|
l = {lID: model.addVar(name=f"l_{lID}", vtype='C', lb=0) for lID in island.Lines}
|
|
261
276
|
for lID, ln in island.LineItems():
|
|
262
|
-
|
|
263
|
-
|
|
277
|
+
if relaxI:
|
|
278
|
+
dlmax[lID] = model.addVar(name=f"dlmax_{lID}", vtype='C', lb=0)
|
|
279
|
+
model.addConstr(l[lID] <= (ln.max_I/island.grid.Ib) ** 2 + dlmax[lID])
|
|
280
|
+
else:
|
|
281
|
+
model.addConstr(l[lID] <= (ln.max_I/island.grid.Ib) ** 2)
|
|
264
282
|
|
|
265
283
|
P = {lID: model.addVar(name=f"P_{lID}", vtype='C', lb=-GRB.INFINITY, ub=GRB.INFINITY) for lID in
|
|
266
284
|
island.Lines}
|
|
@@ -298,7 +316,10 @@ class DistFlowSolver(SolverBase):
|
|
|
298
316
|
|
|
299
317
|
decs = self.C * (Qs(Pdec.values()) + Qs(dvmin.values()) + Qs(dvmax.values()) + Qs(dlmax.values()))
|
|
300
318
|
crpe = Qs(p.CC*(p.P(_t)-pvwp[pID]) for pID, p in island.PVWItems())
|
|
301
|
-
|
|
319
|
+
if self._sec_cost:
|
|
320
|
+
goal = Qs(g.CostA(_t) * pg0[gID] ** 2 + g.CostB(_t) * pg0[gID] + g.CostC(_t) for gID, g in island.GenItems())
|
|
321
|
+
else:
|
|
322
|
+
goal = Qs(g.CostB(_t) * pg0[gID] + g.CostC(_t) for gID, g in island.GenItems())
|
|
302
323
|
|
|
303
324
|
model.setObjective(decs + goal + crpe, GRB.MINIMIZE)
|
|
304
325
|
model.setParam(GRB.Param.OutputFlag, 0)
|
|
@@ -309,21 +330,21 @@ class DistFlowSolver(SolverBase):
|
|
|
309
330
|
model.optimize()
|
|
310
331
|
|
|
311
332
|
if model.Status != GRB.Status.OPTIMAL and model.Status != GRB.Status.SUBOPTIMAL:
|
|
312
|
-
for
|
|
313
|
-
bus.
|
|
314
|
-
|
|
333
|
+
for _, bus in island.BusItems():
|
|
334
|
+
if not bus.FixedV: bus._v = 0
|
|
335
|
+
bus.ShadowPrice = 0
|
|
336
|
+
for _, p in island.PVWItems():
|
|
315
337
|
p._pr = p._qr = p._cr = 0
|
|
316
|
-
for
|
|
338
|
+
for _, line in island.LineItems():
|
|
317
339
|
line.I = line.P = line.Q = 0
|
|
318
340
|
for j, gen in island.GenItems():
|
|
319
341
|
if not gen.FixedP: gen._p = 0
|
|
320
342
|
if not gen.FixedQ: gen._q = 0
|
|
321
|
-
for
|
|
343
|
+
for _, e in island.ESSItems():
|
|
322
344
|
e.P = 0
|
|
323
345
|
return IslandResult.Failed, -1
|
|
324
346
|
|
|
325
347
|
for j, bus in island.BusItems():
|
|
326
|
-
j = bus.ID
|
|
327
348
|
bus._v = v[j].X ** 0.5
|
|
328
349
|
try:
|
|
329
350
|
sp = Pcons[j].Pi
|
|
@@ -351,13 +372,13 @@ class DistFlowSolver(SolverBase):
|
|
|
351
372
|
overflow = False
|
|
352
373
|
self._ofbuses.clear()
|
|
353
374
|
for bID, bv in chain(dvmax.items(), dvmin.items()):
|
|
354
|
-
if bv.X > 1e-
|
|
375
|
+
if bv.X > 1e-8:
|
|
355
376
|
overflow = True
|
|
356
377
|
self._ofbuses.add(bID)
|
|
357
378
|
|
|
358
379
|
self._oflines.clear()
|
|
359
380
|
for lID, lv in dlmax.items():
|
|
360
|
-
if lv.X > 1e-
|
|
381
|
+
if lv.X > 1e-8:
|
|
361
382
|
overflow = True
|
|
362
383
|
self._oflines.add(lID)
|
|
363
384
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: fpowerkit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: A Distflow PDN solver based on Gurobi.
|
|
5
5
|
Author: fmy_xfk
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -12,6 +12,13 @@ License-File: LICENSE
|
|
|
12
12
|
Requires-Dist: feasytools>=0.0.21
|
|
13
13
|
Requires-Dist: gurobipy>=9.1.0
|
|
14
14
|
Requires-Dist: numpy>=1.20.0
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: requires-dist
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
15
22
|
|
|
16
23
|
# FPowerKit - A power distribution network calculation component
|
|
17
24
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|