diff --git a/include/engine/routing_algorithms/routing_base_ch.hpp b/include/engine/routing_algorithms/routing_base_ch.hpp index 5ecbc6b2928..b655437b4d1 100644 --- a/include/engine/routing_algorithms/routing_base_ch.hpp +++ b/include/engine/routing_algorithms/routing_base_ch.hpp @@ -5,6 +5,7 @@ #include "engine/datafacade.hpp" #include "engine/routing_algorithms/routing_base.hpp" #include "engine/search_engine_data.hpp" +#include "engine/unpacking_statistics.hpp" #include "util/typedefs.hpp" @@ -231,6 +232,17 @@ void unpackPath(const DataFacade &facade, BidirectionalIterator packed_path_end, Callback &&callback) { + UnpackingStatistics unpacking_cache(0); + unpackPath(facade,packed_path_begin,packed_path_end, unpacking_cache, callback); +} +template +void unpackPath(const DataFacade &facade, + BidirectionalIterator packed_path_begin, + BidirectionalIterator packed_path_end, + UnpackingStatistics &unpacking_cache, + Callback &&callback) +{ + std::cout << "BidirectionalIterator" << std::endl; // make sure we have at least something to unpack if (packed_path_begin == packed_path_end) return; @@ -244,10 +256,15 @@ void unpackPath(const DataFacade &facade, recursion_stack.emplace(*std::prev(current), *current); } + std::cout << "I get here inside unpackPath to " << std::endl; + unpacking_cache.Print(); std::pair edge; while (!recursion_stack.empty()) { edge = recursion_stack.top(); + std::cout<<"inside the recursion stack loop"; + unpacking_cache.CollectStats(edge); + //unpacking_cache.contains(edge) ? increase edge count (hit) : miss recursion_stack.pop(); // Look for an edge on the forward CH graph (.forward) @@ -295,6 +312,7 @@ void unpackPath(const FacadeT &facade, const PhantomNodes &phantom_nodes, std::vector &unpacked_path) { + std::cout << "RandomIter" << std::endl; const auto nodes_number = std::distance(packed_path_begin, packed_path_end); BOOST_ASSERT(nodes_number > 0); diff --git a/include/engine/search_engine_data.hpp b/include/engine/search_engine_data.hpp index 060599eb740..b828e2e6ed6 100644 --- a/include/engine/search_engine_data.hpp +++ b/include/engine/search_engine_data.hpp @@ -1,6 +1,7 @@ #ifndef SEARCH_ENGINE_DATA_HPP #define SEARCH_ENGINE_DATA_HPP +#include "engine/unpacking_statistics.hpp" #include "engine/algorithm.hpp" #include "util/query_heap.hpp" #include "util/typedefs.hpp" @@ -46,6 +47,7 @@ template <> struct SearchEngineData using SearchEngineHeapPtr = boost::thread_specific_ptr; using ManyToManyHeapPtr = boost::thread_specific_ptr; + using UnpackingStatisticsPtr = boost::thread_specific_ptr; static SearchEngineHeapPtr forward_heap_1; static SearchEngineHeapPtr reverse_heap_1; @@ -54,6 +56,7 @@ template <> struct SearchEngineData static SearchEngineHeapPtr forward_heap_3; static SearchEngineHeapPtr reverse_heap_3; static ManyToManyHeapPtr many_to_many_heap; + static UnpackingStatisticsPtr unpacking_cache; void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes); @@ -62,6 +65,8 @@ template <> struct SearchEngineData void InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes); void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes); + + void InitializeOrClearUnpackingStatisticsThreadLocalStorage(unsigned number_of_nodes); }; struct MultiLayerDijkstraHeapData diff --git a/include/engine/unpacking_statistics.hpp b/include/engine/unpacking_statistics.hpp new file mode 100644 index 00000000000..e5aa14c4e01 --- /dev/null +++ b/include/engine/unpacking_statistics.hpp @@ -0,0 +1,90 @@ +#ifndef UNPACKING_STATISTICS_HPP +#define UNPACKING_STATISTICS_HPP + +#include "util/typedefs.hpp" + +#include +#include + +namespace std +{ + template<> struct hash> + { + typedef std::pair argument_type; + typedef std::size_t result_type; + result_type operator()(argument_type const& pair) const noexcept + { + result_type const h1 ( std::hash{}(pair.first) ); + result_type const h2 ( std::hash{}(pair.second) ); + return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion) + } + }; + +} +namespace osrm +{ +namespace engine +{ +class UnpackingStatistics +{ + std::pair edge; + unsigned number_of_nodes; + + + std::unordered_map, int> cache; + int number_of_lookups; + int number_of_finds; + int number_of_misses; + + public: + UnpackingStatistics(unsigned number_of_nodes) : + number_of_nodes(number_of_nodes), number_of_lookups(0), number_of_finds(0), number_of_misses(0) {} + // UnpackingStatistics(std::pair edge) : edge(edge) {} + + // UnpackingStatistics() : edge(std::make_pair(SPECIAL_NODEID, SPECIAL_NODEID)) {} + + void Clear() + { + cache.clear(); + number_of_lookups = 0; + number_of_finds = 0; + number_of_misses = 0; + } + + void CollectStats(std::pair edge) + { + + // check if edge is in the map + // if edge is in the map : + // - increment number_of_lookups, number_of_finds + // - update cache with edge:number_of_times to edge:number_of_times++ + // if edge is not in map: + // - increment number_of_lookups, number_of_misses + // - insert edge into map with value 1 + + number_of_lookups = number_of_lookups + 1; + + if (cache.find(edge) == cache.end()) { + ++number_of_misses; + } else { + ++number_of_finds; + } + ++cache[edge]; + + std::cout << "Misses :" << number_of_misses << " Finds: " << number_of_finds << " Total Lookups So Far: " << number_of_lookups << std::endl; + } + + void Print(std::pair edge) + { + std::cout << "{" << edge.first << ", " << edge.second << "}" << std::endl; + } + + void Print() + { + std::cout << "{I'm heeeear}" << std::endl; + } +}; +} // engine +} // osrm + +#endif // UNPACKING_STATISTICS_HPP \ No newline at end of file diff --git a/src/engine/routing_algorithms/direct_shortest_path.cpp b/src/engine/routing_algorithms/direct_shortest_path.cpp index 7ba552aeb6f..fe753113e02 100644 --- a/src/engine/routing_algorithms/direct_shortest_path.cpp +++ b/src/engine/routing_algorithms/direct_shortest_path.cpp @@ -53,6 +53,7 @@ InternalRouteResult directShortestPathSearch(SearchEngineData &en ch::unpackPath(facade, packed_leg.begin(), packed_leg.end(), + *engine_working_data.unpacking_cache.get(), [&unpacked_nodes, &unpacked_edges](std::pair &edge, const auto &edge_id) { BOOST_ASSERT(edge.first == unpacked_nodes.back()); diff --git a/src/engine/routing_algorithms/many_to_many_ch.cpp b/src/engine/routing_algorithms/many_to_many_ch.cpp index 44ecc281f27..8f341bd3b8c 100644 --- a/src/engine/routing_algorithms/many_to_many_ch.cpp +++ b/src/engine/routing_algorithms/many_to_many_ch.cpp @@ -169,6 +169,9 @@ std::vector manyToManySearch(SearchEngineData &engi std::vector weights_table(number_of_entries, INVALID_EDGE_WEIGHT); std::vector durations_table(number_of_entries, MAXIMAL_EDGE_DURATION); + engine_working_data.InitializeOrClearUnpackingStatisticsThreadLocalStorage( + facade.GetNumberOfNodes()); + for (std::uint32_t column_idx = 0; column_idx < number_of_targets; ++column_idx) { const auto &target = phantom_nodes[target_indices[column_idx]]; @@ -185,25 +188,20 @@ std::vector manyToManySearch(SearchEngineData &engi std::cout << " row_idx: " << row_idx << std::endl; std::cout << " source: " << source << std::endl; std::cout << " target: " << target << std::endl; - std::cout << " weight: " << result.shortest_path_weight << std::endl; - std::cout << " duration: " << result.duration() <<"\n" << std::endl << std::endl; + std::cout << " row_idx * number_of_targets + column_idx: " << row_idx * number_of_targets + column_idx << std::endl; + std::cout << " number_of_entries: " << number_of_entries << std::endl; weights_table[row_idx * number_of_targets + column_idx] = result.shortest_path_weight; durations_table[row_idx * number_of_targets + column_idx] = result.duration(); - // weights_table.emplace_back(result.shortest_path_weight); - // durations_table.emplace_back(result.duration()); - - -// targets 0 1 2 3 4 5 -// sources 0 0 1 2 3 4 5 -// 1 6 7 8 9 10 11 -// 2 -// 3 -// 4 } } + for (auto i = 0; i < number_of_entries; ++i) { + weights_table[i] = INVALID_EDGE_WEIGHT; + durations_table[i] = MAXIMAL_EDGE_DURATION; + } + std::vector search_space_with_buckets; // Populate buckets with paths from all accessible nodes to destinations via backward searches diff --git a/src/engine/search_engine_data.cpp b/src/engine/search_engine_data.cpp index 0069db56bbd..ad557864f1d 100644 --- a/src/engine/search_engine_data.cpp +++ b/src/engine/search_engine_data.cpp @@ -14,6 +14,7 @@ SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_2; SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_3; SearchEngineData::SearchEngineHeapPtr SearchEngineData::reverse_heap_3; SearchEngineData::ManyToManyHeapPtr SearchEngineData::many_to_many_heap; +SearchEngineData::UnpackingStatisticsPtr SearchEngineData::unpacking_cache; void SearchEngineData::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes) { @@ -90,6 +91,18 @@ void SearchEngineData::InitializeOrClearManyToManyThreadLocalStorage(unsigne } } +void SearchEngineData::InitializeOrClearUnpackingStatisticsThreadLocalStorage(unsigned number_of_nodes) +{ + if (unpacking_cache.get()) + { + unpacking_cache->Clear(); + } + else + { + unpacking_cache.reset(new UnpackingStatistics(number_of_nodes)); + } +} + // MLD using MLD = routing_algorithms::mld::Algorithm; SearchEngineData::SearchEngineHeapPtr SearchEngineData::forward_heap_1;