fpowerkit 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -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
- def _valconv(v:FloatLike, u:str) -> FloatLike:
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
 
@@ -623,13 +627,13 @@ class Grid:
623
627
 
624
628
  assert len(source_buses) > 0, "No source bus specified"
625
629
  for b in source_buses:
626
- model.addConstr(v[b] == source_bus_V_pu, f"src_{b}")
630
+ model.addConstr(v[b] == source_bus_V_pu ** 2, f"src_{b}")
627
631
 
628
632
  model.setObjective(
629
633
  quicksum(g.CostA(_t) * pg0[g.ID] ** 2 + g.CostB(_t) * pg0[g.ID] + g.CostC(_t) for g in self.Gens),
630
634
  GRB.MINIMIZE)
631
635
  model.setParam('OutputFlag', 0)
632
- model.setParam('QCPDual', 1) # 启用二次约束规划对偶
636
+ model.setParam('QCPDual', 1)
633
637
  model.update()
634
638
  model.optimize()
635
639
  if model.Status != GRB.Status.OPTIMAL:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fpowerkit
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: A Distflow PDN solver based on Gurobi.
5
5
  Author: fmy_xfk
6
6
  Classifier: Programming Language :: Python :: 3
@@ -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.4",
8
+ version="0.0.5",
9
9
  author="fmy_xfk",
10
10
  packages=find_packages(),
11
11
  description="A Distflow PDN solver based on Gurobi.",
File without changes
File without changes
File without changes