From cba2942574133986d43cdfd564e5561f8a382689 Mon Sep 17 00:00:00 2001 From: "dmy@lab" Date: Thu, 22 Jan 2015 21:19:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E5=87=A0=E8=8A=82=E7=BA=BF=E8=B7=AF?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E6=88=90=E4=B8=80=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: dmy@lab --- testHasttable/cimexporter.cpp | 18 +++++- testHasttable/element/commontype.h | 2 + testHasttable/elementreduction.cpp | 97 +++++++++++++++++++++++++++--- testHasttable/elementreduction.h | 1 + testHasttable/loadmapping.cpp | 2 +- 5 files changed, 107 insertions(+), 13 deletions(-) diff --git a/testHasttable/cimexporter.cpp b/testHasttable/cimexporter.cpp index de8c931..ab7df8f 100644 --- a/testHasttable/cimexporter.cpp +++ b/testHasttable/cimexporter.cpp @@ -13,6 +13,8 @@ void CIMExporter::add(const QPair& fromTo,Line* line) lineStru.id=line->ac->getID(); lineStru.isZeroBranch=std::fabs(line->length)<1e-5; lineStru.dispose=false; + lineStru.type="AC"; + lineStru.length=line->length; this->line.push_back(lineStru); } @@ -31,6 +33,7 @@ void CIMExporter::add(const QPair& fromTo,Switch* sw) switchStru.id=sw->id; switchStru.isZeroBranch=true; switchStru.dispose=false; + switchStru.type="SW"; this->sw.push_back(switchStru); } void CIMExporter::add(const QPair& fromTo,Transformer* tf) @@ -42,14 +45,13 @@ void CIMExporter::add(const QPair& fromTo,Transformer* tf) tfStru.isZeroBranch=false; tfStru.dispose=false; tfStru.id=tf->getTF()->getID(); + tfStru.type="TF"; this->tf.push_back(tfStru); } void CIMExporter::exportTo(const QString& path,const QString &rootID) { - - //输出到文件 QFile fd(path); if(fd.open(QFile::WriteOnly)) @@ -70,10 +72,19 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID) } ElementReduction elementReduction(elements); elementReduction.doIt(rootID); + //先给所有节点都编号 this->idToNumber(this->line); this->idToNumber(this->sw); this->idToNumber(this->tf); +// for(int i=0;iline.length();i++) +// { +// std::cout<<"test "<line.at(i).length<fromID.toStdString()<<" "<id.toStdString()<<" "<length<<" "<toID.toStdString()<length<<"\t"<id<<"\t"; writer<length<<"\r\n"; + writer<::iterator ite=this->sw.begin(); diff --git a/testHasttable/element/commontype.h b/testHasttable/element/commontype.h index c493b78..1faa8e7 100644 --- a/testHasttable/element/commontype.h +++ b/testHasttable/element/commontype.h @@ -14,6 +14,8 @@ struct BranchStruc QString id;//后面有用的 bool isZeroBranch; bool dispose;//是否丢弃 + QString type; + double length; }; struct LineStru:public BranchStruc { diff --git a/testHasttable/elementreduction.cpp b/testHasttable/elementreduction.cpp index fadc0ea..0617199 100644 --- a/testHasttable/elementreduction.cpp +++ b/testHasttable/elementreduction.cpp @@ -23,7 +23,7 @@ void ElementReduction::calibration(const QString &id,QHash > linkage; + QHash > linkage;//后面经过merge以后这个表就不能用了!! //先记录元件之间的连接关系 QHash idToBranch; foreach(BranchStruc* v,this->branchList) @@ -44,15 +44,16 @@ void ElementReduction::doIt(const QString& rootID) // this->visited.remove(this->branchList.at(2)->id); // 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); + this->reduceSection(); + 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) { @@ -184,3 +185,81 @@ void ElementReduction::buildTreeFrom(QDomElement &element,QDomDocument &root,QHa } +void ElementReduction::reduceSection() +{ + + const QList &branchList=this->branchList; + QHash > linkage; + foreach(BranchStruc* v,branchList) + { + linkage[v->fromID].push_back(v); + linkage[v->toID].push_back(v); +// std::cout<fromID.toStdString()<<" "<id.toStdString()<<" "<toID.toStdString()<dispose || branch->type=="TF") + { + continue; + } + std::cout<<"length "<length<<" id "<id.toStdString()<toID; + //先找一下没有dispose的 + QVector noDispose; + // if(linkage[toID].length()==1)//自己就是末端了 + // { + // branch->dispose=true; + // continue; + // } + std::cout<<"a "<dispose && childBranch->type=="TF") + { + ignore=true;//只要下面接了TF就不删掉 + break; + } + if(!childBranch->dispose) + { + noDispose.push_back(childBranch); + } + } + if(ignore) + { + continue; + } + std::cout<dispose=true; + continue; + } + if(noDispose.length()==1) + { + BranchStruc *cb=noDispose.first(); + std::cout<id.toStdString() <<"m with"<id.toStdString()<< ",add length"<length<length+=cb->length; + branch->toID=cb->toID; + cb->dispose=true; +// break; + reduced=true; + } + + } + + } + + + + +} + diff --git a/testHasttable/elementreduction.h b/testHasttable/elementreduction.h index dabb35f..307038d 100644 --- a/testHasttable/elementreduction.h +++ b/testHasttable/elementreduction.h @@ -23,6 +23,7 @@ private: void merge(QDomElement &element, QHash& idToBranch); void buildTreeTo(QDomElement &element, QDomDocument &root, QHash >& linkage, QHash& idToBranch); void buildTreeFrom(QDomElement &element, QDomDocument &root, QHash >& linkage, QHash& idToBranch); + void reduceSection(); const QList& branchList; QHash visited; }; diff --git a/testHasttable/loadmapping.cpp b/testHasttable/loadmapping.cpp index 0a13263..dd93935 100644 --- a/testHasttable/loadmapping.cpp +++ b/testHasttable/loadmapping.cpp @@ -126,7 +126,7 @@ bool LoadMapping::readLoads(const QString &dir) continue; } QSharedPointer loadInfo=(*this->loadsToLoadInfo)[fileName]; - std::cout<<"file name "<setLoadPath(filePath); }