Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chinese] fixing server crash on 3.0 #1723

Merged
merged 1 commit into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions include/chinese/pgr_chinesePostman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,22 @@ class PgrDirectedChPPGraph {
const pgr_edge_t *dataEdges,
const size_t totalEdges);

double DirectedChPP() {
try {
pgrouting::graph::PgrCostFlowGraph digraph1(edges, sources, targets);
auto minAddedCost = digraph1.MinCostMaxFlow();
auto maxFlow = digraph1.GetMaxFlow();
m_cost = (maxFlow == totalDeg)? minAddedCost + totalCost : -1.0;
} catch (...) {
return m_cost = -1;
}
double DirectedChPP() const {
return m_cost;
}

std::vector<General_path_element_t> GetPathEdges();
std::vector<General_path_element_t> GetPathEdges() const {
return resultPath;
}

~PgrDirectedChPPGraph();


private:
bool EulerCircuitDFS(int64_t p);
void BuildResultGraph();
void BuildResultPath();
void setPathEdges(graph::PgrCostFlowGraph &flowGraph);

private:
int64_t totalDeg;
Expand Down Expand Up @@ -104,7 +100,6 @@ class PgrDirectedChPPGraph {
std::vector<pgr_costFlow_t> edges;
std::set<int64_t> sources;
std::set<int64_t> targets;
graph::PgrCostFlowGraph flowGraph;
};

PgrDirectedChPPGraph::~PgrDirectedChPPGraph() {
Expand Down Expand Up @@ -210,16 +205,25 @@ PgrDirectedChPPGraph::PgrDirectedChPPGraph(
edges.push_back(edge);
}

PgrCostFlowGraph graph(edges, sources, targets);
flowGraph = graph;
PgrCostFlowGraph flowGraph(edges, sources, targets);
pgassert(pathStack.empty());
try {
pgrouting::graph::PgrCostFlowGraph digraph1(edges, sources, targets);
auto minAddedCost = digraph1.MinCostMaxFlow();
auto maxFlow = digraph1.GetMaxFlow();
m_cost = (maxFlow == totalDeg)? minAddedCost + totalCost : -1.0;
} catch (...) {
m_cost = -1;
}
setPathEdges(flowGraph);
}


std::vector<General_path_element_t>
PgrDirectedChPPGraph::GetPathEdges() {
void
PgrDirectedChPPGraph::setPathEdges(graph::PgrCostFlowGraph &flowGraph) {
pgassert(pathStack.empty());
if (m_cost == -1) return std::vector<General_path_element_t>();
resultPath.clear();
if (m_cost == -1) return;
// catch new edges
try {
flowGraph.MinCostMaxFlow();
Expand All @@ -236,7 +240,8 @@ PgrDirectedChPPGraph::GetPathEdges() {
}
}
} catch (...) {
return std::vector<General_path_element_t>();
resultPath.clear();
return;
}

pgassert(pathStack.empty());
Expand All @@ -249,14 +254,15 @@ PgrDirectedChPPGraph::GetPathEdges() {
EulerCircuitDFS(startPoint);

if (!(vertices - vertexVisited).empty()) {
return std::vector<General_path_element_t>();
resultPath.clear();
return;
}
pgassert(!pathStack.empty());

BuildResultPath();


return resultPath;
return;
}

void
Expand Down
2 changes: 1 addition & 1 deletion include/max_flow/pgr_minCostMaxFlow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PgrCostFlowGraph {
return boost::find_flow_cost(graph);
}

PgrCostFlowGraph() = default;
PgrCostFlowGraph() = delete;

PgrCostFlowGraph(
const std::vector<pgr_costFlow_t> &edges,
Expand Down