Commit bde40d2e authored by 刘乐's avatar 刘乐

1, 修复其他问题

parent 0b99f27c
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
#include "CivHydrFuncInter.h" #include "CivHydrFuncInter.h"
#include <iostream> #include <iostream>
CivHydrTest::~CivHydrTest()
{
}
// 水力测试 // 水力测试
void CivConHydrTest::test(char* uri) void CivConHydrTest::test(char* uri)
......
...@@ -5,6 +5,7 @@ class CivHydrTest ...@@ -5,6 +5,7 @@ class CivHydrTest
{ {
public: public:
virtual void test(char* uri) = 0; virtual void test(char* uri) = 0;
virtual ~CivHydrTest();
}; };
// 水力测试 // 水力测试
......
...@@ -21,7 +21,7 @@ int main(int argc, char* argv[]) ...@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
{ {
while (true) while (true)
{ {
const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian3 user=postgres password=admin"; const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin";
char* findUri = const_cast<char*>(uri); char* findUri = const_cast<char*>(uri);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
......
...@@ -72,7 +72,7 @@ void GenAlg::mutate(vector<double>& chromo) ...@@ -72,7 +72,7 @@ void GenAlg::mutate(vector<double>& chromo)
if (random(0,1) < mMutationRate) if (random(0,1) < mMutationRate)
{ {
// 使该权值增加或者减少一个很小的随机数值 // 使该权值增加或者减少一个很小的随机数值
chromo[i] += ((random() - 0.5) * mMaxPerturbation); chromo[i] += ((random() - 0.05) * mMaxPerturbation);
// 左右边界 // 左右边界
if (chromo[i] < mLeftPoint) if (chromo[i] < mLeftPoint)
......
...@@ -109,7 +109,7 @@ private: ...@@ -109,7 +109,7 @@ private:
// 所有个体对应的适应性评分的总和 // 所有个体对应的适应性评分的总和
double mTotalFitness; double mTotalFitness;
//在所有个体当中最适应的个体的适应性评分 // 在所有个体当中最适应的个体的适应性评分
double mBestFitness; double mBestFitness;
// 所有个体的适应性评分的平均值 // 所有个体的适应性评分的平均值
......
...@@ -45,7 +45,7 @@ bool CivOptSchedEngine::optimalScheduling() ...@@ -45,7 +45,7 @@ bool CivOptSchedEngine::optimalScheduling()
genAlg.init(popsize, mMutRate, mCrossRate, mGenLength, 0, 0); genAlg.init(popsize, mMutRate, mCrossRate, mGenLength, 0, 0);
// 构造水力计算对象 // 构造水力计算对象
CivSchedulingCompute schedulingCompute; CivSchedulingCompute schedulingCompute(CivSchedulingCompute::PumpScheduling);
vector<string> monitorVec; vector<string> monitorVec;
for (auto iter = mMonitoring.begin(); iter != mMonitoring.end(); iter++) for (auto iter = mMonitoring.begin(); iter != mMonitoring.end(); iter++)
{ {
...@@ -80,23 +80,22 @@ bool CivOptSchedEngine::optimalScheduling() ...@@ -80,23 +80,22 @@ bool CivOptSchedEngine::optimalScheduling()
vector<map<string, double>> monitorCalcMapValues; vector<map<string, double>> monitorCalcMapValues;
schedulingCompute.getMonitorsValue(monitorCalcMapValues); schedulingCompute.getMonitorsValue(monitorCalcMapValues);
CivReportReader reportReader; // 获取消耗的能量值
float cost = 0; float cost = schedulingCompute.totalEnergy(i);
string rptPath = CivCommonUtils::getExePath() + "//test.rpt";
reportReader.open(rptPath);
// cost = reportReader.readEnergy();
//
// 计算个体自适度 // 计算个体自适度
// genAlg.fitnessfunction(); genAlg.fitnessfunction(cost, monitorCalcMapValues[i]);
} }
// 根据个体自适应度进行选择 // 根据个体自适应度进行选择
genAlg.chromoRoulette();
// 自适应交叉变异 // 自适应交叉变异
genAlg.corssver();
// 产生下一代种群 // 产生下一代种群
std::vector<Genome> newGenmeVec;
genAlg.epoch(newGenmeVec);
} }
// 获取最好的 // 获取最好的
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "types.h" #include "types.h"
#include "CivSysLog.h" #include "CivSysLog.h"
CivSchedulingCompute::CivSchedulingCompute() CivSchedulingCompute::CivSchedulingCompute(SchdulingType schedulingType)
:mChdulingType(schedulingType)
{ {
mRptFile = CivCommonUtils::getExePath() + "\\test.rpt"; mRptFile = CivCommonUtils::getExePath() + "\\test.rpt";
mBinFile = CivCommonUtils::getExePath() + "\\test.bin"; mBinFile = CivCommonUtils::getExePath() + "\\test.bin";
...@@ -66,18 +67,37 @@ bool CivSchedulingCompute::calculate() ...@@ -66,18 +67,37 @@ bool CivSchedulingCompute::calculate()
int linkType; int linkType;
ENgetlinktype(i, &linkType); ENgetlinktype(i, &linkType);
if (linkType != EN_PUMP) if (linkType != EN_PUMP || linkType != EN_PBV)
continue; continue;
char id[128] = ""; switch (mChdulingType)
ENgetlinkid(i, id); {
case PumpScheduling& EN_PUMP:
auto iter = mPumpStatus.find(id); {
if (iter == mPumpStatus.end()) if (linkType != EN_PUMP)
continue; continue;
iter->second; char id[128] = "";
ENsetlinkvalue(i, EN_STATUS, iter->second == '1' ? OPEN : CLOSED); ENgetlinkid(i, id);
auto iter = mPumpStatus.find(id);
if (iter == mPumpStatus.end())
continue;
iter->second;
ENsetlinkvalue(i, EN_STATUS, iter->second == '1' ? OPEN : CLOSED);
}
break;
case PBVScheduling& EN_PBV:
{
if (linkType != EN_PBV)
continue;
}
break;
default:
break;
}
} }
if (ENrunH(&t) > 100) // errcode > 100 是错误 if (ENrunH(&t) > 100) // errcode > 100 是错误
...@@ -91,6 +111,9 @@ bool CivSchedulingCompute::calculate() ...@@ -91,6 +111,9 @@ bool CivSchedulingCompute::calculate()
// 保存 // 保存
saveResult(iTime); saveResult(iTime);
// 水泵能量
getPumpEnergy(iTime);
iTime++; iTime++;
} while (tstep > 0); } while (tstep > 0);
...@@ -142,4 +165,48 @@ void CivSchedulingCompute::saveResult(int time) ...@@ -142,4 +165,48 @@ void CivSchedulingCompute::saveResult(int time)
pressureMap.insert(pair<string, double>(szNo, pressure)); pressureMap.insert(pair<string, double>(szNo, pressure));
} }
mMonitorsValue[time] = pressureMap; mMonitorsValue[time] = pressureMap;
}
void CivSchedulingCompute::getPumpEnergy(int time)
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
for (int i = 0; i < nLinkCount; i++)
{
// 获取管段类型
int linkType;
ENgetlinktype(i, &linkType);
if (EN_PUMP != linkType)
continue;
char szNo[256];
ENgetlinkid(i, szNo);// 编号
float energy;
ENgetlinkvalue(i, EN_ENERGY, &energy);
// 存储每个时刻的消耗的能量
mPumpEnergy[time][szNo] = energy;
}
}
float CivSchedulingCompute::totalEnergy(int index)
{
if (index<0 || index > mPumpEnergy.size()-1)
return 0;
float totalEnergy = 0;
map<string, float> energyMap = mPumpEnergy[index];
map<string, float>::const_iterator const_iter = energyMap.cbegin();
for (; const_iter != energyMap.cend(); const_iter++)
{
totalEnergy += const_iter->second;
}
return totalEnergy;
}
void CivSchedulingCompute::updatePBVSettings(const string& sn, double pressure)
{
} }
\ No newline at end of file
...@@ -10,7 +10,15 @@ using namespace std; ...@@ -10,7 +10,15 @@ using namespace std;
class CivSchedulingCompute class CivSchedulingCompute
{ {
public: public:
CivSchedulingCompute();
// 调度类型
enum SchdulingType
{
PumpScheduling, // 水泵调度
PBVScheduling // 根据压力制动阀调度
};
explicit CivSchedulingCompute(SchdulingType schedulingType);
// 设置监测点 // 设置监测点
void setMonitors(const vector<string>& monitor); void setMonitors(const vector<string>& monitor);
...@@ -30,10 +38,18 @@ public: ...@@ -30,10 +38,18 @@ public:
// 获取监测点计算出的值 // 获取监测点计算出的值
void getMonitorsValue(vector<map<string, double>>& monitorMap); void getMonitorsValue(vector<map<string, double>>& monitorMap);
// 更改压力制动阀压力设置
void updatePBVSettings(const string& sn, double pressure);
// 获取每个时刻消耗的总能量
float totalEnergy(int index);
private: private:
// 保存计算的值 // 保存计算的值
void saveResult(int time); void saveResult(int time);
// 获取计算的水泵的能耗
void getPumpEnergy(int time);
private: private:
std::string mRptFile; std::string mRptFile;
std::string mBinFile; std::string mBinFile;
...@@ -47,6 +63,12 @@ private: ...@@ -47,6 +63,12 @@ private:
// 更新水泵的状态 // 更新水泵的状态
map<string, int> mPumpStatus; map<string, int> mPumpStatus;
// 水泵消耗的能量
vector<map<string, float>> mPumpEnergy;
// 存储测点的计算值 // 存储测点的计算值
vector<map<string, double>> mMonitorsValue; vector<map<string, double>> mMonitorsValue;
SchdulingType mChdulingType;
}; };
#pragma once
#include <vector>
#include<string>
using namespace std;
// 水泵结构体
typedef struct PumpStruct
{
string sz; // 水泵编号
string speedRatio; // 转速比
string status; //水泵状态
string pricePattern;// 价格模式
string energyPrice; // 能量价格
string power; // 功率
};
// 泵站结构体
typedef struct PumpStation
{
string stationName; // 泵站名
vector<PumpStruct> pumps; // 水泵集合
};
...@@ -162,6 +162,7 @@ bool CivInpDbHelper::getPumps(CivPumps& pumps) ...@@ -162,6 +162,7 @@ bool CivInpDbHelper::getPumps(CivPumps& pumps)
fields.push_back(pmTable.startPoint); fields.push_back(pmTable.startPoint);
fields.push_back(pmTable.endPoint); fields.push_back(pmTable.endPoint);
fields.push_back(pmTable.headCurve); fields.push_back(pmTable.headCurve);
fields.push_back(pmTable.ratio);
fields.push_back(pmTable.power); fields.push_back(pmTable.power);
std::vector<std::map<std::string, std::string>> resultVector; std::vector<std::map<std::string, std::string>> resultVector;
...@@ -186,6 +187,10 @@ bool CivInpDbHelper::getPumps(CivPumps& pumps) ...@@ -186,6 +187,10 @@ bool CivInpDbHelper::getPumps(CivPumps& pumps)
if (power != "") if (power != "")
param.append(" power " + power); param.append(" power " + power);
std::string speedRatio = map.find(pmTable.ratio)->second;
if (speedRatio != "")
param.append(" SPEED " + speedRatio);
pump.Parameters = param; pump.Parameters = param;
pumps.addItem(pump); pumps.addItem(pump);
} }
......
...@@ -45,10 +45,16 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params) ...@@ -45,10 +45,16 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
std::map<std::string, std::vector<CivParameter::ParamTable>> tempMap; std::map<std::string, std::vector<CivParameter::ParamTable>> tempMap;
for (int i = 0; i < resultVector.size(); i++) for (int i = 0; i < resultVector.size(); i++)
{ {
CivParameter::ParamTable pTable;
std::map<std::string, std::string> map = resultVector[i]; std::map<std::string, std::string> map = resultVector[i];
std::string pVal = map.find(fields[1])->second;
if (pVal.empty())
continue;
CivParameter::ParamTable pTable;
pTable.name = map.find(fields[0])->second; pTable.name = map.find(fields[0])->second;
pTable.val = map.find(fields[1])->second; pTable.val = pVal;
std::string type = map.find(fields[2])->second; std::string type = map.find(fields[2])->second;
tempMap[type].push_back(pTable); tempMap[type].push_back(pTable);
...@@ -60,7 +66,6 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params) ...@@ -60,7 +66,6 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
CivParameter param; CivParameter param;
std::string type = iter->first; std::string type = iter->first;
std::vector<CivParameter::ParamTable> paramTables = iter->second; std::vector<CivParameter::ParamTable> paramTables = iter->second;
param.setType(type); param.setType(type);
size_t total = paramTables.size(); size_t total = paramTables.size();
...@@ -70,6 +75,55 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params) ...@@ -70,6 +75,55 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
params.push_back(param); params.push_back(param);
} }
// 查询水泵的参数,不同的水泵可能单独有不一样的设置
std::vector<std::map<std::string, std::string>> pumpVector;
mDbConn->query(PUMP, {"本点号","效率曲线","能量价格","价格模式"}, pumpVector);
CivParameter param;
param.setType("ENERGY");
size_t pumpTotal = pumpVector.size();
for (int i = 0; i < pumpTotal; i++)
{
std::map<std::string, std::string> pumpMap = pumpVector[i];
// 本点号不能为空
std::string szNumber = pumpMap.find("本点号")->second;
if (szNumber.empty())
continue;
// 添加单个水泵曲线
std::string curve = pumpMap.find("效率曲线")->second;
if (curve.size() >0)
{
CivParameter::ParamTable table;
table.name = "PUMP " + szNumber +" EFFIC " + curve;
param.addItem(table);
}
// 设置水泵的能量价格
std::string energyPrice = pumpMap.find("能量价格")->second;
if (energyPrice.size()>0)
{
CivParameter::ParamTable table;
table.name = "PUMP " + szNumber + " PRICE " + energyPrice;
param.addItem(table);
}
// 设置水泵的价格模式
std::string pricePattern = pumpMap.find("价格模式")->second;
if (pricePattern.size() > 0)
{
CivParameter::ParamTable table;
table.name = "PUMP " + szNumber + " PRICE " + pricePattern;
param.addItem(table);
}
}
// 判断个别水泵参数是否为空,如果为空就不添加
if(param.mTables.size()>0)
params.push_back(param);
return true; return true;
} }
......
#include "CivPumpHelper.h" #include "CivPumpHelper.h"
#include "CivPgDbConnection.h" #include "CivPgDbConnection.h"
#include <set>
CivPumpHelper::CivPumpHelper(const string& uri) CivPumpHelper::CivPumpHelper(const string& uri)
{ {
...@@ -75,3 +76,42 @@ void CivPumpHelper::getPumpSn(vector<string>& pumpNames) ...@@ -75,3 +76,42 @@ void CivPumpHelper::getPumpSn(vector<string>& pumpNames)
pumpNames.push_back(val); pumpNames.push_back(val);
} }
} }
void CivPumpHelper::getPumpStations(vector<PumpStation>& stations)
{
vector<map<string, string>> vecMap;
if (!mConn->query(mTable, { "本点号","价格模式","能量价格","功率","泵站","水泵状态","转速比" }, vecMap))
return;
if (vecMap.size() <= 0)
return;
size_t total = vecMap.size();
map<string, vector<PumpStruct>> stationMap;
for (int i = 0; i < total; i++)
{
map<string, string> tempMap = vecMap[i];
PumpStruct pumpStruct;
pumpStruct.sz = tempMap.find("本点号")->second;
pumpStruct.pricePattern = tempMap.find("价格模式")->second;
pumpStruct.power = tempMap.find("功率")->second;
pumpStruct.status = tempMap.find("水泵状态")->second;
pumpStruct.speedRatio = tempMap.find("转速比")->second;
string pumpStation = tempMap.find("泵站")->second;
stationMap[pumpStation].push_back(pumpStruct);
}
// 构造泵站集合
map<string, vector<PumpStruct>>::iterator iter = stationMap.begin();
for (; iter != stationMap.end(); iter++)
{
PumpStation station;
station.stationName = iter->first;
station.pumps = iter->second;
stations.push_back(station);
}
}
\ No newline at end of file
...@@ -3,10 +3,10 @@ ...@@ -3,10 +3,10 @@
#include<map> #include<map>
#include<vector> #include<vector>
#include "CivBaseStruct.h"
#include "pandaDbManager.h" #include "pandaDbManager.h"
using namespace std; using namespace std;
class CivConnection; class CivConnection;
/** /**
...@@ -26,6 +26,10 @@ public: ...@@ -26,6 +26,10 @@ public:
// 获取水泵的编号 // 获取水泵的编号
void getPumpSn(vector<string>& pumpNames); void getPumpSn(vector<string>& pumpNames);
// 获取泵站
void getPumpStations(vector<PumpStation>& stations);
private: private:
CivConnection* mConn = nullptr; CivConnection* mConn = nullptr;
......
...@@ -153,6 +153,7 @@ ...@@ -153,6 +153,7 @@
<PostBuildEvent> <PostBuildEvent>
<Command>copy CivTypes.h $(OutDir)..\include /y <Command>copy CivTypes.h $(OutDir)..\include /y
copy CivAssembly.h $(OutDir)..\include /y copy CivAssembly.h $(OutDir)..\include /y
copy CivBaseStruct.h $(OutDir)..\include /y
copy CivInpHelperAbs.h $(OutDir)..\include /y copy CivInpHelperAbs.h $(OutDir)..\include /y
copy CivInpDbHelper.h $(OutDir)..\include /y copy CivInpDbHelper.h $(OutDir)..\include /y
copy CivProjInpDbHelper.h $(OutDir)..\include /y copy CivProjInpDbHelper.h $(OutDir)..\include /y
...@@ -180,6 +181,7 @@ copy CivPumpHelper.h $(OutDir)..\include /y ...@@ -180,6 +181,7 @@ copy CivPumpHelper.h $(OutDir)..\include /y
<ClInclude Include="CivSimuResStruct.h" /> <ClInclude Include="CivSimuResStruct.h" />
<ClInclude Include="CivTableFields.h" /> <ClInclude Include="CivTableFields.h" />
<ClInclude Include="CivTypes.h" /> <ClInclude Include="CivTypes.h" />
<ClInclude Include="CivBaseStruct.h" />
<ClInclude Include="pandaDbManager.h" /> <ClInclude Include="pandaDbManager.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -60,6 +60,9 @@ ...@@ -60,6 +60,9 @@
<ClInclude Include="CivPumpHelper.h"> <ClInclude Include="CivPumpHelper.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CivBaseStruct.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="CivAssembly.cpp"> <ClCompile Include="CivAssembly.cpp">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment