加入了生成批量GAMS文件的py脚本

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-03-11 21:43:58 +08:00
parent d0316a7c50
commit 4d4ca8eb5f
2 changed files with 108 additions and 1 deletions

107
Script/GAMS.py Normal file
View File

@ -0,0 +1,107 @@
__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)

View File

@ -297,7 +297,7 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
ite++)
{
//保存到节点注入功率中
nodePQ.push_back(CIMExporter::NodePQ(ite->toNum,-ite->dg->getPG(0.999)/1000*.5,-ite->dg->getQG(0.999)/1000*.5) );//capapcity的单位是kVA
nodePQ.push_back(CIMExporter::NodePQ(ite->toNum,-ite->dg->getPG(0.95)/1000*0.7,-ite->dg->getQG(0.95)/1000*0.7) );//capapcity的单位是kVA
// writer<<ite->fromNum<<"\t";
// writer<<ite->toNum<<"\t";
// writer<<ite->dg->capacity<<"\r\n";