Commit fea0e9bf authored by 刘乐's avatar 刘乐

1,增加适应度函数计算函数

parent 6cb113e7
......@@ -50,7 +50,7 @@ double FirstOptScheduling::pumpPower(const PumpStruct& pumpParam)
return result;
}
double FirstOptScheduling::waterProductionCost(const std::vector<double>& Q, const std::vector<double>& S3)
double FirstOptScheduling::waterProductionCost(const vector<double>& Q, const vector<double>& S3)
{
if (Q.size() != S3.size())
return 0;
......@@ -65,7 +65,7 @@ double FirstOptScheduling::waterProductionCost(const std::vector<double>& Q, con
return result;
}
double FirstOptScheduling::waterSupplyAndDemand(const std::vector<double>& Q, const double& Qd)
double FirstOptScheduling::waterSupplyAndDemand(const vector<double>& Q, const double& Qd)
{
size_t total = Q.size();
double result = 0;
......@@ -76,3 +76,38 @@ double FirstOptScheduling::waterSupplyAndDemand(const std::vector<double>& Q, co
return std::abs(result - Qd);
}
double FirstOptScheduling::objectiveFunction(float cost, const map<string, double>& monitorVals)
{
// 适应度函数简易版
float sum = 0.0;
map<string, double>::const_iterator conIter = monitorVals.cbegin();
for (; conIter != monitorVals.cend(); conIter++)
{
string key = conIter->first;
double val = conIter->second;
map<string, double>::iterator minIter = mMinMonitorVals.find(key);
if (minIter == mMinMonitorVals.end())
continue;
map<string, double>::iterator maxIter = mMaxMonitorVals.find(key);
if (maxIter == mMaxMonitorVals.end())
continue;
float minVal = minIter->second;
float maxVal = maxIter->second;
float maxMinDiff =maxVal - minVal;
if (val < minVal)
{
sum += ((minVal - val) / maxMinDiff);
}
else if (val > maxVal)
{
sum += ((val - maxVal) / maxMinDiff);
}
}
return 1 / (C1 + cost) * (1 + sum);
}
\ No newline at end of file
......@@ -12,6 +12,12 @@ public:
FirstOptScheduling();
~FirstOptScheduling();
/**
* @brief 目标函数,计算适应度值
* @param [in] monitorVals
*/
virtual double objectiveFunction(float cost, const map<string, double>& monitorVals);
/**
* @brief 供需压差函数
* @param [in] HC[i]: 测压点i预测压力值
......@@ -34,7 +40,7 @@ public:
* @param [vector<double>] S3[i] 第i个泵站的制水成本,单位: 元/m3
* @return
*/
virtual double waterProductionCost(const std::vector<double>& Q, const std::vector<double>& S3);
virtual double waterProductionCost(const vector<double>& Q, const vector<double>& S3);
virtual double waterSupplyAndDemand(const std::vector<double>& Q, const double& Qd);
virtual double waterSupplyAndDemand(const vector<double>& Q, const double& Qd);
};
......@@ -268,3 +268,13 @@ void GenAlg::decoding(vector<char>& chromo, map<string, int>& phenotype)
{
}
void GenAlg::setMaxMonitorVals(const map<string, double>& maxMonitors)
{
mOptScheduling->setMaxMonitorVals(maxMonitors);
}
void GenAlg::setMinMonitorsVals(const map<string, double>& minMonitors)
{
mOptScheduling->setMinMonitorsVals(minMonitors);
}
\ No newline at end of file
......@@ -78,6 +78,10 @@ public:
*/
void decoding(vector<char>& chromo,map<string,int>& phenotype);
void setMaxMonitorVals(const map<string, double>& maxMonitors);
void setMinMonitorsVals(const map<string, double>& minMonitors);
private:
// 产生[a,b)之间的浮点数
double random(int a=0, int b= RAND_MAX);
......
......@@ -10,7 +10,7 @@ OptScheduling::~OptScheduling()
}
double OptScheduling::objectiveFunction()
double OptScheduling::objectiveFunction(float cost, const map<string,double>& monitorVals)
{
double res = 0;
return res;
......@@ -40,3 +40,13 @@ double OptScheduling::waterSupplyAndDemand(const std::vector<double>& Q, const d
double res = 0;
return res;
}
void OptScheduling::setMaxMonitorVals(const map<string, double>& maxMonitors)
{
mMaxMonitorVals = maxMonitors;
}
void OptScheduling::setMinMonitorsVals(const map<string, double>& minMonitors)
{
mMinMonitorVals = minMonitors;
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
#include "pandaAlgorithm.h"
#include <vector>
#include <map>
#include <string>
using namespace std;
......@@ -28,7 +29,11 @@ public:
std::vector<int> mP; //第i泵站中调速泵的台数
};
virtual double objectiveFunction();
/**
* @brief 目标函数,计算适应度值
* @param [in] monitorVals
*/
virtual double objectiveFunction(float cost, const map<string,double>& monitorVals);
/**
* @brief 供需压差函数
......@@ -36,7 +41,7 @@ public:
* @param [in] HF[I]: 测压点i要求的最低供水服务压力。
* @return
*/
virtual double pressureDifference(const std::vector<double>& HC,const std::vector<double>& HF);
virtual double pressureDifference(const vector<double>& HC,const vector<double>& HF);
/**
* @brief 水泵供水功耗
......@@ -52,7 +57,7 @@ public:
* @param
* @return
*/
virtual double waterProductionCost(const std::vector<double>& Q,const std::vector<double>& S3);
virtual double waterProductionCost(const vector<double>& Q,const vector<double>& S3);
/**
* @brief 供需水量
......@@ -60,10 +65,25 @@ public:
* @param [double] Qd 总需水量,预测
* @return
*/
virtual double waterSupplyAndDemand(const std::vector<double>& Q, const double& Qd );
virtual double waterSupplyAndDemand(const vector<double>& Q, const double& Qd );
// 设置监测点的最大值
void setMaxMonitorVals(const map<string, double>& maxMonitors);
// 设置监测点的最小值
void setMinMonitorsVals(const map<string, double>& minMonitors);
protected:
// 惩罚因子1
double C1;
// 惩罚因子2
double C2;
// 设置的监测点的调度最大值
map<string, double> mMaxMonitorVals;
// 设置的监测点的调度最小值
map<string, double> mMinMonitorVals;
};
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
......
#pragma once
#define EnergyHead "能量利用"
#define TotalEnergy "需电费"
#define TotalCost "总成本"
#define LineSeparator "----------------------------------------------------------------------"
#define NodeHead "节点结果"
#define PipeHead "管段结果"
#define Node "节点"
#define Demand "需水量"
#define TotalHead "总水头"
#define Pressure "压力"
#define Quality "水质"
#define Pipe "管段"
#define UnitHeadLoss "单位水头损失"
#define Flow "流量"
#define Velocity "流速"
#define Status "状态"
#define Open "打开"
#define Close "关闭"
#define Pump "水泵"
/***
模拟报告的一些数结构体
*/
// 管段模拟结果值
typedef struct PipeStruct
{
char sz[128];
float flow;
float velocity;// 流速
float unitHeadLosss; // 单位水头损失
char status[256]; // 状态
};
// 节点模拟结果值
typedef struct NodeStruct
{
char sz[128]; // id号
float demand;
float totalHead;
float pressure;
float quality;
};
// 能量报告结构体
typedef struct EnergyStruct
{
char sz[128];
float percentage; // 百分比利用
float averEffic; // 平均效率
float kwm; // kw-hr
float averKilowatt; // 平均千瓦
float dayCost; // 成本/日
};
#include "CivReportReader.h"
#include<fstream>
#include<iostream>
CivReportReader::CivReportReader()
{
}
void CivReportReader::readEnergy(const string& pumpSn, string& enery)
{
}
bool CivReportReader::open(const string& reportFile)
{
ifstream stream(reportFile.c_str());
// жȡ
string sLine;
while (getline(stream, sLine))
{
}
stream.close();
}
#pragma once
#include <string>
#include <vector>
#include <map>
#include "CivReport.h"
using namespace std;
/**
读取模拟计算报告的
*/
class CivReportReader
{
public:
CivReportReader();
bool open(const string& reportFile);
void readEnergy(const string& pumpSn, string& enery);
private:
vector<EnergyStruct> mEnergys; // 能耗读取
vector<NodeStruct> mNodes;
vector<PipeStruct> mPipes;
};
\ No newline at end of file
......@@ -172,6 +172,7 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command>
<ClCompile Include="CivProjManager.cpp" />
<ClCompile Include="CivProjSimulation.cpp" />
<ClCompile Include="CivProjSmulResultCache.cpp" />
<ClCompile Include="CivReportReader.cpp" />
<ClCompile Include="CivSchedulingCompute.cpp" />
<ClCompile Include="CivSimulResultCache.cpp" />
<ClCompile Include="CivStopWaterAnalysis.cpp" />
......@@ -196,6 +197,8 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command>
<ClInclude Include="CivProjManager.h" />
<ClInclude Include="CivProjSimulation.h" />
<ClInclude Include="CivProjSmulResultCache.h" />
<ClInclude Include="CivReport.h" />
<ClInclude Include="CivReportReader.h" />
<ClInclude Include="CivSchedulingCompute.h" />
<ClInclude Include="CivSimulResultCache.h" />
<ClInclude Include="CivStopWaterAnalysis.h" />
......
......@@ -78,6 +78,9 @@
<ClCompile Include="CivSchedulingCompute.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivReportReader.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivHydrFuncInter.h">
......@@ -149,5 +152,11 @@
<ClInclude Include="CivSchedulingCompute.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivReport.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivReportReader.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
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