Commit bb7193b7 authored by 刘乐's avatar 刘乐

1,上下游追踪

parent 81b040f6
......@@ -63,3 +63,53 @@ void CivConGetRptTest::test(char* uri)
std::cout << result << std::endl;
std::cout << "测试结果:" << isSucc << std::endl;
}
void CivUpstreamTrackingTest::test(char* uri)
{
// 追踪节点编号
char sn[32];
strcpy(sn, "JD00000016");
char result[1024 * 32];
bool isSucc = upstreamTracking(uri, sn, result);
std::cout << result << std::endl;
std::cout << "测试结果:" << isSucc << std::endl;
}
/**
下游追踪
*/
void CivDownStreamTrackingTest::test(char* uri)
{
// 追踪节点编号
char sn[32];
strcpy(sn, "JD00000047");
char result[1024 * 128];
bool isSucc = downstreamTracking(uri, sn, result);
std::cout << result << std::endl;
std::cout << "测试结果:" << isSucc << std::endl;
}
/**
水源供水范围分析
*/
void CivWaterSupplyScopeTest::test(char* uri)
{
// 追踪节点编号
char sn[32];
strcpy(sn, "JD00000016");
char result[1024 * 32];
bool isSucc = waterSupplyScopeAnalysis(uri, sn, result);
std::cout << result << std::endl;
std::cout << "测试结果:" << isSucc << std::endl;
}
......@@ -45,3 +45,30 @@ class CivConGetRptTest :public CivHydrTest
public:
virtual void test(char* uri);
};
/**
上游追踪
*/
class CivUpstreamTrackingTest :public CivHydrTest
{
public:
virtual void test(char* uri);
};
/**
下游追踪
*/
class CivDownStreamTrackingTest :public CivHydrTest
{
public:
virtual void test(char* uri);
};
/**
水源供水范围分析
*/
class CivWaterSupplyScopeTest :public CivHydrTest
{
public:
virtual void test(char* uri);
};
......@@ -24,8 +24,8 @@ 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());
......@@ -34,6 +34,20 @@ int main(int argc, char* argv[])
// 测试根据
/* CivTestContext context(new CivConGetRptTest());
context.contextTest(findUri);*/
// 上游追踪
/* CivTestContext context(new CivUpstreamTrackingTest());
context.contextTest(findUri);*/
// 下游追踪
CivTestContext context(new CivDownStreamTrackingTest());
context.contextTest(findUri);
// 水源供水范围分析
/* CivTestContext context(new CivWaterSupplyScopeTest());
context.contextTest(findUri);*/
getchar();
return 0;
}
\ No newline at end of file
......@@ -17,8 +17,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "funcDemo", "funcDemo\funcDe
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pandaLog", "pandaLog\pandaLog.vcxproj", "{4C38D294-830F-441E-B892-60117ABA8BFE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pandaAlgorithm", "pandaAlgorithm\pandaAlgorithm.vcxproj", "{B004F96E-D760-410C-B298-B6E0510E831E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -79,16 +77,6 @@ Global
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x64.Build.0 = Release|x64
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x86.ActiveCfg = Release|Win32
{4C38D294-830F-441E-B892-60117ABA8BFE}.Release|x86.Build.0 = Release|Win32
{B004F96E-D760-410C-B298-B6E0510E831E}.Debug|Any CPU.ActiveCfg = Debug|Win32
{B004F96E-D760-410C-B298-B6E0510E831E}.Debug|x64.ActiveCfg = Debug|x64
{B004F96E-D760-410C-B298-B6E0510E831E}.Debug|x64.Build.0 = Debug|x64
{B004F96E-D760-410C-B298-B6E0510E831E}.Debug|x86.ActiveCfg = Debug|Win32
{B004F96E-D760-410C-B298-B6E0510E831E}.Debug|x86.Build.0 = Debug|Win32
{B004F96E-D760-410C-B298-B6E0510E831E}.Release|Any CPU.ActiveCfg = Release|Win32
{B004F96E-D760-410C-B298-B6E0510E831E}.Release|x64.ActiveCfg = Release|x64
{B004F96E-D760-410C-B298-B6E0510E831E}.Release|x64.Build.0 = Release|x64
{B004F96E-D760-410C-B298-B6E0510E831E}.Release|x86.ActiveCfg = Release|Win32
{B004F96E-D760-410C-B298-B6E0510E831E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
#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, EdgeType c, Edge<EdgeType>* p = NULL)
:nDestVertex(d), edgeObj(c), pNextEdge(p)
{}
};
/**
*@brief 邻接表中表的顶点
*@param VertexType 节点信息
*@param EdgeType 弧信息
*/
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();
void BFS(VertexType vetexType, std::vector<int>& visited);
/**
*@brief 图反向
*/
void graphReverse();
Edge<EdgeType>* reverseList(Edge<EdgeType>* edge);
/**
*@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);
/**
*@brief 获取顶点数据
*/
int getVertexNumber();
/**
*@brief 根据索引获取顶点数据
*@param index 索引值
*/
VertexType getData(IN int index);
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; // 节点数组
};
#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
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{b004f96e-d760-410c-b298-b6e0510e831e}</ProjectGuid>
<RootNamespace>pandaAlgorithm</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</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>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<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="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">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivGraphList.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivHydDataType.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivGraphFactory.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivTrackingAnalysis.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivGraphList.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivHydDataType.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivGraphFactory.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivTrackingAnalysis.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
......@@ -43,6 +43,11 @@ void CivInpBuilder::setQualityType(const QualityAnalyType analyType, const std::
mNewInp->setQualityType(analyType, qulityName);
}
void CivInpBuilder::setDuration(int duration)
{
mNewInp->setDuration(duration);
}
void CivInpBuilder::registDb(CivDbConn* dbConn)
{
mDbConn = dbConn;
......
......@@ -14,6 +14,7 @@ public:
virtual ~CivBuilder();
virtual void setQualityType(const QualityAnalyType analyType, const std::string& qulityName) = 0;
virtual void setDuration(int duration) = 0;
virtual void registDb(CivDbConn* dbConn)=0;
virtual void buildNode() = 0;
virtual void buildPipe() = 0;
......@@ -55,6 +56,7 @@ public:
~CivInpBuilder();
virtual void setQualityType(const QualityAnalyType analyType, const std::string& qulityName);
virtual void setDuration(int duration);
// 注册数据库连接
virtual void registDb(CivDbConn* dbConn);
virtual void buildNode();
......
......@@ -2,18 +2,21 @@
#include "CivGraphList.h"
#include "CivDbConn.h"
#include "CivPgConn.h"
#include "CivTrackingResultCache.h"
CivGraphFactory::CivGraphFactory()
{
}
ALGraph<CivGraphJunction, CivGraphEdage>* CivGraphFactory::createGraph(CivDbConn* dbConn)
bool CivGraphFactory::initGraph(CivDbConn* dbConn, ALGraph<CivGraphJunction, CivGraphEdage>* graph)
{
if (graph == nullptr)
return false;
if (dbConn == nullptr)
return false;
ALGraph<CivGraphJunction, CivGraphEdage>* graph = new ALGraph<CivGraphJunction, CivGraphEdage>();
// 顶点坐标
CivCoordinates coords;
......@@ -50,10 +53,20 @@ ALGraph<CivGraphJunction, CivGraphEdage>* CivGraphFactory::createGraph(CivDbCon
int index2 = graph->getVertexIndex(graphJunction2);
CivGraphJunction endJunction = graph->getData(index2);
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, { sStartjuction.getXCoord(),sStartjuction.getYCoord(),endJunction.getXCoord(),endJunction.getYCoord()});
graph->insertAEdge(sStartjuction, endJunction, edAge);
if (sStartjuction.getHead() > endJunction.getHead())
{
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, { sStartjuction.getXCoord(),sStartjuction.getYCoord(),endJunction.getXCoord(),endJunction.getYCoord() });
graph->insertAEdge(sStartjuction, endJunction, edAge);
}
else
{
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, {endJunction.getXCoord(),endJunction.getYCoord(), sStartjuction.getXCoord(),sStartjuction.getYCoord() });
graph->insertAEdge(endJunction, sStartjuction, edAge);
}
}
return graph;
return true;
}
\ No newline at end of file
#pragma once
#include "CivHydDataType.h"
#include "CivGraphList.h"
// 声明模板图类型
template <class VertexType, class EdgeType> class ALGraph;
class CivDbConn;
class CivGraphJunction;
class CivGraphEdage;
class CivGraphFactory
{
......@@ -16,5 +18,5 @@ public:
*@param dbConn 数据库连接
*@param graph 有向图
*/
ALGraph<CivGraphJunction, CivGraphEdage>* createGraph(CivDbConn* dbConn);
bool initGraph(CivDbConn* dbConn, ALGraph<CivGraphJunction, CivGraphEdage>* graph);
};
#include "CivHydDataType.h"
bool operator==(const CivGraphEdage& left, const CivGraphEdage& right)
{
return left.mSN == right.mSN;
}
bool operator==(const CivGraphJunction& left, const CivGraphJunction& right) {
return left.mSN == right.mSN;
}
CivGraphJunction::CivGraphJunction()
{
}
CivGraphJunction::CivGraphJunction(std::string sN)
: mSN(sN)
{
......@@ -17,6 +31,7 @@ bool CivGraphJunction::operator== (const CivGraphJunction& edage)
return mSN == edage.mSN;
}
CivGraphEdage::CivGraphEdage()
{
}
......@@ -25,7 +40,7 @@ CivGraphEdage::CivGraphEdage()
{
mSN = sn;
mLength = length;
if (position.size() != 5)
if (position.size() != 4)
return;
......@@ -37,7 +52,7 @@ CivGraphEdage::CivGraphEdage()
bool CivGraphEdage::operator== (const CivGraphEdage& edage)
{
return mLength == edage.mLength;
return mSN == edage.mSN;
}
bool CivGraphEdage::operator> (const CivGraphEdage& edage)
......
......@@ -6,25 +6,33 @@
/**
节点
*/
class CivGraphJunction
class CivGraphJunction
{
public:
explicit CivGraphJunction(std::string sN);
explicit CivGraphJunction(std::string sN, std::string xCoord, std::string yCoord);
CivGraphJunction();
bool operator== (const CivGraphJunction& edage);
CivGraphJunction(std::string sN);
CivGraphJunction(std::string sN, std::string xCoord, std::string yCoord);
bool operator== (const CivGraphJunction& j1);
friend bool operator==(const CivGraphJunction& left, const CivGraphJunction& right);
void setSn(const std::string& sn) { mSN = sn; }
std::string getSn() { return mSN; }
void setXCoord(std::string xCoord) { mXCoord = xCoord; }
void setXCoord(const std::string& xCoord) { mXCoord = xCoord; }
std::string getXCoord() { return mXCoord; }
void setYCoord(std::string yCoord) { mXCoord = yCoord; }
void setYCoord(const std::string& yCoord) { mXCoord = yCoord; }
std::string getYCoord() { return mYCoord; }
void setHead(float head) { mHead = head; }
float getHead() { return mHead; }
private:
std::string mSN; // 本点号,
float mHead; // 高程
std::string mXCoord; // 横坐标
std::string mYCoord; // 纵坐标
};
......@@ -41,13 +49,28 @@ 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);
CivGraphEdage();
CivGraphEdage(std::string sn, std::string length, std::vector<std::string> position);
friend bool operator==(const CivGraphEdage& left, const CivGraphEdage& right);
bool operator== (const CivGraphEdage& edage);
bool operator> (const CivGraphEdage& edage);
bool operator< (const CivGraphEdage& edage);
bool operator!= (const CivGraphEdage& edage);
bool operator != (const CivGraphEdage& edage);
std::string getLength() { return mLength; }
std::string getSN() { return mSN; }
std::string getStartX() { return mStartX; }
std::string getStartY() { return mStartY; }
std::string getEndX() { return mEndX; }
std::string getEndY() { return mEndY; }
void setLength(const std::string& length) { mLength = length; }
void setSN(const std::string& sn) { mSN = sn; }
void setStartX(const std::string& startX) { mStartX = startX; }
void setStartY(const std::string& startY) { mStartY = startY; }
void setEndX(const std::string& endX) { mEndX = endX; }
void setEndY(const std::string& endY) { mEndY = endY; }
private:
std::string mSN;// 编号
......
This diff is collapsed.
#pragma once
#include<string>
#include<set>
#include "CivInp.h"
#include "CivSysLog.h"
#include "CivSimulResultCache.h"
class CivDbConnection;
class CivDbConn;
/**
* 水力计算类
*/
class CivHydrCalc
{
public:
CivHydrCalc(char* uri, std::string netName);
~CivHydrCalc();
/**
*@brief 水力模拟计算
*@param inpFile:inp文件
*@param rptFile: 输出文件
*@param binOutFile: 二进制输出文件
*/
bool hydrSimulation(char* inpFile, char* rptFile, char* binOutFile);
/**
*@brief 水质模拟计算
*@param inpFile:inp文件
*@param rptFile: 输出文件
*@param binOutFile: 二进制输出文件
*/
bool qualitySimulation(char* inpFile, char* rptFile, char* binOutFile);
bool getDataByInterval( char* date, char* interval);
/**
*@brief 导出inp文件
*/
bool exportInp(char* fileName);
private:
/**
*@brief 解析表字段名,按顺序写入
*@param table:表
*@param inp: inp文件对象
*/
void assemble(const std::string& table, CivInp& inp);
/*
*@brief 获取节点计算结果
*@param time: 时间
*/
void getNodeResult(short time);
/*
*@brief 获取管线计算结果
*@param time: 时间
*/
void getLinkResult(short time);
/*
*@brief 获取节点的水质计算结果
*@param time: 时间
*/
void getNodeQuality(short time);
/*
*@brief 获取管线水值计算结果
*@param time: 时间
*/
void getLinkQuality(short time);
private:
CivDbConnection* mDbConn;
CivDbConn* mPgConn;
std::string mNetname;
CivSimulResultCache mResultCache; // 存储模拟结果缓存类
};
#include "CivHydrFuncInter.h"
#include "CivHydrCalc.h"
#include "CivSysLog.h"
#include "CivTableTemp.h"
#include "CivPgConn.h"
#include "CivHydrSimulation.h"
bool DLLEXPORT simulation(char* uri, char* netName, char* flag)
{
char fileName[256];
char rptR[256];
char outBinFile[256];
strcpy_s(fileName, "test.inp");
strcpy_s(rptR, "test.rpt");
strcpy_s(outBinFile, "test.bin");
CivHydrCalc* calc = new CivHydrCalc(uri, netName);
CivSysLog::getInstance()->info("开始", "interface", __FUNCTION__);
bool msg = false;
if (strcmp(flag,"HDY")==0)
msg = calc->hydrSimulation( fileName, rptR, outBinFile);
else if(strcmp(flag, "QUALITY")==0)
msg = calc->qualitySimulation(fileName, rptR, outBinFile);
if (msg)
{
CivSysLog::getInstance()->info("成功", "interface", __FUNCTION__);
}
else
{
CivSysLog::getInstance()->info("失败", "interface", __FUNCTION__);
}
delete calc;
return msg;
}
#include "CivTrackingAnalysis.h"
bool DLLEXPORT getDataByInterval(char* uri, char* date, char* interval)
{
......@@ -205,4 +174,73 @@ bool DLLEXPORT getRptByCondition(char* uri, char* type, char* condition, char* r
result[i] = strRes[i];
}
return true;
}
bool DLLEXPORT upstreamTracking(char* uri, char* sn, char* result)
{
// 创建数据库连接
CivDbConn* pgConn = new CivPgConn(uri);
CivTrackingAnalysis analySis;
if (!analySis.createGraphFrom(pgConn))
return false;
std::string res;
std::string strSn = sn;
if (!analySis.upstreamTracking(strSn, res))
{
delete pgConn;
return false;
}
strcpy(result, res.c_str());
delete pgConn;
return true;
}
bool DLLEXPORT downstreamTracking(char* uri, char* sn, char* result)
{
// 创建数据库连接
CivDbConn* pgConn = new CivPgConn(uri);
CivTrackingAnalysis analySis;
if (!analySis.createGraphFrom(pgConn))
return false;
std::string res;
std::string strSn = sn;
if (!analySis.downstreamTracking(strSn, res))
{
delete pgConn;
return false;
}
strcpy(result, res.c_str());
delete pgConn;
return true;
}
bool DLLEXPORT waterSupplyScopeAnalysis(char* uri, char* sn, char* result)
{
// 创建数据库连接
CivDbConn* pgConn = new CivPgConn(uri);
CivTrackingAnalysis analySis;
if (!analySis.createGraphFrom(pgConn))
return false;
std::string res;
std::string strSn = sn;
if (!analySis.waterSupplyScopeAnalysis(strSn, res))
{
delete pgConn;
return false;
}
strcpy(result, res.c_str());
delete pgConn;
return true;
}
\ No newline at end of file
......@@ -6,6 +6,30 @@
extern "C" {
#endif
/**
*@brief 上游追踪
*@param uri 数据库连接地址
*@param sn 追踪节点本点号
*@param result 追踪结果
*/
bool DLLEXPORT upstreamTracking(char* uri, char* sn, char* result);
/**
*@brief 下游追踪
*@param uri 数据库连接地址
*@param sn 追踪节点本点号
*@param result 追踪结果
*/
bool DLLEXPORT downstreamTracking(char* uri, char* sn, char* result);
/**
*@brief 供水范围追踪
*@param uri 数据库连接地址
*@param sn 追踪节点本点号
*@param result 追踪结果
*/
bool DLLEXPORT waterSupplyScopeAnalysis(char* uri, char* sn, char* result);
/**
*@brief 获取当前日期和时段的结果值
*@param uri:数据库连接地址
......@@ -40,14 +64,6 @@ extern "C" {
*/
bool DLLEXPORT trackingSimulation(char* uri, char* sN, int hours,char* result);
/**
*@brief 模拟计算
*@param uri: 管网数据库连接
*@param netName: 管网名
*@param flag: 标记
*/
bool DLLEXPORT simulation(char* uri, char* netName, char* flag);
/**
*@brief 获取管网计算特定时段的结果
*@param uri: 管网数据库连接uri
......
......@@ -115,16 +115,8 @@ bool CivHydrSimulation::convertInp(const QualityAnalyType analyType, const std::
return true;
}
bool CivHydrSimulation::hdyrSimulation()
bool CivHydrSimulation::hdyrCompute()
{
CivSysLog::getInstance()->error("开始水力分析计算", "CivHydrSimulation", __FUNCTION__);
if (!convertInp(ANALYSIS_RESERVE,""))
{
CivSysLog::getInstance()->error("写入inp文件失败", "CivHydrSimulation", __FUNCTION__);
return false;
}
CivSysLog::getInstance()->info("写入inp成功", "CivHydrSimulation", __FUNCTION__);
short hydCode = 1;
long t(0), tstep(0);
int iTime(0);
......@@ -181,7 +173,7 @@ bool CivHydrSimulation::hdyrSimulation()
}
ENnextH(&tstep);
// 获取当前节点和管段数据
getNodeResult(iTime);
getLinkResult(iTime);
......@@ -190,6 +182,79 @@ bool CivHydrSimulation::hdyrSimulation()
ENcloseH();
ENclose();
return true;
}
void CivHydrSimulation::getDataByTime(int time, NodeResultItems& nodeItems, LinkResultItems& linkItems)
{
mResultCache.getResultByTime(time, nodeItems, linkItems);
}
bool CivHydrSimulation::hdyrInstantSimulation()
{
CivBuilder* builder = new CivInpBuilder();
builder->setDuration(0);
builder->setQualityType(ANALYSIS_RESERVE, "");
builder->registDb(mDbConn);
CivInpDirector director;
director.setBuilder(builder);
director.create();
CivNewInp* newInp = builder->getNewInp();
char* inpFileName = getInpFile();
if (inpFileName && (*inpFileName != '\0') && !newInp->writeToFile(inpFileName))
{
delete builder;
return false;
}
delete builder;
// 水力计算
if (!hdyrCompute())
{
CivSysLog::getInstance()->error("水力分析结果存储失败", "CivHydrCalc", __FUNCTION__);
return false;
}
return true;
}
bool CivHydrSimulation::hdyrSimulation()
{
CivBuilder* builder = new CivInpBuilder();
builder->setQualityType(ANALYSIS_RESERVE, "");
builder->registDb(mDbConn);
CivInpDirector director;
director.setBuilder(builder);
director.create();
CivNewInp* newInp = builder->getNewInp();
char* inpFileName = getInpFile();
if (inpFileName && (*inpFileName != '\0') && !newInp->writeToFile(inpFileName))
{
delete builder;
return false;
}
delete builder;
// 水力计算
if (!hdyrCompute())
{
CivSysLog::getInstance()->error("水力分析结果存储失败", "CivHydrCalc", __FUNCTION__);
return false;
}
//模拟数据刷新
if (!brushingResult())
{
......
......@@ -24,6 +24,13 @@ public:
*/
bool hdyrSimulation();
/**
*@brief 瞬时计算
*/
bool hdyrInstantSimulation();
bool hdyrCompute();
/**
*@brief 水质模拟,水龄,化学物质
*/
......@@ -41,6 +48,7 @@ public:
*@param hours: 小时数
*/
bool trackingSimulation(char* snNode, int hours);
void getDataByTime(int time ,NodeResultItems& nodeItems, LinkResultItems& linkItems);
/**
*@brief 导出inp文件
......
This diff is collapsed.
#pragma once
#include <string>
#include <sstream>
#include <vector>
#include "CivTypes.h"
#define CivItem std::vector<std::string>
#define Civitems std::vector<CivItem>
// 模拟选项
struct Options {
// 流量被表达的单位
enum class UNITS
{
LPS,//——升 / 秒
LPM,//——升 / 分
MLD,//——百万升 / 日
CMH,//——立方米 / 小时
CMG,//——立方米 / 日
CFS,//——立方英尺 / 秒
GPM,//——加仑 / 分
MGD,//——百万加仑 / 日
IMGD,//——英制MGD
AFD,//——英亩 - 英尺 / 日
};
// 水头损失公式
enum class HEADLOSS {
HW, // Hazen - Williams(H - W)
DW, //Darcy - Weisbach(D - W)
CM //Chezy - Manning(C - M)
};
// 水质分析的类型
enum class QUALITY
{
NONE, //NONE(无)
CHEMICAL, //CHEMICAL(化学药剂)
AGE, // AGE(水龄)
TRACE // TRACE(跟踪)
};
UNITS units;
HEADLOSS headLoss;
QUALITY quality;
Str VISCOSITY = "0.1"; // 模拟流体的运动粘度
Str DIFFUSIVITY = "1.0"; // 是化合物的分析扩散系数
Str SpecificGravity = "1.0"; // 被模拟流体密度与4摄氏度水的密度之比(无量纲)。
Str TRIALS = "40"; // ,求解管网水力特性使用的最大试算次数
Str ACCURACY = "0.001"; //指定了确定何时达到水力结果的收敛准则
Str UNBALANCED = "STOP"; //“STOP”将在该点终止整个分析。“CONTINUE”将在公布警告消息的情况
Str Pattern = "1";
Str DEMANDMULTIPLIER = "1.0"; // 用于调整所有连接节点的基本需水量数值,以及所有需水量的类型。
Str EMITTEREXPONENT = "0.5"; // 指定了当计算扩散器的流量时,节点压力上升的幂指数
Str TOLERANCE = "0.01"; //水质水平精度
Str MAP;
};
/**
inp文件对象模型
*/
class CivInp
{
public:
// 时间单位
enum TimeUnit { SECONDS, MINUTES, HOURS, DAYS };
CivInp(TimeUnit timetype);
/**
*@brief 保存inp文件
*@paramfileName: 文件名
*/
bool writeToFile(const char* fileName);
/**
*@brief 根据组件类型添加
*@param items: 数据
*@param type: 枚举类型
*/
void writeComponet(const Civitems& items, SectType type);
/**
*@brief 写入IO流
*/
void writeTextStream();
/**
*@brief 定义时间模式
*@param pId: 模式id
*@param pValue: 模式值
*/
void setPattern(StrQuote pId, std::vector<Str> pValue);
/**
*@brief 定义不同的模拟选项。
*@param options: 必选项
*@param others: 选填字段
*/
void setOption(Options options,const std::map<std::string,std::string>& others = std::map<std::string, std::string>());
/**
*@brief 设置模拟的历时
*@param duration: 总时间
*/
void setDuration(int duration);
/**
*@brief 设置时间间隔
*@param type:需要设置的时间步长计算模型:PATTERN,REPORT,QUALITY
*@param step :间隔时长
*/
void setTimestep(Str type, int step);
void setTimeStart(Str type, int step);
void setTimeOthers(Str type, Str val);
/**
*@brief 设置时间单位
*/
void setTimeUnit(TimeUnit timeUnit) { mTimeUnit = timeUnit; }
private:
Str getTimeUnit(TimeUnit timetype);
void writeTitles();
void writeJunctions(Civitems items);
void writePipes(Civitems items);
void writeTanks(Civitems items);
void writeReservoirs(Civitems items);
void writePumps(Civitems items);
void writeValves(Civitems items);
void writeTags(Civitems items);
void writeCoordinates(Civitems items);
void writeLabels(Civitems items);
void writeVertices(Civitems items);
void writeSources(Civitems items);
void writeBackdrop(Civitems items);
void writeEnd();
void writeString(const std::string& s);
void writeStatus(Civitems items);
void writeCurves(Civitems items);
void writeTimes(Civitems items);
void writeControls(Civitems items);
void writeReactions(Civitems items);
void writeMixing(Civitems items);
void writeRules(Civitems items);
void writeEnergy(Civitems items);
void writeEmitters(Civitems items);
void writeQuality(Civitems items);
void writeItems(const Civitems& items);
void writeOptions(const Civitems& items);
void writePatterns(Civitems items);
void writeDemand(Civitems items);
private:
std::ostringstream mTextStream;
TimeUnit mTimeUnit; // 计算时间单位
Civitems mJunctionsItems; // 节点
Civitems mPipesItems; // 管线
Civitems mReservoirsItems; // 水源
Civitems mTanksItems;// 水池
Civitems mPumpsItems; // 水泵
Civitems mValvesItems; // 阀门
Civitems mTagsItems; //
Civitems mStatusItems; // 定义模拟开始时被选管段的初始状态
Civitems mPatternsItems; // 定义时间模式
Civitems mCurvesItems; // 曲线
Civitems mControlsItems; // 控制参数
Civitems mRulesItems; // 定义基于规则控制,根据状况的组合来修改管段。
Civitems mEnergyItems; // 定义计算水泵提升能量和成本的参数
Civitems mEmittersItems; // 将模拟节点定义为扩散器(喷嘴或者孔口)。
Civitems mQualityItems; // 定义节点的初始水质。
Civitems mDemandsItems; //定义连接节点的多模式需水,是对[JUNCTIONS]的补充。
Civitems mSourceItems; //定义水质源头的位置。
Civitems mReactionItems; //定义对应于管网中与化学成分反应的参数。
Civitems mMixingItems; // 确定控制蓄水池混合的模型。
Civitems mReportItems; //描述模拟生成的输出报表内容。
Civitems mOptionsItems; // 定义不同的模拟选项。
Civitems mCoordinatesItems; //
Civitems mVerticesItems; //将内部顶点赋值给管网管段。
Civitems mLabelsItems; // 给地图标签赋以坐标值。
Civitems mBackdropItems; // 标识管网地图的背景图像及其尺寸。
Civitems mTImesItems;//定义模拟中的各种事件时间步长参数。
};
......@@ -23,6 +23,11 @@ void CivNewInp::setQualityType(QualityAnalyType type, const std::string& quality
mQualityName = qualityName;
}
void CivNewInp::setDuration(int duration)
{
mDuration = duration;
}
bool CivNewInp::writeToFile(char* fileName)
{
// 检查是否存在值
......@@ -456,7 +461,15 @@ void CivNewInp::setTimes(const CivParameter& params)
{
CivParameter::ParamTable table = *iter;
writeStringFormat(table.name);
writeString(table.val);
if (mDuration >-1 && table.name == "Duration")
{
writeString(std::to_string(mDuration));
}
else
{
writeString(table.val);
}
}
writeString("");
}
......
......@@ -37,6 +37,7 @@ public:
管网组件
*/
void setQualityType(QualityAnalyType type,const std::string& qualityName);
void setDuration(int duration);
void setTtitle(const std::string& title);
void setNode(const CivNode& node);
void setPipes(const CivPipe& pipes);
......@@ -87,6 +88,8 @@ private:
std::ostringstream mTextStream;
QualityAnalyType mQualityType = ANALYSIS_AGE; //水质分析类型, 默认水龄
std::string mQualityName; // 追踪的节点名 或者化合物名
int mDuration = -1;
std::map<std::string, void (CivNewInp::*)(const CivParameter&)> mParamMap; // 参数类型映射
};
#endif // !CIVNEWINP_H
......
#include "CivTrackingAnalysis.h"
#include "CivSimulResultCache.h"
#include "CivHydrSimulation.h"
#include "CivGraphFactory.h"
CivTrackingAnalysis::CivTrackingAnalysis()
:mGraph(new ALGraph<CivGraphJunction, CivGraphEdage>())
{
}
CivTrackingAnalysis::~CivTrackingAnalysis()
{
delete mGraph;
}
bool CivTrackingAnalysis::createGraphFrom(CivDbConn* dbConn)
{
if (dbConn == nullptr)
return false;
CivHydrSimulation simulation;
simulation.registDb(dbConn);
if (!simulation.hdyrInstantSimulation())
return false;
NodeResultItems nodeItems;
LinkResultItems linkItems;
simulation.getDataByTime(0, nodeItems, linkItems);
if (nodeItems.size() <= 0)
return false;
// 顶点坐标
CivCoordinates coords;
dbConn->getCoordinates(coords);
std::list<CivCoordinates::CoordTable> coordTableLis = coords.mTables;
std::list<CivCoordinates::CoordTable>::iterator iter;
for (iter = coordTableLis.begin(); iter != coordTableLis.end(); iter++)
{
CivCoordinates::CoordTable coordTable = *iter;
// 插入顶点数据
CivGraphJunction graphJunction(coordTable.ID, coordTable.XCoord, coordTable.YCoord);
auto iter = nodeItems.find(coordTable.ID);
if (iter != nodeItems.end())
{
graphJunction.setHead(iter->second.dHead);
}
mGraph->insertAVertex(graphJunction);
}
// 管段
CivPipe civPipe;
dbConn->getPipe(civPipe);
std::list<CivPipe::PipesTable> pipesTableLis = civPipe.mTables;
std::list<CivPipe::PipesTable>::iterator pIter;
for (pIter = pipesTableLis.begin(); pIter != pipesTableLis.end(); pIter++)
{
CivPipe::PipesTable pipeTable = *pIter;
// 获取管段起点坐标
CivGraphJunction graphJunction1(pipeTable.Node1);
int index1 = mGraph->getVertexIndex(graphJunction1);
CivGraphJunction sStartjuction = mGraph->getData(index1);
// 获取管段终点坐标值
CivGraphJunction graphJunction2(pipeTable.Node2);
int index2 = mGraph->getVertexIndex(graphJunction2);
CivGraphJunction endJunction = mGraph->getData(index2);
if (sStartjuction.getHead() > endJunction.getHead())
{
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, { sStartjuction.getXCoord(),sStartjuction.getYCoord(),endJunction.getXCoord(),endJunction.getYCoord() });
mGraph->insertAEdge(sStartjuction, endJunction, edAge);
}
else
{
CivGraphEdage edAge(pipeTable.ID, pipeTable.Length, { endJunction.getXCoord(),endJunction.getYCoord(), sStartjuction.getXCoord(),sStartjuction.getYCoord() });
mGraph->insertAEdge(endJunction, sStartjuction, edAge);
}
}
return true;
}
bool CivTrackingAnalysis::transformJson(const std::vector<CivGraphJunction>& junctions,
const std::vector<CivGraphEdage>& pipes, std::string& jsonResult)
{
jsonResult.append("{\"node\":[");
// 节点
size_t juncTotal = junctions.size();
for (int i = 0; i < juncTotal; i++)
{
CivGraphJunction junction = junctions.at(i);
std::string sn = junction.getSn();
std::string xCoord = junction.getXCoord();
std::string yCoord = junction.getYCoord();
jsonResult.append("[");
jsonResult.append(sn);
jsonResult.append(",");
jsonResult.append(xCoord);
jsonResult.append(",");
jsonResult.append(yCoord);
jsonResult.append("],");
}
jsonResult = jsonResult.substr(0, jsonResult.length() - 1);
jsonResult.append("],\"pipes\":[");
// 管段
size_t pipesTotal = pipes.size();
for (int i = 0; i < pipesTotal; i++)
{
CivGraphEdage edge = pipes[i];
if (edge.getSN().empty())
continue;
jsonResult.append("[");
jsonResult.append(edge.getSN());
jsonResult.append(",");
jsonResult.append(edge.getLength());
jsonResult.append(",");
jsonResult.append(edge.getStartX());
jsonResult.append(",");
jsonResult.append(edge.getStartY());
jsonResult.append(",");
jsonResult.append(edge.getEndX());
jsonResult.append(",");
jsonResult.append(edge.getEndY());
jsonResult.append("],");
}
jsonResult = jsonResult.substr(0, jsonResult.length() - 1);
jsonResult.append("]}");
return true;
}
bool CivTrackingAnalysis::upstreamTracking(const std::string& sN, std::string& jsonResult)
{
std::vector<CivGraphJunction> junctions;
std::vector<CivGraphEdage> edges;
if (!upstreamTracking(sN, junctions, edges))
{
return false;
}
// 将查询到的信息拼接成字符串
if (!transformJson(junctions, edges, jsonResult))
{
return false;
}
return true;
}
bool CivTrackingAnalysis::downstreamTracking(const std::string& sN, std::string& jsonResult)
{
std::vector<CivGraphJunction> junctions;
std::vector<CivGraphEdage> edges;
if (!downstreamTracking(sN, junctions, edges))
{
return false;
}
// 将查询到的信息拼接成字符串
if (!transformJson(junctions, edges,jsonResult))
{
return false;
}
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)
{
// 上溯,图反向
ALGraph<CivGraphJunction, CivGraphEdage>* graph = mGraph->reverseGraph();
CivGraphJunction junction(sN);
graph->getVisitedResult(junction, junctions, pipes);
delete graph;
return true;
}
bool CivTrackingAnalysis::downstreamTracking(const std::string& sN,
std::vector<CivGraphJunction>& junctions,
std::vector<CivGraphEdage>& pipes)
{
CivGraphJunction junction(sN);
mGraph->getVisitedResult(junction, junctions, pipes);
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
......@@ -2,6 +2,7 @@
#include "CivHydDataType.h"
#include "CivGraphList.h"
#include "CivTrackingResultCache.h"
#include <vector>
#define ALGORITHMEXPORT __declspec(dllexport)
......@@ -37,11 +38,20 @@ public:
/**
*@brief 计算管网中某个水源所能供水的范围
*@param sN 水源的编号
*@param junctions jsonResult 结果字符串
*@param jsonResult 结果字符串
*/
bool waterSupplyScopeAnalysis(const std::string& sN, std::string& jsonResult);
private:
/**
*@brief 节点和管段集合信息转换成json字符串
*@param junctions 节点信息集合
*@param pipes 管段信息集合
*@param jsonResult 输出的结果字符串
*/
bool transformJson(const std::vector<CivGraphJunction>& junctions,
const std::vector<CivGraphEdage>& pipes, std::string& jsonResult);
/**
*@brief 追踪节点上游路径
*@param sN 节点本点号
......
......@@ -153,25 +153,28 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\pandaDbManager\CivCommonUtils.cpp" />
<ClCompile Include="CivHydrCalc.cpp" />
<ClCompile Include="CivGraphFactory.cpp" />
<ClCompile Include="CivHydDataType.cpp" />
<ClCompile Include="CivHydrFuncInter.cpp" />
<ClCompile Include="CivHydrSimulation.cpp" />
<ClCompile Include="CivInp.cpp" />
<ClCompile Include="CivBuilder.cpp" />
<ClCompile Include="CivInpDirector.cpp" />
<ClCompile Include="CivNewInp.cpp" />
<ClCompile Include="CivSimulResultCache.cpp" />
<ClCompile Include="CivTrackingAnalysis.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivHydrCalc.h" />
<ClInclude Include="CivGraphFactory.h" />
<ClInclude Include="CivGraphList.h" />
<ClInclude Include="CivHydDataType.h" />
<ClInclude Include="CivHydrFuncInter.h" />
<ClInclude Include="CivHydrSimulation.h" />
<ClInclude Include="CivInp.h" />
<ClInclude Include="CivBuilder.h" />
<ClInclude Include="CivInpDirector.h" />
<ClInclude Include="CivMiddlewareQuery.h" />
<ClInclude Include="CivNewInp.h" />
<ClInclude Include="CivSimulResultCache.h" />
<ClInclude Include="CivTrackingAnalysis.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -15,12 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="CivHydrCalc.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivInp.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivHydrFuncInter.cpp">
<Filter>源文件</Filter>
</ClCompile>
......@@ -42,14 +36,17 @@
<ClCompile Include="CivHydrSimulation.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivTrackingAnalysis.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivHydDataType.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="CivGraphFactory.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="CivHydrCalc.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivInp.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivHydrFuncInter.h">
<Filter>头文件</Filter>
</ClInclude>
......@@ -71,5 +68,17 @@
<ClInclude Include="CivHydrSimulation.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivTrackingAnalysis.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivGraphList.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivHydDataType.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="CivGraphFactory.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
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