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
6cb113e7
Commit
6cb113e7
authored
Oct 28, 2020
by
刘乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1, 代码优化
parent
4828200d
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
165 additions
and
60 deletions
+165
-60
GenAlg.cpp
pandaAlgorithm/GenAlg.cpp
+6
-5
GenAlg.h
pandaAlgorithm/GenAlg.h
+3
-4
Genome.h
pandaAlgorithm/Genome.h
+0
-1
pandaAlgorithm.vcxproj
pandaAlgorithm/pandaAlgorithm.vcxproj
+5
-1
CivOptSchedEngine.cpp
pandaAnalysis/CivOptSchedEngine.cpp
+9
-0
CivOptSchedEngine.h
pandaAnalysis/CivOptSchedEngine.h
+16
-0
CivOptSchedPumpEngine.cpp
pandaAnalysis/CivOptSchedPumpEngine.cpp
+0
-8
CivOptSchedPumpEngine.h
pandaAnalysis/CivOptSchedPumpEngine.h
+0
-27
CivSchedulingCompute.cpp
pandaAnalysis/CivSchedulingCompute.cpp
+34
-2
CivSchedulingCompute.h
pandaAnalysis/CivSchedulingCompute.h
+18
-3
pandaAnalysis.vcxproj
pandaAnalysis/pandaAnalysis.vcxproj
+0
-2
pandaAnalysis.vcxproj.filters
pandaAnalysis/pandaAnalysis.vcxproj.filters
+0
-6
CivPumpHelper.cpp
pandaDbManager/CivPumpHelper.cpp
+36
-0
CivPumpHelper.h
pandaDbManager/CivPumpHelper.h
+27
-0
CivSimulResHelperAbs.h
pandaDbManager/CivSimulResHelperAbs.h
+1
-1
pandaDbManager.vcxproj
pandaDbManager/pandaDbManager.vcxproj
+3
-0
pandaDbManager.vcxproj.filters
pandaDbManager/pandaDbManager.vcxproj.filters
+7
-0
No files found.
pandaAlgorithm/GenAlg.cpp
View file @
6cb113e7
...
...
@@ -4,11 +4,11 @@
#include <stdio.h>
#include <random>
#include "OptScheduling.h"
#include "FirstOptScheduling.h"
GenAlg
::
GenAlg
(
OptScheduling
*
optScheduling
,
GenType
genType
)
:
mOptScheduling
(
std
::
unique_ptr
<
OptScheduling
>
(
optScheduling
)),
mGenType
(
genType
)
GenAlg
::
GenAlg
(
GenType
genType
)
:
mGenType
(
genType
)
{
mOptScheduling
=
std
::
make_unique
<
FirstOptScheduling
>
();
}
double
GenAlg
::
random
(
int
min
,
int
max
)
...
...
@@ -253,9 +253,10 @@ double GenAlg::averageFitness()
return
mAverageFitness
;
}
void
GenAlg
::
fitnessfunction
()
void
GenAlg
::
fitnessfunction
(
map
<
string
,
double
>&
monitorValues
)
{
// 计算适应
double
objVal
=
mOptScheduling
->
objectiveFunction
();
}
void
GenAlg
::
encoding
(
map
<
string
,
int
>&
phenotype
,
vector
<
char
>&
chromo
)
...
...
pandaAlgorithm/GenAlg.h
View file @
6cb113e7
...
...
@@ -28,7 +28,7 @@ public:
};
//构造函数
GenAlg
(
OptScheduling
*
optScheduling
,
GenType
genType
);
explicit
GenAlg
(
GenType
genType
);
//初始化变量
void
reset
();
...
...
@@ -42,7 +42,6 @@ public:
// 轮盘赌选择函数
Genome
chromoRoulette
();
// 基因变异函数(实值编码)
void
mutate
(
vector
<
double
>&
chromo
);
...
...
@@ -64,8 +63,8 @@ public:
// 选择运算,前群体中适应度较高的个体按某种规则或模型遗传到下一代群体中
void
select
();
// 计算个体自适应度
void
fitnessfunction
();
//
根据监测点计算值,
计算个体自适应度
void
fitnessfunction
(
map
<
string
,
double
>&
monitorValues
);
/**
* @brief 编码, 将水泵开关状态编码成二进制状态:0表示管,1表示开
...
...
pandaAlgorithm/Genome.h
View file @
6cb113e7
...
...
@@ -10,7 +10,6 @@ public:
friend
class
GenAlg
;
friend
class
GenEngine
;
Genome
()
:
fitness
(
0
)
{}
Genome
(
std
::
vector
<
double
>
vec
,
double
f
)
:
vecGenome
(
vec
),
fitness
(
f
)
{}
//类的带参数初始化参数。
Genome
(
std
::
vector
<
char
>
vec
,
double
f
)
:
mBinaryGenVec
(
vec
),
fitness
(
f
)
{}
...
...
pandaAlgorithm/pandaAlgorithm.vcxproj
View file @
6cb113e7
...
...
@@ -143,7 +143,11 @@
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>
copy pandaAlgorithm.h $(OutDir)..\include /y
</Command>
<Command>
copy pandaAlgorithm.h $(OutDir)..\include /y
copy GenAlg.h $(OutDir)..\include /y
copy Genome.h $(OutDir)..\include /y
copy FirstOptScheduling.h $(OutDir)..\include /y
copy OptScheduling.h $(OutDir)..\include /y
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
...
...
pandaAnalysis/CivOptSchedEngine.cpp
View file @
6cb113e7
#include "CivOptSchedEngine.h"
#include "CivInpConvertor.h"
#include "GenAlg.h"
#include "FirstOptScheduling.h"
CivOptSchedEngine
::
CivOptSchedEngine
(
const
string
&
uri
)
:
mUri
(
uri
)
{
...
...
@@ -13,7 +17,12 @@ bool CivOptSchedEngine::optimalScheduling()
string
inpFile
=
convertor
.
convertBaseInp
();
//
GenAlg
genAlg
(
GenAlg
::
BinaryCoding
);
// Ⱥʼ
popsize
=
100
;
genAlg
.
init
(
popsize
,
mMutRate
,
mCrossRate
,
mGenLength
,
0
,
0
);
// genAlg.epoch();
}
...
...
pandaAnalysis/CivOptSchedEngine.h
View file @
6cb113e7
...
...
@@ -52,4 +52,20 @@ private:
// 调度结束时段
string
mEndTime
;
// 初始中群大小
int
popsize
;
// 变异率
double
mMutRate
;
// 交叉率
double
mCrossRate
;
//基因编码长度
int
mGenLength
;
// 针对浮点数编码
double
mLeftPoint
;
double
mRightPoint
;
};
pandaAnalysis/CivOptSchedPumpEngine.cpp
deleted
100644 → 0
View file @
4828200d
#include "CivOptSchedPumpEngine.h"
CivOptSchedPumpEngine
::
CivOptSchedPumpEngine
(
const
std
::
string
&
uri
)
:
CivOptSchedEngine
(
uri
)
{
}
\ No newline at end of file
pandaAnalysis/CivOptSchedPumpEngine.h
deleted
100644 → 0
View file @
4828200d
#pragma once
#include "CivOptSchedEngine.h"
#include <string>
#include <map>
#include <vector>
using
namespace
std
;
/**
վŻ
*/
class
CivOptSchedPumpEngine
:
public
CivOptSchedEngine
{
public
:
explicit
CivOptSchedPumpEngine
(
const
std
::
string
&
uri
);
private
:
// ֮ǰ
vector
<
map
<
string
,
double
>>
mBeforeScheduling
;
// ֮
vector
<
map
<
string
,
double
>>
mSchduling
;
// ˮӳ
map
<
string
,
string
>
mPumpMap
;
};
pandaAnalysis/CivSchedulingCompute.cpp
View file @
6cb113e7
...
...
@@ -66,7 +66,6 @@ bool CivSchedulingCompute::calculate()
int
linkType
;
ENgetlinktype
(
i
,
&
linkType
);
if
(
linkType
!=
EN_PUMP
)
continue
;
...
...
@@ -89,6 +88,8 @@ bool CivSchedulingCompute::calculate()
ENnextH
(
&
tstep
);
// 保存
saveResult
(
iTime
);
iTime
++
;
}
while
(
tstep
>
0
);
...
...
@@ -110,5 +111,35 @@ void CivSchedulingCompute::updatePumpStatus(const map<string, char>& pumpStatus)
void
CivSchedulingCompute
::
getMonitorsValue
(
vector
<
map
<
string
,
double
>>&
monitorMap
)
{
monitorMap
=
mMonitors
;
monitorMap
=
mMonitorsValue
;
}
void
CivSchedulingCompute
::
setMonitors
(
const
vector
<
string
>&
monitor
)
{
mMonitors
=
monitor
;
}
void
CivSchedulingCompute
::
saveResult
(
int
time
)
{
// 计算节点
int
nNodeCount
;
ENgetcount
(
EN_NODECOUNT
,
&
nNodeCount
);
map
<
string
,
double
>
pressureMap
;
for
(
int
i
=
1
;
i
<=
nNodeCount
;
i
++
)
{
char
szNo
[
256
];
ENgetnodeid
(
i
,
szNo
);
// 编号
// 判断是不是监测点
auto
iter
=
std
::
find
(
mMonitors
.
begin
(),
mMonitors
.
end
(),
szNo
);
if
(
iter
==
mMonitors
.
end
())
continue
;
float
pressure
;
ENgetnodevalue
(
i
,
EN_PRESSURE
,
&
pressure
);
// 压力
pressureMap
.
insert
(
pair
<
string
,
double
>
(
szNo
,
pressure
));
}
mMonitorsValue
[
time
]
=
pressureMap
;
}
\ No newline at end of file
pandaAnalysis/CivSchedulingCompute.h
View file @
6cb113e7
...
...
@@ -3,29 +3,44 @@
#include <string>
using
namespace
std
;
/**
优化调度计算类
优化调度计算类
*/
class
CivSchedulingCompute
{
public
:
CivSchedulingCompute
();
// 设置监测点
void
setMonitors
(
const
vector
<
string
>&
monitor
);
// 读入inp文件
bool
openFile
(
string
&
inpFILE
);
// 水力计算
bool
calculate
();
// 结束计算,关闭文件句柄
void
close
();
// 更新水泵开关状态
void
updatePumpStatus
(
const
map
<
string
,
char
>&
pumpStatus
);
// 获取监测点计算出的值
void
getMonitorsValue
(
vector
<
map
<
string
,
double
>>&
monitorMap
);
private
:
// 保存计算的值
void
saveResult
(
int
time
);
private
:
std
::
string
mRptFile
;
std
::
string
mBinFile
;
// 水泵编号和code的映射
vector
<
string
>
mMonitors
;
// 错误吗
int
mErrcode
=
0
;
...
...
@@ -33,5 +48,5 @@ private:
map
<
string
,
char
>
mPumpStatus
;
// 存储测点的计算值
vector
<
map
<
string
,
double
>>
mMonitors
;
vector
<
map
<
string
,
double
>>
mMonitors
Value
;
};
pandaAnalysis/pandaAnalysis.vcxproj
View file @
6cb113e7
...
...
@@ -168,7 +168,6 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command>
<ClCompile
Include=
"CivInpProject.cpp"
/>
<ClCompile
Include=
"CivNewInp.cpp"
/>
<ClCompile
Include=
"CivOptSchedEngine.cpp"
/>
<ClCompile
Include=
"CivOptSchedPumpEngine.cpp"
/>
<ClCompile
Include=
"CivProjInpBuilder.cpp"
/>
<ClCompile
Include=
"CivProjManager.cpp"
/>
<ClCompile
Include=
"CivProjSimulation.cpp"
/>
...
...
@@ -193,7 +192,6 @@ copy pandaAnalysis.h $(OutDir)..\include /y</Command>
<ClInclude
Include=
"CivInpProject.h"
/>
<ClInclude
Include=
"CivNewInp.h"
/>
<ClInclude
Include=
"CivOptSchedEngine.h"
/>
<ClInclude
Include=
"CivOptSchedPumpEngine.h"
/>
<ClInclude
Include=
"CivProjInpBuilder.h"
/>
<ClInclude
Include=
"CivProjManager.h"
/>
<ClInclude
Include=
"CivProjSimulation.h"
/>
...
...
pandaAnalysis/pandaAnalysis.vcxproj.filters
View file @
6cb113e7
...
...
@@ -75,9 +75,6 @@
<ClCompile
Include=
"CivOptSchedEngine.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
<ClCompile
Include=
"CivOptSchedPumpEngine.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
<ClCompile
Include=
"CivSchedulingCompute.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
...
...
@@ -149,9 +146,6 @@
<ClInclude
Include=
"CivOptSchedEngine.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
<ClInclude
Include=
"CivOptSchedPumpEngine.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
<ClInclude
Include=
"CivSchedulingCompute.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
...
...
pandaDbManager/CivPumpHelper.cpp
0 → 100644
View file @
6cb113e7
#include "CivPumpHelper.h"
#include "CivPgDbConnection.h"
CivPumpHelper
::
CivPumpHelper
(
const
string
&
uri
)
{
mConn
=
new
CivPgDbConnection
();
mConn
->
connect
(
uri
);
}
CivPumpHelper
::~
CivPumpHelper
()
{
mConn
->
disconnect
();
delete
mConn
;
}
void
CivPumpHelper
::
getMap
(
const
string
&
key
,
const
string
&
val
,
map
<
string
,
string
>&
res
)
{
vector
<
map
<
string
,
string
>>
vecMap
;
if
(
!
mConn
->
query
(
mTable
,
{
key
,
val
},
vecMap
))
return
;
if
(
vecMap
.
size
()
<=
0
)
return
;
size_t
total
=
vecMap
.
size
();
for
(
int
i
=
0
;
i
<
total
;
i
++
)
{
map
<
string
,
string
>
tempMap
=
vecMap
[
i
];
string
keyVal
=
tempMap
.
find
(
key
)
->
second
;
string
valVal
=
tempMap
.
find
(
val
)
->
second
;
res
.
insert
(
pair
<
string
,
string
>
(
keyVal
,
valVal
));
}
}
\ No newline at end of file
pandaDbManager/CivPumpHelper.h
0 → 100644
View file @
6cb113e7
#pragma once
#include<string>
#include<map>
#include "pandaDbManager.h"
using
namespace
std
;
class
CivConnection
;
/**
水泵查询接口
*/
class
PANDADBMANAGER_API
CivPumpHelper
{
public
:
explicit
CivPumpHelper
(
const
string
&
uri
);
~
CivPumpHelper
();
// 获取指定属性字段键值对映射
void
getMap
(
const
string
&
key
,
const
string
&
val
,
map
<
string
,
string
>&
res
);
private
:
CivConnection
*
mConn
=
nullptr
;
const
string
mTable
=
"水泵"
;
};
pandaDbManager/CivSimulResHelperAbs.h
View file @
6cb113e7
...
...
@@ -13,7 +13,7 @@ class CivConnection;
class
PANDADBMANAGER_API
CivSimulResHelperAbs
{
public
:
explicit
CivSimulResHelperAbs
();
CivSimulResHelperAbs
();
virtual
~
CivSimulResHelperAbs
();
virtual
bool
insertNodes
(
const
NodeResultItems
&
nodeitems
);
...
...
pandaDbManager/pandaDbManager.vcxproj
View file @
6cb113e7
...
...
@@ -161,6 +161,7 @@ copy CivSimulResHelperAbs.h $(OutDir)..\include /y
copy CivSimulResDbHelper.h $(OutDir)..\include /y
copy CivHydrTableHelper.h $(OutDir)..\include /y
copy CIvProjSimulResHelper.h $(OutDir)..\include /y
copy CivPumpHelper.h $(OutDir)..\include /y
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
...
...
@@ -173,6 +174,7 @@ copy CIvProjSimulResHelper.h $(OutDir)..\include /y
<ClInclude
Include=
"CivPgDbConnection.h"
/>
<ClInclude
Include=
"CivProjInpDbHelper.h"
/>
<ClInclude
Include=
"CIvProjSimulResHelper.h"
/>
<ClInclude
Include=
"CivPumpHelper.h"
/>
<ClInclude
Include=
"CivSimulResDbHelper.h"
/>
<ClInclude
Include=
"CivSimulResHelperAbs.h"
/>
<ClInclude
Include=
"CivSimuResStruct.h"
/>
...
...
@@ -189,6 +191,7 @@ copy CIvProjSimulResHelper.h $(OutDir)..\include /y
<ClCompile
Include=
"CivPgDbConnection.cpp"
/>
<ClCompile
Include=
"CivProjInpDbHelper.cpp"
/>
<ClCompile
Include=
"CIvProjSimulResHelper.cpp"
/>
<ClCompile
Include=
"CivPumpHelper.cpp"
/>
<ClCompile
Include=
"CivSimulResDbHelper.cpp"
/>
<ClCompile
Include=
"CivSimulResHelperAbs.cpp"
/>
</ItemGroup>
...
...
pandaDbManager/pandaDbManager.vcxproj.filters
View file @
6cb113e7
...
...
@@ -57,6 +57,9 @@
<ClInclude
Include=
"pandaDbManager.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
<ClInclude
Include=
"CivPumpHelper.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"CivAssembly.cpp"
>
...
...
@@ -89,5 +92,8 @@
<ClCompile
Include=
"CIvProjSimulResHelper.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
<ClCompile
Include=
"CivPumpHelper.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
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