cimforreduceloss/Script/GAMS.py

107 lines
4.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

__author__ = 'dmy'
import math
import shutil
class Instantce:#仿真的实例
def __init__(self,instance,ipsoData):
self._ipsoData=ipsoData
self._genInstance(instance)
pass
def _genInstance(self,instance):
#序号 投入点 功率因数
#DGnode=DGnode.split(',')
#iPsodf=iPsoData(r'D:\Project\佛山项目\大学路西线_3447519_2013-10-29\大学路西线_3447519_2013-10-29_iPso_newFile.txt')
iPsodf=self._ipsoData
#22500
nodePow=iPsodf.GetNodePower()
#先统计一下总的负荷是多少
sumS=0
for n in nodePow:
P=float(n[6])
Q=float(n[7])
S=math.sqrt(P*P+Q*Q)
sumS+=S
#按系数重新分配负荷
for n in nodePow:
P=float(n[6])
Q=float(n[7])
if math.fabs(P)<1e-5 or math.fabs(Q)<1e-5:
continue
S=math.sqrt(P*P+Q*Q)
loadFactor=1#负荷比例
newS=S/sumS
newP=math.cos(math.atan(Q/P))*newS
newQ=math.sin(math.atan(Q/P))*newS
n[6]=newP
n[7]=newQ
self._ipsoData=iPsodf
return iPsodf
pass
def _copyGAMS(self,dirPath):
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\try8.gms", dirPath+'/try8.gms')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\opf.gms", dirPath+'/opf.gms')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\main.m", dirPath+'/main.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\readOPF.m", dirPath+'/readOPF.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\FormY.m", dirPath+'/FormY.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\pfxiugai.m", dirPath+'/pfxiugai.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\FormSet.m", dirPath+'/FormSet.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\FormParameter.m", dirPath+'/FormParameter.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\doMain.m", dirPath+'/doMain.m')
shutil.copyfile(r"D:\Project\佛山项目\Code\GAMS\xiangmu\generateGDX.m", dirPath+'/generateGDX.m')
def ToDataFile(self,fileName):
newFilePath=fileName
iPsodf=self._ipsoData
with open(newFilePath,'w') as f:
for b in iPsodf.GetBasicInfo():
#f.write('%d,%d,%d,%.10f,%d\n'%(b[0],b[1],1,b[3],b[4]))
f.write('%d,%d,%d,%.10f,%d\n'%(b[0],b[1],1,b[3],1))
f.write('0\n')
for b in iPsodf.GetBalance():
f.write('%d,%d,%.10f\n'%(b[0],b[1],b[2]))
f.write('0\n')
for b in iPsodf.GetLine():
f.write('%d,%d,%d,%.10f,%.10f,%.10f,%.10f\n'%(b[0],b[1],b[2],b[3],b[4],b[5],b[6]))
f.write('0\n')
for b in iPsodf.GetTrans():
f.write('%d,%d,%d,%d,%.10f,%.10f,%.10f,%.10f,%.10f,%d\n'%(
b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9]))
f.write('0\n')
f.write('0\n')
for b in iPsodf.GetGround():
f.write('%d,%d,%.10f,%.10f\n'%(b[0],b[1],b[2],b[3]))
f.write('0\n')
for b in iPsodf.GetCap():
f.write('%d,%d,%d,%.10f,%.10f,%d,%d,%d\n'%(b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7]))
f.write('0\n')
f.write('0\n')
for b in iPsodf.GetNodePower():
f.write('%d,%d,%d,%d,%.10f,%.10f,%.10f,%.10f,%f,%.10f\n'%(
b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9]))
f.write('0\n')
for b in iPsodf.GetGen():
f.write('%d,%d,%d,%d,%.10f,%.10f,%.10f,%.10f,%.10f,%.10f\n'%(
b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9]))
f.write('0\n')
f.write('0\n')
for b in iPsodf.GetReactiveGen():
f.write('%d,%d,%d,%d,%.10f,%.10f,%.10f\n'%(b[0],b[1],b[2],b[3],b[4],b[5],b[6]))
f.write('0\n')
f.write('0\n')
#for b in iPsodf.GetVoltLimit():
#f.write('%d,%d,%.10f,%.10f\n'%(b[0],b[1],b[2],b[3]))
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
f.write('0\n')
copyGAMSPath=os.path.dirname(newFilePath)
self._copyGAMS(copyGAMSPath)