fpowerkit 0.0.3__tar.gz → 0.0.5__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.0.3 → fpowerkit-0.0.5}/PKG-INFO +1 -1
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit/grid.py +16 -9
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit.egg-info/PKG-INFO +1 -1
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/setup.py +1 -1
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/LICENSE +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/README.md +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit/__init__.py +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit.egg-info/SOURCES.txt +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit.egg-info/dependency_links.txt +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit.egg-info/requires.txt +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/fpowerkit.egg-info/top_level.txt +0 -0
- {fpowerkit-0.0.3 → fpowerkit-0.0.5}/setup.cfg +0 -0
|
@@ -7,6 +7,7 @@ from gurobipy import Model, GRB, quicksum, Var, Constr
|
|
|
7
7
|
|
|
8
8
|
FloatVar = Optional[float]
|
|
9
9
|
FloatLike = Union[int, float, TimeFunc, 'list[tuple[int, float]]']
|
|
10
|
+
FloatVals = Union[int, float]
|
|
10
11
|
Qs = quicksum
|
|
11
12
|
|
|
12
13
|
|
|
@@ -50,8 +51,9 @@ def _readVal(s: str) -> 'tuple[float, str]':
|
|
|
50
51
|
return float(s), ""
|
|
51
52
|
|
|
52
53
|
|
|
53
|
-
def _readFloatLike(e: Element, sb_mva:float, ub_kv:float) -> FloatLike:
|
|
54
|
-
|
|
54
|
+
def _readFloatLike(e: Optional[Element], sb_mva:float, ub_kv:float) -> FloatLike:
|
|
55
|
+
assert e is not None
|
|
56
|
+
def _valconv(v:FloatVals, u:str) -> FloatVals:
|
|
55
57
|
if u == "pu":
|
|
56
58
|
return v
|
|
57
59
|
elif u == "kVA":
|
|
@@ -130,7 +132,7 @@ class Bus:
|
|
|
130
132
|
return f"Bus(id='{self.ID}', v_pu={_tfv(self.V)}, pd_pu={self.Pd(_t)}, qd_pu={self.Qd(_t)}, lat={self.Lat}, lon={self.Lon})"
|
|
131
133
|
|
|
132
134
|
@property
|
|
133
|
-
def position(self) -> 'tuple[float, float]':
|
|
135
|
+
def position(self) -> 'tuple[Optional[float], Optional[float]]':
|
|
134
136
|
'''Return the position of the bus, (lat, lon)'''
|
|
135
137
|
return self.Lat, self.Lon
|
|
136
138
|
|
|
@@ -140,7 +142,9 @@ class Bus:
|
|
|
140
142
|
p = _readFloatLike(node.find("Pd"), Sb_MVA, Ub_kV)
|
|
141
143
|
q = _readFloatLike(node.find("Qd"), Sb_MVA, Ub_kV)
|
|
142
144
|
lat = node.attrib.get("Lat", None)
|
|
145
|
+
if lat is not None: lat = float(lat)
|
|
143
146
|
lon = node.attrib.get("Lon", None)
|
|
147
|
+
if lon is not None: lon = float(lon)
|
|
144
148
|
return Bus(id, p, q, lat, lon)
|
|
145
149
|
|
|
146
150
|
@staticmethod
|
|
@@ -174,12 +178,12 @@ class Bus:
|
|
|
174
178
|
q = q * loop_times
|
|
175
179
|
bn = ret[0].strip().split('|')
|
|
176
180
|
if len(bn) == 1:
|
|
177
|
-
return bn[0], makeFunc(tl, p), makeFunc(tl, q)
|
|
181
|
+
return bn[0], makeFunc(tl, p), makeFunc(tl, q), None, None
|
|
178
182
|
elif len(bn) == 3:
|
|
179
183
|
return bn[0], makeFunc(tl, p), makeFunc(tl, q), float(bn[1]), float(bn[2])
|
|
180
184
|
else:
|
|
181
185
|
raise ValueError(f"Bad bus name format at line {i} in bus CSV file, should be 'name' or 'name|lat|lon'")
|
|
182
|
-
|
|
186
|
+
|
|
183
187
|
return [Bus(*parseline(ln,i)) for i,ln in enumerate(data[1:],start=1)]
|
|
184
188
|
|
|
185
189
|
|
|
@@ -569,7 +573,8 @@ class Grid:
|
|
|
569
573
|
raise ValueError(f"Invalid power unit: {gens_unit}")
|
|
570
574
|
return Grid(Sb, Ub, buses, lines, gens, holdShadowPrice)
|
|
571
575
|
|
|
572
|
-
def solve(self, _t: int, /, *, max_v_pu:float = 1.1, min_v_pu: float = 0.9, max_I_kA: float = 0.866,
|
|
576
|
+
def solve(self, _t: int, /, *, max_v_pu:float = 1.1, min_v_pu: float = 0.9, max_I_kA: float = 0.866,
|
|
577
|
+
source_buses:'list[BusID]' = [], source_bus_V_pu:float = 1.0) -> 'tuple[bool, float]':
|
|
573
578
|
'''Get the best result at time _t, return a tuple: (success?, optimal objective value)'''
|
|
574
579
|
model = Model("model")
|
|
575
580
|
max_v = max_v_pu ** 2
|
|
@@ -622,17 +627,19 @@ class Grid:
|
|
|
622
627
|
|
|
623
628
|
assert len(source_buses) > 0, "No source bus specified"
|
|
624
629
|
for b in source_buses:
|
|
625
|
-
model.addConstr(v[b] ==
|
|
630
|
+
model.addConstr(v[b] == source_bus_V_pu ** 2, f"src_{b}")
|
|
626
631
|
|
|
627
632
|
model.setObjective(
|
|
628
633
|
quicksum(g.CostA(_t) * pg0[g.ID] ** 2 + g.CostB(_t) * pg0[g.ID] + g.CostC(_t) for g in self.Gens),
|
|
629
634
|
GRB.MINIMIZE)
|
|
630
635
|
model.setParam('OutputFlag', 0)
|
|
631
|
-
model.setParam('QCPDual', 1)
|
|
636
|
+
model.setParam('QCPDual', 1)
|
|
632
637
|
model.update()
|
|
633
638
|
model.optimize()
|
|
634
639
|
if model.Status != GRB.Status.OPTIMAL:
|
|
635
|
-
|
|
640
|
+
model.optimize()
|
|
641
|
+
if model.Status != GRB.Status.OPTIMAL:
|
|
642
|
+
return False, 0
|
|
636
643
|
|
|
637
644
|
for bus in self.Buses:
|
|
638
645
|
j = bus.ID
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|