1.修复了单例模板的bug

2.正在加DG

Signed-off-by: dmy@lab <dmy@lab.lab>
This commit is contained in:
dmy@lab 2015-01-30 21:34:31 +08:00
parent cba2942574
commit d0b9071577
15 changed files with 167 additions and 45 deletions

View File

@ -24,12 +24,6 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Switch* sw)
switchStru.sw=sw;
switchStru.fromID=fromTo.first;
switchStru.toID=fromTo.second;
// if(fromTo.second.trimmed()=="")
// {
//// QString id=sw->id;
//// switchStru.toID=id.section('-',0,0)+id.section('-',0,0)+id.section('-',1,1);//定义一个虚拟的
// switchStru.toID=sw->id;
// }
switchStru.id=sw->id;
switchStru.isZeroBranch=true;
switchStru.dispose=false;
@ -49,6 +43,18 @@ void CIMExporter::add(const QPair<QString,QString>& fromTo,Transformer* tf)
this->tf.push_back(tfStru);
}
void CIMExporter::add(const QPair<QString,QString>& fromTo,DG* dg)
{
DGStru dgStru;
dgStru.dg=dg;
dgStru.fromID=fromTo.first;
dgStru.toID=fromTo.second;
dgStru.isZeroBranch=false;
dgStru.dispose=false;
dgStru.id=dg->id;
dgStru.type="DG";
this->dg.push_back(dgStru);
}
void CIMExporter::exportTo(const QString& path,const QString &rootID)
{
@ -71,20 +77,11 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
elements.push_back( &(this->tf[i]) );
}
ElementReduction elementReduction(elements);
elementReduction.doIt(rootID);
// elementReduction.doIt(rootID);//消除0阻抗支路把几段线路连成一段
//先给所有节点都编号
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);
@ -169,6 +166,7 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
// std::cout<<"search for "<<targetBasename.baseName().toLocal8Bit().data()<<std::endl;
if( baseNames.contains( targetBasename.baseName()) and !usedLoad.contains(targetBasename.baseName()))
{
// std::cout<<targetBasename.baseName().toLocal8Bit().data()<<" used "<<std::endl;
usedLoad<<targetBasename.baseName();
writer<<ite->fromNum<<"\t";
writer<<ite->toNum<<"\t";
@ -180,6 +178,15 @@ void CIMExporter::exportTo(const QString& path,const QString &rootID)
}
}
//列出DG
for(QList<DGStru>::iterator ite=this->dg.begin();
ite!=this->dg.end();
ite++)
{
writer<<ite->fromNum<<"\t";
writer<<ite->toNum<<"\t";
writer<<ite->dg->capacity<<"\r\n";
}
//列出没有用的负荷文件
foreach(QString name, baseNames)
{

View File

@ -32,12 +32,14 @@ public:
void add(const QPair<QString,QString>& fromTo,Line* line);
void add(const QPair<QString,QString>& fromTo,Switch* sw);
void add(const QPair<QString,QString>& fromTo,Transformer* tf);
void add(const QPair<QString,QString>& fromTo,DG* dg);
void exportTo(const QString& path, const QString &rootID);
private:
bool topologyTest();
QList<LineStru> line;
QList<SwitchStru> sw;
QList<TransformerStru> tf;
QList<DGStru> dg;
QHash<QString,int> number;
int numberIt(const QString &id);//编号
template<typename T>

View File

@ -12,6 +12,15 @@ DGMapping::~DGMapping()
}
QVector<QSharedPointer<DGInfo> > DGMapping::getDGBySubstationID(const QString& id)
{
if(this->ht.contains(id))
{
return this->ht.get(id);
}
return QVector<QSharedPointer<DGInfo> >();
}
bool DGMapping::load(const QString &filePath)
{
//格式

View File

@ -19,6 +19,7 @@ class DGMapping
public:
DGMapping();
~DGMapping();
QVector<QSharedPointer<DGInfo> > getDGBySubstationID(const QString& id);
bool load(const QString &filePath);
private:
htType ht;

View File

@ -5,6 +5,7 @@
#include "line.h"
#include "switch.h"
#include "transformer.h"
#include "dg.h"
struct BranchStruc
{
QString fromID;
@ -33,6 +34,11 @@ struct TransformerStru:public BranchStruc
};
struct DGStru:public BranchStruc
{
DG *dg;
};
#endif // COMMONTYPE

View File

@ -0,0 +1,28 @@
#include "dg.h"
DG::DG(const QPair<QString, QString> &fromTo, double DGCapacity,const QString &id,QObject *parent):Branch(fromTo.first,fromTo.second,parent)
{
this->id=id;
this->capacity=DGCapacity;
}
DG::~DG()
{
}
void DG::extract()
{
//单位阻抗
double r0=0;
double x0=0.001;
double g0=0;
double b0=0;
this->r=r0;
this->x=x0;
this->g1=g0;
this->g2=g0;
this->b1=b0;
this->b2=b0;
}

View File

@ -0,0 +1,20 @@
#ifndef DG_H
#define DG_H
#include <QPair>
#include <QString>
#include "branch.h"
class DG:public Branch
{
public:
DG(const QPair<QString, QString> &fromTo, double DGCapacity, const QString &id, QObject *parent=0);
DG();
~DG();
QString id;
double capacity;
private:
virtual void extract();
};
#endif // DG_H

View File

@ -2,6 +2,7 @@
#include <iostream>
#include <QFile>
#include <QTextStream>
#include "element/commontype.h"
ElementReduction::ElementReduction(const QList<BranchStruc *> &branchList):branchList(branchList)
{
@ -45,15 +46,15 @@ void ElementReduction::doIt(const QString& rootID)
// this->buildTreeFrom(element,root,linkage,idToBranch);
this->merge(element,idToBranch);
this->reduceSection();
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)
{
@ -202,11 +203,11 @@ void ElementReduction::reduceSection()
reduced=false;
foreach(BranchStruc *branch,branchList)
{
if(branch->dispose || branch->type=="TF")
if(branch->dispose || branch->type=="TF"||branch->type=="DG")
{
continue;
}
std::cout<<"length "<<branch->length<<" id "<<branch->id.toStdString()<<std::endl;
// std::cout<<"length "<<branch->length<<" id "<<branch->id.toStdString()<<std::endl;
QString toID=branch->toID;
//先找一下没有dispose的
QVector<BranchStruc *> noDispose;
@ -215,7 +216,7 @@ void ElementReduction::reduceSection()
// branch->dispose=true;
// continue;
// }
std::cout<<"a "<<linkage[toID].length()<<" "<<toID.toStdString()<<std::endl;
// std::cout<<"a "<<linkage[toID].length()<<" "<<toID.toStdString()<<std::endl;
bool ignore=false;
foreach(BranchStruc *childBranch,linkage[toID])
{
@ -223,7 +224,7 @@ void ElementReduction::reduceSection()
{
continue;
}
if(!childBranch->dispose && childBranch->type=="TF")
if(!childBranch->dispose && (childBranch->type=="TF"||childBranch->type=="DG" ) )
{
ignore=true;//只要下面接了TF就不删掉
break;
@ -237,7 +238,7 @@ void ElementReduction::reduceSection()
{
continue;
}
std::cout<<noDispose.length()<<std::endl;
// std::cout<<noDispose.length()<<std::endl;
if(noDispose.length()==0)//自己就是末端了
{
branch->dispose=true;
@ -246,8 +247,16 @@ void ElementReduction::reduceSection()
if(noDispose.length()==1)
{
BranchStruc *cb=noDispose.first();
std::cout<<branch->id.toStdString() <<"m with"<<cb->id.toStdString()<< ",add length"<<cb->length<<std::endl;
// std::cout<<branch->id.toStdString() <<"m with"<<cb->id.toStdString()<< ",add length"<<cb->length<<std::endl;
branch->length+=cb->length;
LineStru *lineBranch=static_cast<LineStru *>(branch);
if(lineBranch)
{
lineBranch->line->length=branch->length;
}else
{
std::cout<<"can not conver from BranchStruc to LineStru"<<std::endl;
}
branch->toID=cb->toID;
cb->dispose=true;
// break;

View File

@ -135,8 +135,12 @@ int main(int argc, char *argv[])
// {
// std::cout<<l.toLocal8Bit().data()<<std::endl;
// }
// {
DGMapping dgMapping;
dgMapping.load("D:/Project/佛山项目/数据/DG.txt");
// }
// DGMapping dgMapping;
// std::cout<<dgMapping.getDGBySubstationID("SFD-42876").first()->getCapacity()<<std::endl;
// return a.exec();
ElementHashtable eleReader;
eleReader.Parse("D:/Project/佛山项目/数据/df8003/df8600/exportfiles/exportmodel_pw.xml","D:/Project/佛山项目/佛山收资/exportmodel_zwyth20141204/exportmodel_zwyth.xml");

View File

@ -4,6 +4,8 @@
//做一个单例
#include <QHash>
#include <QList>
//#include <iostream>
template<typename KeyType,typename ValueType,typename ChildType>
class SingletonBase
{
@ -26,6 +28,7 @@ public:
{
QHash<KeyType,ValueType> *t=SingletonBase<KeyType,ValueType,ChildType>::ht;
return (*t)[key];
}
QList<KeyType> keys()
{
@ -36,13 +39,17 @@ private:
void initInstance()
{
if(SingletonBase<KeyType,ValueType,ChildType>::ht)
// if(SingletonBase<KeyType,ValueType,ChildType>::ht)
// {
// delete SingletonBase<KeyType,ValueType,ChildType>::ht;
// SingletonBase<KeyType,ValueType,ChildType>::ht==NULL;
// }
if(!SingletonBase<KeyType,ValueType,ChildType>::ht)
{
delete SingletonBase<KeyType,ValueType,ChildType>::ht;
SingletonBase<KeyType,ValueType,ChildType>::ht==NULL;
}
SingletonBase<KeyType,ValueType,ChildType>::ht=new QHash<KeyType,ValueType>;
}
}
protected:
class CG // 它的唯一工作就是在析构函数中删除CSingleton的实例

View File

@ -71,7 +71,6 @@ void Task::doAgainstTaskFile(ElementHashtable &eleHT)
eleHT.GoPath();
eleHT.ExportTo(QString("D:/MyPro/cimforreduceloss/testHasttable/output/pan/")+sep.at(0)+".txt");
eleHT.ShowContainerInfo(lineName);
break;
}
file.close();

View File

@ -1,8 +1,5 @@
#727泰林东乙线,AC-671678,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\727泰林东乙线,(FD-2096,),
#721南源线,AC-591821,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\721南源线,(FD-2014,FD-2019,FD-2000,)
#726制钢甲线,AC-671677,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\726制钢甲线,(FD-2038)
#721南源线,AC-591821,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\721南源线,(FD-2014,FD-2019,FD-2000,)
#701欲华线,AC-591811,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\701欲华线,(FD-2000,FD-2000,)
727泰林东乙线,AC-671678,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\727泰林东乙线,(FD-2096,)
709美的甲线,AC-671399,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\709美的甲线、720美的乙线,(FD-2003,)
720美的乙线,AC-671401,D:\Project\佛山项目\数据\搭网架参数文件\北滘\北滘负荷\709美的甲线、720美的乙线,(FD-2003,)
@ -41,7 +38,7 @@
713泰林东甲线,AC-671669,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\713泰林东甲线,(FD-2098,FD-2096)
709泰兴乙线,AC-671665,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\709泰兴乙线,(FD-1988,)
702沿江线,AC-803934,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\702沿江线,(FD-1998,)
715加利源线,AC-1140123,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\715加利源线,(FD-65488,)
#715加利源线,AC-1140123,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\715加利源线,(FD-65488,)
701港前南线,AC-671660,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\701港前南线,(FD-1993,)
721威特线,AC-671673,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\721威特线,(FD-1990,)
707威奇线,AC-671663,D:\Project\佛山项目\数据\搭网架参数文件\泰安\泰安负荷\707威奇线,(FD-1986)

View File

@ -45,7 +45,8 @@ SOURCES += main.cpp \
dgmapping.cpp \
dginfo.cpp \
topologytest.cpp \
elementreduction.cpp
elementreduction.cpp \
element/dg.cpp
HEADERS += \
elementhashtable.h \
@ -78,7 +79,8 @@ HEADERS += \
dginfo.h \
topologytest.h \
elementreduction.h \
element/commontype.h
element/commontype.h \
element/dg.h
#release{
DEFINES += QT_NO_DEBUG_OUTPUT

View File

@ -10,6 +10,29 @@ TopologyRecorder::~TopologyRecorder()
}
bool TopologyRecorder::addDG(const QString& substationID, const QString &fromNodeID)
{
// std::cout<<"sub id"<<substationID.toStdString()<<std::endl;
DGMapping dgMapping;
QVector<QSharedPointer<DGInfo> > DGs=dgMapping.getDGBySubstationID(substationID);
foreach(QSharedPointer<DGInfo> _DG,DGs)
{
double capacity=_DG->getCapacity();
QPair<QString,QString> fromTo;
fromTo.first=fromNodeID;
fromTo.second=_DG->getName();//虚拟节点
if(this->usedDG.contains(_DG->getName()))
{
break;//这个Substation下面已经添加过DG不用再添加了。
}
DG *DGP=new DG(fromTo,capacity,_DG->getName(),this);
this->cimExporter.add(fromTo,DGP);
std::cout<<"add "<<_DG->getName().toLocal8Bit().data()<<std::endl;
this->usedDG[_DG->getName()]=0;//用过了,做个记号
}
return true;
}
bool TopologyRecorder::isEquipmentNeeded(const QString& substatinID)
{
const QHash<QString,BasicElementInfo*> &ht=this->eleHT;
@ -297,8 +320,10 @@ bool TopologyRecorder::startWithNode(const QString& node)
break;
case TopologyRecorder::Type::TF:
branch=new Transformer(fromTo,static_cast<PowerTransformer *>(foundEle),this);
// std::cout<<"add tf"<<std::endl;
this->cimExporter.add(fromTo,static_cast<Transformer *>(branch));
//把DG接在变压器旁边
this->addDG(static_cast<PowerTransformer *>(foundEle)->getEquipmentMemberOf_EquipmentContainer(),fromTo.first);
break;
default:
break;

View File

@ -16,10 +16,13 @@
#include "busbarsection.h"
#include "disconnector.h"
#include "cimexporter.h"
#include "dginfo.h"
#include "dgmapping.h"
#include "element/branch.h"
#include "element/line.h"
#include "element/switch.h"
#include "element/transformer.h"
#include "element/dg.h"
class TopologyRecorder:public QObject
{
Q_OBJECT
@ -44,7 +47,10 @@ private:
CIMExporter cimExporter;
QHash<QString,char> hasAdded;
QString rootID;
QHash<QString,char> usedDG;
bool addDG(const QString &substationID,const QString& fromNodeID);
bool isEquipmentNeeded(const QString& substatinID);
};
#endif // TOPOLOGYRECORDER_H