parent
7611abc82a
commit
fadc4d7c94
|
|
@ -0,0 +1,26 @@
|
|||
__author__ = 'dmy'
|
||||
|
||||
import numpy
|
||||
|
||||
import scipy.sparse as sparse
|
||||
|
||||
import scipy.sparse
|
||||
|
||||
def FormYMatrix(lineBlock,transBlock,busNum):
|
||||
r=lineBlock[:,3]
|
||||
x=lineBlock[:,4]
|
||||
gb=1/(r+1j*x)
|
||||
y=sparse.coo_matrix((gb,(lineBlock[:,1]-1,lineBlock[:,2]-1)),shape=(busNum,busNum))
|
||||
#加接地支路
|
||||
b2=lineBlock[:,5]
|
||||
y+=sparse.coo_matrix((1j*b2,(lineBlock[:,1]-1,lineBlock[:,1]-1)),shape=(busNum,busNum))
|
||||
y+=sparse.coo_matrix((1j*b2,(lineBlock[:,2]-1,lineBlock[:,2]-1)),shape=(busNum,busNum))
|
||||
print(y.sum(1))
|
||||
print(numpy.arange(int(busNum)).shape[0])
|
||||
y+=sparse.coo_matrix((numpy.array(y.sum(1)),(numpy.arange(int(busNum)),numpy.arange(int(busNum)))),shape=(busNum,busNum))
|
||||
#加变压器
|
||||
#TODO:没有考虑变比
|
||||
transX=transBlock[:,3]
|
||||
transR=transBlock[:,4]
|
||||
transGB=1/(transR+1j*transX)
|
||||
y+=sparse.coo_matrix((transGB,(transBlock[:,1]-1,transBlock[:,2]-1)),shape=(busNum,busNum))
|
||||
2
pso.py
2
pso.py
|
|
@ -1,7 +1,9 @@
|
|||
__author__ = 'dmy'
|
||||
|
||||
from reader import *
|
||||
from YMatrix import *
|
||||
|
||||
if __name__=='__main__':
|
||||
ieeeData=IEEEData('IEEE4.dat')
|
||||
yMatrix=FormYMatrix(ieeeData.lineBlock,ieeeData.transBlock,ieeeData.busNum)
|
||||
print('Finished.')
|
||||
44
reader.py
44
reader.py
|
|
@ -8,9 +8,17 @@ class IEEEData:
|
|||
self._seperator=seperator
|
||||
self._read()
|
||||
def _convertToVector(self,lineVec):#把数据文件按分隔符存成矩阵,像Matlab一样。
|
||||
self._array=numpy.array(lineVec)
|
||||
print(lineVec)
|
||||
print(self._array[0])
|
||||
#先全部转换为列表
|
||||
maxLen=0
|
||||
for v in lineVec:
|
||||
if maxLen<len(v):
|
||||
maxLen=len(v)
|
||||
array=numpy.zeros( (len(lineVec),maxLen),dtype=float)
|
||||
for (i,c) in enumerate(lineVec):
|
||||
for (j,v) in enumerate(c):
|
||||
array[i,j]=v
|
||||
self._array=array
|
||||
return self._array
|
||||
|
||||
def _read(self):
|
||||
lineVec=[]
|
||||
|
|
@ -19,7 +27,35 @@ class IEEEData:
|
|||
if len(line.strip())==0:
|
||||
continue
|
||||
lineVec.append([float(x) for x in line.split(self._seperator)])
|
||||
self._convertToVector(lineVec)
|
||||
array=self._convertToVector(lineVec)
|
||||
self._toLine(array)
|
||||
self._toTrans(array)
|
||||
self._toPQbus(array)
|
||||
self._toPG(array)
|
||||
self._toQG(array)
|
||||
self.busNum=array[0,1]
|
||||
|
||||
def _toTrans(self,array):
|
||||
zeros=numpy.where(array[:,0]==0)[0]
|
||||
self.transBlock=array[zeros[2]+1:zeros[3],:]
|
||||
|
||||
def _toLine(self,array):
|
||||
zeros=numpy.where(array[:,0]==0)[0]
|
||||
lineBlock=array[zeros[0]+1:zeros[1],:]
|
||||
self.lineBlock=lineBlock
|
||||
|
||||
def _toPG(self,array):
|
||||
zeros=numpy.where(array[:,0]==0)[0]
|
||||
self.PGBlock=array[zeros[4]+1:zeros[5],:]
|
||||
|
||||
def _toPQbus(self,array):
|
||||
zeros=numpy.where(array[:,0]==0)[0]
|
||||
self.PQbus=array[zeros[3]+1:zeros[4],:]
|
||||
|
||||
def _toQG(self,array):
|
||||
zeros=numpy.where(array[:,0]==0)[0]
|
||||
self.QG=array[zeros[4]+1:zeros[5],:]
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue