parent
ca60dffe53
commit
8f512b0242
|
|
@ -35,6 +35,7 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
|
||||||
tfStru.toID=fromTo.second;
|
tfStru.toID=fromTo.second;
|
||||||
tfStru.isZeroBranch=false;
|
tfStru.isZeroBranch=false;
|
||||||
tfStru.dispose=false;
|
tfStru.dispose=false;
|
||||||
|
tfStru.id=tf->getTF()->getID();
|
||||||
this->tf.push_back(tfStru);
|
this->tf.push_back(tfStru);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,6 +78,10 @@ void CIMExporter::exportTo(const QString& path)
|
||||||
ite++)
|
ite++)
|
||||||
{
|
{
|
||||||
LineStru l=*ite;
|
LineStru l=*ite;
|
||||||
|
if(l.dispose)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
writer<<l.fromNum<<"\t";
|
writer<<l.fromNum<<"\t";
|
||||||
writer<<l.toNum<<"\t";
|
writer<<l.toNum<<"\t";
|
||||||
writer<<"type"<<"\t";
|
writer<<"type"<<"\t";
|
||||||
|
|
@ -87,6 +92,10 @@ void CIMExporter::exportTo(const QString& path)
|
||||||
ite!=this->sw.end();
|
ite!=this->sw.end();
|
||||||
ite++)
|
ite++)
|
||||||
{
|
{
|
||||||
|
if(ite->dispose)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
writer<<ite->fromNum<<"\t";
|
writer<<ite->fromNum<<"\t";
|
||||||
writer<<ite->toNum<<"\t";
|
writer<<ite->toNum<<"\t";
|
||||||
writer<<"type"<<"\t";
|
writer<<"type"<<"\t";
|
||||||
|
|
@ -111,6 +120,10 @@ void CIMExporter::exportTo(const QString& path)
|
||||||
ite!=this->tf.end();
|
ite!=this->tf.end();
|
||||||
ite++)
|
ite++)
|
||||||
{
|
{
|
||||||
|
if(ite->dispose)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
PowerTransformer *tf=ite->tf->getTF();
|
PowerTransformer *tf=ite->tf->getTF();
|
||||||
QString subID=tf->getEquipmentMemberOf_EquipmentContainer();//所属Substation的ID
|
QString subID=tf->getEquipmentMemberOf_EquipmentContainer();//所属Substation的ID
|
||||||
Substation *sub=static_cast<Substation *>(this->eleHT[subID]);
|
Substation *sub=static_cast<Substation *>(this->eleHT[subID]);
|
||||||
|
|
@ -196,18 +209,30 @@ bool CIMExporter::topologyTest()
|
||||||
ite!=this->line.end();
|
ite!=this->line.end();
|
||||||
ite++)
|
ite++)
|
||||||
{
|
{
|
||||||
|
if(ite->dispose)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
||||||
}
|
}
|
||||||
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
||||||
ite!=this->sw.end();
|
ite!=this->sw.end();
|
||||||
ite++)
|
ite++)
|
||||||
{
|
{
|
||||||
|
if(ite->dispose)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
||||||
}
|
}
|
||||||
for(QList<TransformerStru>::iterator ite=this->tf.begin();
|
for(QList<TransformerStru>::iterator ite=this->tf.begin();
|
||||||
ite!=this->tf.end();
|
ite!=this->tf.end();
|
||||||
ite++)
|
ite++)
|
||||||
{
|
{
|
||||||
|
if(ite->dispose)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
linkage.push_back(QPair<int,int>(ite->fromNum,ite->toNum));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include "elementreduction.h"
|
#include "elementreduction.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList)
|
ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -14,43 +16,185 @@ void ElementReduction::doIt()
|
||||||
{
|
{
|
||||||
QHash<QString,QVector<BranchStruc *> > linkage;
|
QHash<QString,QVector<BranchStruc *> > linkage;
|
||||||
//先记录元件之间的连接关系
|
//先记录元件之间的连接关系
|
||||||
|
QHash<QString,BranchStruc *> idToBranch;
|
||||||
foreach(BranchStruc* v,this->branchList)
|
foreach(BranchStruc* v,this->branchList)
|
||||||
{
|
{
|
||||||
std::cout<<v->id.toStdString()<<std::endl;
|
idToBranch[v->id]=v;
|
||||||
linkage[v->fromID].push_back(v);
|
linkage[v->fromID].push_back(v);
|
||||||
linkage[v->toID].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 "<<v->id.toStdString()<<std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//合并
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementReduction::merge()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ElementReduction::buildTree(QDomElement &element,QDomDocument &root,QHash<QString,QVector<BranchStruc *> >& linkage,QHash<QString,BranchStruc *>& idToBranch)
|
||||||
|
{
|
||||||
|
|
||||||
|
QString id=element.tagName();
|
||||||
|
if(this->visited.contains(id))
|
||||||
|
{
|
||||||
|
// std::cout<<"visited "<<branch->id.toStdString()<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->visited[id]=0;
|
||||||
|
BranchStruc * branch=idToBranch[id];
|
||||||
|
QString nextTo;
|
||||||
|
nextTo=branch->toID;
|
||||||
|
QVector<BranchStruc *> nextVec;
|
||||||
|
nextVec=linkage[nextTo];
|
||||||
|
foreach(BranchStruc *n,nextVec)
|
||||||
|
{
|
||||||
|
if(this->visited.contains(n->id))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// std::cout<<"add "<<n->id.toStdString()<<std::endl;
|
||||||
|
QDomElement newEle=root.createElement(n->id);
|
||||||
|
element.appendChild(newEle);
|
||||||
|
this->buildTree(newEle,root,linkage,idToBranch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementReduction::buildTree2(QDomElement &element,QDomDocument &root,QHash<QString,QVector<BranchStruc *> >& linkage,QHash<QString,BranchStruc *>& idToBranch)
|
||||||
|
{
|
||||||
|
|
||||||
|
QString id=element.tagName();
|
||||||
|
if(this->visited.contains(id))
|
||||||
|
{
|
||||||
|
std::cout<<"visited "<<id.toStdString()<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->visited[id]=0;
|
||||||
|
BranchStruc * branch=idToBranch[id];
|
||||||
|
QString nextFrom=branch->fromID;
|
||||||
|
QVector<BranchStruc *> nextFromVec;
|
||||||
|
nextFromVec=linkage[nextFrom];
|
||||||
|
foreach(BranchStruc *n,nextFromVec)
|
||||||
|
{
|
||||||
|
if(this->visited.contains(n->id))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// std::cout<<"add "<<n->id.toStdString()<<std::endl;
|
||||||
|
QDomElement newEle=root.createElement(n->id);
|
||||||
|
element.appendChild(newEle);
|
||||||
|
this->buildTree2(newEle,root,linkage,idToBranch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementReduction::visit(BranchStruc* branch,QHash<QString,QVector<BranchStruc *> >& linkage)
|
void ElementReduction::visit(BranchStruc* branch,QHash<QString,QVector<BranchStruc *> >& linkage)
|
||||||
{
|
{
|
||||||
std::cout<<"visit "<<branch->id.toStdString()<<std::endl;
|
std::cout<<"visit "<<branch->id.toStdString()<<std::endl;
|
||||||
if(this->visited.contains(branch->id))
|
// if(this->visited.contains(branch->id))
|
||||||
return;
|
// {
|
||||||
|
// std::cout<<"visited "<<branch->id.toStdString()<<std::endl;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
this->visited[branch->id]=0;
|
this->visited[branch->id]=0;
|
||||||
QString next;
|
QString next;
|
||||||
next=branch->toID;
|
next=branch->toID;
|
||||||
QVector<BranchStruc* > nextVec;
|
QVector<BranchStruc* > nextVec;
|
||||||
nextVec=linkage[next];
|
nextVec=linkage[next];
|
||||||
|
// std::cout<<"next length"<<nextVec.length()<<std::endl;
|
||||||
foreach(BranchStruc* v,nextVec)
|
foreach(BranchStruc* v,nextVec)
|
||||||
{
|
{
|
||||||
if(v->dispose)
|
if(v->dispose)
|
||||||
|
{
|
||||||
|
// std::cout<<"disposed "<<v->id.toStdString()<<std::endl;
|
||||||
continue;//丢弃的元件
|
continue;//丢弃的元件
|
||||||
|
}
|
||||||
if(v->isZeroBranch)//是0阻抗
|
if(v->isZeroBranch)//是0阻抗
|
||||||
{
|
{
|
||||||
|
std::cout<<"merge "<<branch->id.toStdString()<<" and "<<v->id.toStdString()<<std::endl;
|
||||||
//进行合并
|
//进行合并
|
||||||
std::cout<<"merge "<<v->id.toStdString()<<std::endl;
|
|
||||||
branch->toID=v->toID;
|
branch->toID=v->toID;
|
||||||
v->dispose=true;
|
v->dispose=true;
|
||||||
foreach(BranchStruc* change,linkage[branch->toID])
|
foreach(BranchStruc* change,linkage[branch->toID])
|
||||||
{
|
{
|
||||||
if(change->id==branch->id)
|
if(change->id==branch->id)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
change->fromID=branch->toID;
|
change->fromID=branch->toID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->visit(branch,linkage);//深度优先
|
// std::cout<<"start to visit next"<<std::endl;
|
||||||
|
if(v->id!=branch->id)
|
||||||
|
{
|
||||||
|
this->visit(v,linkage);//深度优先
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementReduction::visit2(BranchStruc* branch,QHash<QString,QVector<BranchStruc *> >& linkage)
|
||||||
|
{
|
||||||
|
// std::cout<<"visit "<<branch->id.toStdString()<<std::endl;
|
||||||
|
if(this->visited.contains(branch->id))
|
||||||
|
{
|
||||||
|
std::cout<<"visited "<<branch->id.toStdString()<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->visited[branch->id]=0;
|
||||||
|
QString next;
|
||||||
|
next=branch->fromID;
|
||||||
|
QVector<BranchStruc* > nextVec;
|
||||||
|
nextVec=linkage[next];
|
||||||
|
// std::cout<<"next length"<<nextVec.length()<<std::endl;
|
||||||
|
foreach(BranchStruc* v,nextVec)
|
||||||
|
{
|
||||||
|
if(v->dispose)
|
||||||
|
{
|
||||||
|
// std::cout<<"disposed "<<v->id.toStdString()<<std::endl;
|
||||||
|
continue;//丢弃的元件
|
||||||
|
}
|
||||||
|
if(v->isZeroBranch)//是0阻抗
|
||||||
|
{
|
||||||
|
std::cout<<"merge "<<branch->id.toStdString()<<" and "<<v->id.toStdString()<<std::endl;
|
||||||
|
//进行合并
|
||||||
|
branch->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"<<std::endl;
|
||||||
|
this->visit(v,linkage);//深度优先
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QDomElement>
|
||||||
|
#include <QDomDocument>
|
||||||
#include "element/commontype.h"
|
#include "element/commontype.h"
|
||||||
//把电阻等于0的元件都去掉
|
//把电阻等于0的元件都去掉
|
||||||
class ElementReduction
|
class ElementReduction
|
||||||
|
|
@ -14,7 +16,10 @@ public:
|
||||||
void doIt();
|
void doIt();
|
||||||
~ElementReduction();
|
~ElementReduction();
|
||||||
private:
|
private:
|
||||||
|
void buildTree(QDomElement &element, QDomDocument &root, QHash<QString,QVector<BranchStruc *> >& linkage, QHash<QString,BranchStruc *>& idToBranch);
|
||||||
|
void buildTree2(QDomElement &element, QDomDocument &root, QHash<QString,QVector<BranchStruc *> >& linkage, QHash<QString,BranchStruc *>& idToBranch);
|
||||||
void visit(BranchStruc* branch, QHash<QString, QVector<BranchStruc *> > &linkage);
|
void visit(BranchStruc* branch, QHash<QString, QVector<BranchStruc *> > &linkage);
|
||||||
|
void visit2(BranchStruc* branch, QHash<QString, QVector<BranchStruc *> > &linkage);
|
||||||
const QList<BranchStruc*>& branchList;
|
const QList<BranchStruc*>& branchList;
|
||||||
QHash<QString,char> visited;
|
QHash<QString,char> visited;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "topologyrecorder.h"
|
#include "topologyrecorder.h"
|
||||||
//#include <iostream>
|
#include <iostream>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
TopologyRecorder::TopologyRecorder(const QHash<QString,BasicElementInfo *>& elementHT, const QVector<QString> &FDSet,const QString& loadFilePath, QObject *parent):QObject(parent),eleHT(elementHT),FDSet(FDSet),cimExporter(elementHT,loadFilePath)
|
TopologyRecorder::TopologyRecorder(const QHash<QString,BasicElementInfo *>& elementHT, const QVector<QString> &FDSet,const QString& loadFilePath, QObject *parent):QObject(parent),eleHT(elementHT),FDSet(FDSet),cimExporter(elementHT,loadFilePath)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -54,18 +54,18 @@ bool TopologyTest::start(const QList<QPair<int,int> >& linkage)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// if(!flag)
|
if(!flag)
|
||||||
// {
|
{
|
||||||
// std::cout<<"no!!"<<std::endl;
|
std::cout<<"no!!"<<std::endl;
|
||||||
// for(int i=0;i<this->access.length();i++)
|
for(int i=0;i<this->access.length();i++)
|
||||||
// {
|
{
|
||||||
// if(this->access.at(i)==-100)
|
if(this->access.at(i)==-100)
|
||||||
// {
|
{
|
||||||
// std::cout<<i+1<<",";
|
std::cout<<i+1<<",";
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
// }
|
}
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
// std::cout<<"yes!!"<<std::endl;
|
// std::cout<<"yes!!"<<std::endl;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue