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
a0d30126
Commit
a0d30126
authored
Jul 20, 2020
by
刘乐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,有向图算法
parent
6e13faf4
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
496 additions
and
24 deletions
+496
-24
CivHydrTest.cpp
funcDemo/CivHydrTest.cpp
+2
-2
main.cpp
funcDemo/main.cpp
+4
-4
CivGraph.cpp
pandaAlgorithm/CivGraph.cpp
+0
-2
CivGraph.h
pandaAlgorithm/CivGraph.h
+0
-12
CivGraphList.cpp
pandaAlgorithm/CivGraphList.cpp
+351
-0
CivGraphList.h
pandaAlgorithm/CivGraphList.h
+122
-0
pandaAlgorithm.vcxproj
pandaAlgorithm/pandaAlgorithm.vcxproj
+9
-2
pandaAlgorithm.vcxproj.filters
pandaAlgorithm/pandaAlgorithm.vcxproj.filters
+2
-2
CivNewInp.cpp
pandaAnalysis/CivNewInp.cpp
+5
-0
CivTrackingResultCache.h
pandaDbManager/CivTrackingResultCache.h
+1
-0
水力模型产品规划V1.0-UPDATE.xmind
建模文档/水力模型产品规划V1.0-UPDATE.xmind
+0
-0
No files found.
funcDemo/CivHydrTest.cpp
View file @
a0d30126
...
...
@@ -23,9 +23,9 @@ void CivConTrackTest::test(char* uri)
char
result
[
1024
*
32
];
char
sn
[
32
];
strcpy_s
(
sn
,
"JD00000
680
"
);
strcpy_s
(
sn
,
"JD00000
016
"
);
int
succ
=
trackingSimulation
(
uri
,
sn
,
3
,
result
);
int
succ
=
trackingSimulation
(
uri
,
sn
,
5
,
result
);
std
::
cout
<<
result
<<
std
::
endl
;
std
::
cout
<<
"测试结果:"
<<
succ
<<
std
::
endl
;
...
...
funcDemo/main.cpp
View file @
a0d30126
...
...
@@ -24,12 +24,12 @@ int main(int argc, char* argv[])
context.contextTest(findUri);*/
// 测试追踪分析
/*
CivTestContext context(new CivConTrackTest());
context.contextTest(findUri);
*/
CivTestContext
context
(
new
CivConTrackTest
());
context
.
contextTest
(
findUri
);
// 测试根据时段获取值
CivTestContext
context
(
new
CivConGetDataTest
());
context
.
contextTest
(
findUri
);
/*
CivTestContext context(new CivConGetDataTest());
context.contextTest(findUri);
*/
// 测试根据
/* CivTestContext context(new CivConGetRptTest());
...
...
pandaAlgorithm/CivGraph.cpp
deleted
100644 → 0
View file @
6e13faf4
#include "CivGraph.h"
pandaAlgorithm/CivGraph.h
deleted
100644 → 0
View file @
6e13faf4
#pragma once
/**
ͼ
*/
template
<
class
Item
>
class
CivDGraph
{
public
:
};
pandaAlgorithm/CivGraphList.cpp
0 → 100644
View file @
a0d30126
#include "CivGraphList.h"
#include "CivPgConn.h"
#include "CivDbConn.h"
template
<
class
VertexType
,
class
EdgeType
>
ALGraph
<
VertexType
,
EdgeType
>::
ALGraph
()
{
}
template
<
class
VertexType
,
class
EdgeType
>
void
ALGraph
<
VertexType
,
EdgeType
>::
createGraph
(
CivDbConn
*
dbConn
)
{
if
(
dbConn
==
nullptr
)
return
;
}
template
<
class
VertexType
,
class
EdgeType
>
ALGraph
<
VertexType
,
EdgeType
>::~
ALGraph
()
{
for
(
auto
iter
=
m_vertexArray
.
begin
();
iter
!=
m_vertexArray
.
end
();
iter
++
)
{
Edge
<
weight
>*
p
=
iter
->
pAdjEdges
;
while
(
NULL
!=
p
)
{
iter
->
pAdjEdges
=
p
->
pNextEdge
;
delete
p
;
p
=
iter
->
pAdjEdges
;
}
}
if
(
!
m_vertexArray
.
empty
())
{
m_vertexArray
.
clear
();
}
}
template
<
class
VertexType
,
class
EdgeType
>
bool
ALGraph
<
VertexType
,
EdgeType
>::
insertAVertex
(
IN
const
VertexType
&
vertexName
)
{
Vertex
<
VertexType
,
EdgeType
>
VertexInstance
(
vertexName
,
NULL
);
m_vertexArray
.
push_back
(
VertexInstance
);
return
true
;
}
template
<
class
VertexType
,
class
EdgeType
>
bool
ALGraph
<
VertexType
,
EdgeType
>::
insertAEdge
(
IN
const
VertexType
vertexName1
,
IN
const
VertexType
vertexName2
,
IN
const
EdgeType
edgeWeight
)
{
int
v1
=
getVertexIndex
(
vertexName1
);
if
(
-
1
==
v1
)
{
cerr
<<
"There is no vertex 1"
<<
endl
;
return
false
;
}
int
v2
=
getVertexIndex
(
vertexName2
);
if
(
-
1
==
v2
)
{
cerr
<<
"There is no vertex 2"
<<
endl
;
return
false
;
}
Edge
<
weight
>*
p
=
m_vertexArray
.
at
(
v1
).
pAdjEdges
;
while
(
p
!=
NULL
&&
p
->
nDestVertex
!=
v2
)
{
p
=
p
->
pNextEdge
;
}
if
(
NULL
==
p
)
{
p
=
new
Edge
<
weight
>
(
v2
,
edgeWeight
,
m_vertexArray
.
at
(
v1
).
pAdjEdges
);
m_vertexArray
.
at
(
v1
).
pAdjEdges
=
p
;
return
true
;
}
if
(
v2
==
p
->
nDestVertex
)
{
Edge
<
weight
>*
q
=
p
;
p
=
new
Edge
<
weight
>
(
v2
,
edgeWeight
,
q
->
pNextEdge
);
q
->
pNextEdge
=
p
;
return
true
;
}
return
false
;
}
template
<
class
VertexType
,
class
EdgeType
>
bool
ALGraph
<
VertexType
,
EdgeType
>::
removeAEdge
(
IN
const
VertexType
&
vertexName1
,
IN
const
VertexType
&
vertexName2
,
IN
const
EdgeType
&
edgeWeight
)
{
int
v1
=
getVertexIndex
(
vertexName1
);
if
(
-
1
==
v1
)
{
cerr
<<
"There is no vertex 1"
<<
endl
;
return
false
;
}
int
v2
=
getVertexIndex
(
vertexName2
);
if
(
-
1
==
v2
)
{
cerr
<<
"There is no vertex 2"
<<
endl
;
return
false
;
}
Edge
<
EdgeType
>*
p
=
m_vertexArray
.
at
(
v1
).
pAdjEdges
;
Edge
<
EdgeType
>*
q
=
NULL
;
while
(
p
!=
NULL
&&
p
->
nDestVertex
!=
v2
)
{
q
=
p
;
p
=
p
->
pNextEdge
;
}
if
(
NULL
==
p
)
{
cerr
<<
"Edge is not found"
<<
endl
;
return
false
;
}
while
(
edgeWeight
!=
p
->
edgeWeight
&&
p
->
nDestVertex
==
v2
)
{
q
=
p
;
p
=
p
->
pNextEdge
;
}
if
(
v2
!=
p
->
nDestVertex
)
{
cerr
<<
"Edge is not found"
<<
endl
;
return
false
;
}
q
->
pNextEdge
=
p
->
pNextEdge
;
delete
p
;
return
true
;
}
template
<
class
VertexType
,
class
EdgeType
>
EdgeType
ALGraph
<
VertexType
,
EdgeType
>::
getEdgeWeight
(
IN
const
Edge
<
EdgeType
>*
pEdge
)
{
return
pEdge
->
edgeWeight
;
}
template
<
class
VertexType
,
class
EdgeType
>
void
ALGraph
<
VertexType
,
EdgeType
>::
getVertexEdgeWeight
(
IN
const
int
v1
,
OUT
vector
<
EdgeType
>&
DistanceArray
)
{
Edge
<
weight
>*
p
=
m_vertexArray
.
at
(
v1
).
pAdjEdges
;
int
prevIndex
=
-
1
;
weight
tmp
;
while
(
NULL
!=
p
)
{
//consider the same edges exist
if
(
prevIndex
==
p
->
nDestVertex
)
{
if
(
tmp
>
p
->
edgeWeight
)
{
DistanceArray
[
prevIndex
]
=
p
->
edgeWeight
;
}
}
else
{
DistanceArray
[
p
->
nDestVertex
]
=
p
->
edgeWeight
;
prevIndex
=
p
->
nDestVertex
;
tmp
=
p
->
edgeWeight
;
}
p
=
p
->
pNextEdge
;
}
}
template
<
class
VertexType
,
class
EdgeType
>
EdgeType
ALGraph
<
VertexType
,
EdgeType
>::
getMinWeight
(
IN
const
VertexType
vertexName1
,
IN
const
VertexType
vertexName2
)
{
Edge
<
EdgeType
>*
pEdge
=
NULL
;
int
v1
=
getVertexIndex
(
vertexName1
);
if
(
-
1
==
v1
)
{
cerr
<<
"There is no vertex 1"
<<
endl
;
return
false
;
}
int
v2
=
getVertexIndex
(
vertexName2
);
if
(
-
1
==
v2
)
{
cerr
<<
"There is no vertex 2"
<<
endl
;
return
false
;
}
Edge
<
EdgeType
>*
p
=
m_vertexArray
.
at
(
v1
).
pAdjEdges
;
while
(
p
!=
NULL
&&
p
->
nDestVertex
!=
v2
)
{
p
=
p
->
pNextEdge
;
}
if
(
NULL
==
p
)
{
pEdge
=
NULL
;
return
weight
(
0
);
}
EdgeType
tmp
=
getEdgeWeight
(
p
);
pEdge
=
p
;
while
(
NULL
!=
p
&&
v2
==
p
->
nDestVertex
)
{
if
(
tmp
>
getEdgeWeight
(
p
))
{
tmp
=
getEdgeWeight
(
p
);
pEdge
=
p
;
}
p
=
p
->
pNextEdge
;
}
return
tmp
;
}
template
<
class
VertexType
,
class
EdgeType
>
int
ALGraph
<
VertexType
,
EdgeType
>::
getVertexIndex
(
IN
const
VertexType
vertexName
)
{
for
(
int
i
=
0
;
i
<
m_vertexArray
.
size
();
i
++
)
{
if
(
vertexName
==
getData
(
i
))
{
return
i
;
}
}
return
-
1
;
}
template
<
class
VertexType
,
class
EdgeType
>
int
ALGraph
<
VertexType
,
EdgeType
>::
getVertexNumber
()
{
return
m_vertexArray
.
size
();
}
template
<
class
VertexType
,
class
EdgeType
>
VertexType
ALGraph
<
VertexType
,
EdgeType
>::
getData
(
IN
int
index
)
{
return
m_vertexArray
.
at
(
index
).
vertexName
;
}
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
,
weight
(
INT_MAX
));
vecDistanceArray
[
sourceIndex
]
=
weight
(
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
=
weight
(
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
=
m_vertexArray
[
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
.
m_vertexArray
.
at
(
i
).
pAdjEdges
;
while
(
NULL
!=
p
)
{
out
<<
"("
<<
x1
<<
","
<<
graphInstance
.
getData
(
p
->
nDestVertex
)
<<
","
<<
p
->
edgeWeight
<<
") "
;
p
=
p
->
pNextEdge
;
}
out
<<
endl
;
}
return
out
;
}
pandaAlgorithm/CivGraphList.h
0 → 100644
View file @
a0d30126
#pragma once
#include <iostream>
#include <cstdio>
#include <vector>
#define IN
#define OUT
#define INOUT
using
namespace
std
;
class
CivDbConn
;
/**
*@brief 边结构体模板
*@param weight 权重类型
*/
template
<
class
EdgeType
>
struct
Edge
{
int
nDestVertex
;
// 目标节点个数
EdgeType
edgeObj
;
// 边的属性值对象
Edge
<
EdgeType
>*
pNextEdge
;
// 连接下一条边
Edge
(
int
d
,
weight
c
,
Edge
<
EdgeType
>*
p
=
NULL
)
:
nDestVertex
(
d
),
edgeObj
(
c
),
pNextEdge
(
p
)
{}
};
/**
*@brief 节点结构体模板
*@param vertextype 节点类型
*@param weight 权重类型
*/
template
<
class
VertexType
,
class
EdgeType
>
struct
Vertex
{
VertexType
mVertex
;
Edge
<
EdgeType
>*
pAdjEdges
;
Vertex
(
VertexType
x
,
Edge
<
EdgeType
>*
p
=
NULL
)
:
mVertex
(
x
),
pAdjEdges
(
p
)
{}
};
/**
基于邻接表的图
*/
template
<
class
VertexType
,
class
EdgeType
>
class
ALGraph
{
public
:
explicit
ALGraph
();
~
ALGraph
();
/**
*@brief 根据数库管网表生成图数据
*/
void
createGraph
(
CivDbConn
*
dbConn
);
public
:
/**
*@brief 往图中插入一个节点
*@param vertexName 节点值
*/
bool
insertAVertex
(
IN
const
VertexType
&
vertexName
);
/**
*@brief 两个节点之间插入一条边
*@param vertexName1 节点对象1
*@param vertexName2 节点对象2
*@param edge 边
*/
bool
insertAEdge
(
IN
const
VertexType
vertexName1
,
IN
const
VertexType
vertexName2
,
IN
const
EdgeType
edge
);
/**
*@brief 移除两个节点的边
*@param vertexName1 节点对象1
*@param vertexName2 节点对象2
*@param edge 边
*/
bool
removeAEdge
(
IN
const
VertexType
&
vertexName1
,
IN
const
VertexType
&
vertexName2
,
IN
const
EdgeType
&
edgeWeight
);
/**
*@brief 获取两个节点之间连接的最小权重值
*@param vertexName1 节点1
*@param vertexName2 节点2
*/
EdgeType
getMinWeight
(
IN
const
VertexType
vertexName1
,
IN
const
VertexType
vertexName2
);
/**
*@brief 获取两个节点之间连接的最小权重值
*@param vertexName1 节点1
*@param vertexName2 节点2
*/
int
getVertexIndex
(
IN
const
VertexType
vertexName
);
int
getVertexNumber
();
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
);
public
:
EdgeType
getEdgeWeight
(
IN
const
Edge
<
EdgeType
>*
pEdge
);
void
getVertexEdgeWeight
(
IN
const
int
v1
,
OUT
vector
<
EdgeType
>&
DistanceArray
);
vector
<
Vertex
<
VertexType
,
EdgeType
>
>
m_vertexArray
;
};
pandaAlgorithm/pandaAlgorithm.vcxproj
View file @
a0d30126
...
...
@@ -81,6 +81,8 @@
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<LinkIncremental>
false
</LinkIncremental>
<OutDir>
..\..\hModelProgram\Program\
</OutDir>
<IncludePath>
$(OUTDIR)..\include;$(IncludePath)
</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
...
...
@@ -130,19 +132,24 @@
<SDLCheck>
true
</SDLCheck>
<PreprocessorDefinitions>
NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
</PreprocessorDefinitions>
<ConformanceMode>
true
</ConformanceMode>
<Optimization>
Disabled
</Optimization>
<AdditionalIncludeDirectories>
$(OUTDIR)..\include;$(SolutionDir)pandaDbManager;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>
Console
</SubSystem>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<AdditionalDependencies>
pandaDbManager.lib;%(AdditionalDependencies)
</AdditionalDependencies>
<AdditionalLibraryDirectories>
$(OUTDIR)..\lib
</AdditionalLibraryDirectories>
<ImportLibrary>
$(OutDir)..\lib\$(TargetName).lib
</ImportLibrary>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude
Include=
"CivGraph.h"
/>
<ClInclude
Include=
"CivGraph
List
.h"
/>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"CivGraph.cpp"
/>
<ClCompile
Include=
"CivGraph
List
.cpp"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
...
...
pandaAlgorithm/pandaAlgorithm.vcxproj.filters
View file @
a0d30126
...
...
@@ -15,12 +15,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"CivGraph.h"
>
<ClInclude
Include=
"CivGraph
List
.h"
>
<Filter>
头文件
</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"CivGraph.cpp"
>
<ClCompile
Include=
"CivGraph
List
.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
</ItemGroup>
...
...
pandaAnalysis/CivNewInp.cpp
View file @
a0d30126
...
...
@@ -317,6 +317,11 @@ void CivNewInp::setQuality(const CivQuality& quality)
writeStringFormat
(
table
.
ID
);
if
(
mQualityType
==
ANALYSIS_TRACE
)
{
if
(
table
.
ID
==
mQualityName
)
{
writeString
(
"1"
);
continue
;
}
writeString
(
"0"
);
}
else
...
...
pandaDbManager/CivTrackingResultCache.h
View file @
a0d30126
...
...
@@ -4,6 +4,7 @@
#include <vector>
class
CivDbConn
;
#define CACHEEXPORT __declspec(dllexport)
// 节点
typedef
struct
...
...
建模文档/水力模型产品规划V1.0-UPDATE.xmind
View file @
a0d30126
No preview for this file type
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