fpowerkit 0.4.0__tar.gz → 0.4.1__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.4.0 → fpowerkit-0.4.1}/PKG-INFO +3 -3
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/gen.py +2 -2
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/solbase.py +51 -2
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/solcmb.py +3 -3
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/soldist.py +9 -46
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/solldf.py +21 -7
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/solldf2.py +21 -6
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/solnt.py +3 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/pyproject.toml +3 -3
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/.gitignore +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/LICENSE +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/README.md +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/desc.md +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/__init__.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/bus.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/cases.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/ess.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/grid.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/island.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/line.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/lpwrapper.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/pvwind.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/solcvx.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/soldss.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/fpowerkit/utils.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/main.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/test.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/test314t.py +0 -0
- {fpowerkit-0.4.0 → fpowerkit-0.4.1}/test_cmb.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fpowerkit
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.1
|
|
4
4
|
Summary: A PDN solver with multiple solutions.
|
|
5
5
|
Author: fmy-xfk
|
|
6
6
|
License-Expression: MIT
|
|
@@ -12,13 +12,13 @@ Requires-Python: >=3.8
|
|
|
12
12
|
Requires-Dist: feasytools>=0.0.21
|
|
13
13
|
Requires-Dist: numpy>=1.19.0
|
|
14
14
|
Provides-Extra: distflow
|
|
15
|
+
Requires-Dist: cbc; extra == 'distflow'
|
|
15
16
|
Requires-Dist: cvxpy; extra == 'distflow'
|
|
16
|
-
Requires-Dist: ecos; extra == 'distflow'
|
|
17
17
|
Provides-Extra: dss
|
|
18
18
|
Requires-Dist: py-dss-interface; extra == 'dss'
|
|
19
19
|
Provides-Extra: full
|
|
20
|
+
Requires-Dist: cbc; extra == 'full'
|
|
20
21
|
Requires-Dist: cvxpy; extra == 'full'
|
|
21
|
-
Requires-Dist: ecos; extra == 'full'
|
|
22
22
|
Requires-Dist: py-dss-interface; extra == 'full'
|
|
23
23
|
Provides-Extra: ldf
|
|
24
24
|
Requires-Dist: scipy; extra == 'ldf'
|
|
@@ -56,7 +56,7 @@ class Generator(PositionBase):
|
|
|
56
56
|
self.Pmin = Float2Func(pmin_pu)
|
|
57
57
|
self.Pmax = Float2Func(pmax_pu)
|
|
58
58
|
else:
|
|
59
|
-
raise ValueError("Either P or (pmin, pmax) should be provided.")
|
|
59
|
+
raise ValueError(f"Either P or (pmin, pmax) should be provided for {id}.")
|
|
60
60
|
if Q is not None:
|
|
61
61
|
self._q = Float2Func(Q)
|
|
62
62
|
self._fixed_q = True
|
|
@@ -68,7 +68,7 @@ class Generator(PositionBase):
|
|
|
68
68
|
self.Qmin = Float2Func(qmin_pu)
|
|
69
69
|
self.Qmax = Float2Func(qmax_pu)
|
|
70
70
|
else:
|
|
71
|
-
raise ValueError("Either Q or (qmin, qmax) should be provided.")
|
|
71
|
+
raise ValueError(f"Either Q or (qmin, qmax) should be provided for {id}.")
|
|
72
72
|
self.CostA = Float2Func(costA)
|
|
73
73
|
self.CostB = Float2Func(costB)
|
|
74
74
|
self.CostC = Float2Func(costC)
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Optional, List, Dict
|
|
4
|
+
from feasytools import TimeFunc
|
|
2
5
|
from enum import IntEnum
|
|
3
6
|
from pathlib import Path
|
|
7
|
+
from .utils import FloatVar
|
|
4
8
|
from .island import *
|
|
5
9
|
from .grid import *
|
|
6
10
|
|
|
@@ -38,7 +42,7 @@ class SolverBase(ABC):
|
|
|
38
42
|
self._islands = Island.from_grid(grid)
|
|
39
43
|
|
|
40
44
|
@property
|
|
41
|
-
def Islands(self) ->
|
|
45
|
+
def Islands(self) -> List[Island]:
|
|
42
46
|
'''Get the islands of the grid'''
|
|
43
47
|
return self._islands
|
|
44
48
|
|
|
@@ -86,4 +90,49 @@ class SolverBase(ABC):
|
|
|
86
90
|
'''Solve the island'''
|
|
87
91
|
raise NotImplementedError
|
|
88
92
|
|
|
89
|
-
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class LoadReduceModule:
|
|
96
|
+
'''Load Reduce module'''
|
|
97
|
+
Bus: BusID
|
|
98
|
+
Limit: TimeFunc # The maximum load can be reduced. Should be set as the total **charging** load of the bus.
|
|
99
|
+
Reduction: FloatVar = None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class LRSolverBase(SolverBase):
|
|
103
|
+
def __init__(self, grid:Grid, eps:float = 1e-6, max_iter:int = 1000, *, mlrp: float = 0.5, bigM: float = 1e6, default_saveto:str = DEFAULT_SAVETO, **kwargs):
|
|
104
|
+
super().__init__(grid, eps, max_iter, default_saveto=default_saveto, **kwargs)
|
|
105
|
+
self.C = bigM
|
|
106
|
+
self._mlrp = mlrp
|
|
107
|
+
self._decb: Dict[BusID, LoadReduceModule] = {}
|
|
108
|
+
|
|
109
|
+
@property
|
|
110
|
+
def MLRP(self):
|
|
111
|
+
'''Get the maximum load reduction proportion'''
|
|
112
|
+
return self._mlrp
|
|
113
|
+
@MLRP.setter
|
|
114
|
+
def MLRP(self, v: float):
|
|
115
|
+
'''Set the maximum load reduction proportion'''
|
|
116
|
+
if v < 0 or v > 1:
|
|
117
|
+
raise ValueError("Invalid maximum load reduction proportion")
|
|
118
|
+
self._mlrp = v
|
|
119
|
+
|
|
120
|
+
def AddReduce(self, bus: BusID, limit: TimeFunc, reduction: Optional[FloatVar] = None):
|
|
121
|
+
'''Add a load reduction module'''
|
|
122
|
+
self._decb[bus] = LoadReduceModule(bus, limit, reduction)
|
|
123
|
+
|
|
124
|
+
def RemoveReduce(self, bus: BusID):
|
|
125
|
+
'''Remove a load reduction module'''
|
|
126
|
+
if bus in self._decb:
|
|
127
|
+
del self._decb[bus]
|
|
128
|
+
|
|
129
|
+
def GetReduce(self, bus: BusID) -> LoadReduceModule:
|
|
130
|
+
'''Get the load reduction module'''
|
|
131
|
+
return self._decb[bus]
|
|
132
|
+
|
|
133
|
+
@property
|
|
134
|
+
def DecBuses(self):
|
|
135
|
+
return self._decb
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
__all__ = ['SolverBase', 'GridSolveResult', 'DEFAULT_SAVETO', 'LoadReduceModule', 'LRSolverBase']
|
|
@@ -22,16 +22,16 @@ class CombinedSolver(SolverBase):
|
|
|
22
22
|
"""
|
|
23
23
|
def __init__(self, grid:Grid, eps:float = 1e-6, max_iter:int = 1000, *, mlrp:float = 0.5,
|
|
24
24
|
default_saveto:str = DEFAULT_SAVETO, estimator:Union[Estimator, SolverBase] = Estimator.DistFlow,
|
|
25
|
-
calculator:Calculator = Calculator.Newton, source_bus:'Union[str,Iterable[str]]' = ""):
|
|
25
|
+
calculator:Calculator = Calculator.Newton, source_bus:'Union[str, Iterable[str]]' = "", estimator_solver = "ECOS"):
|
|
26
26
|
super().__init__(grid, eps, max_iter, default_saveto = default_saveto)
|
|
27
27
|
|
|
28
28
|
if isinstance(estimator, Estimator):
|
|
29
29
|
if estimator == Estimator.DistFlow:
|
|
30
30
|
from .soldist import DistFlowSolver
|
|
31
|
-
estimator = DistFlowSolver(grid, mlrp = mlrp, default_saveto=default_saveto)
|
|
31
|
+
estimator = DistFlowSolver(grid, mlrp = mlrp, default_saveto=default_saveto, solver=estimator_solver)
|
|
32
32
|
elif estimator == Estimator.LinDistFlow:
|
|
33
33
|
from .solldf import LinDistFlowSolver
|
|
34
|
-
estimator = LinDistFlowSolver(grid, default_saveto=default_saveto)
|
|
34
|
+
estimator = LinDistFlowSolver(grid, default_saveto=default_saveto, solver=estimator_solver)
|
|
35
35
|
elif estimator == Estimator.LinDistFlow2:
|
|
36
36
|
from .solldf2 import LinDistFlow2Solver
|
|
37
37
|
estimator = LinDistFlow2Solver(grid, default_saveto=default_saveto)
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import math
|
|
2
2
|
import warnings
|
|
3
3
|
from itertools import chain
|
|
4
|
-
from typing import
|
|
5
|
-
from dataclasses import dataclass
|
|
4
|
+
from typing import Union
|
|
6
5
|
from feasytools import TimeFunc
|
|
7
|
-
from .utils import FloatVar
|
|
8
6
|
from .solbase import *
|
|
9
7
|
from .island import *
|
|
10
8
|
|
|
11
9
|
VF = Union['Var', float] # type: ignore
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
class LoadReduceModule:
|
|
15
|
-
'''Load Reduce module'''
|
|
16
|
-
Bus: BusID
|
|
17
|
-
Limit: TimeFunc
|
|
18
|
-
Reduction: FloatVar = None
|
|
19
|
-
|
|
20
|
-
class DistFlowSolver(SolverBase):
|
|
11
|
+
class DistFlowSolver(LRSolverBase):
|
|
21
12
|
'''DistFlow solver'''
|
|
22
13
|
def __init__(self, grid:Grid, eps:float = 1e-6, max_iter:int = 1000, *,
|
|
23
|
-
|
|
14
|
+
default_saveto:str = DEFAULT_SAVETO, mlrp: float = 0.5,
|
|
15
|
+
secondary_cost: bool = True, bigM: float = 1e6, solver = "CBC"):
|
|
24
16
|
'''
|
|
25
17
|
Initialize
|
|
26
18
|
grid: Grid object
|
|
@@ -30,13 +22,11 @@ class DistFlowSolver(SolverBase):
|
|
|
30
22
|
If False, the cost is calculated as CostB * Pg + CostC;
|
|
31
23
|
If True, the cost is calculated as CostA * Pg^2 + CostB * Pg + CostC.
|
|
32
24
|
'''
|
|
33
|
-
super().__init__(grid, eps, max_iter, default_saveto = default_saveto)
|
|
34
|
-
self._decb: dict[BusID, LoadReduceModule] = {}
|
|
35
|
-
self.C = bigM
|
|
36
|
-
self._mlrp = mlrp
|
|
25
|
+
super().__init__(grid, eps, max_iter, mlrp = mlrp, bigM = bigM, default_saveto = default_saveto)
|
|
37
26
|
self._oflines: set[LineID] = set()
|
|
38
27
|
self._ofbuses: set[BusID] = set()
|
|
39
28
|
self._sec_cost = secondary_cost
|
|
29
|
+
self.__solver = solver
|
|
40
30
|
|
|
41
31
|
@property
|
|
42
32
|
def OverflowLines(self):
|
|
@@ -53,34 +43,6 @@ class DistFlowSolver(SolverBase):
|
|
|
53
43
|
super().UpdateGrid(grid)
|
|
54
44
|
self.__il_relax = [False] * len(self._islands)
|
|
55
45
|
|
|
56
|
-
@property
|
|
57
|
-
def MLRP(self):
|
|
58
|
-
'''Get the maximum load reduction proportion'''
|
|
59
|
-
return self._mlrp
|
|
60
|
-
@MLRP.setter
|
|
61
|
-
def MLRP(self, v: float):
|
|
62
|
-
'''Set the maximum load reduction proportion'''
|
|
63
|
-
if v < 0 or v > 1:
|
|
64
|
-
raise ValueError("Invalid maximum load reduction proportion")
|
|
65
|
-
self._mlrp = v
|
|
66
|
-
|
|
67
|
-
def AddReduce(self, bus: BusID, limit: TimeFunc, reduction: Optional[FloatVar] = None):
|
|
68
|
-
'''Add a load reduction module'''
|
|
69
|
-
self._decb[bus] = LoadReduceModule(bus, limit, reduction)
|
|
70
|
-
|
|
71
|
-
def RemoveReduce(self, bus: BusID):
|
|
72
|
-
'''Remove a load reduction module'''
|
|
73
|
-
if bus in self._decb:
|
|
74
|
-
del self._decb[bus]
|
|
75
|
-
|
|
76
|
-
def GetReduce(self, bus: BusID) -> LoadReduceModule:
|
|
77
|
-
'''Get the load reduction module'''
|
|
78
|
-
return self._decb[bus]
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def DecBuses(self):
|
|
82
|
-
return self._decb
|
|
83
|
-
|
|
84
46
|
def solve(self, _t: int, /, *, timeout_s: float = 1) -> 'tuple[GridSolveResult, float]':
|
|
85
47
|
'''Get the best result at time _t, return a tuple: (result status, optimal objective value)'''
|
|
86
48
|
allOK = True
|
|
@@ -232,7 +194,7 @@ class DistFlowSolver(SolverBase):
|
|
|
232
194
|
|
|
233
195
|
Pdec: dict[BusID, Var] = {
|
|
234
196
|
bus: Var(name=f"Pdec_{bus}", nonneg=True)
|
|
235
|
-
for bus
|
|
197
|
+
for bus in self._decb
|
|
236
198
|
}
|
|
237
199
|
for bus, lim in self._decb.items():
|
|
238
200
|
cons.append(Pdec[bus] <= lim.Limit(_t) * self._mlrp)
|
|
@@ -291,7 +253,7 @@ class DistFlowSolver(SolverBase):
|
|
|
291
253
|
problem = cp.Problem(cp.Minimize(decs + goal + crpe), cons)
|
|
292
254
|
|
|
293
255
|
try:
|
|
294
|
-
problem.solve(solver=
|
|
256
|
+
problem.solve(solver=self.__solver, verbose=False, max_iters=self.max_iter)
|
|
295
257
|
except cp.SolverError as e:
|
|
296
258
|
if "installed" in e.args[0]:
|
|
297
259
|
raise e
|
|
@@ -314,6 +276,7 @@ class DistFlowSolver(SolverBase):
|
|
|
314
276
|
|
|
315
277
|
for j, bus in island.BusItems():
|
|
316
278
|
bus._v = self.__chkv(v[j].value) ** 0.5
|
|
279
|
+
bus._t = 0.0 # Theta is not calculated in DistFlow
|
|
317
280
|
|
|
318
281
|
for lid, line in island.LineItems():
|
|
319
282
|
line.I = self.__chkv(l[lid].value) ** 0.5
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from typing import Dict,
|
|
1
|
+
from typing import Dict, Tuple, Union
|
|
2
2
|
from feasytools import TimeFunc
|
|
3
|
-
from .solbase import DEFAULT_SAVETO, IslandResult,
|
|
3
|
+
from .solbase import DEFAULT_SAVETO, IslandResult, LRSolverBase
|
|
4
4
|
from .grid import Grid
|
|
5
5
|
from .island import Island
|
|
6
6
|
|
|
@@ -11,10 +11,10 @@ def _parse(x, t:int):
|
|
|
11
11
|
if isinstance(x, TimeFunc): return x(t)
|
|
12
12
|
raise TypeError("Unsupported type for parsing")
|
|
13
13
|
|
|
14
|
-
class LinDistFlowSolver(
|
|
14
|
+
class LinDistFlowSolver(LRSolverBase):
|
|
15
15
|
def __init__(self, grid:Grid, eps:float = 1e-6, max_iter:int = 1000, *,
|
|
16
|
-
default_saveto:str = DEFAULT_SAVETO, solver = "
|
|
17
|
-
super().__init__(grid, eps, max_iter, default_saveto=default_saveto)
|
|
16
|
+
mlrp: float = 0.5, bigM: float = 1e6, default_saveto:str = DEFAULT_SAVETO, solver = "CBC"):
|
|
17
|
+
super().__init__(grid, eps, max_iter, mlrp = mlrp, bigM = bigM, default_saveto=default_saveto)
|
|
18
18
|
self.__solver = solver
|
|
19
19
|
|
|
20
20
|
def solve_island(self, i:int, island:Island, _t:int, **kwargs) -> Tuple[IslandResult, float]:
|
|
@@ -28,6 +28,12 @@ class LinDistFlowSolver(SolverBase):
|
|
|
28
28
|
qg: 'dict[str, list]' = {b: [] for b in island.Buses}
|
|
29
29
|
pd: 'dict[str, float]' = {bID: b.Pd(_t) for bID, b in island.BusItems()}
|
|
30
30
|
qd: 'dict[str, float]' = {bID: b.Qd(_t) for bID, b in island.BusItems()}
|
|
31
|
+
Pdec: 'dict[str, cp.Variable]' = {
|
|
32
|
+
bus: cp.Variable(name = f"Pdec_{bus}", nonneg=True)
|
|
33
|
+
for bus in self._decb
|
|
34
|
+
}
|
|
35
|
+
for bus, lim in self._decb.items():
|
|
36
|
+
cons.append(Pdec[bus] <= lim.Limit(_t) * self._mlrp)
|
|
31
37
|
|
|
32
38
|
# Collect power generation data and set objective
|
|
33
39
|
for gID, g in island.GenItems():
|
|
@@ -87,11 +93,12 @@ class LinDistFlowSolver(SolverBase):
|
|
|
87
93
|
for j, bus in island.BusItems():
|
|
88
94
|
flow_in = island.grid.LinesOfTBus(j)
|
|
89
95
|
flow_out = island.grid.LinesOfFBus(j)
|
|
96
|
+
dec = Pdec[j] if j in Pdec else 0
|
|
90
97
|
|
|
91
98
|
# P constraint
|
|
92
99
|
inflow = cp.sum([pl[ln.ID] for ln in flow_in if ln.ID in island.Lines])
|
|
93
100
|
outflow = cp.sum([pl[ln.ID] for ln in flow_out if ln.ID in island.Lines])
|
|
94
|
-
cons.append(inflow + cp.sum(pg[j]) == outflow + pd[j])
|
|
101
|
+
cons.append(inflow + cp.sum(pg[j]) == outflow + pd[j] - dec)
|
|
95
102
|
|
|
96
103
|
# flow_in and flow_out are Python generators, which cannot be reused, thus needed to be re-assigned
|
|
97
104
|
flow_in = island.grid.LinesOfTBus(j)
|
|
@@ -110,7 +117,8 @@ class LinDistFlowSolver(SolverBase):
|
|
|
110
117
|
cons.append(v2[tbus.ID] == v2[fbus.ID] - 2*l.R*pl[lid] - 2*l.X*ql[lid])
|
|
111
118
|
l.I = None # Clear the current variable to avoid confusion
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
decs = self.C * cp.sum([Pdec[bus] for bus in Pdec])
|
|
121
|
+
prob = cp.Problem(cp.Minimize(obj + decs), cons)
|
|
114
122
|
prob.solve(solver=self.__solver, verbose=False, max_iters=self.max_iter)
|
|
115
123
|
if prob.status in (cp.OPTIMAL, cp.OPTIMAL_INACCURATE):
|
|
116
124
|
# Solution found
|
|
@@ -147,6 +155,12 @@ class LinDistFlowSolver(SolverBase):
|
|
|
147
155
|
p._pr = this_pr.item()
|
|
148
156
|
p._qr = p._pr * p.PF if p._pr is not None else 0
|
|
149
157
|
|
|
158
|
+
for bus, lim in self._decb.items():
|
|
159
|
+
v = Pdec[bus].value
|
|
160
|
+
assert v is not None
|
|
161
|
+
lim.Reduction = float(v.item())
|
|
162
|
+
if lim.Reduction < 1e-8: lim.Reduction = 0
|
|
163
|
+
|
|
150
164
|
obj_out = prob.value
|
|
151
165
|
assert isinstance(obj_out, (int, float))
|
|
152
166
|
return IslandResult.OK, float(obj_out)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from typing import Dict, Tuple, Union
|
|
2
2
|
from feasytools import TimeFunc
|
|
3
|
-
from .solbase import DEFAULT_SAVETO, IslandResult,
|
|
3
|
+
from .solbase import DEFAULT_SAVETO, IslandResult, LRSolverBase
|
|
4
4
|
from .grid import Grid
|
|
5
5
|
from .island import Island
|
|
6
6
|
|
|
@@ -11,9 +11,10 @@ def _parse(x, t:int):
|
|
|
11
11
|
if isinstance(x, TimeFunc): return x(t)
|
|
12
12
|
raise TypeError("Unsupported type for parsing")
|
|
13
13
|
|
|
14
|
-
class LinDistFlow2Solver(
|
|
15
|
-
def __init__(self, grid:Grid, eps:float = 1e-6, max_iter:int = 1000, *,
|
|
16
|
-
|
|
14
|
+
class LinDistFlow2Solver(LRSolverBase):
|
|
15
|
+
def __init__(self, grid:Grid, eps:float = 1e-6, max_iter:int = 1000, *,
|
|
16
|
+
mlrp = 0.5, bigM = 1e6, default_saveto:str = DEFAULT_SAVETO):
|
|
17
|
+
super().__init__(grid, eps, max_iter, mlrp = mlrp, bigM = bigM, default_saveto=default_saveto)
|
|
17
18
|
|
|
18
19
|
def solve_island(self, i:int, island:Island, _t:int, **kwargs) -> Tuple[IslandResult, float]:
|
|
19
20
|
from .lpwrapper import LinProgProblem, quicksum, _LPVar
|
|
@@ -28,6 +29,12 @@ class LinDistFlow2Solver(SolverBase):
|
|
|
28
29
|
qg_abs: 'dict[str, list]' = {b: [] for b in island.Buses}
|
|
29
30
|
pd: 'dict[str, float]' = {bID: b.Pd(_t) for bID, b in island.BusItems()}
|
|
30
31
|
qd: 'dict[str, float]' = {bID: b.Qd(_t) for bID, b in island.BusItems()}
|
|
32
|
+
Pdec: 'dict[str, _LPVar]' = {
|
|
33
|
+
bus: prob.add_var(f"Pdec_{bus}", 0, None)
|
|
34
|
+
for bus in self._decb
|
|
35
|
+
}
|
|
36
|
+
for bus, lim in self._decb.items():
|
|
37
|
+
prob.add_cons(Pdec[bus] <= lim.Limit(_t) * self._mlrp)
|
|
31
38
|
|
|
32
39
|
# Collect power generation data and set objective
|
|
33
40
|
for gID, g in island.GenItems():
|
|
@@ -92,11 +99,12 @@ class LinDistFlow2Solver(SolverBase):
|
|
|
92
99
|
for j, bus in island.BusItems():
|
|
93
100
|
flow_in = island.grid.LinesOfTBus(j)
|
|
94
101
|
flow_out = island.grid.LinesOfFBus(j)
|
|
102
|
+
dec = Pdec[j] if j in Pdec else 0
|
|
95
103
|
|
|
96
104
|
# P constraint
|
|
97
105
|
inflow = quicksum(pl[ln.ID] for ln in flow_in if ln.ID in island.Lines)
|
|
98
106
|
outflow = quicksum(pl[ln.ID] for ln in flow_out if ln.ID in island.Lines)
|
|
99
|
-
prob.add_cons(inflow + quicksum(pg[j]) == outflow + pd[j])
|
|
107
|
+
prob.add_cons(inflow + quicksum(pg[j]) == outflow + pd[j] - dec)
|
|
100
108
|
|
|
101
109
|
# flow_in and flow_out are Python generators, which cannot be reused, thus needed to be re-assigned
|
|
102
110
|
flow_in = island.grid.LinesOfTBus(j)
|
|
@@ -115,7 +123,8 @@ class LinDistFlow2Solver(SolverBase):
|
|
|
115
123
|
prob.add_cons(v2[tbus.ID] == v2[fbus.ID] - 2*l.R*pl[lid] - 2*l.X*ql[lid])
|
|
116
124
|
l.I = None # Clear the current variable to avoid confusion
|
|
117
125
|
|
|
118
|
-
|
|
126
|
+
decs = self.C * quicksum(Pdec[bus] for bus in Pdec)
|
|
127
|
+
prob.set_objective(obj + decs)
|
|
119
128
|
status, obj = prob.solve(minimize=True)
|
|
120
129
|
if status == 0:
|
|
121
130
|
# Solution found
|
|
@@ -142,6 +151,12 @@ class LinDistFlow2Solver(SolverBase):
|
|
|
142
151
|
p._pr = pv0[pID].x
|
|
143
152
|
p._qr = p._pr * p.PF if p._pr is not None else 0
|
|
144
153
|
|
|
154
|
+
for bus, lim in self._decb.items():
|
|
155
|
+
v = Pdec[bus].x
|
|
156
|
+
assert v is not None
|
|
157
|
+
lim.Reduction = v
|
|
158
|
+
if lim.Reduction < 1e-8: lim.Reduction = 0
|
|
159
|
+
|
|
145
160
|
return IslandResult.OK, obj
|
|
146
161
|
else:
|
|
147
162
|
return IslandResult.Failed, obj
|
|
@@ -283,6 +283,9 @@ class NewtonSolver(SolverBase):
|
|
|
283
283
|
obj += g.CostB(_t) * q_abs * 0.1
|
|
284
284
|
prob.add_cons(quicksum(p_dict.values()) == pg)
|
|
285
285
|
prob.add_cons(quicksum(q_dict.values()) == qg)
|
|
286
|
+
if isinstance(obj, int) and obj == 0:
|
|
287
|
+
# No free generator to adjust
|
|
288
|
+
return IslandResult.Failed, 0.0
|
|
286
289
|
prob.set_objective(obj)
|
|
287
290
|
prob.solve()
|
|
288
291
|
for gid, var in p_dict.items():
|
|
@@ -12,7 +12,7 @@ exclude = [
|
|
|
12
12
|
|
|
13
13
|
[project]
|
|
14
14
|
name = "fpowerkit"
|
|
15
|
-
version = "0.4.
|
|
15
|
+
version = "0.4.1"
|
|
16
16
|
requires-python = ">=3.8"
|
|
17
17
|
description = "A PDN solver with multiple solutions."
|
|
18
18
|
readme = "desc.md"
|
|
@@ -34,12 +34,12 @@ authors = [
|
|
|
34
34
|
[project.optional-dependencies]
|
|
35
35
|
full = [
|
|
36
36
|
"cvxpy",
|
|
37
|
-
"
|
|
37
|
+
"cbc",
|
|
38
38
|
"py_dss_interface",
|
|
39
39
|
]
|
|
40
40
|
distflow = [
|
|
41
41
|
"cvxpy",
|
|
42
|
-
"
|
|
42
|
+
"cbc",
|
|
43
43
|
]
|
|
44
44
|
ldf = [
|
|
45
45
|
"scipy"
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|