fix invalid contract node

This commit is contained in:
xin.wang 2024-11-11 16:26:53 +08:00
parent 3614af7f64
commit 7542f1a64a
3 changed files with 19 additions and 10 deletions

View File

@ -13,6 +13,7 @@ namespace osrm::contractor
void search(ContractorHeap &heap, void search(ContractorHeap &heap,
const ContractorGraph &graph, const ContractorGraph &graph,
const std::vector<bool> &contractable,
const unsigned number_of_targets, const unsigned number_of_targets,
const int node_limit, const int node_limit,
const EdgeWeight weight_limit, const EdgeWeight weight_limit,

View File

@ -10,6 +10,7 @@ namespace
{ {
void relaxNode(ContractorHeap &heap, void relaxNode(ContractorHeap &heap,
const ContractorGraph &graph, const ContractorGraph &graph,
const std::vector<bool> &contractable,
const NodeID node, const NodeID node,
const EdgeWeight node_weight, const EdgeWeight node_weight,
const NodeID forbidden_node) const NodeID forbidden_node)
@ -34,6 +35,9 @@ void relaxNode(ContractorHeap &heap,
// New Node discovered -> Add to Heap + Node Info Storage // New Node discovered -> Add to Heap + Node Info Storage
if (!toHeapNode) if (!toHeapNode)
{ {
if (!contractable[to]) {
continue;
}
heap.Insert(to, to_weight, ContractorHeapData{current_hop, false}); heap.Insert(to, to_weight, ContractorHeapData{current_hop, false});
} }
// Found a shorter Path -> Update weight // Found a shorter Path -> Update weight
@ -49,6 +53,7 @@ void relaxNode(ContractorHeap &heap,
void search(ContractorHeap &heap, void search(ContractorHeap &heap,
const ContractorGraph &graph, const ContractorGraph &graph,
const std::vector<bool> &contractable,
const unsigned number_of_targets, const unsigned number_of_targets,
const int node_limit, const int node_limit,
const EdgeWeight weight_limit, const EdgeWeight weight_limit,
@ -80,7 +85,7 @@ void search(ContractorHeap &heap,
} }
} }
relaxNode(heap, graph, node, node_weight, forbidden_node); relaxNode(heap, graph, contractable, node, node_weight, forbidden_node);
} }
} }
} // namespace osrm::contractor } // namespace osrm::contractor

View File

@ -138,6 +138,7 @@ void ContractNode(ContractorThreadData *data,
const ContractorGraph &graph, const ContractorGraph &graph,
const NodeID node, const NodeID node,
std::vector<EdgeWeight> &node_weights, std::vector<EdgeWeight> &node_weights,
const std::vector<bool> &contractable,
ContractionStats *stats = nullptr) ContractionStats *stats = nullptr)
{ {
auto &heap = data->heap; auto &heap = data->heap;
@ -245,12 +246,12 @@ void ContractNode(ContractorThreadData *data,
if (RUNSIMULATION) if (RUNSIMULATION)
{ {
const int constexpr SIMULATION_SEARCH_SPACE_SIZE = 1000; const int constexpr SIMULATION_SEARCH_SPACE_SIZE = 1000;
search(heap, graph, number_of_targets, SIMULATION_SEARCH_SPACE_SIZE, max_weight, node); search(heap, graph, contractable, number_of_targets, SIMULATION_SEARCH_SPACE_SIZE, max_weight, node);
} }
else else
{ {
const int constexpr FULL_SEARCH_SPACE_SIZE = 2000; const int constexpr FULL_SEARCH_SPACE_SIZE = 2000;
search(heap, graph, number_of_targets, FULL_SEARCH_SPACE_SIZE, max_weight, node); search(heap, graph, contractable, number_of_targets, FULL_SEARCH_SPACE_SIZE, max_weight, node);
} }
for (auto out_edge : graph.GetAdjacentEdgeRange(node)) for (auto out_edge : graph.GetAdjacentEdgeRange(node))
{ {
@ -344,18 +345,20 @@ void ContractNode(ContractorThreadData *data,
void ContractNode(ContractorThreadData *data, void ContractNode(ContractorThreadData *data,
const ContractorGraph &graph, const ContractorGraph &graph,
const NodeID node, const NodeID node,
std::vector<EdgeWeight> &node_weights) std::vector<EdgeWeight> &node_weights,
const std::vector<bool> &contractable)
{ {
ContractNode<false>(data, graph, node, node_weights, nullptr); ContractNode<false>(data, graph, node, node_weights, contractable, nullptr);
} }
ContractionStats SimulateNodeContraction(ContractorThreadData *data, ContractionStats SimulateNodeContraction(ContractorThreadData *data,
const ContractorGraph &graph, const ContractorGraph &graph,
const NodeID node, const NodeID node,
std::vector<EdgeWeight> &node_weights) std::vector<EdgeWeight> &node_weights,
const std::vector<bool> &contractable)
{ {
ContractionStats stats; ContractionStats stats;
ContractNode<true>(data, graph, node, node_weights, &stats); ContractNode<true>(data, graph, node, node_weights, contractable, &stats);
return stats; return stats;
} }
@ -487,7 +490,7 @@ bool UpdateNodeNeighbours(ContractorNodeData &node_data,
if (node_data.contractable[u]) if (node_data.contractable[u])
{ {
node_data.priorities[u] = EvaluateNodePriority( node_data.priorities[u] = EvaluateNodePriority(
SimulateNodeContraction(data, graph, u, node_data.weights), node_data.depths[u]); SimulateNodeContraction(data, graph, u, node_data.weights, node_data.contractable), node_data.depths[u]);
} }
} }
return true; return true;
@ -627,7 +630,7 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
auto node = remaining_nodes[x].id; auto node = remaining_nodes[x].id;
BOOST_ASSERT(node_data.contractable[node]); BOOST_ASSERT(node_data.contractable[node]);
node_data.priorities[node] = EvaluateNodePriority( node_data.priorities[node] = EvaluateNodePriority(
SimulateNodeContraction(data, graph, node, node_data.weights), SimulateNodeContraction(data, graph, node, node_data.weights, node_data.contractable),
node_data.depths[node]); node_data.depths[node]);
} }
}); });
@ -688,7 +691,7 @@ std::vector<bool> contractGraph(ContractorGraph &graph,
for (auto position = range.begin(), end = range.end(); position != end; ++position) for (auto position = range.begin(), end = range.end(); position != end; ++position)
{ {
const NodeID node = remaining_nodes[position].id; const NodeID node = remaining_nodes[position].id;
ContractNode(data, graph, node, node_data.weights); ContractNode(data, graph, node, node_data.weights, node_data.contractable);
} }
}); });