From 7542f1a64aed3e20e040f930a29de91eace2110f Mon Sep 17 00:00:00 2001 From: "xin.wang" Date: Mon, 11 Nov 2024 16:26:53 +0800 Subject: [PATCH] fix invalid contract node --- include/contractor/contractor_search.hpp | 1 + src/contractor/contractor_search.cpp | 7 ++++++- src/contractor/graph_contractor.cpp | 21 ++++++++++++--------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/include/contractor/contractor_search.hpp b/include/contractor/contractor_search.hpp index 2adcf212d04..6911a44bb2c 100644 --- a/include/contractor/contractor_search.hpp +++ b/include/contractor/contractor_search.hpp @@ -13,6 +13,7 @@ namespace osrm::contractor void search(ContractorHeap &heap, const ContractorGraph &graph, + const std::vector &contractable, const unsigned number_of_targets, const int node_limit, const EdgeWeight weight_limit, diff --git a/src/contractor/contractor_search.cpp b/src/contractor/contractor_search.cpp index 6fa860f46b0..8226e513f37 100644 --- a/src/contractor/contractor_search.cpp +++ b/src/contractor/contractor_search.cpp @@ -10,6 +10,7 @@ namespace { void relaxNode(ContractorHeap &heap, const ContractorGraph &graph, + const std::vector &contractable, const NodeID node, const EdgeWeight node_weight, const NodeID forbidden_node) @@ -34,6 +35,9 @@ void relaxNode(ContractorHeap &heap, // New Node discovered -> Add to Heap + Node Info Storage if (!toHeapNode) { + if (!contractable[to]) { + continue; + } heap.Insert(to, to_weight, ContractorHeapData{current_hop, false}); } // Found a shorter Path -> Update weight @@ -49,6 +53,7 @@ void relaxNode(ContractorHeap &heap, void search(ContractorHeap &heap, const ContractorGraph &graph, + const std::vector &contractable, const unsigned number_of_targets, const int node_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 diff --git a/src/contractor/graph_contractor.cpp b/src/contractor/graph_contractor.cpp index 9bee894b253..c449590d405 100644 --- a/src/contractor/graph_contractor.cpp +++ b/src/contractor/graph_contractor.cpp @@ -138,6 +138,7 @@ void ContractNode(ContractorThreadData *data, const ContractorGraph &graph, const NodeID node, std::vector &node_weights, + const std::vector &contractable, ContractionStats *stats = nullptr) { auto &heap = data->heap; @@ -245,12 +246,12 @@ void ContractNode(ContractorThreadData *data, if (RUNSIMULATION) { 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 { 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)) { @@ -344,18 +345,20 @@ void ContractNode(ContractorThreadData *data, void ContractNode(ContractorThreadData *data, const ContractorGraph &graph, const NodeID node, - std::vector &node_weights) + std::vector &node_weights, + const std::vector &contractable) { - ContractNode(data, graph, node, node_weights, nullptr); + ContractNode(data, graph, node, node_weights, contractable, nullptr); } ContractionStats SimulateNodeContraction(ContractorThreadData *data, const ContractorGraph &graph, const NodeID node, - std::vector &node_weights) + std::vector &node_weights, + const std::vector &contractable) { ContractionStats stats; - ContractNode(data, graph, node, node_weights, &stats); + ContractNode(data, graph, node, node_weights, contractable, &stats); return stats; } @@ -487,7 +490,7 @@ bool UpdateNodeNeighbours(ContractorNodeData &node_data, if (node_data.contractable[u]) { 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; @@ -627,7 +630,7 @@ std::vector contractGraph(ContractorGraph &graph, auto node = remaining_nodes[x].id; BOOST_ASSERT(node_data.contractable[node]); 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]); } }); @@ -688,7 +691,7 @@ std::vector contractGraph(ContractorGraph &graph, for (auto position = range.begin(), end = range.end(); position != end; ++position) { const NodeID node = remaining_nodes[position].id; - ContractNode(data, graph, node, node_data.weights); + ContractNode(data, graph, node, node_data.weights, node_data.contractable); } });