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
81b040f6
Commit
81b040f6
authored
Jul 22, 2020
by
刘乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,追踪分析接口
parent
29f1f6e6
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
237 additions
and
134 deletions
+237
-134
CivGraphFactory.cpp
pandaAlgorithm/CivGraphFactory.cpp
+4
-4
CivGraphFactory.h
pandaAlgorithm/CivGraphFactory.h
+1
-1
CivGraphList.cpp
pandaAlgorithm/CivGraphList.cpp
+57
-120
CivGraphList.h
pandaAlgorithm/CivGraphList.h
+9
-9
CivHydDataType.cpp
pandaAlgorithm/CivHydDataType.cpp
+4
-0
CivHydDataType.h
pandaAlgorithm/CivHydDataType.h
+1
-0
CivTrackingAnalysis.cpp
pandaAlgorithm/CivTrackingAnalysis.cpp
+75
-0
CivTrackingAnalysis.h
pandaAlgorithm/CivTrackingAnalysis.h
+77
-0
pandaAlgorithm.vcxproj
pandaAlgorithm/pandaAlgorithm.vcxproj
+2
-0
pandaAlgorithm.vcxproj.filters
pandaAlgorithm/pandaAlgorithm.vcxproj.filters
+7
-0
No files found.
pandaAlgorithm/CivGraphFactory.cpp
View file @
81b040f6
...
...
@@ -8,13 +8,12 @@ CivGraphFactory::CivGraphFactory()
}
bool
CivGraphFactory
::
createGraph
(
CivDbConn
*
dbConn
,
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>*
graph
)
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>*
CivGraphFactory
::
createGraph
(
CivDbConn
*
dbConn
)
{
if
(
dbConn
==
nullptr
)
return
false
;
if
(
graph
==
nullptr
)
return
false
;
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>*
graph
=
new
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>
();
// 顶点坐标
CivCoordinates
coords
;
...
...
@@ -56,5 +55,5 @@ bool CivGraphFactory::createGraph(CivDbConn* dbConn, ALGraph<CivGraphJunction,
graph
->
insertAEdge
(
sStartjuction
,
endJunction
,
edAge
);
}
return
true
;
return
graph
;
}
\ No newline at end of file
pandaAlgorithm/CivGraphFactory.h
View file @
81b040f6
...
...
@@ -16,5 +16,5 @@ public:
*@param dbConn 数据库连接
*@param graph 有向图
*/
bool
createGraph
(
CivDbConn
*
dbConn
,
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>*
graph
);
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>*
createGraph
(
CivDbConn
*
dbConn
);
};
pandaAlgorithm/CivGraphList.cpp
View file @
81b040f6
...
...
@@ -10,7 +10,7 @@ ALGraph<VertexType, EdgeType>::ALGraph()
}
template
<
class
VertexType
,
class
EdgeType
>
void
ALGraph
<
VertexType
,
EdgeType
>::
BFS
(
VertexType
vertexName
,
int
visit
[]
)
void
ALGraph
<
VertexType
,
EdgeType
>::
BFS
(
VertexType
vertexName
,
std
::
vector
<
int
>&
visited
)
{
// 获取输入顶点索引
int
vi
=
getVertexIndex
(
vertexName
);
...
...
@@ -20,27 +20,29 @@ void ALGraph<VertexType, EdgeType>::BFS(VertexType vertexName, int visit[])
return
false
;
}
int
vi
=
0
;
Edge
<
EdgeType
>*
edageNext
;
// 初始化队列
std
::
queue
<
int
>
Q
;
Q
.
push
(
node
);
visit
[
vi
]
=
1
;
visit
ed
.
push_back
(
vi
)
;
while
(
!
Q
.
empty
())
{
int
node
=
Q
.
front
();
Q
.
pop
();
edageNext
=
mVertexArray
.
at
(
node
).
.
pAdjEdges
;
edageNext
=
mVertexArray
.
at
(
node
).
pAdjEdges
;
while
(
edageNext
)
{
// 未访问过的放入队列
if
(
!
visit
[
edageNext
->
nDestVertex
])
int
pVal
=
edageNext
->
nDestVertex
;
auto
iter
=
std
::
find
(
visited
.
begin
(),
visited
.
end
(),
pVal
);
if
(
iter
==
visited
.
end
())
{
visit
[
edageNext
->
nDestVertex
]
=
1
;
Q
.
push
(
edageNext
->
nDestVertex
);
visit
ed
.
push_back
(
pVal
)
;
Q
.
push
(
pVal
);
}
// 后移
...
...
@@ -49,6 +51,53 @@ void ALGraph<VertexType, EdgeType>::BFS(VertexType vertexName, int visit[])
}
}
template
<
class
VertexType
,
class
EdgeType
>
Edge
<
EdgeType
>*
ALGraph
<
VertexType
,
EdgeType
>::
reverseList
(
Edge
<
EdgeType
>*
edge
)
{
Edge
<
EdgeType
>*
resultList
=
new
Edge
<
EdgeType
>
(
0
,
EdgeType
());
result
->
pNextEdge
=
edge
;
Edge
<
EdgeType
>*
p
=
edge
;
Edge
<
EdgeType
>*
pNext
=
p
->
pNextEdge
;
while
(
pNext
!=
nullptr
)
{
p
->
pNextEdge
=
pNext
->
pNextEdge
;
pNext
->
pNextEdge
=
resultList
->
pNextEdge
;
resultList
->
pNextEdge
=
pNext
;
pNext
=
p
->
pNextEdge
;
}
Edge
<
EdgeType
>*
node
=
resultList
->
pNextEdge
;
delete
resultList
;
return
node
;
}
template
<
class
VertexType
,
class
EdgeType
>
void
ALGraph
<
VertexType
,
EdgeType
>::
graphReverse
()
{
for
(
int
i
=
0
;
i
<
mVertexArray
.
size
();
i
++
)
{
Vertex
<
VertexType
,
EdgeType
>
vetex
=
mVertexArray
.
at
(
i
);
Edge
<
EdgeType
>*
p
=
vetex
.
pAdjEdges
;
Edge
<
EdgeType
>*
pNext
=
p
->
pNextEdge
;
while
(
pNext
!=
nullptr
)
{
p
->
pNextEdge
=
pNext
->
pNextEdge
;
pNext
->
pNextEdge
=
vetex
.
pAdjEdges
;
vetex
.
pAdjEdges
=
pNext
;
pNext
=
p
->
pNextEdge
;
}
}
return
;
}
template
<
class
VertexType
,
class
EdgeType
>
ALGraph
<
VertexType
,
EdgeType
>::~
ALGraph
()
...
...
@@ -185,7 +234,7 @@ void ALGraph<VertexType, EdgeType>::getVertexEdgeWeight(IN const int v1, OUT vec
while
(
NULL
!=
p
)
{
//
consider the same edges exist
//
存在相同的边
if
(
prevIndex
==
p
->
nDestVertex
)
{
if
(
tmp
>
p
->
edgeWeight
)
...
...
@@ -270,115 +319,4 @@ template <class VertexType, class EdgeType>
VertexType
ALGraph
<
VertexType
,
EdgeType
>::
getData
(
IN
int
index
)
{
return
mVertexArray
.
at
(
index
).
mVertex
;
}
template
<
class
VertexType
,
class
EdgeType
>
int
ALGraph
<
VertexType
,
EdgeType
>::
Dijkstra
(
IN
const
VertexType
&
vertexName1
)
{
int
sourceIndex
=
getVertexIndex
(
vertexName1
);
if
(
-
1
==
sourceIndex
)
{
cerr
<<
"There is no vertex "
<<
endl
;
return
false
;
}
int
nVertexNo
=
getVertexNumber
();
//the array to record the points have been included, if included the value is true
//else is false
vector
<
bool
>
vecIncludeArray
;
vecIncludeArray
.
assign
(
nVertexNo
,
false
);
vecIncludeArray
[
sourceIndex
]
=
true
;
//the array to record the distance from vertex1
vector
<
EdgeType
>
vecDistanceArray
;
vecDistanceArray
.
assign
(
nVertexNo
,
EdgeType
(
INT_MAX
));
vecDistanceArray
[
sourceIndex
]
=
EdgeType
(
0
);
//prev array to record the previous vertex
vector
<
int
>
vecPrevVertex
;
vecPrevVertex
.
assign
(
nVertexNo
,
sourceIndex
);
getVertexEdgeWeight
(
sourceIndex
,
vecDistanceArray
);
int
vFrom
,
vTo
;
while
(
1
)
{
EdgeType
minWeight
=
EdgeType
(
INT_MAX
);
vFrom
=
sourceIndex
;
vTo
=
-
1
;
for
(
int
i
=
0
;
i
<
nVertexNo
;
i
++
)
{
if
(
!
vecIncludeArray
[
i
]
&&
minWeight
>
vecDistanceArray
[
i
])
{
minWeight
=
vecDistanceArray
[
i
];
vFrom
=
i
;
}
}
if
(
EdgeType
(
INT_MAX
)
==
minWeight
)
{
break
;
}
vecIncludeArray
[
vFrom
]
=
true
;
Edge
<
EdgeType
>*
p
=
mVertexArray
[
vFrom
].
pAdjEdges
;
while
(
NULL
!=
p
)
{
EdgeType
wFT
=
p
->
edgeWeight
;
vTo
=
p
->
nDestVertex
;
if
(
!
vecIncludeArray
[
vTo
]
&&
vecDistanceArray
[
vTo
]
>
wFT
+
vecDistanceArray
[
vFrom
])
{
vecDistanceArray
[
vTo
]
=
wFT
+
vecDistanceArray
[
vFrom
];
vecPrevVertex
[
vTo
]
=
vFrom
;
}
p
=
p
->
pNextEdge
;
}
}
//print the shortest route of all vertexes
for
(
int
i
=
0
;
i
<
nVertexNo
;
i
++
)
{
if
(
EdgeType
(
INT_MAX
)
!=
vecDistanceArray
[
i
])
{
cout
<<
getData
(
sourceIndex
)
<<
"->"
<<
getData
(
i
)
<<
": "
;
DijkstraPrint
(
i
,
sourceIndex
,
vecPrevVertex
);
cout
<<
" "
<<
vecDistanceArray
[
i
];
cout
<<
endl
;
}
}
return
0
;
}
template
<
class
VertexType
,
class
EdgeType
>
void
ALGraph
<
VertexType
,
EdgeType
>::
DijkstraPrint
(
IN
int
index
,
IN
int
sourceIndex
,
IN
vector
<
int
>
vecPreVertex
)
{
if
(
sourceIndex
!=
index
)
{
DijkstraPrint
(
vecPreVertex
[
index
],
sourceIndex
,
vecPreVertex
);
}
cout
<<
getData
(
index
)
<<
" "
;
}
template
<
class
VertexType
,
class
EdgeType
>
ostream
&
operator
<<
(
OUT
ostream
&
out
,
IN
ALGraph
<
VertexType
,
EdgeType
>&
graphInstance
)
{
int
vertexNo
=
graphInstance
.
getVertexNumber
();
out
<<
"This graph has "
<<
vertexNo
<<
"vertexes"
<<
endl
;
for
(
int
i
=
0
;
i
<
vertexNo
;
i
++
)
{
VertexType
x1
=
graphInstance
.
getData
(
i
);
out
<<
x1
<<
": "
;
Edge
<
EdgeType
>*
p
=
graphInstance
.
mVertexArray
.
at
(
i
).
pAdjEdges
;
while
(
NULL
!=
p
)
{
out
<<
"("
<<
x1
<<
","
<<
graphInstance
.
getData
(
p
->
nDestVertex
)
<<
","
<<
p
->
edgeWeight
<<
") "
;
p
=
p
->
pNextEdge
;
}
out
<<
endl
;
}
return
out
;
}
\ No newline at end of file
pandaAlgorithm/CivGraphList.h
View file @
81b040f6
...
...
@@ -34,7 +34,7 @@ struct Edge
*@param VertexType 节点信息
*@param EdgeType 弧信息
*/
template
<
class
VertexType
,
class
EdgeType
>
template
<
class
VertexType
,
class
EdgeType
>
struct
Vertex
{
VertexType
mVertex
;
// 顶点信息
...
...
@@ -56,9 +56,14 @@ public:
explicit
ALGraph
();
~
ALGraph
();
void
BFS
(
VertexType
vetexType
,
std
::
vector
<
int
>&
visited
);
/**
*@brief 图反向
*/
void
graphReverse
();
void
BFS
(
VertexType
vetexType
,
int
visit
[]
);
Edge
<
EdgeType
>*
reverseList
(
Edge
<
EdgeType
>*
edge
);
/**
*@brief 往图中插入一个节点
...
...
@@ -107,18 +112,13 @@ public:
*/
VertexType
getData
(
IN
int
index
);
int
Dijkstra
(
IN
const
VertexType
&
vertexName1
);
void
DijkstraPrint
(
IN
int
index
,
IN
int
sourceIndex
,
IN
vector
<
int
>
vecPreVertex
);
friend
ostream
&
operator
<<
(
OUT
ostream
&
out
,
IN
const
ALGraph
<
VertexType
,
EdgeType
>&
graphInstance
);
private
:
bool
isReverse
=
false
;
EdgeType
getEdgeWeight
(
IN
const
Edge
<
EdgeType
>*
pEdge
);
void
getVertexEdgeWeight
(
IN
const
int
v1
,
OUT
vector
<
EdgeType
>&
DistanceArray
);
vector
<
Vertex
<
VertexType
,
EdgeType
>
>
mVertexArray
;
// 节点数组
vector
<
Vertex
<
VertexType
,
EdgeType
>>
mVertexArray
;
// 节点数组
};
...
...
pandaAlgorithm/CivHydDataType.cpp
View file @
81b040f6
...
...
@@ -17,6 +17,10 @@ bool CivGraphJunction::operator== (const CivGraphJunction& edage)
return
mSN
==
edage
.
mSN
;
}
CivGraphEdage
::
CivGraphEdage
()
{
}
CivGraphEdage
::
CivGraphEdage
(
std
::
string
sn
,
std
::
string
length
,
std
::
vector
<
std
::
string
>
position
)
{
mSN
=
sn
;
...
...
pandaAlgorithm/CivHydDataType.h
View file @
81b040f6
...
...
@@ -41,6 +41,7 @@ public:
*@param length 管长
*@param position 注意顺序,[length, startx, starty, endx, endy]
*/
explicit
CivGraphEdage
();
explicit
CivGraphEdage
(
std
::
string
sn
,
std
::
string
length
,
std
::
vector
<
std
::
string
>
position
);
bool
operator
==
(
const
CivGraphEdage
&
edage
);
...
...
pandaAlgorithm/CivTrackingAnalysis.cpp
0 → 100644
View file @
81b040f6
#include "CivTrackingAnalysis.h"
#include "CivGraphFactory.h"
CivTrackingAnalysis
::
CivTrackingAnalysis
()
:
mGraph
(
nullptr
)
{
}
CivTrackingAnalysis
::~
CivTrackingAnalysis
()
{
delete
mGraph
;
}
bool
CivTrackingAnalysis
::
createGraphFrom
(
CivDbConn
*
dbConn
)
{
if
(
dbConn
==
nullptr
)
return
false
;
CivGraphFactory
factory
;
mGraph
=
factory
.
createGraph
(
dbConn
);
if
(
mGraph
==
nullptr
)
return
false
;
return
true
;
}
bool
CivTrackingAnalysis
::
upstreamTracking
(
const
std
::
string
&
sN
,
std
::
string
&
jsonResult
)
{
return
true
;
}
bool
CivTrackingAnalysis
::
downstreamTracking
(
const
std
::
string
&
sN
,
std
::
string
&
jsonResult
)
{
return
true
;
}
bool
CivTrackingAnalysis
::
waterSupplyScopeAnalysis
(
const
std
::
string
&
sN
,
std
::
string
&
jsonResult
)
{
return
true
;
}
bool
CivTrackingAnalysis
::
upstreamTracking
(
const
std
::
string
&
sN
,
std
::
vector
<
CivGraphJunction
>&
junctions
,
std
::
vector
<
CivGraphEdage
>&
pipes
)
{
return
true
;
}
bool
CivTrackingAnalysis
::
downstreamTracking
(
const
std
::
string
&
sN
,
std
::
vector
<
CivGraphJunction
>&
junctions
,
std
::
vector
<
CivGraphEdage
>&
pipes
)
{
if
(
mGraph
==
nullptr
)
return
false
;
CivGraphJunction
junction
(
sN
);
std
::
vector
<
int
>
visited
;
mGraph
->
BFS
(
junction
,
visited
);
return
true
;
}
bool
CivTrackingAnalysis
::
waterSupplyScopeAnalysis
(
const
std
::
string
&
sN
,
std
::
vector
<
CivGraphJunction
>&
junctions
,
std
::
vector
<
CivGraphEdage
>&
pipes
)
{
return
true
;
}
\ No newline at end of file
pandaAlgorithm/CivTrackingAnalysis.h
0 → 100644
View file @
81b040f6
#pragma once
#include "CivHydDataType.h"
#include "CivGraphList.h"
#include <vector>
#define ALGORITHMEXPORT __declspec(dllexport)
class
CivDbConn
;
class
ALGORITHMEXPORT
CivTrackingAnalysis
{
public
:
explicit
CivTrackingAnalysis
();
~
CivTrackingAnalysis
();
/**
*@brief 根据数据库管网构建管网有向图
*@param dbConn 数据库连接
*/
bool
createGraphFrom
(
CivDbConn
*
dbConn
);
/**
*@brief 追踪节点上游路径
*@param sN 节点本点号
*@param jsonResult 追踪的结果json字符串
*/
bool
upstreamTracking
(
const
std
::
string
&
sN
,
std
::
string
&
jsonResult
);
/**
*@brief 追踪节点下游路径
*@param sN 节点本点号
*@param jsonResult 追踪的结果集字符串
*/
bool
downstreamTracking
(
const
std
::
string
&
sN
,
std
::
string
&
jsonResult
);
/**
*@brief 计算管网中某个水源所能供水的范围
*@param sN 水源的编号
*@param junctions jsonResult 结果字符串
*/
bool
waterSupplyScopeAnalysis
(
const
std
::
string
&
sN
,
std
::
string
&
jsonResult
);
private
:
/**
*@brief 追踪节点上游路径
*@param sN 节点本点号
*@param junctions 追踪到的节点集合
*@param pipes 追踪到的管段集合
*/
bool
upstreamTracking
(
const
std
::
string
&
sN
,
std
::
vector
<
CivGraphJunction
>&
junctions
,
std
::
vector
<
CivGraphEdage
>&
pipes
);
/**
*@brief 追踪节点下游路径
*@param sN 节点本点号
*@param junctions 追踪到的节点集合
*@param pipes 追踪到的管段集合
*/
bool
downstreamTracking
(
const
std
::
string
&
sN
,
std
::
vector
<
CivGraphJunction
>&
junctions
,
std
::
vector
<
CivGraphEdage
>&
pipes
);
/**
*@brief 计算管网中某个水源所能供水的范围
*@param sN 水源的编号
*@param junctions 可以供水的节点
*@param pipes 可以供水的管段
*/
bool
waterSupplyScopeAnalysis
(
const
std
::
string
&
sN
,
std
::
vector
<
CivGraphJunction
>&
junctions
,
std
::
vector
<
CivGraphEdage
>&
pipes
);
private
:
ALGraph
<
CivGraphJunction
,
CivGraphEdage
>*
mGraph
;
// 管网有向图
};
pandaAlgorithm/pandaAlgorithm.vcxproj
View file @
81b040f6
...
...
@@ -149,11 +149,13 @@
<ClInclude
Include=
"CivGraphFactory.h"
/>
<ClInclude
Include=
"CivGraphList.h"
/>
<ClInclude
Include=
"CivHydDataType.h"
/>
<ClInclude
Include=
"CivTrackingAnalysis.h"
/>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"CivGraphFactory.cpp"
/>
<ClCompile
Include=
"CivGraphList.cpp"
/>
<ClCompile
Include=
"CivHydDataType.cpp"
/>
<ClCompile
Include=
"CivTrackingAnalysis.cpp"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
...
...
pandaAlgorithm/pandaAlgorithm.vcxproj.filters
View file @
81b040f6
...
...
@@ -24,6 +24,9 @@
<ClInclude
Include=
"CivGraphFactory.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
<ClInclude
Include=
"CivTrackingAnalysis.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"CivGraphList.cpp"
>
...
...
@@ -35,5 +38,8 @@
<ClCompile
Include=
"CivGraphFactory.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
<ClCompile
Include=
"CivTrackingAnalysis.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