parent
479bfc778a
commit
ca60dffe53
|
|
@ -11,6 +11,8 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Line* line)
|
|||
lineStru.fromID=fromTo.first;
|
||||
lineStru.toID=fromTo.second;
|
||||
lineStru.id=line->ac->getID();
|
||||
lineStru.isZeroBranch=false;
|
||||
lineStru.dispose=false;
|
||||
this->line.push_back(lineStru);
|
||||
|
||||
}
|
||||
|
|
@ -21,6 +23,8 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
|
|||
switchStru.fromID=fromTo.first;
|
||||
switchStru.toID=fromTo.second;
|
||||
switchStru.id=sw->id;
|
||||
switchStru.isZeroBranch=true;
|
||||
switchStru.dispose=false;
|
||||
this->sw.push_back(switchStru);
|
||||
}
|
||||
void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
|
||||
|
|
@ -29,6 +33,8 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
|
|||
tfStru.tf=tf;
|
||||
tfStru.fromID=fromTo.first;
|
||||
tfStru.toID=fromTo.second;
|
||||
tfStru.isZeroBranch=false;
|
||||
tfStru.dispose=false;
|
||||
this->tf.push_back(tfStru);
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +47,22 @@ void CIMExporter::exportTo(const QString& path)
|
|||
QFile fd(path);
|
||||
if(fd.open(QFile::WriteOnly))
|
||||
{
|
||||
//消减元件
|
||||
QList<BranchStruc*> elements;
|
||||
for(int i=0;i<this->line.length();i++)
|
||||
{
|
||||
elements.push_back( &(this->line[i]) );
|
||||
}
|
||||
for(int i=0;i<this->sw.length();i++)
|
||||
{
|
||||
elements.push_back( &(this->sw[i]) );
|
||||
}
|
||||
for(int i=0;i<this->tf.length();i++)
|
||||
{
|
||||
elements.push_back( &(this->tf[i]) );
|
||||
}
|
||||
ElementReduction elementReduction(elements);
|
||||
elementReduction.doIt();
|
||||
//先给所有节点都编号
|
||||
this->idToNumber(this->line);
|
||||
this->idToNumber(this->sw);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "loadinfo.h"
|
||||
#include <QVector>
|
||||
#include "topologytest.h"
|
||||
#include "elementreduction.h"
|
||||
//#include "elementhashtable.h"
|
||||
//class Substation;
|
||||
class CIMExporter
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ struct BranchStruc
|
|||
int fromNum;
|
||||
int toNum;
|
||||
QString id;//后面有用的
|
||||
bool isZeroBranch;
|
||||
bool dispose;//是否丢弃
|
||||
};
|
||||
struct LineStru:public BranchStruc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "elementreduction.h"
|
||||
|
||||
ElementReduction::ElementReduction(const QList<Branch *> &branchList):branchList(branchList)
|
||||
#include <iostream>
|
||||
ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -12,11 +12,45 @@ ElementReduction::~ElementReduction()
|
|||
|
||||
void ElementReduction::doIt()
|
||||
{
|
||||
//先重新编号
|
||||
int add=0;
|
||||
foreach(Branch *v,this->branchList)
|
||||
QHash<QString,QVector<BranchStruc *> > linkage;
|
||||
//先记录元件之间的连接关系
|
||||
foreach(BranchStruc* v,this->branchList)
|
||||
{
|
||||
v->id=add++;
|
||||
std::cout<<v->id.toStdString()<<std::endl;
|
||||
linkage[v->fromID].push_back(v);
|
||||
linkage[v->toID].push_back(v);
|
||||
}
|
||||
this->visit(this->branchList.last(),linkage);
|
||||
}
|
||||
|
||||
void ElementReduction::visit(BranchStruc* branch,QHash<QString,QVector<BranchStruc *> >& linkage)
|
||||
{
|
||||
std::cout<<"visit "<<branch->id.toStdString()<<std::endl;
|
||||
if(this->visited.contains(branch->id))
|
||||
return;
|
||||
this->visited[branch->id]=0;
|
||||
QString next;
|
||||
next=branch->toID;
|
||||
QVector<BranchStruc* > nextVec;
|
||||
nextVec=linkage[next];
|
||||
foreach(BranchStruc* v,nextVec)
|
||||
{
|
||||
if(v->dispose)
|
||||
continue;//丢弃的元件
|
||||
if(v->isZeroBranch)//是0阻抗
|
||||
{
|
||||
//进行合并
|
||||
std::cout<<"merge "<<v->id.toStdString()<<std::endl;
|
||||
branch->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);//深度优先
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,21 @@
|
|||
#define ELEMENTREDUCTION_H
|
||||
|
||||
#include <QList>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include "element/commontype.h"
|
||||
//把电阻等于0的元件都去掉
|
||||
class ElementReduction
|
||||
{
|
||||
public:
|
||||
explicit ElementReduction(const QList<Branch*>& branchList);
|
||||
explicit ElementReduction(const QList<BranchStruc*>& branchList);
|
||||
void doIt();
|
||||
~ElementReduction();
|
||||
private:
|
||||
const QList<Branch*>& branchList;
|
||||
void visit(BranchStruc* branch, QHash<QString, QVector<BranchStruc *> > &linkage);
|
||||
const QList<BranchStruc*>& branchList;
|
||||
QHash<QString,char> visited;
|
||||
};
|
||||
|
||||
#endif // ELEMENTREDUCTION_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue