1.修复了单例模板的bug

2.正在加DG

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-01-30 21:34:31 +08:00
parent cba2942574
commit d0b9071577
15 changed files with 167 additions and 45 deletions

View File

@ -24,12 +24,6 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
switchStru.sw=sw; switchStru.sw=sw;
switchStru.fromID=fromTo.first; switchStru.fromID=fromTo.first;
switchStru.toID=fromTo.second; switchStru.toID=fromTo.second;
// if(fromTo.second.trimmed()=="")
// {
//// QString id=sw->id;
//// switchStru.toID=id.section('-',0,0)+id.section('-',0,0)+id.section('-',1,1);//定义一个虚拟的
// switchStru.toID=sw->id;
// }
switchStru.id=sw->id; switchStru.id=sw->id;
switchStru.isZeroBranch=true; switchStru.isZeroBranch=true;
switchStru.dispose=false; switchStru.dispose=false;
@ -49,6 +43,18 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
this->tf.push_back(tfStru); this->tf.push_back(tfStru);
} }
void CIMExporter::add(const QPair<QString,QString>& fromTo,DG* dg)
{
DGStru dgStru;
dgStru.dg=dg;
dgStru.fromID=fromTo.first;
dgStru.toID=fromTo.second;
dgStru.isZeroBranch=false;
dgStru.dispose=false;
dgStru.id=dg->id;
dgStru.type="DG";
this->dg.push_back(dgStru);
}
void CIMExporter::exportTo(const QString& path,const QString &rootID) void CIMExporter::exportTo(const QString& path,const QString &rootID)
{ {
@ -71,20 +77,11 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
elements.push_back( &(this->tf[i]) ); elements.push_back( &(this->tf[i]) );
} }
ElementReduction elementReduction(elements); ElementReduction elementReduction(elements);
elementReduction.doIt(rootID); // elementReduction.doIt(rootID);//消除0阻抗支路把几段线路连成一段
//先给所有节点都编号 //先给所有节点都编号
this->idToNumber(this->line); this->idToNumber(this->line);
this->idToNumber(this->sw); this->idToNumber(this->sw);
this->idToNumber(this->tf); this->idToNumber(this->tf);
// for(int i=0;i<this->line.length();i++)
// {
// std::cout<<"test "<<this->line.at(i).length<<std::endl;
// }
// foreach(BranchStruc* v,elements)
// {
// std::cout<<"bg" << v->fromID.toStdString()<<" "<<v->id.toStdString()<<" "<<v->length<<" "<<v->toID.toStdString()<<std::endl;
// }
//开始按要求输出 //开始按要求输出
//先输出线路 //先输出线路
QTextStream writer(&fd); QTextStream writer(&fd);
@ -169,6 +166,7 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
// std::cout<<"search for "<<targetBasename.baseName().toLocal8Bit().data()<<std::endl; // std::cout<<"search for "<<targetBasename.baseName().toLocal8Bit().data()<<std::endl;
if( baseNames.contains( targetBasename.baseName()) and !usedLoad.contains(targetBasename.baseName())) if( baseNames.contains( targetBasename.baseName()) and !usedLoad.contains(targetBasename.baseName()))
{ {
// std::cout<<targetBasename.baseName().toLocal8Bit().data()<<" used "<<std::endl;
usedLoad<<targetBasename.baseName(); usedLoad<<targetBasename.baseName();
writer<<ite->fromNum<<"\t"; writer<<ite->fromNum<<"\t";
writer<<ite->toNum<<"\t"; writer<<ite->toNum<<"\t";
@ -180,6 +178,15 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
} }
} }
//列出DG
for(QList<DGStru>::iterator ite=this->dg.begin();
ite!=this->dg.end();
ite++)
{
writer<<ite->fromNum<<"\t";
writer<<ite->toNum<<"\t";
writer<<ite->dg->capacity<<"\r\n";
}
//列出没有用的负荷文件 //列出没有用的负荷文件
foreach(QString name, baseNames) foreach(QString name, baseNames)
{ {

View File

@ -32,12 +32,14 @@ public:
void add(const QPair<QString,QString>& fromTo,Line* line); void add(const QPair<QString,QString>& fromTo,Line* line);
void add(const QPair<QString,QString>& fromTo,Switch* sw); void add(const QPair<QString,QString>& fromTo,Switch* sw);
void add(const QPair<QString,QString>& fromTo,Transformer* tf); void add(const QPair<QString,QString>& fromTo,Transformer* tf);
void add(const QPair<QString,QString>& fromTo,DG* dg);
void exportTo(const QString& path, const QString &rootID); void exportTo(const QString& path, const QString &rootID);
private: private:
bool topologyTest(); bool topologyTest();
QList<LineStru> line; QList<LineStru> line;
QList<SwitchStru> sw; QList<SwitchStru> sw;
QList<TransformerStru> tf; QList<TransformerStru> tf;
QList<DGStru> dg;
QHash<QString,int> number; QHash<QString,int> number;
int numberIt(const QString &id);//编号 int numberIt(const QString &id);//编号
template<typename T> template<typename T>

View File

@ -12,6 +12,15 @@ DGMapping::~DGMapping()
} }
QVector<QSharedPointer<DGInfo> > DGMapping::getDGBySubstationID(const QString& id)
{
if(this->ht.contains(id))
{
return this->ht.get(id);
}
return QVector<QSharedPointer<DGInfo> >();
}
bool DGMapping::load(const QString &filePath) bool DGMapping::load(const QString &filePath)
{ {
//格式 //格式

View File

@ -19,6 +19,7 @@ class DGMapping
public: public:
DGMapping(); DGMapping();
~DGMapping(); ~DGMapping();
QVector<QSharedPointer<DGInfo> > getDGBySubstationID(const QString& id);
bool load(const QString &filePath); bool load(const QString &filePath);
private: private:
htType ht; htType ht;

View File

@ -5,6 +5,7 @@
#include "line.h" #include "line.h"
#include "switch.h" #include "switch.h"
#include "transformer.h" #include "transformer.h"
#include "dg.h"
struct BranchStruc struct BranchStruc
{ {
QString fromID; QString fromID;
@ -33,6 +34,11 @@ struct TransformerStru:public BranchStruc
}; };
struct DGStru:public BranchStruc
{
DG *dg;
};
#endif // COMMONTYPE #endif // COMMONTYPE

View File

@ -0,0 +1,28 @@
#include "dg.h"
DG::DG(const QPair<QString, QString> &fromTo, double DGCapacity,const QString &id,QObject *parent):Branch(fromTo.first,fromTo.second,parent)
{
this->id=id;
this->capacity=DGCapacity;
}
DG::~DG()
{
}
void DG::extract()
{
//单位阻抗
double r0=0;
double x0=0.001;
double g0=0;
double b0=0;
this->r=r0;
this->x=x0;
this->g1=g0;
this->g2=g0;
this->b1=b0;
this->b2=b0;
}

View File

@ -0,0 +1,20 @@
#ifndef DG_H
#define DG_H
#include <QPair>
#include <QString>
#include "branch.h"
class DG:public Branch
{
public:
DG(const QPair<QString, QString> &fromTo, double DGCapacity, const QString &id, QObject *parent=0);
DG();
~DG();
QString id;
double capacity;
private:
virtual void extract();
};
#endif // DG_H

View File

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include "element/commontype.h"
ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList) ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList)
{ {
@ -45,15 +46,15 @@ void ElementReduction::doIt(const QString& rootID)
// this->buildTreeFrom(element,root,linkage,idToBranch); // this->buildTreeFrom(element,root,linkage,idToBranch);
this->merge(element,idToBranch); this->merge(element,idToBranch);
this->reduceSection(); this->reduceSection();
QFile file("1.xml"); // QFile file("1.xml");
if(file.open(QFile::WriteOnly)) // if(file.open(QFile::WriteOnly))
{ // {
// root.setContent(&file); //// root.setContent(&file);
QTextStream writer(&file); // QTextStream writer(&file);
root.save(writer,4); // root.save(writer,4);
file.close(); // file.close();
} // }
//看看是不是每个都访问到了 //看看是不是每个都访问到了
foreach(BranchStruc* v,this->branchList) foreach(BranchStruc* v,this->branchList)
{ {
@ -202,11 +203,11 @@ void ElementReduction::reduceSection()
reduced=false; reduced=false;
foreach(BranchStruc *branch,branchList) foreach(BranchStruc *branch,branchList)
{ {
if(branch->dispose || branch->type=="TF") if(branch->dispose || branch->type=="TF"||branch->type=="DG")
{ {
continue; continue;
} }
std::cout<<"length "<<branch->length<<" id "<<branch->id.toStdString()<<std::endl; // std::cout<<"length "<<branch->length<<" id "<<branch->id.toStdString()<<std::endl;
QString toID=branch->toID; QString toID=branch->toID;
//先找一下没有dispose的 //先找一下没有dispose的
QVector<BranchStruc *> noDispose; QVector<BranchStruc *> noDispose;
@ -215,7 +216,7 @@ void ElementReduction::reduceSection()
// branch->dispose=true; // branch->dispose=true;
// continue; // continue;
// } // }
std::cout<<"a "<<linkage[toID].length()<<" "<<toID.toStdString()<<std::endl; // std::cout<<"a "<<linkage[toID].length()<<" "<<toID.toStdString()<<std::endl;
bool ignore=false; bool ignore=false;
foreach(BranchStruc *childBranch,linkage[toID]) foreach(BranchStruc *childBranch,linkage[toID])
{ {
@ -223,7 +224,7 @@ void ElementReduction::reduceSection()
{ {
continue; continue;
} }
if(!childBranch->dispose && childBranch->type=="TF") if(!childBranch->dispose && (childBranch->type=="TF"||childBranch->type=="DG" ) )
{ {
ignore=true;//只要下面接了TF就不删掉 ignore=true;//只要下面接了TF就不删掉
break; break;
@ -237,7 +238,7 @@ void ElementReduction::reduceSection()
{ {
continue; continue;
} }
std::cout<<noDispose.length()<<std::endl; // std::cout<<noDispose.length()<<std::endl;
if(noDispose.length()==0)//自己就是末端了 if(noDispose.length()==0)//自己就是末端了
{ {
branch->dispose=true; branch->dispose=true;
@ -246,8 +247,16 @@ void ElementReduction::reduceSection()
if(noDispose.length()==1) if(noDispose.length()==1)
{ {
BranchStruc *cb=noDispose.first(); BranchStruc *cb=noDispose.first();
std::cout<<branch->id.toStdString() <<"m with"<<cb->id.toStdString()<< ",add length"<<cb->length<<std::endl; // std::cout<<branch->id.toStdString() <<"m with"<<cb->id.toStdString()<< ",add length"<<cb->length<<std::endl;
branch->length+=cb->length; branch->length+=cb->length;
LineStru *lineBranch=static_cast<LineStru *>(branch);
if(lineBranch)
{
lineBranch->line->length=branch->length;
}else
{
std::cout<<"can not conver from BranchStruc to LineStru"<<std::endl;
}
branch->toID=cb->toID; branch->toID=cb->toID;
cb->dispose=true; cb->dispose=true;
// break; // break;

View File

@ -135,8 +135,12 @@ int main(int argc, char *argv[])
// { // {
// std::cout<<l.toLocal8Bit().data()<<std::endl; // std::cout<<l.toLocal8Bit().data()<<std::endl;
// } // }
DGMapping dgMapping; // {
DGMapping dgMapping;
dgMapping.load("D:/Project/佛山项目/数据/DG.txt"); dgMapping.load("D:/Project/佛山项目/数据/DG.txt");
// }
// DGMapping dgMapping;
// std::cout<<dgMapping.getDGBySubstationID("SFD-42876").first()->getCapacity()<<std::endl;
// return a.exec(); // return a.exec();
ElementHashtable eleReader; ElementHashtable eleReader;
eleReader.Parse("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml","D:/Project/佛山项目/佛山收资/exportmodel_zwyth20141204/exportmodel_zwyth.xml"); eleReader.Parse("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml","D:/Project/佛山项目/佛山收资/exportmodel_zwyth20141204/exportmodel_zwyth.xml");

View File

@ -4,6 +4,8 @@
//做一个单例 //做一个单例
#include <QHash> #include <QHash>
#include <QList> #include <QList>
//#include <iostream>
template<typename KeyType,typename ValueType,typename ChildType> template<typename KeyType,typename ValueType,typename ChildType>
class SingletonBase class SingletonBase
{ {
@ -26,6 +28,7 @@ public:
{ {
QHash<KeyType,ValueType> *t=SingletonBase<KeyType,ValueType,ChildType>::ht; QHash<KeyType,ValueType> *t=SingletonBase<KeyType,ValueType,ChildType>::ht;
return (*t)[key]; return (*t)[key];
} }
QList<KeyType> keys() QList<KeyType> keys()
{ {
@ -36,12 +39,16 @@ private:
void initInstance() void initInstance()
{ {
if(SingletonBase<KeyType,ValueType,ChildType>::ht) // if(SingletonBase<KeyType,ValueType,ChildType>::ht)
// {
// delete SingletonBase<KeyType,ValueType,ChildType>::ht;
// SingletonBase<KeyType,ValueType,ChildType>::ht==NULL;
// }
if(!SingletonBase<KeyType,ValueType,ChildType>::ht)
{ {
delete SingletonBase<KeyType,ValueType,ChildType>::ht; SingletonBase<KeyType,ValueType,ChildType>::ht=new QHash<KeyType,ValueType>;
SingletonBase<KeyType,ValueType,ChildType>::ht==NULL;
} }
SingletonBase<KeyType,ValueType,ChildType>::ht=new QHash<KeyType,ValueType>;
} }
protected: protected:

View File

@ -71,7 +71,6 @@ void Task::doAgainstTaskFile(ElementHashtable &eleHT)
eleHT.GoPath(); eleHT.GoPath();
eleHT.ExportTo(QString("D:/MyPro/cimforreduceloss/testHasttable/output/pan/")+sep.at(0)+".txt"); eleHT.ExportTo(QString("D:/MyPro/cimforreduceloss/testHasttable/output/pan/")+sep.at(0)+".txt");
eleHT.ShowContainerInfo(lineName); eleHT.ShowContainerInfo(lineName);
break; break;
} }
file.close(); file.close();

View File

@ -1,8 +1,5 @@
#727泰林东乙线,AC-671678,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\727泰林东乙线,(FD-2096,), 727泰林东乙线,AC-671678,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\727泰林东乙线,(FD-2096,)
#721南源线,AC-591821,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\721南源线,(FD-2014,FD-2019,FD-2000,)
#726制钢甲线,AC-671677,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\726制钢甲线,(FD-2038)
#721南源线,AC-591821,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\721南源线,(FD-2014,FD-2019,FD-2000,)
#701欲华线,AC-591811,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\701欲华线,(FD-2000,FD-2000,)
709美的甲线,AC-671399,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\709美的甲线、720美的乙线,(FD-2003,) 709美的甲线,AC-671399,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\709美的甲线、720美的乙线,(FD-2003,)
720美的乙线,AC-671401,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\709美的甲线、720美的乙线,(FD-2003,) 720美的乙线,AC-671401,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\709美的甲线、720美的乙线,(FD-2003,)
@ -41,7 +38,7 @@
713泰林东甲线,AC-671669,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\713泰林东甲线,(FD-2098,FD-2096) 713泰林东甲线,AC-671669,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\713泰林东甲线,(FD-2098,FD-2096)
709泰兴乙线,AC-671665,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\709泰兴乙线,(FD-1988,) 709泰兴乙线,AC-671665,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\709泰兴乙线,(FD-1988,)
702沿江线,AC-803934,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\702沿江线,(FD-1998,) 702沿江线,AC-803934,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\702沿江线,(FD-1998,)
715加利源线,AC-1140123,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\715加利源线,(FD-65488,) #715加利源线,AC-1140123,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\715加利源线,(FD-65488,)
701港前南线,AC-671660,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\701港前南线,(FD-1993,) 701港前南线,AC-671660,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\701港前南线,(FD-1993,)
721威特线,AC-671673,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\721威特线,(FD-1990,) 721威特线,AC-671673,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\721威特线,(FD-1990,)
707威奇线,AC-671663,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\707威奇线,(FD-1986) 707威奇线,AC-671663,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\707威奇线,(FD-1986)

View File

@ -45,7 +45,8 @@ SOURCES += main.cpp \
dgmapping.cpp \ dgmapping.cpp \
dginfo.cpp \ dginfo.cpp \
topologytest.cpp \ topologytest.cpp \
elementreduction.cpp elementreduction.cpp \
element/dg.cpp
HEADERS += \ HEADERS += \
elementhashtable.h \ elementhashtable.h \
@ -78,7 +79,8 @@ HEADERS += \
dginfo.h \ dginfo.h \
topologytest.h \ topologytest.h \
elementreduction.h \ elementreduction.h \
element/commontype.h element/commontype.h \
element/dg.h
#release{ #release{
DEFINES += QT_NO_DEBUG_OUTPUT DEFINES += QT_NO_DEBUG_OUTPUT

View File

@ -10,6 +10,29 @@ TopologyRecorder::~TopologyRecorder()
} }
bool TopologyRecorder::addDG(const QString& substationID, const QString &fromNodeID)
{
// std::cout<<"sub id"<<substationID.toStdString()<<std::endl;
DGMapping dgMapping;
QVector<QSharedPointer<DGInfo> > DGs=dgMapping.getDGBySubstationID(substationID);
foreach(QSharedPointer<DGInfo> _DG,DGs)
{
double capacity=_DG->getCapacity();
QPair<QString,QString> fromTo;
fromTo.first=fromNodeID;
fromTo.second=_DG->getName();//虚拟节点
if(this->usedDG.contains(_DG->getName()))
{
break;//这个Substation下面已经添加过DG不用再添加了。
}
DG *DGP=new DG(fromTo,capacity,_DG->getName(),this);
this->cimExporter.add(fromTo,DGP);
std::cout<<"add "<<_DG->getName().toLocal8Bit().data()<<std::endl;
this->usedDG[_DG->getName()]=0;//用过了,做个记号
}
return true;
}
bool TopologyRecorder::isEquipmentNeeded(const QString& substatinID) bool TopologyRecorder::isEquipmentNeeded(const QString& substatinID)
{ {
const QHash<QString,BasicElementInfo*> &ht=this->eleHT; const QHash<QString,BasicElementInfo*> &ht=this->eleHT;
@ -297,8 +320,10 @@ bool TopologyRecorder::startWithNode(const QString& node)
break; break;
case TopologyRecorder::Type::TF: case TopologyRecorder::Type::TF:
branch=new Transformer(fromTo,static_cast<PowerTransformer *>(foundEle),this); branch=new Transformer(fromTo,static_cast<PowerTransformer *>(foundEle),this);
// std::cout<<"add tf"<<std::endl;
this->cimExporter.add(fromTo,static_cast<Transformer *>(branch)); this->cimExporter.add(fromTo,static_cast<Transformer *>(branch));
//把DG接在变压器旁边
this->addDG(static_cast<PowerTransformer *>(foundEle)->getEquipmentMemberOf_EquipmentContainer(),fromTo.first);
break; break;
default: default:
break; break;

View File

@ -16,10 +16,13 @@
#include "busbarsection.h" #include "busbarsection.h"
#include "disconnector.h" #include "disconnector.h"
#include "cimexporter.h" #include "cimexporter.h"
#include "dginfo.h"
#include "dgmapping.h"
#include "element/branch.h" #include "element/branch.h"
#include "element/line.h" #include "element/line.h"
#include "element/switch.h" #include "element/switch.h"
#include "element/transformer.h" #include "element/transformer.h"
#include "element/dg.h"
class TopologyRecorder:public QObject class TopologyRecorder:public QObject
{ {
Q_OBJECT Q_OBJECT
@ -44,7 +47,10 @@ private:
CIMExporter cimExporter; CIMExporter cimExporter;
QHash<QString,char> hasAdded; QHash<QString,char> hasAdded;
QString rootID; QString rootID;
QHash<QString,char> usedDG;
bool addDG(const QString &substationID,const QString& fromNodeID);
bool isEquipmentNeeded(const QString& substatinID); bool isEquipmentNeeded(const QString& substatinID);
}; };
#endif // TOPOLOGYRECORDER_H #endif // TOPOLOGYRECORDER_H