踩了无数个坑,终于把零阻抗消除的功能写好了。
Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
parent
8f512b0242
commit
7ec471c87e
|
|
@ -85,6 +85,7 @@ void CIMExporter::exportTo(const QString& path)
|
|||
writer<<l.fromNum<<"\t";
|
||||
writer<<l.toNum<<"\t";
|
||||
writer<<"type"<<"\t";
|
||||
writer<<l.id<<"\t";
|
||||
writer<<l.line->length<<"\r\n";
|
||||
}
|
||||
//输出刀闸
|
||||
|
|
@ -99,6 +100,7 @@ void CIMExporter::exportTo(const QString& path)
|
|||
writer<<ite->fromNum<<"\t";
|
||||
writer<<ite->toNum<<"\t";
|
||||
writer<<"type"<<"\t";
|
||||
writer<<ite->id<<"\t";
|
||||
writer<<0<<"\r\n";
|
||||
}
|
||||
//输出负荷
|
||||
|
|
@ -147,6 +149,7 @@ void CIMExporter::exportTo(const QString& path)
|
|||
writer<<ite->fromNum<<"\t";
|
||||
writer<<ite->toNum<<"\t";
|
||||
writer<<"type"<<"\t";
|
||||
writer<<ite->id<<"\t";
|
||||
writer<<tf->getMVA()<<"\r\n";
|
||||
break;
|
||||
}
|
||||
|
|
@ -178,6 +181,12 @@ void CIMExporter::idToNumber(QList<T> &s)//把所有元件的标识进行编号
|
|||
ite++
|
||||
)
|
||||
{
|
||||
if(ite->dispose)
|
||||
{
|
||||
std::cout<<ite->id.toStdString()<<" dispose"<<std::endl;
|
||||
continue;
|
||||
|
||||
}
|
||||
T _t=*ite;
|
||||
_t.fromNum=this->numberIt(_t.fromID);
|
||||
_t.toNum=this->numberIt(_t.toID);
|
||||
|
|
@ -195,6 +204,7 @@ int CIMExporter::numberIt(const QString& id)
|
|||
{
|
||||
int n=this->number.keys().length()+1;
|
||||
this->number[id]=n;
|
||||
std::cout<<id.toStdString()<<" "<<n<<std::endl;
|
||||
return n;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ void ElementReduction::doIt()
|
|||
this->buildTree(element,root,linkage,idToBranch);
|
||||
this->visited.remove(this->branchList.at(2)->id);
|
||||
this->buildTree2(element,root,linkage,idToBranch);
|
||||
this->merge(element,idToBranch);
|
||||
QFile file("1.xml");
|
||||
if(file.open(QFile::WriteOnly))
|
||||
{
|
||||
|
|
@ -48,11 +49,87 @@ void ElementReduction::doIt()
|
|||
}
|
||||
//合并
|
||||
|
||||
//从新给连接关系编号
|
||||
|
||||
}
|
||||
|
||||
void ElementReduction::merge()
|
||||
|
||||
//void ElementReduction::re_establishConnection(QDomElement &element,QHash<QString,BranchStruc *>& idToBranch)
|
||||
//{
|
||||
// QDomNodeList list=element.childNodes();
|
||||
// for(int i=0;i<list.length();i++)
|
||||
// {
|
||||
// QDomNode node=list.at(i);
|
||||
// QString id;
|
||||
// id=node.nodeName();
|
||||
// BranchStruc *branch=idToBranch[id];
|
||||
// if(branch->isZeroBranch)
|
||||
// {
|
||||
// branch->dispose=true;
|
||||
// QDomNodeList child=node.childNodes();
|
||||
// for(int j=0;j<child.length();j++)
|
||||
// {
|
||||
// QDomNode c=child.at(j);
|
||||
// element.appendChild(node.removeChild(c));
|
||||
// }
|
||||
// }
|
||||
// this->merge((QDomElement &)node,idToBranch);
|
||||
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
void ElementReduction::merge(QDomElement &element,QHash<QString,BranchStruc *>& idToBranch)
|
||||
{
|
||||
QString parentID=idToBranch[element.tagName()]->id;
|
||||
QStringList sep=parentID.split('-');
|
||||
// QString fromID=sep.at(0)+sep.at(1);
|
||||
QString toID=sep.at(1)+sep.at(0);
|
||||
idToBranch[element.tagName()]->toID=toID;
|
||||
element.setAttribute("toID",toID);
|
||||
//顺便编号
|
||||
//采用广度优先
|
||||
bool merged=true;
|
||||
while(merged)
|
||||
{
|
||||
merged=false;
|
||||
QDomNodeList list=element.childNodes();
|
||||
int length=list.length();
|
||||
for(int i=0;i<length;i++)
|
||||
{
|
||||
QDomNode nod=list.at(i);
|
||||
if(nod.isNull())
|
||||
{
|
||||
std::cout<<"isNULL"<<std::endl;
|
||||
}
|
||||
QDomElement &node=(QDomElement &)nod;
|
||||
QString id;
|
||||
id=node.nodeName();
|
||||
BranchStruc *branch=idToBranch[id];
|
||||
branch->fromID=toID;
|
||||
node.setAttribute("fromID",toID);
|
||||
if(branch->isZeroBranch)
|
||||
{
|
||||
branch->dispose=true;
|
||||
while(node.childNodes().length()>0)
|
||||
{
|
||||
std::cout<<"append "<<node.firstChild().nodeName().toStdString()<<" to "<<element.tagName().toStdString()<<std::endl;
|
||||
element.appendChild(node.removeChild(node.firstChild()));
|
||||
}
|
||||
element.removeChild(node);
|
||||
merged=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
QDomNodeList list=element.childNodes();
|
||||
for(int i=0;i<list.length();i++)
|
||||
{
|
||||
QDomNode nod=list.at(i);
|
||||
QDomElement &node=(QDomElement &)nod;
|
||||
this->merge((QDomElement &)node,idToBranch);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -80,6 +157,7 @@ void ElementReduction::buildTree(QDomElement &element,QDomDocument &root,QHash<Q
|
|||
}
|
||||
// std::cout<<"add "<<n->id.toStdString()<<std::endl;
|
||||
QDomElement newEle=root.createElement(n->id);
|
||||
std::cout<<"create "<<n->id.toStdString()<<std::endl;
|
||||
element.appendChild(newEle);
|
||||
this->buildTree(newEle,root,linkage,idToBranch);
|
||||
}
|
||||
|
|
@ -107,6 +185,7 @@ void ElementReduction::buildTree2(QDomElement &element,QDomDocument &root,QHash<
|
|||
}
|
||||
// std::cout<<"add "<<n->id.toStdString()<<std::endl;
|
||||
QDomElement newEle=root.createElement(n->id);
|
||||
// std::cout<<"create "<<n->id.toStdString()<<std::endl;
|
||||
element.appendChild(newEle);
|
||||
this->buildTree2(newEle,root,linkage,idToBranch);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
#include <QVector>
|
||||
#include <QDomElement>
|
||||
#include <QDomDocument>
|
||||
#include <QDomNodeList>
|
||||
#include <QDomNode>
|
||||
#include <QStringList>
|
||||
#include "element/commontype.h"
|
||||
//把电阻等于0的元件都去掉
|
||||
class ElementReduction
|
||||
|
|
@ -16,6 +19,7 @@ public:
|
|||
void doIt();
|
||||
~ElementReduction();
|
||||
private:
|
||||
void merge(QDomElement &element, QHash<QString,BranchStruc *>& idToBranch);
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue