From 8f512b024218a086f283bed6fbec41000d5cad75 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Wed, 21 Jan 2015 14:03:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E6=88=90=E7=94=A8XML=E6=9D=A5?= =?UTF-8?q?=E5=BD=A2=E6=88=90=E6=8B=93=E6=89=91=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/cimexporter.cpp | 25 +++++ testHasttable/elementreduction.cpp | 156 +++++++++++++++++++++++++++-- testHasttable/elementreduction.h | 5 + testHasttable/topologyrecorder.cpp | 2 +- testHasttable/topologytest.cpp | 24 ++--- 5 files changed, 193 insertions(+), 19 deletions(-) diff --git a/testHasttable/cimexporter.cpp b/testHasttable/cimexporter.cpp index 226aab2..9d70039 100644 --- a/testHasttable/cimexporter.cpp +++ b/testHasttable/cimexporter.cpp @@ -35,6 +35,7 @@ void CIMExporter::add(const QPair& fromTo,Transformer* tf) tfStru.toID=fromTo.second; tfStru.isZeroBranch=false; tfStru.dispose=false; + tfStru.id=tf->getTF()->getID(); this->tf.push_back(tfStru); } @@ -77,6 +78,10 @@ void CIMExporter::exportTo(const QString& path) ite++) { LineStru l=*ite; + if(l.dispose) + { + continue; + } writer<sw.end(); ite++) { + if(ite->dispose) + { + continue; + } writer<fromNum<<"\t"; writer<toNum<<"\t"; writer<<"type"<<"\t"; @@ -111,6 +120,10 @@ void CIMExporter::exportTo(const QString& path) ite!=this->tf.end(); ite++) { + if(ite->dispose) + { + continue; + } PowerTransformer *tf=ite->tf->getTF(); QString subID=tf->getEquipmentMemberOf_EquipmentContainer();//所属Substation的ID Substation *sub=static_cast(this->eleHT[subID]); @@ -196,18 +209,30 @@ bool CIMExporter::topologyTest() ite!=this->line.end(); ite++) { + if(ite->dispose) + { + continue; + } linkage.push_back(QPair(ite->fromNum,ite->toNum)); } for(QList::iterator ite=this->sw.begin(); ite!=this->sw.end(); ite++) { + if(ite->dispose) + { + continue; + } linkage.push_back(QPair(ite->fromNum,ite->toNum)); } for(QList::iterator ite=this->tf.begin(); ite!=this->tf.end(); ite++) { + if(ite->dispose) + { + continue; + } linkage.push_back(QPair(ite->fromNum,ite->toNum)); } diff --git a/testHasttable/elementreduction.cpp b/testHasttable/elementreduction.cpp index a9d4b72..6ee967d 100644 --- a/testHasttable/elementreduction.cpp +++ b/testHasttable/elementreduction.cpp @@ -1,5 +1,7 @@ #include "elementreduction.h" #include +#include +#include ElementReduction::ElementReduction(const QList &branchList):branchList(branchList) { @@ -14,43 +16,185 @@ void ElementReduction::doIt() { QHash > linkage; //先记录元件之间的连接关系 + QHash idToBranch; foreach(BranchStruc* v,this->branchList) { - std::cout<id.toStdString()<id]=v; linkage[v->fromID].push_back(v); linkage[v->toID].push_back(v); } - this->visit(this->branchList.last(),linkage); + QDomDocument root; + QDomElement element=root.createElement(this->branchList.at(2)->id); + root.appendChild(element); + this->buildTree(element,root,linkage,idToBranch); + this->visited.remove(this->branchList.at(2)->id); + this->buildTree2(element,root,linkage,idToBranch); + QFile file("1.xml"); + if(file.open(QFile::WriteOnly)) + { +// root.setContent(&file); + QTextStream writer(&file); + + root.save(writer,4); + file.close(); + } + //看看是不是每个都访问到了 + foreach(BranchStruc* v,this->branchList) + { + if(!this->visited.contains(v->id)) + { + std::cout<<"unvisited "<id.toStdString()< >& linkage,QHash& idToBranch) +{ + + QString id=element.tagName(); + if(this->visited.contains(id)) + { +// std::cout<<"visited "<id.toStdString()<visited[id]=0; + BranchStruc * branch=idToBranch[id]; + QString nextTo; + nextTo=branch->toID; + QVector nextVec; + nextVec=linkage[nextTo]; + foreach(BranchStruc *n,nextVec) + { + if(this->visited.contains(n->id)) + { + continue; + } +// std::cout<<"add "<id.toStdString()<id); + element.appendChild(newEle); + this->buildTree(newEle,root,linkage,idToBranch); + } +} + +void ElementReduction::buildTree2(QDomElement &element,QDomDocument &root,QHash >& linkage,QHash& idToBranch) +{ + + QString id=element.tagName(); + if(this->visited.contains(id)) + { + std::cout<<"visited "<visited[id]=0; + BranchStruc * branch=idToBranch[id]; + QString nextFrom=branch->fromID; + QVector nextFromVec; + nextFromVec=linkage[nextFrom]; + foreach(BranchStruc *n,nextFromVec) + { + if(this->visited.contains(n->id)) + { + continue; + } +// std::cout<<"add "<id.toStdString()<id); + element.appendChild(newEle); + this->buildTree2(newEle,root,linkage,idToBranch); + } } void ElementReduction::visit(BranchStruc* branch,QHash >& linkage) { std::cout<<"visit "<id.toStdString()<visited.contains(branch->id)) - return; +// if(this->visited.contains(branch->id)) +// { +// std::cout<<"visited "<id.toStdString()<visited[branch->id]=0; QString next; next=branch->toID; QVector nextVec; nextVec=linkage[next]; +// std::cout<<"next length"<dispose) + { +// std::cout<<"disposed "<id.toStdString()<isZeroBranch)//是0阻抗 { + std::cout<<"merge "<id.toStdString()<<" and "<id.toStdString()<id.toStdString()<toID=v->toID; v->dispose=true; foreach(BranchStruc* change,linkage[branch->toID]) { if(change->id==branch->id) + { continue; + } change->fromID=branch->toID; } } - this->visit(branch,linkage);//深度优先 +// std::cout<<"start to visit next"<id!=branch->id) + { + this->visit(v,linkage);//深度优先 + } + + } +} + +void ElementReduction::visit2(BranchStruc* branch,QHash >& linkage) +{ +// std::cout<<"visit "<id.toStdString()<visited.contains(branch->id)) + { + std::cout<<"visited "<id.toStdString()<visited[branch->id]=0; + QString next; + next=branch->fromID; + QVector nextVec; + nextVec=linkage[next]; +// std::cout<<"next length"<dispose) + { +// std::cout<<"disposed "<id.toStdString()<isZeroBranch)//是0阻抗 + { + std::cout<<"merge "<id.toStdString()<<" and "<id.toStdString()<fromID=v->fromID; + v->dispose=true; + foreach(BranchStruc* change,linkage[branch->fromID]) + { + if(change->id==branch->id) + { + continue; + } + change->toID=branch->fromID; + } + } +// std::cout<<"start to visit next"<visit(v,linkage);//深度优先 } } diff --git a/testHasttable/elementreduction.h b/testHasttable/elementreduction.h index 42768fc..d445249 100644 --- a/testHasttable/elementreduction.h +++ b/testHasttable/elementreduction.h @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include "element/commontype.h" //把电阻等于0的元件都去掉 class ElementReduction @@ -14,7 +16,10 @@ public: void doIt(); ~ElementReduction(); private: + void buildTree(QDomElement &element, QDomDocument &root, QHash >& linkage, QHash& idToBranch); + void buildTree2(QDomElement &element, QDomDocument &root, QHash >& linkage, QHash& idToBranch); void visit(BranchStruc* branch, QHash > &linkage); + void visit2(BranchStruc* branch, QHash > &linkage); const QList& branchList; QHash visited; }; diff --git a/testHasttable/topologyrecorder.cpp b/testHasttable/topologyrecorder.cpp index 6318cc6..2fd4fce 100644 --- a/testHasttable/topologyrecorder.cpp +++ b/testHasttable/topologyrecorder.cpp @@ -1,5 +1,5 @@ #include "topologyrecorder.h" -//#include +#include #include TopologyRecorder::TopologyRecorder(const QHash& elementHT, const QVector &FDSet,const QString& loadFilePath, QObject *parent):QObject(parent),eleHT(elementHT),FDSet(FDSet),cimExporter(elementHT,loadFilePath) { diff --git a/testHasttable/topologytest.cpp b/testHasttable/topologytest.cpp index 9e81053..aa8286c 100644 --- a/testHasttable/topologytest.cpp +++ b/testHasttable/topologytest.cpp @@ -54,18 +54,18 @@ bool TopologyTest::start(const QList >& linkage) } } -// if(!flag) -// { -// std::cout<<"no!!"<access.length();i++) -// { -// if(this->access.at(i)==-100) -// { -// std::cout<access.length();i++) + { + if(this->access.at(i)==-100) + { + std::cout<