Skip to content

Commit 7542f1a

Browse files
author
xin.wang
committed
fix invalid contract node
1 parent 3614af7 commit 7542f1a

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

include/contractor/contractor_search.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace osrm::contractor
1313

1414
void search(ContractorHeap &heap,
1515
const ContractorGraph &graph,
16+
const std::vector<bool> &contractable,
1617
const unsigned number_of_targets,
1718
const int node_limit,
1819
const EdgeWeight weight_limit,

src/contractor/contractor_search.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace
1010
{
1111
void relaxNode(ContractorHeap &heap,
1212
const ContractorGraph &graph,
13+
const std::vector<bool> &contractable,
1314
const NodeID node,
1415
const EdgeWeight node_weight,
1516
const NodeID forbidden_node)
@@ -34,6 +35,9 @@ void relaxNode(ContractorHeap &heap,
3435
// New Node discovered -> Add to Heap + Node Info Storage
3536
if (!toHeapNode)
3637
{
38+
if (!contractable[to]) {
39+
continue;
40+
}
3741
heap.Insert(to, to_weight, ContractorHeapData{current_hop, false});
3842
}
3943
// Found a shorter Path -> Update weight
@@ -49,6 +53,7 @@ void relaxNode(ContractorHeap &heap,
4953

5054
void search(ContractorHeap &heap,
5155
const ContractorGraph &graph,
56+
const std::vector<bool> &contractable,
5257
const unsigned number_of_targets,
5358
const int node_limit,
5459
const EdgeWeight weight_limit,
@@ -80,7 +85,7 @@ void search(ContractorHeap &heap,
8085
}
8186
}
8287

83-
relaxNode(heap, graph, node, node_weight, forbidden_node);
88+
relaxNode(heap, graph, contractable, node, node_weight, forbidden_node);
8489
}
8590
}
8691
} // namespace osrm::contractor

src/contractor/graph_contractor.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ void ContractNode(ContractorThreadData *data,
138138
const ContractorGraph &graph,
139139
const NodeID node,
140140
std::vector<EdgeWeight> &node_weights,
141+
const std::vector<bool> &contractable,
141142
ContractionStats *stats = nullptr)
142143
{
143144
auto &heap = data->heap;
@@ -245,12 +246,12 @@ void ContractNode(ContractorThreadData *data,
245246
if (RUNSIMULATION)
246247
{
247248
const int constexpr SIMULATION_SEARCH_SPACE_SIZE = 1000;
248-
search(heap, graph, number_of_targets, SIMULATION_SEARCH_SPACE_SIZE, max_weight, node);
249+
search(heap, graph, contractable, number_of_targets, SIMULATION_SEARCH_SPACE_SIZE, max_weight, node);
249250
}
250251
else
251252
{
252253
const int constexpr FULL_SEARCH_SPACE_SIZE = 2000;
253-
search(heap, graph, number_of_targets, FULL_SEARCH_SPACE_SIZE, max_weight, node);
254+
search(heap, graph, contractable, number_of_targets, FULL_SEARCH_SPACE_SIZE, max_weight, node);
254255
}
255256
for (auto out_edge : graph.GetAdjacentEdgeRange(node))
256257
{
@@ -344,18 +345,20 @@ void ContractNode(ContractorThreadData *data,
344345
void ContractNode(ContractorThreadData *data,
345346
const ContractorGraph &graph,
346347
const NodeID node,
347-
std::vector<EdgeWeight> &node_weights)
348+
std::vector<EdgeWeight> &node_weights,
349+
const std::vector<bool> &contractable)
348350
{
349-
ContractNode<false>(data, graph, node, node_weights, nullptr);
351+
ContractNode<false>(data, graph, node, node_weights, contractable, nullptr);
350352
}
351353

352354
ContractionStats SimulateNodeContraction(ContractorThreadData *data,
353355
const ContractorGraph &graph,
354356
const NodeID node,
355-
std::vector<EdgeWeight> &node_weights)
357+
std::vector<EdgeWeight> &node_weights,
358+
const std::vector<bool> &contractable)
356359
{
357360
ContractionStats stats;
358-
ContractNode<true>(data, graph, node, node_weights, &stats);
361+
ContractNode<true>(data, graph, node, node_weights, contractable, &stats);
359362
return stats;
360363
}
361364

@@ -487,7 +490,7 @@ bool UpdateNodeNeighbours(ContractorNodeData &node_data,
487490
if (node_data.contractable[u])
488491
{
489492
node_data.priorities[u] = EvaluateNodePriority(
490-
SimulateNodeContraction(data, graph, u, node_data.weights), node_data.depths[u]);
493+
SimulateNodeContraction(data, graph, u, node_data.weights, node_data.contractable), node_data.depths[u]);
491494
}
492495
}
493496
return true;
@@ -627,7 +630,7 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
627630
auto node = remaining_nodes[x].id;
628631
BOOST_ASSERT(node_data.contractable[node]);
629632
node_data.priorities[node] = EvaluateNodePriority(
630-
SimulateNodeContraction(data, graph, node, node_data.weights),
633+
SimulateNodeContraction(data, graph, node, node_data.weights, node_data.contractable),
631634
node_data.depths[node]);
632635
}
633636
});
@@ -688,7 +691,7 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
688691
for (auto position = range.begin(), end = range.end(); position != end; ++position)
689692
{
690693
const NodeID node = remaining_nodes[position].id;
691-
ContractNode(data, graph, node, node_data.weights);
694+
ContractNode(data, graph, node, node_data.weights, node_data.contractable);
692695
}
693696
});
694697

0 commit comments

Comments
 (0)