Skip to content

Commit

Permalink
attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshkaj committed Jan 26, 2018
1 parent 68f7948 commit 505fa89
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 12 deletions.
18 changes: 18 additions & 0 deletions include/engine/routing_algorithms/routing_base_ch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -231,6 +232,17 @@ void unpackPath(const DataFacade<Algorithm> &facade,
BidirectionalIterator packed_path_end,
Callback &&callback)
{
UnpackingStatistics unpacking_cache(0);
unpackPath(facade,packed_path_begin,packed_path_end, unpacking_cache, callback);
}
template <typename BidirectionalIterator, typename Callback>
void unpackPath(const DataFacade<Algorithm> &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;
Expand All @@ -244,10 +256,15 @@ void unpackPath(const DataFacade<Algorithm> &facade,
recursion_stack.emplace(*std::prev(current), *current);
}

std::cout << "I get here inside unpackPath to " << std::endl;
unpacking_cache.Print();
std::pair<NodeID, NodeID> 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)
Expand Down Expand Up @@ -295,6 +312,7 @@ void unpackPath(const FacadeT &facade,
const PhantomNodes &phantom_nodes,
std::vector<PathData> &unpacked_path)
{
std::cout << "RandomIter" << std::endl;
const auto nodes_number = std::distance(packed_path_begin, packed_path_end);
BOOST_ASSERT(nodes_number > 0);

Expand Down
5 changes: 5 additions & 0 deletions include/engine/search_engine_data.hpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -46,6 +47,7 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>

using SearchEngineHeapPtr = boost::thread_specific_ptr<QueryHeap>;
using ManyToManyHeapPtr = boost::thread_specific_ptr<ManyToManyQueryHeap>;
using UnpackingStatisticsPtr = boost::thread_specific_ptr<UnpackingStatistics>;

static SearchEngineHeapPtr forward_heap_1;
static SearchEngineHeapPtr reverse_heap_1;
Expand All @@ -54,6 +56,7 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>
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);

Expand All @@ -62,6 +65,8 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>
void InitializeOrClearThirdThreadLocalStorage(unsigned number_of_nodes);

void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes);

void InitializeOrClearUnpackingStatisticsThreadLocalStorage(unsigned number_of_nodes);
};

struct MultiLayerDijkstraHeapData
Expand Down
90 changes: 90 additions & 0 deletions include/engine/unpacking_statistics.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#ifndef UNPACKING_STATISTICS_HPP
#define UNPACKING_STATISTICS_HPP

#include "util/typedefs.hpp"

#include <utility>
#include <unordered_map>

namespace std
{
template<> struct hash<std::pair<NodeID, NodeID>>
{
typedef std::pair<NodeID, NodeID> argument_type;
typedef std::size_t result_type;
result_type operator()(argument_type const& pair) const noexcept
{
result_type const h1 ( std::hash<unsigned int>{}(pair.first) );
result_type const h2 ( std::hash<unsigned int>{}(pair.second) );
return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion)
}
};

}
namespace osrm
{
namespace engine
{
class UnpackingStatistics
{
std::pair<NodeID, NodeID> edge;
unsigned number_of_nodes;


std::unordered_map<std::pair<NodeID, NodeID>, 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<NodeID, NodeID> 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<NodeID, NodeID> 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<NodeID, NodeID> edge)
{
std::cout << "{" << edge.first << ", " << edge.second << "}" << std::endl;
}

void Print()
{
std::cout << "{I'm heeeear}" << std::endl;
}
};
} // engine
} // osrm

#endif // UNPACKING_STATISTICS_HPP
1 change: 1 addition & 0 deletions src/engine/routing_algorithms/direct_shortest_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ InternalRouteResult directShortestPathSearch(SearchEngineData<ch::Algorithm> &en
ch::unpackPath(facade,
packed_leg.begin(),
packed_leg.end(),
*engine_working_data.unpacking_cache.get(),
[&unpacked_nodes, &unpacked_edges](std::pair<NodeID, NodeID> &edge,
const auto &edge_id) {
BOOST_ASSERT(edge.first == unpacked_nodes.back());
Expand Down
22 changes: 10 additions & 12 deletions src/engine/routing_algorithms/many_to_many_ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ std::vector<EdgeDuration> manyToManySearch(SearchEngineData<ch::Algorithm> &engi
std::vector<EdgeWeight> weights_table(number_of_entries, INVALID_EDGE_WEIGHT);
std::vector<EdgeDuration> 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]];
Expand All @@ -185,25 +188,20 @@ std::vector<EdgeDuration> manyToManySearch(SearchEngineData<ch::Algorithm> &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<NodeBucket> search_space_with_buckets;

// Populate buckets with paths from all accessible nodes to destinations via backward searches
Expand Down
13 changes: 13 additions & 0 deletions src/engine/search_engine_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_2;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::forward_heap_3;
SearchEngineData<CH>::SearchEngineHeapPtr SearchEngineData<CH>::reverse_heap_3;
SearchEngineData<CH>::ManyToManyHeapPtr SearchEngineData<CH>::many_to_many_heap;
SearchEngineData<CH>::UnpackingStatisticsPtr SearchEngineData<CH>::unpacking_cache;

void SearchEngineData<CH>::InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes)
{
Expand Down Expand Up @@ -90,6 +91,18 @@ void SearchEngineData<CH>::InitializeOrClearManyToManyThreadLocalStorage(unsigne
}
}

void SearchEngineData<CH>::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<MLD>::SearchEngineHeapPtr SearchEngineData<MLD>::forward_heap_1;
Expand Down

0 comments on commit 505fa89

Please sign in to comment.