Skip to content

Commit

Permalink
accurate stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoshkaj committed Jan 29, 2018
1 parent 2eb82f8 commit 9ca8415
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
8 changes: 4 additions & 4 deletions include/engine/routing_algorithms/routing_base_ch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void unpackPath(const DataFacade<Algorithm> &facade,
BidirectionalIterator packed_path_end,
Callback &&callback)
{
UnpackingStatistics unpacking_cache(0);
UnpackingStatistics unpacking_cache;
unpackPath(facade, packed_path_begin, packed_path_end, unpacking_cache, callback);
}
template <typename BidirectionalIterator, typename Callback>
Expand Down Expand Up @@ -264,13 +264,13 @@ void unpackPath(const DataFacade<Algorithm> &facade,
if (!std::get<2>(edge))
{

if (unpacking_cache.EdgeInCache(std::make_pair(std::get<0>(edge), std::get<1>(edge))))
if (unpacking_cache.IsEdgeInCache(std::make_pair(std::get<0>(edge), std::get<1>(edge))))
{
std::get<2>(edge) = true;
}

if (!std::get<2>(edge))
unpacking_cache.CollectStats(std::make_pair(std::get<0>(edge), std::get<1>(edge)));
// if (!std::get<2>(edge))
unpacking_cache.CollectStats(std::make_pair(std::get<0>(edge), std::get<1>(edge)));
}

// Look for an edge on the forward CH graph (.forward)
Expand Down
2 changes: 1 addition & 1 deletion include/engine/search_engine_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>

void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes);

void InitializeOrClearUnpackingStatisticsThreadLocalStorage(unsigned number_of_nodes);
void InitializeOrClearUnpackingStatisticsThreadLocalStorage();
};

struct MultiLayerDijkstraHeapData
Expand Down
35 changes: 15 additions & 20 deletions include/engine/unpacking_statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,13 @@ 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)) {}
UnpackingStatistics() : number_of_lookups(0), number_of_finds(0), number_of_misses(0) {}

void Clear()
{
Expand All @@ -52,7 +43,17 @@ class UnpackingStatistics
number_of_misses = 0;
}

bool EdgeInCache(std::pair<NodeID, NodeID> edge) { return cache.find(edge) != cache.end(); }
bool IsEdgeInCache(std::pair<NodeID, NodeID> edge)
{
++number_of_lookups;
bool edge_is_in_cache = cache.find(edge) != cache.end();
// if (edge_is_in_cache) {
// std::cout << edge.first << ", " << edge.second << " true" << std::endl;
// } else {
// std::cout << edge.first << ", " << edge.second << " false" << std::endl;
// }
return edge_is_in_cache;
}

void CollectStats(std::pair<NodeID, NodeID> edge)
{
Expand All @@ -65,8 +66,6 @@ class UnpackingStatistics
// - 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;
Expand All @@ -84,13 +83,9 @@ class UnpackingStatistics
<< " Total Lookups: " << number_of_lookups << std::endl;
}

void PrintEdgeLookups(std::pair<NodeID, NodeID> edge)
{
if (cache.find(edge) == cache.end())
{
}
std::cout << "{I'm heeeear}" << std::endl;
}
// void PrintEdgeLookups(std::pair<NodeID, NodeID> edge)
// {
// }
};
} // engine
} // osrm
Expand Down
3 changes: 1 addition & 2 deletions src/engine/routing_algorithms/many_to_many_ch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ 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());
engine_working_data.InitializeOrClearUnpackingStatisticsThreadLocalStorage();

for (std::uint32_t column_idx = 0; column_idx < number_of_targets; ++column_idx)
{
Expand Down
5 changes: 2 additions & 3 deletions src/engine/search_engine_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,15 @@ void SearchEngineData<CH>::InitializeOrClearManyToManyThreadLocalStorage(unsigne
}
}

void SearchEngineData<CH>::InitializeOrClearUnpackingStatisticsThreadLocalStorage(
unsigned number_of_nodes)
void SearchEngineData<CH>::InitializeOrClearUnpackingStatisticsThreadLocalStorage()
{
if (unpacking_cache.get())
{
unpacking_cache->Clear();
}
else
{
unpacking_cache.reset(new UnpackingStatistics(number_of_nodes));
unpacking_cache.reset(new UnpackingStatistics());
}
}

Expand Down

0 comments on commit 9ca8415

Please sign in to comment.