From d0b90715775606fb1640e6a095ba3a5914903cc3 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Fri, 30 Jan 2015 21:34:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=8D=95=E4=BE=8B?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E7=9A=84bug=202.=E6=AD=A3=E5=9C=A8=E5=8A=A0D?= =?UTF-8?q?G?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/cimexporter.cpp | 39 ++++++++++++++++++------------ testHasttable/cimexporter.h | 2 ++ testHasttable/dgmapping.cpp | 9 +++++++ testHasttable/dgmapping.h | 1 + testHasttable/element/commontype.h | 6 +++++ testHasttable/element/dg.cpp | 28 +++++++++++++++++++++ testHasttable/element/dg.h | 20 +++++++++++++++ testHasttable/elementreduction.cpp | 37 +++++++++++++++++----------- testHasttable/main.cpp | 6 ++++- testHasttable/singletonbase.h | 15 +++++++++--- testHasttable/task.cpp | 1 - testHasttable/task.txt | 9 +++---- testHasttable/testHasttable.pro | 6 +++-- testHasttable/topologyrecorder.cpp | 27 ++++++++++++++++++++- testHasttable/topologyrecorder.h | 6 +++++ 15 files changed, 167 insertions(+), 45 deletions(-) create mode 100644 testHasttable/element/dg.cpp create mode 100644 testHasttable/element/dg.h diff --git a/testHasttable/cimexporter.cpp b/testHasttable/cimexporter.cpp index ab7df8f..efd573d 100644 --- a/testHasttable/cimexporter.cpp +++ b/testHasttable/cimexporter.cpp @@ -24,12 +24,6 @@ void CIMExporter::add(const QPair& fromTo,Switch* sw) switchStru.sw=sw; switchStru.fromID=fromTo.first; 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.isZeroBranch=true; switchStru.dispose=false; @@ -49,6 +43,18 @@ void CIMExporter::add(const QPair& fromTo,Transformer* tf) this->tf.push_back(tfStru); } +void CIMExporter::add(const QPair& 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) { @@ -71,20 +77,11 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID) elements.push_back( &(this->tf[i]) ); } ElementReduction elementReduction(elements); - elementReduction.doIt(rootID); - +// elementReduction.doIt(rootID);//消除0阻抗支路,把几段线路连成一段 //先给所有节点都编号 this->idToNumber(this->line); this->idToNumber(this->sw); this->idToNumber(this->tf); -// for(int i=0;iline.length();i++) -// { -// std::cout<<"test "<line.at(i).length<fromID.toStdString()<<" "<id.toStdString()<<" "<length<<" "<toID.toStdString()<fromNum<<"\t"; writer<toNum<<"\t"; @@ -180,6 +178,15 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID) } } + //列出DG + for(QList::iterator ite=this->dg.begin(); + ite!=this->dg.end(); + ite++) + { + writer<fromNum<<"\t"; + writer<toNum<<"\t"; + writer<dg->capacity<<"\r\n"; + } //列出没有用的负荷文件 foreach(QString name, baseNames) { diff --git a/testHasttable/cimexporter.h b/testHasttable/cimexporter.h index 716ec0a..2dabd1d 100644 --- a/testHasttable/cimexporter.h +++ b/testHasttable/cimexporter.h @@ -32,12 +32,14 @@ public: void add(const QPair& fromTo,Line* line); void add(const QPair& fromTo,Switch* sw); void add(const QPair& fromTo,Transformer* tf); + void add(const QPair& fromTo,DG* dg); void exportTo(const QString& path, const QString &rootID); private: bool topologyTest(); QList line; QList sw; QList tf; + QList dg; QHash number; int numberIt(const QString &id);//编号 template diff --git a/testHasttable/dgmapping.cpp b/testHasttable/dgmapping.cpp index af583b1..9c1599b 100644 --- a/testHasttable/dgmapping.cpp +++ b/testHasttable/dgmapping.cpp @@ -12,6 +12,15 @@ DGMapping::~DGMapping() } +QVector > DGMapping::getDGBySubstationID(const QString& id) +{ + if(this->ht.contains(id)) + { + return this->ht.get(id); + } + return QVector >(); +} + bool DGMapping::load(const QString &filePath) { //格式 diff --git a/testHasttable/dgmapping.h b/testHasttable/dgmapping.h index 81700d8..1513710 100644 --- a/testHasttable/dgmapping.h +++ b/testHasttable/dgmapping.h @@ -19,6 +19,7 @@ class DGMapping public: DGMapping(); ~DGMapping(); + QVector > getDGBySubstationID(const QString& id); bool load(const QString &filePath); private: htType ht; diff --git a/testHasttable/element/commontype.h b/testHasttable/element/commontype.h index 1faa8e7..b116b1a 100644 --- a/testHasttable/element/commontype.h +++ b/testHasttable/element/commontype.h @@ -5,6 +5,7 @@ #include "line.h" #include "switch.h" #include "transformer.h" +#include "dg.h" struct BranchStruc { QString fromID; @@ -33,6 +34,11 @@ struct TransformerStru:public BranchStruc }; +struct DGStru:public BranchStruc +{ + + DG *dg; +}; #endif // COMMONTYPE diff --git a/testHasttable/element/dg.cpp b/testHasttable/element/dg.cpp new file mode 100644 index 0000000..6b01639 --- /dev/null +++ b/testHasttable/element/dg.cpp @@ -0,0 +1,28 @@ +#include "dg.h" + +DG::DG(const QPair &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; +} + diff --git a/testHasttable/element/dg.h b/testHasttable/element/dg.h new file mode 100644 index 0000000..5a2f2d3 --- /dev/null +++ b/testHasttable/element/dg.h @@ -0,0 +1,20 @@ +#ifndef DG_H +#define DG_H + +#include +#include +#include "branch.h" +class DG:public Branch +{ +public: + DG(const QPair &fromTo, double DGCapacity, const QString &id, QObject *parent=0); + DG(); + ~DG(); + QString id; + double capacity; +private: + virtual void extract(); + +}; + +#endif // DG_H diff --git a/testHasttable/elementreduction.cpp b/testHasttable/elementreduction.cpp index 0617199..52adbc0 100644 --- a/testHasttable/elementreduction.cpp +++ b/testHasttable/elementreduction.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "element/commontype.h" ElementReduction::ElementReduction(const QList &branchList):branchList(branchList) { @@ -45,15 +46,15 @@ void ElementReduction::doIt(const QString& rootID) // this->buildTreeFrom(element,root,linkage,idToBranch); this->merge(element,idToBranch); this->reduceSection(); - QFile file("1.xml"); - if(file.open(QFile::WriteOnly)) - { -// root.setContent(&file); - QTextStream writer(&file); +// QFile file("1.xml"); +// if(file.open(QFile::WriteOnly)) +// { +//// root.setContent(&file); +// QTextStream writer(&file); - root.save(writer,4); - file.close(); - } +// root.save(writer,4); +// file.close(); +// } //看看是不是每个都访问到了 foreach(BranchStruc* v,this->branchList) { @@ -202,11 +203,11 @@ void ElementReduction::reduceSection() reduced=false; foreach(BranchStruc *branch,branchList) { - if(branch->dispose || branch->type=="TF") + if(branch->dispose || branch->type=="TF"||branch->type=="DG") { continue; } - std::cout<<"length "<length<<" id "<id.toStdString()<length<<" id "<id.toStdString()<toID; //先找一下没有dispose的 QVector noDispose; @@ -215,7 +216,7 @@ void ElementReduction::reduceSection() // branch->dispose=true; // continue; // } - std::cout<<"a "<dispose && childBranch->type=="TF") + if(!childBranch->dispose && (childBranch->type=="TF"||childBranch->type=="DG" ) ) { ignore=true;//只要下面接了TF就不删掉 break; @@ -237,7 +238,7 @@ void ElementReduction::reduceSection() { continue; } - std::cout<dispose=true; @@ -246,8 +247,16 @@ void ElementReduction::reduceSection() if(noDispose.length()==1) { BranchStruc *cb=noDispose.first(); - std::cout<id.toStdString() <<"m with"<id.toStdString()<< ",add length"<length<id.toStdString() <<"m with"<id.toStdString()<< ",add length"<length<length+=cb->length; + LineStru *lineBranch=static_cast(branch); + if(lineBranch) + { + lineBranch->line->length=branch->length; + }else + { + std::cout<<"can not conver from BranchStruc to LineStru"<toID=cb->toID; cb->dispose=true; // break; diff --git a/testHasttable/main.cpp b/testHasttable/main.cpp index 441e0a7..ffcbff1 100644 --- a/testHasttable/main.cpp +++ b/testHasttable/main.cpp @@ -135,8 +135,12 @@ int main(int argc, char *argv[]) // { // std::cout<getCapacity()< #include + +//#include template class SingletonBase { @@ -26,6 +28,7 @@ public: { QHash *t=SingletonBase::ht; return (*t)[key]; + } QList keys() { @@ -36,12 +39,16 @@ private: void initInstance() { - if(SingletonBase::ht) +// if(SingletonBase::ht) +// { +// delete SingletonBase::ht; +// SingletonBase::ht==NULL; +// } + if(!SingletonBase::ht) { - delete SingletonBase::ht; - SingletonBase::ht==NULL; + SingletonBase::ht=new QHash; } - SingletonBase::ht=new QHash; + } protected: diff --git a/testHasttable/task.cpp b/testHasttable/task.cpp index a80da37..fe5b8c4 100644 --- a/testHasttable/task.cpp +++ b/testHasttable/task.cpp @@ -71,7 +71,6 @@ void Task::doAgainstTaskFile(ElementHashtable &eleHT) eleHT.GoPath(); eleHT.ExportTo(QString("D:/MyPro/cimforreduceloss/testHasttable/output/pan/")+sep.at(0)+".txt"); eleHT.ShowContainerInfo(lineName); - break; } file.close(); diff --git a/testHasttable/task.txt b/testHasttable/task.txt index e6383a3..a2bcdd5 100644 --- a/testHasttable/task.txt +++ b/testHasttable/task.txt @@ -1,8 +1,5 @@ -#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,) +727ֶ̩,AC-671678,D:\Project\ɽĿ\\ܲļ\̩\̩\727ֶ̩,(FD-2096,) + 709ļ,AC-671399,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) 709̩,AC-671665,D:\Project\ɽĿ\\ܲļ\̩\̩\709̩,(FD-1988,) 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,) 721,AC-671673,D:\Project\ɽĿ\\ܲļ\̩\̩\721,(FD-1990,) 707,AC-671663,D:\Project\ɽĿ\\ܲļ\̩\̩\707,(FD-1986) diff --git a/testHasttable/testHasttable.pro b/testHasttable/testHasttable.pro index f5b945d..61a64e8 100644 --- a/testHasttable/testHasttable.pro +++ b/testHasttable/testHasttable.pro @@ -45,7 +45,8 @@ SOURCES += main.cpp \ dgmapping.cpp \ dginfo.cpp \ topologytest.cpp \ - elementreduction.cpp + elementreduction.cpp \ + element/dg.cpp HEADERS += \ elementhashtable.h \ @@ -78,7 +79,8 @@ HEADERS += \ dginfo.h \ topologytest.h \ elementreduction.h \ - element/commontype.h + element/commontype.h \ + element/dg.h #release{ DEFINES += QT_NO_DEBUG_OUTPUT diff --git a/testHasttable/topologyrecorder.cpp b/testHasttable/topologyrecorder.cpp index 8e6427f..6326387 100644 --- a/testHasttable/topologyrecorder.cpp +++ b/testHasttable/topologyrecorder.cpp @@ -10,6 +10,29 @@ TopologyRecorder::~TopologyRecorder() } +bool TopologyRecorder::addDG(const QString& substationID, const QString &fromNodeID) +{ +// std::cout<<"sub id"< > DGs=dgMapping.getDGBySubstationID(substationID); + foreach(QSharedPointer _DG,DGs) + { + double capacity=_DG->getCapacity(); + QPair 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()<usedDG[_DG->getName()]=0;//用过了,做个记号 + } + return true; +} + bool TopologyRecorder::isEquipmentNeeded(const QString& substatinID) { const QHash &ht=this->eleHT; @@ -297,8 +320,10 @@ bool TopologyRecorder::startWithNode(const QString& node) break; case TopologyRecorder::Type::TF: branch=new Transformer(fromTo,static_cast(foundEle),this); -// std::cout<<"add tf"<cimExporter.add(fromTo,static_cast(branch)); + //把DG接在变压器旁边 + + this->addDG(static_cast(foundEle)->getEquipmentMemberOf_EquipmentContainer(),fromTo.first); break; default: break; diff --git a/testHasttable/topologyrecorder.h b/testHasttable/topologyrecorder.h index f346b33..9d0a446 100644 --- a/testHasttable/topologyrecorder.h +++ b/testHasttable/topologyrecorder.h @@ -16,10 +16,13 @@ #include "busbarsection.h" #include "disconnector.h" #include "cimexporter.h" +#include "dginfo.h" +#include "dgmapping.h" #include "element/branch.h" #include "element/line.h" #include "element/switch.h" #include "element/transformer.h" +#include "element/dg.h" class TopologyRecorder:public QObject { Q_OBJECT @@ -44,7 +47,10 @@ private: CIMExporter cimExporter; QHash hasAdded; QString rootID; + QHash usedDG; + bool addDG(const QString &substationID,const QString& fromNodeID); bool isEquipmentNeeded(const QString& substatinID); + }; #endif // TOPOLOGYRECORDER_H