Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hydraulicModel
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘乐
hydraulicModel
Commits
bde40d2e
Commit
bde40d2e
authored
Nov 10, 2020
by
刘乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1, 修复其他问题
parent
0b99f27c
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
256 additions
and
28 deletions
+256
-28
CivHydrTest.cpp
funcDemo/CivHydrTest.cpp
+4
-0
CivHydrTest.h
funcDemo/CivHydrTest.h
+1
-0
main.cpp
funcDemo/main.cpp
+1
-1
GenAlg.cpp
pandaAlgorithm/GenAlg.cpp
+1
-1
GenAlg.h
pandaAlgorithm/GenAlg.h
+1
-1
CivOptSchedEngine.cpp
pandaAnalysis/CivOptSchedEngine.cpp
+8
-9
CivSchedulingCompute.cpp
pandaAnalysis/CivSchedulingCompute.cpp
+79
-11
CivSchedulingCompute.h
pandaAnalysis/CivSchedulingCompute.h
+23
-1
CivBaseStruct.h
pandaDbManager/CivBaseStruct.h
+25
-0
CivInpDbHelper.cpp
pandaDbManager/CivInpDbHelper.cpp
+5
-0
CivInpHelperAbs.cpp
pandaDbManager/CivInpHelperAbs.cpp
+57
-3
CivPumpHelper.cpp
pandaDbManager/CivPumpHelper.cpp
+41
-0
CivPumpHelper.h
pandaDbManager/CivPumpHelper.h
+5
-1
pandaDbManager.vcxproj
pandaDbManager/pandaDbManager.vcxproj
+2
-0
pandaDbManager.vcxproj.filters
pandaDbManager/pandaDbManager.vcxproj.filters
+3
-0
No files found.
funcDemo/CivHydrTest.cpp
View file @
bde40d2e
...
...
@@ -2,6 +2,10 @@
#include "CivHydrFuncInter.h"
#include <iostream>
CivHydrTest
::~
CivHydrTest
()
{
}
// 水力测试
void
CivConHydrTest
::
test
(
char
*
uri
)
...
...
funcDemo/CivHydrTest.h
View file @
bde40d2e
...
...
@@ -5,6 +5,7 @@ class CivHydrTest
{
public
:
virtual
void
test
(
char
*
uri
)
=
0
;
virtual
~
CivHydrTest
();
};
// 水力测试
...
...
funcDemo/main.cpp
View file @
bde40d2e
...
...
@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
{
while
(
true
)
{
const
char
*
uri
=
"host=192.168.19.100 port=5432 dbname=JinXian
3
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
);
SetConsoleTextAttribute
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
FOREGROUND_INTENSITY
|
FOREGROUND_GREEN
);
...
...
pandaAlgorithm/GenAlg.cpp
View file @
bde40d2e
...
...
@@ -72,7 +72,7 @@ void GenAlg::mutate(vector<double>& chromo)
if
(
random
(
0
,
1
)
<
mMutationRate
)
{
// 使该权值增加或者减少一个很小的随机数值
chromo
[
i
]
+=
((
random
()
-
0.5
)
*
mMaxPerturbation
);
chromo
[
i
]
+=
((
random
()
-
0.
0
5
)
*
mMaxPerturbation
);
// 左右边界
if
(
chromo
[
i
]
<
mLeftPoint
)
...
...
pandaAlgorithm/GenAlg.h
View file @
bde40d2e
...
...
@@ -109,7 +109,7 @@ private:
// 所有个体对应的适应性评分的总和
double
mTotalFitness
;
//在所有个体当中最适应的个体的适应性评分
//
在所有个体当中最适应的个体的适应性评分
double
mBestFitness
;
// 所有个体的适应性评分的平均值
...
...
pandaAnalysis/CivOptSchedEngine.cpp
View file @
bde40d2e
...
...
@@ -45,7 +45,7 @@ bool CivOptSchedEngine::optimalScheduling()
genAlg
.
init
(
popsize
,
mMutRate
,
mCrossRate
,
mGenLength
,
0
,
0
);
// 构造水力计算对象
CivSchedulingCompute
schedulingCompute
;
CivSchedulingCompute
schedulingCompute
(
CivSchedulingCompute
::
PumpScheduling
)
;
vector
<
string
>
monitorVec
;
for
(
auto
iter
=
mMonitoring
.
begin
();
iter
!=
mMonitoring
.
end
();
iter
++
)
{
...
...
@@ -80,23 +80,22 @@ bool CivOptSchedEngine::optimalScheduling()
vector
<
map
<
string
,
double
>>
monitorCalcMapValues
;
schedulingCompute
.
getMonitorsValue
(
monitorCalcMapValues
);
CivReportReader
reportReader
;
float
cost
=
0
;
string
rptPath
=
CivCommonUtils
::
getExePath
()
+
"//test.rpt"
;
reportReader
.
open
(
rptPath
);
// cost = reportReader.readEnergy();
// 获取消耗的能量值
float
cost
=
schedulingCompute
.
totalEnergy
(
i
);
//
// 计算个体自适度
// genAlg.fitnessfunction(
);
genAlg
.
fitnessfunction
(
cost
,
monitorCalcMapValues
[
i
]
);
}
// 根据个体自适应度进行选择
genAlg
.
chromoRoulette
();
// 自适应交叉变异
genAlg
.
corssver
();
// 产生下一代种群
std
::
vector
<
Genome
>
newGenmeVec
;
genAlg
.
epoch
(
newGenmeVec
);
}
// 获取最好的
...
...
pandaAnalysis/CivSchedulingCompute.cpp
View file @
bde40d2e
...
...
@@ -4,7 +4,8 @@
#include "types.h"
#include "CivSysLog.h"
CivSchedulingCompute
::
CivSchedulingCompute
()
CivSchedulingCompute
::
CivSchedulingCompute
(
SchdulingType
schedulingType
)
:
mChdulingType
(
schedulingType
)
{
mRptFile
=
CivCommonUtils
::
getExePath
()
+
"
\\
test.rpt"
;
mBinFile
=
CivCommonUtils
::
getExePath
()
+
"
\\
test.bin"
;
...
...
@@ -66,18 +67,37 @@ bool CivSchedulingCompute::calculate()
int
linkType
;
ENgetlinktype
(
i
,
&
linkType
);
if
(
linkType
!=
EN_PUMP
)
if
(
linkType
!=
EN_PUMP
||
linkType
!=
EN_PBV
)
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
);
switch
(
mChdulingType
)
{
case
PumpScheduling
&
EN_PUMP
:
{
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
);
}
break
;
case
PBVScheduling
&
EN_PBV
:
{
if
(
linkType
!=
EN_PBV
)
continue
;
}
break
;
default
:
break
;
}
}
if
(
ENrunH
(
&
t
)
>
100
)
// errcode > 100 是错误
...
...
@@ -91,6 +111,9 @@ bool CivSchedulingCompute::calculate()
// 保存
saveResult
(
iTime
);
// 水泵能量
getPumpEnergy
(
iTime
);
iTime
++
;
}
while
(
tstep
>
0
);
...
...
@@ -142,4 +165,48 @@ void CivSchedulingCompute::saveResult(int time)
pressureMap
.
insert
(
pair
<
string
,
double
>
(
szNo
,
pressure
));
}
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
pandaAnalysis/CivSchedulingCompute.h
View file @
bde40d2e
...
...
@@ -10,7 +10,15 @@ using namespace std;
class
CivSchedulingCompute
{
public
:
CivSchedulingCompute
();
// 调度类型
enum
SchdulingType
{
PumpScheduling
,
// 水泵调度
PBVScheduling
// 根据压力制动阀调度
};
explicit
CivSchedulingCompute
(
SchdulingType
schedulingType
);
// 设置监测点
void
setMonitors
(
const
vector
<
string
>&
monitor
);
...
...
@@ -30,10 +38,18 @@ public:
// 获取监测点计算出的值
void
getMonitorsValue
(
vector
<
map
<
string
,
double
>>&
monitorMap
);
// 更改压力制动阀压力设置
void
updatePBVSettings
(
const
string
&
sn
,
double
pressure
);
// 获取每个时刻消耗的总能量
float
totalEnergy
(
int
index
);
private
:
// 保存计算的值
void
saveResult
(
int
time
);
// 获取计算的水泵的能耗
void
getPumpEnergy
(
int
time
);
private
:
std
::
string
mRptFile
;
std
::
string
mBinFile
;
...
...
@@ -47,6 +63,12 @@ private:
// 更新水泵的状态
map
<
string
,
int
>
mPumpStatus
;
// 水泵消耗的能量
vector
<
map
<
string
,
float
>>
mPumpEnergy
;
// 存储测点的计算值
vector
<
map
<
string
,
double
>>
mMonitorsValue
;
SchdulingType
mChdulingType
;
};
pandaDbManager/CivBaseStruct.h
0 → 100644
View file @
bde40d2e
#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
;
// 水泵集合
};
pandaDbManager/CivInpDbHelper.cpp
View file @
bde40d2e
...
...
@@ -162,6 +162,7 @@ bool CivInpDbHelper::getPumps(CivPumps& pumps)
fields
.
push_back
(
pmTable
.
startPoint
);
fields
.
push_back
(
pmTable
.
endPoint
);
fields
.
push_back
(
pmTable
.
headCurve
);
fields
.
push_back
(
pmTable
.
ratio
);
fields
.
push_back
(
pmTable
.
power
);
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>
resultVector
;
...
...
@@ -186,6 +187,10 @@ bool CivInpDbHelper::getPumps(CivPumps& pumps)
if
(
power
!=
""
)
param
.
append
(
" power "
+
power
);
std
::
string
speedRatio
=
map
.
find
(
pmTable
.
ratio
)
->
second
;
if
(
speedRatio
!=
""
)
param
.
append
(
" SPEED "
+
speedRatio
);
pump
.
Parameters
=
param
;
pumps
.
addItem
(
pump
);
}
...
...
pandaDbManager/CivInpHelperAbs.cpp
View file @
bde40d2e
...
...
@@ -45,10 +45,16 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
std
::
map
<
std
::
string
,
std
::
vector
<
CivParameter
::
ParamTable
>>
tempMap
;
for
(
int
i
=
0
;
i
<
resultVector
.
size
();
i
++
)
{
CivParameter
::
ParamTable
pTable
;
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
.
val
=
map
.
find
(
fields
[
1
])
->
second
;
pTable
.
val
=
pVal
;
std
::
string
type
=
map
.
find
(
fields
[
2
])
->
second
;
tempMap
[
type
].
push_back
(
pTable
);
...
...
@@ -60,7 +66,6 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
CivParameter
param
;
std
::
string
type
=
iter
->
first
;
std
::
vector
<
CivParameter
::
ParamTable
>
paramTables
=
iter
->
second
;
param
.
setType
(
type
);
size_t
total
=
paramTables
.
size
();
...
...
@@ -70,6 +75,55 @@ bool CivInpHelperAbs::getParameter(std::vector<CivParameter>& params)
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
;
}
...
...
pandaDbManager/CivPumpHelper.cpp
View file @
bde40d2e
#include "CivPumpHelper.h"
#include "CivPgDbConnection.h"
#include <set>
CivPumpHelper
::
CivPumpHelper
(
const
string
&
uri
)
{
...
...
@@ -75,3 +76,42 @@ void CivPumpHelper::getPumpSn(vector<string>& pumpNames)
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
pandaDbManager/CivPumpHelper.h
View file @
bde40d2e
...
...
@@ -3,10 +3,10 @@
#include<map>
#include<vector>
#include "CivBaseStruct.h"
#include "pandaDbManager.h"
using
namespace
std
;
class
CivConnection
;
/**
...
...
@@ -26,6 +26,10 @@ public:
// 获取水泵的编号
void
getPumpSn
(
vector
<
string
>&
pumpNames
);
// 获取泵站
void
getPumpStations
(
vector
<
PumpStation
>&
stations
);
private
:
CivConnection
*
mConn
=
nullptr
;
...
...
pandaDbManager/pandaDbManager.vcxproj
View file @
bde40d2e
...
...
@@ -153,6 +153,7 @@
<PostBuildEvent>
<Command>
copy CivTypes.h $(OutDir)..\include /y
copy CivAssembly.h $(OutDir)..\include /y
copy CivBaseStruct.h $(OutDir)..\include /y
copy CivInpHelperAbs.h $(OutDir)..\include /y
copy CivInpDbHelper.h $(OutDir)..\include /y
copy CivProjInpDbHelper.h $(OutDir)..\include /y
...
...
@@ -180,6 +181,7 @@ copy CivPumpHelper.h $(OutDir)..\include /y
<ClInclude
Include=
"CivSimuResStruct.h"
/>
<ClInclude
Include=
"CivTableFields.h"
/>
<ClInclude
Include=
"CivTypes.h"
/>
<ClInclude
Include=
"CivBaseStruct.h"
/>
<ClInclude
Include=
"pandaDbManager.h"
/>
</ItemGroup>
<ItemGroup>
...
...
pandaDbManager/pandaDbManager.vcxproj.filters
View file @
bde40d2e
...
...
@@ -60,6 +60,9 @@
<ClInclude
Include=
"CivPumpHelper.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
<ClInclude
Include=
"CivBaseStruct.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"CivAssembly.cpp"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment