57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#include "elementreduction.h"
|
|
#include <iostream>
|
|
ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList)
|
|
{
|
|
|
|
}
|
|
|
|
ElementReduction::~ElementReduction()
|
|
{
|
|
|
|
}
|
|
|
|
void ElementReduction::doIt()
|
|
{
|
|
QHash<QString,QVector<BranchStruc *> > linkage;
|
|
//先记录元件之间的连接关系
|
|
foreach(BranchStruc* v,this->branchList)
|
|
{
|
|
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);//深度优先
|
|
}
|
|
}
|
|
|