#include "elementreduction.h" #include ElementReduction::ElementReduction(const QList &branchList):branchList(branchList) { } ElementReduction::~ElementReduction() { } void ElementReduction::doIt() { QHash > linkage; //先记录元件之间的连接关系 foreach(BranchStruc* v,this->branchList) { std::cout<id.toStdString()<fromID].push_back(v); linkage[v->toID].push_back(v); } this->visit(this->branchList.last(),linkage); } void ElementReduction::visit(BranchStruc* branch,QHash >& linkage) { std::cout<<"visit "<id.toStdString()<visited.contains(branch->id)) return; this->visited[branch->id]=0; QString next; next=branch->toID; QVector nextVec; nextVec=linkage[next]; foreach(BranchStruc* v,nextVec) { if(v->dispose) continue;//丢弃的元件 if(v->isZeroBranch)//是0阻抗 { //进行合并 std::cout<<"merge "<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);//深度优先 } }