Commit 4828200d authored by 刘乐's avatar 刘乐

1, 优化调度框架搭建

parent fcd5a414
...@@ -161,7 +161,8 @@ copy epanet2.h $(OutDir)..\include /y</Command> ...@@ -161,7 +161,8 @@ copy epanet2.h $(OutDir)..\include /y</Command>
</ProjectReference> </ProjectReference>
<PostBuildEvent> <PostBuildEvent>
<Command>copy Epanet2Out.h $(OutDir)..\include /y <Command>copy Epanet2Out.h $(OutDir)..\include /y
copy epanet2.h $(OutDir)..\include /y</Command> copy epanet2.h $(OutDir)..\include /y
copy types.h $(OutDir)..\include /y</Command>
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
......
...@@ -16,19 +16,9 @@ ...@@ -16,19 +16,9 @@
using namespace std; using namespace std;
float random()
{
return rand() / (RAND_MAX + 1.0);
}
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srand((unsigned)time(NULL)); /*这一句dao很重要,zhi如果没有的话,每dao次产生内的数据都是不变的。*/
for (int i = 0; i < 10; i++)
{
printf("%d",rand()%2);/*产生10个0到容1的随机数*/
}
while (true) while (true)
{ {
const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin"; const char* uri = "host=192.168.19.100 port=5432 dbname=JinXian user=postgres password=admin";
...@@ -43,6 +33,7 @@ int main(int argc, char* argv[]) ...@@ -43,6 +33,7 @@ int main(int argc, char* argv[])
cout << "\t5.下游追踪\n"; cout << "\t5.下游追踪\n";
cout << "\t6.水源供水范围分析\n"; cout << "\t6.水源供水范围分析\n";
cout << "\t7.方案模拟\n"; cout << "\t7.方案模拟\n";
cout << "\t8.优化调度测试\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
int test_no; int test_no;
...@@ -88,6 +79,9 @@ int main(int argc, char* argv[]) ...@@ -88,6 +79,9 @@ int main(int argc, char* argv[])
context.setHydrTest(new CivProjSimulationTest()); context.setHydrTest(new CivProjSimulationTest());
context.contextTest(findUri); context.contextTest(findUri);
break; break;
case 8: // 8 优化调度测试
break;
default: default:
cout << "输入测试号错误!" << endl; cout << "输入测试号错误!" << endl;
break; break;
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#include "genome.h" #include "genome.h"
#include <memory> #include <memory>
#include <string>
#include <vector> #include <vector>
#include <map>
#include <time.h> #include <time.h>
#include<stdlib.h> #include<stdlib.h>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "CivHydrSimulation.h" #include "CivHydrSimulation.h"
#include "CivTrackingAnalysis.h" #include "CivTrackingAnalysis.h"
#include "CivProjSimulation.h" #include "CivProjSimulation.h"
#include "JsonParseObject.h"
bool PANDANALYSIS_API hdyrSimulation(char* uri) bool PANDANALYSIS_API hdyrSimulation(char* uri)
{ {
...@@ -70,5 +71,29 @@ bool PANDANALYSIS_API projSimulation(char* uri, char* projCode, char* time) ...@@ -70,5 +71,29 @@ bool PANDANALYSIS_API projSimulation(char* uri, char* projCode, char* time)
if (!projSimulation.simulationProj(projCode, time)) if (!projSimulation.simulationProj(projCode, time))
return false; return false;
return true;
}
bool PANDANALYSIS_API optimalSchedulingSimulation(char* uri, char* condition, char* timeInterval, char* result)
{
// 类型装换
string uriStr = uri;
string conditionStr = condition;
string timeStr = timeInterval;
// 解析输入的字符串转换位对应容器数据
JsonParseObject jsonObj;
jsonObj.parse(conditionStr);
map<string, string> condiTionMap;
jsonObj.read(condiTionMap);
// 清楚
jsonObj.clear();
jsonObj.parse(timeStr);
return true; return true;
} }
\ No newline at end of file
...@@ -61,7 +61,14 @@ extern "C" { ...@@ -61,7 +61,14 @@ extern "C" {
*/ */
bool PANDANALYSIS_API projSimulation(char* uri, char* projCode, char* time); bool PANDANALYSIS_API projSimulation(char* uri, char* projCode, char* time);
/**
*@brief 优化调度模拟
*@param [in] uri:condition
*@param [in] condition:约束条件, 格式: json字符串 {"测压点1":[32,46],"测压点2":[28,33]}
*@param [in] timeInterval:时段,格式:{"start":'2020-10-27 00:00:00',"end":'2020-10-27 08:00:00' }
*@param [out] result: 模拟的调度结果
*/
bool PANDANALYSIS_API optimalSchedulingSimulation(char* uri, char* condition, char* timeInterval, char* result);
#if defined(__cplusplus) #if defined(__cplusplus)
} }
#endif #endif
......
#include "CivOptSchedEngine.h" #include "CivOptSchedEngine.h"
#include "CivInpConvertor.h"
CivOptSchedEngine::CivOptSchedEngine(const string& uri):mUri(uri) CivOptSchedEngine::CivOptSchedEngine(const string& uri):mUri(uri)
{ {
} }
bool CivOptSchedEngine::optimal() bool CivOptSchedEngine::optimalScheduling()
{ {
// תinpļ // תinpļ
CivInpConvertor convertor(mUri);
string inpFile = convertor.convertBaseInp();
//
// ¿ªÊ¼¼ÆËã
} }
...@@ -17,3 +21,23 @@ void CivOptSchedEngine::schedulingResultToJson(string& json) ...@@ -17,3 +21,23 @@ void CivOptSchedEngine::schedulingResultToJson(string& json)
{ {
} }
void CivOptSchedEngine::setMonitor(const map<string, vector<double>>& monitorMap)
{
mMonitoring = monitorMap;
}
void CivOptSchedEngine::setDecisionVariableStatusBit(const map<int,string>& statusMap)
{
mStatusBit = statusMap;
}
void CivOptSchedEngine::setStartTime(const string& time)
{
mStartTime = time;
}
void CivOptSchedEngine::setEndTime(const string& time)
{
mEndTime = time;
}
\ No newline at end of file
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <vector> #include <vector>
#include <map> #include <map>
using namespace std; using namespace std;
/** /**
...@@ -14,7 +13,19 @@ class CivOptSchedEngine ...@@ -14,7 +13,19 @@ class CivOptSchedEngine
public: public:
explicit CivOptSchedEngine(const string& uri); explicit CivOptSchedEngine(const string& uri);
bool optimal(); bool optimalScheduling();
// 设置监测点
void setMonitor(const map<string, vector<double>>& monitorMap);
// 设置决策变量状态位
void setDecisionVariableStatusBit(const map<int, string>& statusMap);
// 设置调度开始时段
void setStartTime(const string& time);
// 设置调度结束时段
void setEndTime(const string& time);
protected: protected:
/** /**
...@@ -24,13 +35,21 @@ protected: ...@@ -24,13 +35,21 @@ protected:
void schedulingResultToJson(string& json); void schedulingResultToJson(string& json);
private: private:
// 编码与状态的映射 // 编码与状态的映射
map<string, int> mStatus; map<int, string> mStatusBit;
// 调度结果 // 调度结果
vector<map<string, int>> mSchedulingResults; vector<map<string, int>> mSchedulingResults;
// 监测点
map<string, vector<double>> mMonitoring;
// 数据连接地址 // 数据连接地址
string mUri; string mUri;
// 调度开始时段
string mStartTime;
// 调度结束时段
string mEndTime;
}; };
#pragma once #pragma once
#include "CivOptSchedEngine.h" #include "CivOptSchedEngine.h"
#include <string>
#include <map>
#include <vector>
using namespace std;
/** /**
վŻ վŻ
*/ */
...@@ -9,6 +14,14 @@ class CivOptSchedPumpEngine: public CivOptSchedEngine ...@@ -9,6 +14,14 @@ class CivOptSchedPumpEngine: public CivOptSchedEngine
public: public:
explicit CivOptSchedPumpEngine(const std::string& uri); explicit CivOptSchedPumpEngine(const std::string& uri);
private: private:
// ֮ǰ
vector<map<string, double>> mBeforeScheduling;
// ֮
vector<map<string, double>> mSchduling;
// ˮӳ
map<string, string> mPumpMap;
}; };
#include "CivSchedulingCompute.h"
#include "CivCommonUtils.h"
#include "epanet2.h"
#include "types.h"
#include "CivSysLog.h"
CivSchedulingCompute::CivSchedulingCompute()
{
mRptFile = CivCommonUtils::getExePath() + "\\test.rpt";
mBinFile = CivCommonUtils::getExePath() + "\\test.bin";
}
bool CivSchedulingCompute::openFile(string& inpFILE)
{
char inpFile[256];
strcpy_s(inpFile, inpFILE.c_str());
char rptFile[128];
strcpy_s(rptFile, mRptFile.c_str());
char binFile[128];
strcpy_s(binFile, mBinFile.c_str());
CivSysLog::getInstance()->info("打开inp文件", "CivHydrCompute", __FUNCTION__);
mErrcode = ENopen(inpFile, rptFile, binFile);
if (mErrcode > 0)
{
CivSysLog::getInstance()->error("ENopen 失败", "CivHydrCompute", __FUNCTION__);
ENclose();
return false;
}
if (ENopenH() > 0)
{
CivSysLog::getInstance()->error("ENopenH 失败", "CivHydrCompute", __FUNCTION__);
ENclose();
return false;
}
if (ENinitH(EN_SAVE) > 0)
{
CivSysLog::getInstance()->error("ENinitH 失败", "CivHydrCompute", __FUNCTION__);
ENclose();
return false;
}
return true;
}
bool CivSchedulingCompute::calculate()
{
short hydCode = 1;
long t(0), tstep(0);
int iTime(0);
float dHStep;
ENGetVal(4, &dHStep);
do
{
int nLinkCount;
ENgetcount(EN_LINKCOUNT, &nLinkCount);
for (int i = 1; i <= nLinkCount; i++)
{
// 获取管段类型
int linkType;
ENgetlinktype(i, &linkType);
if (linkType != EN_PUMP)
continue;
char id[128] = "";
ENgetlinkid(i, id);
auto iter = mPumpStatus.find(id);
if (iter == mPumpStatus.end())
continue;
iter->second;
ENsetlinkvalue(i, EN_STATUS, iter->second == '1' ? OPEN : CLOSED);
}
if (ENrunH(&t) > 100) // errcode > 100 是错误
{
ENclose();
return false;
}
ENnextH(&tstep);
iTime++;
} while (tstep > 0);
return true;
}
void CivSchedulingCompute::close()
{
ENcloseH();
ENclose();
}
void CivSchedulingCompute::updatePumpStatus(const map<string, char>& pumpStatus)
{
mPumpStatus.clear();
mPumpStatus = pumpStatus;
}
void CivSchedulingCompute::getMonitorsValue(vector<map<string, double>>& monitorMap)
{
monitorMap = mMonitors;
}
\ No newline at end of file
#pragma once
#include <map>
#include <string>
using namespace std;
/**
优化调度计算类
*/
class CivSchedulingCompute
{
public:
CivSchedulingCompute();
bool openFile(string& inpFILE);
bool calculate();
void close();
void updatePumpStatus(const map<string, char>& pumpStatus);
void getMonitorsValue(vector<map<string, double>>& monitorMap);
private:
std::string mRptFile;
std::string mBinFile;
// 错误吗
int mErrcode = 0;
// 更新水泵的状态
map<string, char> mPumpStatus;
// 存储测点的计算值
vector<map<string, double>> mMonitors;
};
...@@ -173,6 +173,7 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command> ...@@ -173,6 +173,7 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command>
<ClCompile Include="CivProjManager.cpp" /> <ClCompile Include="CivProjManager.cpp" />
<ClCompile Include="CivProjSimulation.cpp" /> <ClCompile Include="CivProjSimulation.cpp" />
<ClCompile Include="CivProjSmulResultCache.cpp" /> <ClCompile Include="CivProjSmulResultCache.cpp" />
<ClCompile Include="CivSchedulingCompute.cpp" />
<ClCompile Include="CivSimulResultCache.cpp" /> <ClCompile Include="CivSimulResultCache.cpp" />
<ClCompile Include="CivStopWaterAnalysis.cpp" /> <ClCompile Include="CivStopWaterAnalysis.cpp" />
<ClCompile Include="CivTrackingAnalysis.cpp" /> <ClCompile Include="CivTrackingAnalysis.cpp" />
...@@ -197,6 +198,7 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command> ...@@ -197,6 +198,7 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command>
<ClInclude Include="CivProjManager.h" /> <ClInclude Include="CivProjManager.h" />
<ClInclude Include="CivProjSimulation.h" /> <ClInclude Include="CivProjSimulation.h" />
<ClInclude Include="CivProjSmulResultCache.h" /> <ClInclude Include="CivProjSmulResultCache.h" />
<ClInclude Include="CivSchedulingCompute.h" />
<ClInclude Include="CivSimulResultCache.h" /> <ClInclude Include="CivSimulResultCache.h" />
<ClInclude Include="CivStopWaterAnalysis.h" /> <ClInclude Include="CivStopWaterAnalysis.h" />
<ClInclude Include="CivTrackingAnalysis.h" /> <ClInclude Include="CivTrackingAnalysis.h" />
......
...@@ -78,6 +78,9 @@ ...@@ -78,6 +78,9 @@
<ClCompile Include="CivOptSchedPumpEngine.cpp"> <ClCompile Include="CivOptSchedPumpEngine.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="CivSchedulingCompute.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="CivHydrFuncInter.h"> <ClInclude Include="CivHydrFuncInter.h">
...@@ -149,5 +152,8 @@ ...@@ -149,5 +152,8 @@
<ClInclude Include="CivOptSchedPumpEngine.h"> <ClInclude Include="CivOptSchedPumpEngine.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="CivSchedulingCompute.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -80,7 +80,6 @@ bool CivInpHelperAbs::getPatterns(CivPatterns& patterns) ...@@ -80,7 +80,6 @@ bool CivInpHelperAbs::getPatterns(CivPatterns& patterns)
return true; return true;
} }
PatternTable patternTable; PatternTable patternTable;
std::vector<std::string> fields = { std::vector<std::string> fields = {
......
#include "JsonParseObject.h" #include "JsonParseObject.h"
#include "cJSON.h"
JsonParseObject::JsonParseObject() JsonParseObject::JsonParseObject()
{ {
...@@ -7,5 +9,27 @@ JsonParseObject::JsonParseObject() ...@@ -7,5 +9,27 @@ JsonParseObject::JsonParseObject()
JsonParseObject::~JsonParseObject() JsonParseObject::~JsonParseObject()
{ {
cJSON_Delete(mResultJson);
}
bool JsonParseObject::getKeys(vector<string>& keys)
{
return true;
}
void JsonParseObject::parse(string& jsonStr)
{
// jsonַתλjsonṹ
const char* json = jsonStr.c_str();
mResultJson = cJSON_Parse(json);
}
void JsonParseObject::read(map<string, string>& resMap)
{
}
void JsonParseObject::clear()
{
cJSON_Delete(mResultJson);
} }
\ No newline at end of file
#pragma once #pragma once
#include <string>
#include <vector>
#include <map>
#include "pandaLog.h"
using namespace std;
class cJSON;
/** /**
json解析对象 json解析对象
*/ */
class JsonParseObject class PANDALOG_API JsonParseObject
{ {
public: public:
JsonParseObject(); JsonParseObject();
~JsonParseObject(); ~JsonParseObject();
bool getKeys(vector<string>& keys);
void parse(string& jsonStr);
void read(map<string, string>& resMap);
// 主动销毁已读取的数据
void clear();
private:
struct cJSON* mResultJson; // json字符串对象
}; };
\ No newline at end of file
...@@ -149,7 +149,8 @@ copy CivCsvReader.h $(OutDir)..\include /y ...@@ -149,7 +149,8 @@ copy CivCsvReader.h $(OutDir)..\include /y
copy CivCommonUtils.h $(OutDir)..\include /y copy CivCommonUtils.h $(OutDir)..\include /y
copy CivDate.h $(OutDir)..\include /y copy CivDate.h $(OutDir)..\include /y
copy StringUtils.h $(OutDir)..\include /y copy StringUtils.h $(OutDir)..\include /y
copy pandaLog.h $(OutDir)..\include /y</Command> copy pandaLog.h $(OutDir)..\include /y
copy JsonParseObject.h $(OutDir)..\include /y</Command>
</PostBuildEvent> </PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
......
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