1.删减了已经没用的代码。

2.把零阻抗线路也合并。

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-01-21 22:05:19 +08:00
parent 7ec471c87e
commit 6da7e677d0
4 changed files with 24 additions and 139 deletions

View File

@ -11,7 +11,7 @@ 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.isZeroBranch=std::fabs(line->length)<1e-5;
lineStru.dispose=false;
this->line.push_back(lineStru);
@ -85,7 +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.id<<"\t";
writer<<l.line->length<<"\r\n";
}
//输出刀闸
@ -100,7 +100,7 @@ void CIMExporter::exportTo(const QString& path)
writer<<ite->fromNum<<"\t";
writer<<ite->toNum<<"\t";
writer<<"type"<<"\t";
writer<<ite->id<<"\t";
// writer<<ite->id<<"\t";
writer<<0<<"\r\n";
}
//输出负荷
@ -149,7 +149,7 @@ void CIMExporter::exportTo(const QString& path)
writer<<ite->fromNum<<"\t";
writer<<ite->toNum<<"\t";
writer<<"type"<<"\t";
writer<<ite->id<<"\t";
// writer<<ite->id<<"\t";
writer<<tf->getMVA()<<"\r\n";
break;
}
@ -204,7 +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;
// std::cout<<id.toStdString()<<" "<<n<<std::endl;
return n;
}

View File

@ -20,6 +20,7 @@
#include <QVector>
#include "topologytest.h"
#include "elementreduction.h"
#include <cmath>
//#include "elementhashtable.h"
//class Substation;
class CIMExporter

View File

@ -26,19 +26,19 @@ void ElementReduction::doIt()
QDomDocument root;
QDomElement element=root.createElement(this->branchList.at(2)->id);
root.appendChild(element);
this->buildTree(element,root,linkage,idToBranch);
this->buildTreeTo(element,root,linkage,idToBranch);
this->visited.remove(this->branchList.at(2)->id);
this->buildTree2(element,root,linkage,idToBranch);
this->buildTreeFrom(element,root,linkage,idToBranch);
this->merge(element,idToBranch);
QFile file("1.xml");
if(file.open(QFile::WriteOnly))
{
// root.setContent(&file);
QTextStream writer(&file);
// QFile file("1.xml");
// if(file.open(QFile::WriteOnly))
// {
//// root.setContent(&file);
// QTextStream writer(&file);
root.save(writer,4);
file.close();
}
// root.save(writer,4);
// file.close();
// }
//看看是不是每个都访问到了
foreach(BranchStruc* v,this->branchList)
{
@ -54,36 +54,11 @@ void ElementReduction::doIt()
}
//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);
@ -98,10 +73,6 @@ void ElementReduction::merge(QDomElement &element,QHash<QString,BranchStruc *>&
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();
@ -134,7 +105,7 @@ void ElementReduction::merge(QDomElement &element,QHash<QString,BranchStruc *>&
}
void ElementReduction::buildTree(QDomElement &element,QDomDocument &root,QHash<QString,QVector<BranchStruc *> >& linkage,QHash<QString,BranchStruc *>& idToBranch)
void ElementReduction::buildTreeTo(QDomElement &element,QDomDocument &root,QHash<QString,QVector<BranchStruc *> >& linkage,QHash<QString,BranchStruc *>& idToBranch)
{
QString id=element.tagName();
@ -157,13 +128,13 @@ 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;
// std::cout<<"create "<<n->id.toStdString()<<std::endl;
element.appendChild(newEle);
this->buildTree(newEle,root,linkage,idToBranch);
this->buildTreeTo(newEle,root,linkage,idToBranch);
}
}
void ElementReduction::buildTree2(QDomElement &element,QDomDocument &root,QHash<QString,QVector<BranchStruc *> >& linkage,QHash<QString,BranchStruc *>& idToBranch)
void ElementReduction::buildTreeFrom(QDomElement &element,QDomDocument &root,QHash<QString,QVector<BranchStruc *> >& linkage,QHash<QString,BranchStruc *>& idToBranch)
{
QString id=element.tagName();
@ -187,93 +158,8 @@ void ElementReduction::buildTree2(QDomElement &element,QDomDocument &root,QHash<
QDomElement newEle=root.createElement(n->id);
// std::cout<<"create "<<n->id.toStdString()<<std::endl;
element.appendChild(newEle);
this->buildTree2(newEle,root,linkage,idToBranch);
this->buildTreeFrom(newEle,root,linkage,idToBranch);
}
}
void ElementReduction::visit(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->toID;
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->toID=v->toID;
v->dispose=true;
foreach(BranchStruc* change,linkage[branch->toID])
{
if(change->id==branch->id)
{
continue;
}
change->fromID=branch->toID;
}
}
// 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);//深度优先
}
}

View File

@ -20,10 +20,8 @@ public:
~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);
void visit2(BranchStruc* branch, QHash<QString, QVector<BranchStruc *> > &linkage);
void buildTreeTo(QDomElement &element, QDomDocument &root, QHash<QString,QVector<BranchStruc *> >& linkage, QHash<QString,BranchStruc *>& idToBranch);
void buildTreeFrom(QDomElement &element, QDomDocument &root, QHash<QString,QVector<BranchStruc *> >& linkage, QHash<QString,BranchStruc *>& idToBranch);
const QList<BranchStruc*>& branchList;
QHash<QString,char> visited;
};