Skip to content

Commit

Permalink
[chinese] fixing server crash
Browse files Browse the repository at this point in the history
  • Loading branch information
cvvergara committed Nov 5, 2020
1 parent 554e202 commit 13923bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
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

0 comments on commit 13923bd

Please sign in to comment.