把几节线路合并成一节

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-01-22 21:19:43 +08:00
parent 01c77d2045
commit cba2942574
5 changed files with 107 additions and 13 deletions

View File

@ -13,6 +13,8 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Line* line)
lineStru.id=line->ac->getID(); lineStru.id=line->ac->getID();
lineStru.isZeroBranch=std::fabs(line->length)<1e-5; lineStru.isZeroBranch=std::fabs(line->length)<1e-5;
lineStru.dispose=false; lineStru.dispose=false;
lineStru.type="AC";
lineStru.length=line->length;
this->line.push_back(lineStru); this->line.push_back(lineStru);
} }
@ -31,6 +33,7 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
switchStru.id=sw->id; switchStru.id=sw->id;
switchStru.isZeroBranch=true; switchStru.isZeroBranch=true;
switchStru.dispose=false; switchStru.dispose=false;
switchStru.type="SW";
this->sw.push_back(switchStru); this->sw.push_back(switchStru);
} }
void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf) void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
@ -42,14 +45,13 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
tfStru.isZeroBranch=false; tfStru.isZeroBranch=false;
tfStru.dispose=false; tfStru.dispose=false;
tfStru.id=tf->getTF()->getID(); tfStru.id=tf->getTF()->getID();
tfStru.type="TF";
this->tf.push_back(tfStru); this->tf.push_back(tfStru);
} }
void CIMExporter::exportTo(const QString& path,const QString &rootID) void CIMExporter::exportTo(const QString& path,const QString &rootID)
{ {
//输出到文件 //输出到文件
QFile fd(path); QFile fd(path);
if(fd.open(QFile::WriteOnly)) if(fd.open(QFile::WriteOnly))
@ -70,10 +72,19 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
} }
ElementReduction elementReduction(elements); ElementReduction elementReduction(elements);
elementReduction.doIt(rootID); elementReduction.doIt(rootID);
//先给所有节点都编号 //先给所有节点都编号
this->idToNumber(this->line); this->idToNumber(this->line);
this->idToNumber(this->sw); this->idToNumber(this->sw);
this->idToNumber(this->tf); this->idToNumber(this->tf);
// for(int i=0;i<this->line.length();i++)
// {
// std::cout<<"test "<<this->line.at(i).length<<std::endl;
// }
// foreach(BranchStruc* v,elements)
// {
// std::cout<<"bg" << v->fromID.toStdString()<<" "<<v->id.toStdString()<<" "<<v->length<<" "<<v->toID.toStdString()<<std::endl;
// }
//开始按要求输出 //开始按要求输出
//先输出线路 //先输出线路
QTextStream writer(&fd); QTextStream writer(&fd);
@ -88,11 +99,12 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
{ {
continue; continue;
} }
// writer<<elements.first()->length<<"\t"<<elements.first()->id<<"\t";
writer<<l.fromNum<<"\t"; writer<<l.fromNum<<"\t";
writer<<l.toNum<<"\t"; writer<<l.toNum<<"\t";
writer<<"type"<<"\t"; writer<<"type"<<"\t";
// writer<<l.id<<"\t"; // writer<<l.id<<"\t";
writer<<l.line->length<<"\r\n"; writer<<l.length<<"\r\n";
} }
//输出刀闸 //输出刀闸
for(QList<SwitchStru>::iterator ite=this->sw.begin(); for(QList<SwitchStru>::iterator ite=this->sw.begin();

View File

@ -14,6 +14,8 @@ struct BranchStruc
QString id;//后面有用的 QString id;//后面有用的
bool isZeroBranch; bool isZeroBranch;
bool dispose;//是否丢弃 bool dispose;//是否丢弃
QString type;
double length;
}; };
struct LineStru:public BranchStruc struct LineStru:public BranchStruc
{ {

View File

@ -23,7 +23,7 @@ void ElementReduction::calibration(const QString &id,QHash<QString,BranchStruc *
void ElementReduction::doIt(const QString& rootID) void ElementReduction::doIt(const QString& rootID)
{ {
QHash<QString,QVector<BranchStruc *> > linkage; QHash<QString,QVector<BranchStruc *> > linkage;//后面经过merge以后这个表就不能用了
//先记录元件之间的连接关系 //先记录元件之间的连接关系
QHash<QString,BranchStruc *> idToBranch; QHash<QString,BranchStruc *> idToBranch;
foreach(BranchStruc* v,this->branchList) foreach(BranchStruc* v,this->branchList)
@ -44,15 +44,16 @@ void ElementReduction::doIt(const QString& rootID)
// this->visited.remove(this->branchList.at(2)->id); // this->visited.remove(this->branchList.at(2)->id);
// this->buildTreeFrom(element,root,linkage,idToBranch); // this->buildTreeFrom(element,root,linkage,idToBranch);
this->merge(element,idToBranch); this->merge(element,idToBranch);
// QFile file("1.xml"); this->reduceSection();
// if(file.open(QFile::WriteOnly)) QFile file("1.xml");
// { if(file.open(QFile::WriteOnly))
//// root.setContent(&file); {
// QTextStream writer(&file); // root.setContent(&file);
QTextStream writer(&file);
// root.save(writer,4); root.save(writer,4);
// file.close(); file.close();
// } }
//看看是不是每个都访问到了 //看看是不是每个都访问到了
foreach(BranchStruc* v,this->branchList) foreach(BranchStruc* v,this->branchList)
{ {
@ -184,3 +185,81 @@ void ElementReduction::buildTreeFrom(QDomElement &element,QDomDocument &root,QHa
} }
void ElementReduction::reduceSection()
{
const QList<BranchStruc *> &branchList=this->branchList;
QHash<QString,QVector<BranchStruc *> > linkage;
foreach(BranchStruc* v,branchList)
{
linkage[v->fromID].push_back(v);
linkage[v->toID].push_back(v);
// std::cout<<v->fromID.toStdString()<<" "<<v->id.toStdString()<<" "<<v->toID.toStdString()<<std::endl;
}
bool reduced=true;
while(reduced)
{
reduced=false;
foreach(BranchStruc *branch,branchList)
{
if(branch->dispose || branch->type=="TF")
{
continue;
}
std::cout<<"length "<<branch->length<<" id "<<branch->id.toStdString()<<std::endl;
QString toID=branch->toID;
//先找一下没有dispose的
QVector<BranchStruc *> noDispose;
// if(linkage[toID].length()==1)//自己就是末端了
// {
// branch->dispose=true;
// continue;
// }
std::cout<<"a "<<linkage[toID].length()<<" "<<toID.toStdString()<<std::endl;
bool ignore=false;
foreach(BranchStruc *childBranch,linkage[toID])
{
if(childBranch==branch)
{
continue;
}
if(!childBranch->dispose && childBranch->type=="TF")
{
ignore=true;//只要下面接了TF就不删掉
break;
}
if(!childBranch->dispose)
{
noDispose.push_back(childBranch);
}
}
if(ignore)
{
continue;
}
std::cout<<noDispose.length()<<std::endl;
if(noDispose.length()==0)//自己就是末端了
{
branch->dispose=true;
continue;
}
if(noDispose.length()==1)
{
BranchStruc *cb=noDispose.first();
std::cout<<branch->id.toStdString() <<"m with"<<cb->id.toStdString()<< ",add length"<<cb->length<<std::endl;
branch->length+=cb->length;
branch->toID=cb->toID;
cb->dispose=true;
// break;
reduced=true;
}
}
}
}

View File

@ -23,6 +23,7 @@ private:
void merge(QDomElement &element, QHash<QString,BranchStruc *>& idToBranch); void merge(QDomElement &element, QHash<QString,BranchStruc *>& idToBranch);
void buildTreeTo(QDomElement &element, QDomDocument &root, QHash<QString,QVector<BranchStruc *> >& linkage, QHash<QString,BranchStruc *>& idToBranch); 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); void buildTreeFrom(QDomElement &element, QDomDocument &root, QHash<QString,QVector<BranchStruc *> >& linkage, QHash<QString,BranchStruc *>& idToBranch);
void reduceSection();
const QList<BranchStruc*>& branchList; const QList<BranchStruc*>& branchList;
QHash<QString,char> visited; QHash<QString,char> visited;
}; };

View File

@ -126,7 +126,7 @@ bool LoadMapping::readLoads(const QString &dir)
continue; continue;
} }
QSharedPointer<LoadInfo> loadInfo=(*this->loadsToLoadInfo)[fileName]; QSharedPointer<LoadInfo> loadInfo=(*this->loadsToLoadInfo)[fileName];
std::cout<<"file name "<<fileName.toLocal8Bit().data()<<std::endl; // std::cout<<"file name "<<fileName.toLocal8Bit().data()<<std::endl;
loadInfo->setLoadPath(filePath); loadInfo->setLoadPath(filePath);
} }