parent
01c77d2045
commit
cba2942574
|
|
@ -13,6 +13,8 @@ void CIMExporter::add(const QPair<QString,QString>& 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<QString,QString>& 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<QString,QString>& fromTo,Transformer* tf)
|
||||
|
|
@ -42,14 +45,13 @@ void CIMExporter::add(const QPair<QString,QString>& 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;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);
|
||||
|
|
@ -88,11 +99,12 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
|
|||
{
|
||||
continue;
|
||||
}
|
||||
// writer<<elements.first()->length<<"\t"<<elements.first()->id<<"\t";
|
||||
writer<<l.fromNum<<"\t";
|
||||
writer<<l.toNum<<"\t";
|
||||
writer<<"type"<<"\t";
|
||||
// writer<<l.id<<"\t";
|
||||
writer<<l.line->length<<"\r\n";
|
||||
writer<<l.length<<"\r\n";
|
||||
}
|
||||
//输出刀闸
|
||||
for(QList<SwitchStru>::iterator ite=this->sw.begin();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ struct BranchStruc
|
|||
QString id;//后面有用的
|
||||
bool isZeroBranch;
|
||||
bool dispose;//是否丢弃
|
||||
QString type;
|
||||
double length;
|
||||
};
|
||||
struct LineStru:public BranchStruc
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ void ElementReduction::calibration(const QString &id,QHash<QString,BranchStruc *
|
|||
|
||||
void ElementReduction::doIt(const QString& rootID)
|
||||
{
|
||||
QHash<QString,QVector<BranchStruc *> > linkage;
|
||||
QHash<QString,QVector<BranchStruc *> > linkage;//后面经过merge以后这个表就不能用了!!
|
||||
//先记录元件之间的连接关系
|
||||
QHash<QString,BranchStruc *> 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<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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ private:
|
|||
void merge(QDomElement &element, 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 reduceSection();
|
||||
const QList<BranchStruc*>& branchList;
|
||||
QHash<QString,char> visited;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ bool LoadMapping::readLoads(const QString &dir)
|
|||
continue;
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue