Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a8e52b6af9 | |||
| edd9dcca47 | |||
| ecbaabc15f | |||
| f909d89381 | |||
| 36d91d61d7 | |||
| 5769d0d46e | |||
| da6d08e759 | |||
| 44056eda0b | |||
| d76d5e7d5f | |||
| ed49564e27 | |||
| fe339b385c | |||
| 5fc269c50a | |||
| 6f2b8f44d0 | |||
| 2e2ce1d421 | |||
| 4a34c86544 | |||
| 2b38c936d5 | |||
| b577558980 | |||
| f1ce2e6384 |
+601
-590
File diff suppressed because it is too large
Load Diff
@@ -116,8 +116,8 @@ class CellCustomizer
|
||||
const std::vector<bool> &allowed_nodes,
|
||||
CellMetric &metric) const
|
||||
{
|
||||
const auto number_of_nodes = graph.GetNumberOfNodes();
|
||||
HeapPtr heaps([number_of_nodes] { return Heap{number_of_nodes}; });
|
||||
Heap heap_exemplar(graph.GetNumberOfNodes());
|
||||
HeapPtr heaps(heap_exemplar);
|
||||
|
||||
for (std::size_t level = 1; level < partition.GetNumberOfLevels(); ++level)
|
||||
{
|
||||
|
||||
@@ -460,6 +460,19 @@ void search(SearchEngineData<Algorithm> &engine_working_data,
|
||||
duration_upper_bound);
|
||||
}
|
||||
|
||||
inline std::vector<double> getNetworkDistances(
|
||||
SearchEngineData<Algorithm> &,
|
||||
const DataFacade<ch::Algorithm> &,
|
||||
SearchEngineData<Algorithm>::QueryHeap &,
|
||||
const std::vector<std::unique_ptr<typename SearchEngineData<Algorithm>::QueryHeap>> &,
|
||||
const PhantomNode &,
|
||||
const std::vector<PhantomNode> &,
|
||||
EdgeWeight /*duration_upper_bound*/ = INVALID_EDGE_WEIGHT)
|
||||
{
|
||||
std::vector<double> distances;
|
||||
return distances;
|
||||
}
|
||||
|
||||
// Requires the heaps for be empty
|
||||
// If heaps should be adjusted to be initialized outside of this function,
|
||||
// the addition of force_step parameters might be required
|
||||
|
||||
@@ -38,10 +38,13 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
|
||||
return INVALID_LEVEL_ID;
|
||||
};
|
||||
|
||||
return std::min(std::min(level(source.forward_segment_id, target.forward_segment_id),
|
||||
level(source.forward_segment_id, target.reverse_segment_id)),
|
||||
std::min(level(source.reverse_segment_id, target.forward_segment_id),
|
||||
level(source.reverse_segment_id, target.reverse_segment_id)));
|
||||
auto res = std::min(std::min(level(source.forward_segment_id, target.forward_segment_id),
|
||||
level(source.forward_segment_id, target.reverse_segment_id)),
|
||||
std::min(level(source.reverse_segment_id, target.forward_segment_id),
|
||||
level(source.reverse_segment_id, target.reverse_segment_id)));
|
||||
|
||||
// std::cerr << "OLD!!! " << (int)res << std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename MultiLevelPartition>
|
||||
@@ -92,6 +95,7 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
|
||||
getNodeQueryLevel(partition, node, source, target));
|
||||
}));
|
||||
});
|
||||
// std::cerr << "NEW " << (int)min_level << std::endl;
|
||||
return min_level;
|
||||
}
|
||||
|
||||
@@ -140,6 +144,8 @@ inline LevelID getNodeQueryLevel(const MultiLevelPartition &partition,
|
||||
highest_different_level(phantom_node.reverse_segment_id));
|
||||
return std::min(current_level, highest_level);
|
||||
});
|
||||
|
||||
// std::cerr << "NEW!!! " << (int)node_level << std::endl;
|
||||
return node_level;
|
||||
}
|
||||
|
||||
@@ -300,7 +306,6 @@ void relaxOutgoingEdges(const DataFacade<Algorithm> &facade,
|
||||
const auto &metric = facade.GetCellMetric();
|
||||
|
||||
const auto level = getNodeQueryLevel(partition, heapNode.node, args...);
|
||||
|
||||
static constexpr auto IS_MAP_MATCHING =
|
||||
std::is_same_v<typename SearchEngineData<mld::Algorithm>::MapMatchingQueryHeap, Heap>;
|
||||
|
||||
@@ -457,6 +462,15 @@ void routingStep(const DataFacade<Algorithm> &facade,
|
||||
|
||||
BOOST_ASSERT(!facade.ExcludeNode(heapNode.node));
|
||||
|
||||
if (DIRECTION == FORWARD_DIRECTION)
|
||||
{
|
||||
// std::cerr << "FORWARDO " << heapNode.node << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// std::cerr << "REVERSEO " << heapNode.node << std::endl;
|
||||
}
|
||||
|
||||
// Upper bound for the path source -> target with
|
||||
// weight(source -> node) = weight weight(to -> target) ≤ reverse_weight
|
||||
// is weight + reverse_weight
|
||||
@@ -644,6 +658,7 @@ searchDistance(SearchEngineData<Algorithm> &,
|
||||
|
||||
auto [middle, _] = *searchResult;
|
||||
|
||||
// std::cerr << "old " << middle << std::endl;
|
||||
auto distance = forward_heap.GetData(middle).distance + reverse_heap.GetData(middle).distance;
|
||||
|
||||
return distance;
|
||||
@@ -763,6 +778,307 @@ double getNetworkDistance(SearchEngineData<Algorithm> &engine_working_data,
|
||||
return from_alias<double>(distance);
|
||||
}
|
||||
|
||||
|
||||
template <typename Algorithm, typename Heap>
|
||||
std::vector<NodeID>
|
||||
runSearch2(const DataFacade<Algorithm> &facade,
|
||||
Heap &forward_heap,
|
||||
const std::vector<std::unique_ptr<Heap>> &reverse_heap,
|
||||
size_t candidatesCount,
|
||||
const std::vector<NodeID> &force_step_nodes,
|
||||
EdgeWeight weight_upper_bound,
|
||||
const PhantomEndpointCandidates &candidates)
|
||||
{
|
||||
// if (forward_heap.Empty() || reverse_heap.Empty())
|
||||
// {
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// BOOST_ASSERT(!forward_heap.Empty() && forward_heap.MinKey() < INVALID_EDGE_WEIGHT);
|
||||
// BOOST_ASSERT(!reverse_heap.Empty() && reverse_heap.MinKey() < INVALID_EDGE_WEIGHT);
|
||||
|
||||
std::vector<NodeID> middles;
|
||||
std::vector<EdgeWeight> weights;
|
||||
|
||||
middles.resize(candidatesCount, SPECIAL_NODEID);
|
||||
weights.resize(candidatesCount, weight_upper_bound);
|
||||
|
||||
// run two-Target Dijkstra routing step.
|
||||
EdgeWeight forward_heap_min = forward_heap.MinKey();
|
||||
std::vector<EdgeWeight> reverse_heap_mins;
|
||||
for (size_t i = 0; i < candidatesCount; ++i)
|
||||
{
|
||||
reverse_heap_mins.push_back(reverse_heap[i]->MinKey());
|
||||
}
|
||||
|
||||
auto shouldContinue = [&]()
|
||||
{
|
||||
bool cont = false;
|
||||
for (size_t i = 0; i < candidatesCount; ++i)
|
||||
{
|
||||
if ((forward_heap.Size() + reverse_heap[i]->Size() > 0) &&
|
||||
(forward_heap_min + reverse_heap_mins[i]) < weights[i])
|
||||
{
|
||||
cont = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return cont;
|
||||
};
|
||||
|
||||
bool cont = shouldContinue();
|
||||
while (cont)
|
||||
{
|
||||
if (!forward_heap.Empty())
|
||||
{
|
||||
const auto heapNode = forward_heap.DeleteMinGetHeapNode();
|
||||
// std::cerr << "FORWARDN " << heapNode.node << std::endl;
|
||||
// auto heapNode = routingStep2<FORWARD_DIRECTION>(facade, forward_heap, args...);
|
||||
|
||||
for (size_t i = 0; i < candidatesCount; ++i)
|
||||
{
|
||||
auto &rh = reverse_heap[i];
|
||||
const auto reverseHeapNode = rh->GetHeapNodeIfWasInserted(heapNode.node);
|
||||
if (reverseHeapNode)
|
||||
{
|
||||
auto reverse_weight = reverseHeapNode->weight;
|
||||
auto path_weight = heapNode.weight + reverse_weight;
|
||||
|
||||
if (!shouldForceStep(force_step_nodes, heapNode, *reverseHeapNode) &&
|
||||
(path_weight >= EdgeWeight{0}) && (path_weight < weights[i]))
|
||||
{
|
||||
middles[i] = heapNode.node;
|
||||
weights[i] = path_weight;
|
||||
|
||||
// auto distance =
|
||||
// forward_heap.GetData(middles[i]).distance +
|
||||
// reverse_heap[i]->GetData(middles[i]).distance;
|
||||
// std::cerr << "RFOUNDN " << i <<" " << distance << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
relaxOutgoingEdges<FORWARD_DIRECTION>(facade, forward_heap, heapNode, candidates);
|
||||
|
||||
if (!forward_heap.Empty())
|
||||
forward_heap_min = forward_heap.MinKey();
|
||||
}
|
||||
|
||||
cont = false;
|
||||
for (size_t i = 0; i < candidatesCount; ++i)
|
||||
{
|
||||
if ((forward_heap.Size() + reverse_heap[i]->Size() > 0) &&
|
||||
(forward_heap_min + reverse_heap_mins[i]) < weights[i])
|
||||
{
|
||||
cont = true;
|
||||
}
|
||||
if (!reverse_heap[i]->Empty() && (forward_heap_min + reverse_heap_mins[i]) < weights[i])
|
||||
{
|
||||
const auto heapNode = reverse_heap[i]->DeleteMinGetHeapNode();
|
||||
// std::cerr << "REVERSEN " << i << " " << heapNode.node << std::endl;
|
||||
|
||||
const auto reverseHeapNode = forward_heap.GetHeapNodeIfWasInserted(heapNode.node);
|
||||
if (reverseHeapNode)
|
||||
{
|
||||
auto reverse_weight = reverseHeapNode->weight;
|
||||
auto path_weight = heapNode.weight + reverse_weight;
|
||||
|
||||
if (!shouldForceStep(force_step_nodes, heapNode, *reverseHeapNode) &&
|
||||
(path_weight >= EdgeWeight{0}) && (path_weight < weights[i]))
|
||||
{
|
||||
|
||||
middles[i] = heapNode.node;
|
||||
weights[i] = path_weight;
|
||||
|
||||
// auto distance =
|
||||
// forward_heap.GetData(middles[i]).distance +
|
||||
// reverse_heap[i]->GetData(middles[i]).distance;
|
||||
// std::cerr << "FFOUNDN " << i << " " << distance << std::endl;
|
||||
}
|
||||
}
|
||||
relaxOutgoingEdges<REVERSE_DIRECTION>(
|
||||
facade, *reverse_heap[i], heapNode, candidates);
|
||||
|
||||
if (!reverse_heap[i]->Empty())
|
||||
reverse_heap_mins[i] = reverse_heap[i]->MinKey();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return middles;
|
||||
// std::vector<std::optional<std::pair<NodeID, EdgeWeight>>> results;
|
||||
// results.reserve(candidatesCount);
|
||||
// for (size_t i = 0; i < candidatesCount; ++i)
|
||||
// {
|
||||
// if (weights[i] >= weight_upper_bound || SPECIAL_NODEID == middles[i])
|
||||
// {
|
||||
// results.push_back({});
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// results.push_back({{middles[i], weights[i]}});
|
||||
// }
|
||||
// }
|
||||
// return results;
|
||||
|
||||
// // run two-Target Dijkstra routing step.
|
||||
// NodeID middle = SPECIAL_NODEID;
|
||||
// EdgeWeight weight = weight_upper_bound;
|
||||
// EdgeWeight forward_heap_min = forward_heap.MinKey();
|
||||
// EdgeWeight reverse_heap_min = reverse_heap.MinKey();
|
||||
// while (forward_heap.Size() + reverse_heap.Size() > 0 &&
|
||||
// forward_heap_min + reverse_heap_min < weight)
|
||||
// {
|
||||
// if (!forward_heap.Empty())
|
||||
// {
|
||||
// routingStep<FORWARD_DIRECTION>(
|
||||
// facade, forward_heap, reverse_heap, middle, weight, force_step_nodes, args...);
|
||||
// if (!forward_heap.Empty())
|
||||
// forward_heap_min = forward_heap.MinKey();
|
||||
// }
|
||||
// if (!reverse_heap.Empty())
|
||||
// {
|
||||
// routingStep<REVERSE_DIRECTION>(
|
||||
// facade, reverse_heap, forward_heap, middle, weight, force_step_nodes, args...);
|
||||
// if (!reverse_heap.Empty())
|
||||
// reverse_heap_min = reverse_heap.MinKey();
|
||||
// }
|
||||
// };
|
||||
|
||||
// // No path found for both target nodes?
|
||||
// if (weight >= weight_upper_bound || SPECIAL_NODEID == middle)
|
||||
// {
|
||||
// return {};
|
||||
// }
|
||||
|
||||
// return {{middle, weight}};
|
||||
}
|
||||
|
||||
template <typename Algorithm>
|
||||
std::vector<double> searchDistance2(
|
||||
SearchEngineData<Algorithm> &,
|
||||
const DataFacade<Algorithm> &facade,
|
||||
typename SearchEngineData<Algorithm>::MapMatchingQueryHeap &forward_heap,
|
||||
const std::vector<std::unique_ptr<typename SearchEngineData<Algorithm>::MapMatchingQueryHeap>>
|
||||
&reverse_heaps,
|
||||
size_t candidatesCount,
|
||||
const std::vector<NodeID> &force_step_nodes,
|
||||
EdgeWeight weight_upper_bound,
|
||||
const PhantomEndpointCandidates &candidates)
|
||||
{
|
||||
auto searchResults = runSearch2(facade,
|
||||
forward_heap,
|
||||
reverse_heaps,
|
||||
candidatesCount,
|
||||
force_step_nodes,
|
||||
weight_upper_bound,
|
||||
candidates);
|
||||
std::vector<double> res;
|
||||
res.reserve(candidatesCount);
|
||||
for (size_t i = 0; i < searchResults.size(); ++i)
|
||||
{
|
||||
if (searchResults[i] == SPECIAL_NODEID)
|
||||
{
|
||||
res.push_back(std::numeric_limits<double>::max());
|
||||
}
|
||||
else
|
||||
{
|
||||
auto middle = searchResults[i];
|
||||
|
||||
// std::cerr << "new " << i << " " << middle << std::endl;
|
||||
|
||||
auto distance =
|
||||
forward_heap.GetData(middle).distance + reverse_heaps[i]->GetData(middle).distance;
|
||||
res.push_back(from_alias<double>(distance));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
template <typename Algorithm>
|
||||
std::vector<double> getNetworkDistances(
|
||||
SearchEngineData<Algorithm> &engine_working_data,
|
||||
const DataFacade<Algorithm> &facade,
|
||||
typename SearchEngineData<Algorithm>::MapMatchingQueryHeap &forward_heap,
|
||||
const std::vector<std::unique_ptr<typename SearchEngineData<Algorithm>::MapMatchingQueryHeap>>
|
||||
&reverse_heaps,
|
||||
const PhantomNode &source_phantom,
|
||||
const std::vector<PhantomNode> &target_phantoms,
|
||||
EdgeWeight weight_upper_bound = INVALID_EDGE_WEIGHT)
|
||||
{
|
||||
forward_heap.Clear();
|
||||
for (const auto &heap : reverse_heaps)
|
||||
{
|
||||
heap->Clear();
|
||||
}
|
||||
// std::vector<std::unique_ptr<Heap>> reverse_heaps;
|
||||
// const auto nodes_number = facade.GetNumberOfNodes();
|
||||
// const auto border_nodes_number = facade.GetMaxBorderNodeID() + 1;
|
||||
// for (const auto &target_phantom : target_phantoms)
|
||||
// {
|
||||
// (void)target_phantom;
|
||||
// reverse_heaps.emplace_back(std::make_unique<Heap>(nodes_number, border_nodes_number));
|
||||
// }
|
||||
|
||||
if (source_phantom.IsValidForwardSource())
|
||||
{
|
||||
forward_heap.Insert(source_phantom.forward_segment_id.id,
|
||||
EdgeWeight{0} - source_phantom.GetForwardWeightPlusOffset(),
|
||||
{source_phantom.forward_segment_id.id,
|
||||
false,
|
||||
EdgeDistance{0} - source_phantom.GetForwardDistance()});
|
||||
}
|
||||
|
||||
if (source_phantom.IsValidReverseSource())
|
||||
{
|
||||
forward_heap.Insert(source_phantom.reverse_segment_id.id,
|
||||
EdgeWeight{0} - source_phantom.GetReverseWeightPlusOffset(),
|
||||
{source_phantom.reverse_segment_id.id,
|
||||
false,
|
||||
EdgeDistance{0} - source_phantom.GetReverseDistance()});
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < target_phantoms.size(); ++i)
|
||||
{
|
||||
auto &reverse_heap = *reverse_heaps[i];
|
||||
const auto &target_phantom = target_phantoms[i];
|
||||
if (target_phantom.IsValidForwardTarget())
|
||||
{
|
||||
reverse_heap.Insert(
|
||||
target_phantom.forward_segment_id.id,
|
||||
target_phantom.GetForwardWeightPlusOffset(),
|
||||
{target_phantom.forward_segment_id.id, false, target_phantom.GetForwardDistance()});
|
||||
}
|
||||
|
||||
if (target_phantom.IsValidReverseTarget())
|
||||
{
|
||||
reverse_heap.Insert(
|
||||
target_phantom.reverse_segment_id.id,
|
||||
target_phantom.GetReverseWeightPlusOffset(),
|
||||
{target_phantom.reverse_segment_id.id, false, target_phantom.GetReverseDistance()});
|
||||
}
|
||||
}
|
||||
|
||||
// PhantomEndpoints endpoints{};
|
||||
// endpoints.push_back(source_phantom);
|
||||
// for (const auto &target_phantom : target_phantoms)
|
||||
// {
|
||||
// endpoints.push_back(target_phantom);
|
||||
// }
|
||||
std::vector<PhantomNode> source_phantomes;
|
||||
source_phantomes.push_back(source_phantom);
|
||||
PhantomEndpointCandidates phantom_candidates{source_phantomes, target_phantoms};
|
||||
|
||||
auto distances = searchDistance2(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heaps,
|
||||
target_phantoms.size(),
|
||||
{},
|
||||
weight_upper_bound,
|
||||
phantom_candidates);
|
||||
return distances;
|
||||
}
|
||||
|
||||
} // namespace osrm::engine::routing_algorithms::mld
|
||||
|
||||
#endif // OSRM_ENGINE_ROUTING_BASE_MLD_HPP
|
||||
|
||||
@@ -56,6 +56,7 @@ template <> struct SearchEngineData<routing_algorithms::ch::Algorithm>
|
||||
static thread_local ManyToManyHeapPtr many_to_many_heap;
|
||||
static thread_local SearchEngineHeapPtr map_matching_forward_heap_1;
|
||||
static thread_local SearchEngineHeapPtr map_matching_reverse_heap_1;
|
||||
static thread_local std::vector<SearchEngineHeapPtr> map_matching_reverse_heaps;
|
||||
|
||||
void InitializeOrClearMapMatchingThreadLocalStorage(unsigned number_of_nodes);
|
||||
|
||||
@@ -133,13 +134,15 @@ template <> struct SearchEngineData<routing_algorithms::mld::Algorithm>
|
||||
static thread_local SearchEngineHeapPtr reverse_heap_1;
|
||||
static thread_local MapMatchingHeapPtr map_matching_forward_heap_1;
|
||||
static thread_local MapMatchingHeapPtr map_matching_reverse_heap_1;
|
||||
static thread_local std::vector<MapMatchingHeapPtr> map_matching_reverse_heaps;
|
||||
|
||||
static thread_local ManyToManyHeapPtr many_to_many_heap;
|
||||
|
||||
void InitializeOrClearFirstThreadLocalStorage(unsigned number_of_nodes,
|
||||
unsigned number_of_boundary_nodes);
|
||||
void InitializeOrClearMapMatchingThreadLocalStorage(unsigned number_of_nodes,
|
||||
unsigned number_of_boundary_nodes);
|
||||
unsigned number_of_boundary_nodes,
|
||||
size_t max_candidates);
|
||||
|
||||
void InitializeOrClearManyToManyThreadLocalStorage(unsigned number_of_nodes,
|
||||
unsigned number_of_boundary_nodes);
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <boost/assert.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <new>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm::util
|
||||
{
|
||||
|
||||
inline size_t align_up(size_t n, size_t alignment)
|
||||
{
|
||||
return (n + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
|
||||
inline size_t get_next_power_of_two_exponent(size_t n)
|
||||
{
|
||||
BOOST_ASSERT(n > 0);
|
||||
return (sizeof(size_t) * 8) - std::countl_zero(n - 1);
|
||||
}
|
||||
|
||||
class MemoryPool
|
||||
{
|
||||
private:
|
||||
constexpr static size_t MIN_CHUNK_SIZE_BYTES = 4096;
|
||||
|
||||
public:
|
||||
static std::shared_ptr<MemoryPool> instance()
|
||||
{
|
||||
static thread_local std::shared_ptr<MemoryPool> instance;
|
||||
if (!instance)
|
||||
{
|
||||
instance = std::shared_ptr<MemoryPool>(new MemoryPool());
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
template <typename T> T *allocate(std::size_t items_count)
|
||||
{
|
||||
static_assert(alignof(T) <= alignof(std::max_align_t),
|
||||
"Type is over-aligned for this allocator.");
|
||||
|
||||
size_t free_list_index = get_next_power_of_two_exponent(items_count * sizeof(T));
|
||||
auto &free_list = free_lists_[free_list_index];
|
||||
if (free_list.empty())
|
||||
{
|
||||
size_t block_size_in_bytes = 1u << free_list_index;
|
||||
block_size_in_bytes = align_up(block_size_in_bytes, alignof(std::max_align_t));
|
||||
// check if there is space in current memory chunk
|
||||
if (current_chunk_left_bytes_ < block_size_in_bytes)
|
||||
{
|
||||
allocate_chunk(block_size_in_bytes);
|
||||
}
|
||||
|
||||
free_list.push_back(current_chunk_ptr_);
|
||||
current_chunk_left_bytes_ -= block_size_in_bytes;
|
||||
current_chunk_ptr_ += block_size_in_bytes;
|
||||
}
|
||||
auto ptr = reinterpret_cast<T *>(free_list.back());
|
||||
free_list.pop_back();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
template <typename T> void deallocate(T *p, std::size_t n) noexcept
|
||||
{
|
||||
size_t free_list_index = get_next_power_of_two_exponent(n * sizeof(T));
|
||||
// NOLINTNEXTLINE(bugprone-multi-level-implicit-pointer-conversion)
|
||||
free_lists_[free_list_index].push_back(reinterpret_cast<void *>(p));
|
||||
}
|
||||
|
||||
~MemoryPool()
|
||||
{
|
||||
for (auto chunk : chunks_)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
|
||||
std::free(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MemoryPool() = default;
|
||||
MemoryPool(const MemoryPool &) = delete;
|
||||
MemoryPool &operator=(const MemoryPool &) = delete;
|
||||
|
||||
void allocate_chunk(size_t bytes)
|
||||
{
|
||||
auto chunk_size = std::max(bytes, MIN_CHUNK_SIZE_BYTES);
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-no-malloc)
|
||||
void *chunk = std::malloc(chunk_size);
|
||||
if (!chunk)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
chunks_.push_back(chunk);
|
||||
current_chunk_ptr_ = static_cast<uint8_t *>(chunk);
|
||||
current_chunk_left_bytes_ = chunk_size;
|
||||
}
|
||||
|
||||
// we have 64 free lists, one for each possible power of two
|
||||
std::array<std::vector<void *>, sizeof(std::size_t) * 8> free_lists_;
|
||||
|
||||
// list of allocated memory chunks, we don't free them until the pool is destroyed
|
||||
std::vector<void *> chunks_;
|
||||
|
||||
uint8_t *current_chunk_ptr_ = nullptr;
|
||||
size_t current_chunk_left_bytes_ = 0;
|
||||
};
|
||||
|
||||
template <typename T> class PoolAllocator
|
||||
{
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
PoolAllocator() noexcept : pool(MemoryPool::instance()){};
|
||||
|
||||
template <typename U>
|
||||
PoolAllocator(const PoolAllocator<U> &) noexcept : pool(MemoryPool::instance())
|
||||
{
|
||||
}
|
||||
|
||||
template <typename U> struct rebind
|
||||
{
|
||||
using other = PoolAllocator<U>;
|
||||
};
|
||||
|
||||
T *allocate(std::size_t n) { return pool->allocate<T>(n); }
|
||||
|
||||
void deallocate(T *p, std::size_t n) noexcept { pool->deallocate<T>(p, n); }
|
||||
|
||||
PoolAllocator(const PoolAllocator &) = default;
|
||||
PoolAllocator &operator=(const PoolAllocator &) = default;
|
||||
PoolAllocator(PoolAllocator &&) noexcept = default;
|
||||
PoolAllocator &operator=(PoolAllocator &&) noexcept = default;
|
||||
|
||||
private:
|
||||
// using shared_ptr guarantees that memory pool won't be destroyed before all allocators using
|
||||
// it (important if there are static instances of PoolAllocator)
|
||||
std::shared_ptr<MemoryPool> pool;
|
||||
};
|
||||
template <typename T, typename U>
|
||||
bool operator==(const PoolAllocator<T> &, const PoolAllocator<U> &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
bool operator!=(const PoolAllocator<T> &, const PoolAllocator<U> &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace osrm::util
|
||||
@@ -1,16 +1,17 @@
|
||||
#ifndef OSRM_UTIL_QUERY_HEAP_HPP
|
||||
#define OSRM_UTIL_QUERY_HEAP_HPP
|
||||
|
||||
#include "util/pool_allocator.hpp"
|
||||
#include <algorithm>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/heap/d_ary_heap.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace osrm::util
|
||||
{
|
||||
|
||||
@@ -55,11 +56,7 @@ template <typename NodeID, typename Key> class UnorderedMapStorage
|
||||
void Clear() { nodes.clear(); }
|
||||
|
||||
private:
|
||||
template <typename K, typename V>
|
||||
using UnorderedMap = std::
|
||||
unordered_map<K, V, std::hash<K>, std::equal_to<K>, PoolAllocator<std::pair<const K, V>>>;
|
||||
|
||||
UnorderedMap<NodeID, Key> nodes;
|
||||
std::unordered_map<NodeID, Key> nodes;
|
||||
};
|
||||
|
||||
template <typename NodeID,
|
||||
@@ -145,12 +142,10 @@ class QueryHeap
|
||||
return weight > other.weight;
|
||||
}
|
||||
};
|
||||
|
||||
using HeapContainer = boost::heap::d_ary_heap<HeapData,
|
||||
boost::heap::arity<4>,
|
||||
boost::heap::mutable_<true>,
|
||||
boost::heap::compare<std::greater<HeapData>>,
|
||||
boost::heap::allocator<PoolAllocator<HeapData>>>;
|
||||
boost::heap::compare<std::greater<HeapData>>>;
|
||||
using HeapHandle = typename HeapContainer::handle_type;
|
||||
|
||||
public:
|
||||
@@ -165,9 +160,6 @@ class QueryHeap
|
||||
Data data;
|
||||
};
|
||||
|
||||
QueryHeap(const QueryHeap &other) = delete;
|
||||
QueryHeap(QueryHeap &&other) = delete;
|
||||
|
||||
template <typename... StorageArgs> explicit QueryHeap(StorageArgs... args) : node_index(args...)
|
||||
{
|
||||
Clear();
|
||||
|
||||
@@ -50,26 +50,27 @@ function measure_peak_ram_and_time {
|
||||
}
|
||||
|
||||
function run_benchmarks_for_folder {
|
||||
rm -rf $RESULTS_FOLDER
|
||||
mkdir -p $RESULTS_FOLDER
|
||||
|
||||
BENCHMARKS_FOLDER="$BINARIES_FOLDER/src/benchmarks"
|
||||
|
||||
echo "Running match-bench MLD"
|
||||
$BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
|
||||
echo "Running match-bench CH"
|
||||
$BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench"
|
||||
echo "Running route-bench MLD"
|
||||
$BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench"
|
||||
echo "Running route-bench CH"
|
||||
$BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench"
|
||||
echo "Running alias"
|
||||
$BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench"
|
||||
echo "Running json-render-bench"
|
||||
$BENCHMARKS_FOLDER/json-render-bench "$FOLDER/test/data/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench"
|
||||
echo "Running packedvector-bench"
|
||||
$BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"
|
||||
echo "Running rtree-bench"
|
||||
$BENCHMARKS_FOLDER/rtree-bench "$FOLDER/test/data/monaco.osrm.ramIndex" "$FOLDER/test/data/monaco.osrm.fileIndex" "$FOLDER/test/data/monaco.osrm.nbg_nodes" > "$RESULTS_FOLDER/rtree.bench"
|
||||
# echo "Running match-bench MLD"
|
||||
# $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/match_mld.bench"
|
||||
# echo "Running match-bench CH"
|
||||
# $BENCHMARKS_FOLDER/match-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/match_ch.bench"
|
||||
# echo "Running route-bench MLD"
|
||||
# $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/mld/monaco.osrm" mld > "$RESULTS_FOLDER/route_mld.bench"
|
||||
# echo "Running route-bench CH"
|
||||
# $BENCHMARKS_FOLDER/route-bench "$FOLDER/test/data/ch/monaco.osrm" ch > "$RESULTS_FOLDER/route_ch.bench"
|
||||
# echo "Running alias"
|
||||
# $BENCHMARKS_FOLDER/alias-bench > "$RESULTS_FOLDER/alias.bench"
|
||||
# echo "Running json-render-bench"
|
||||
# $BENCHMARKS_FOLDER/json-render-bench "$FOLDER/test/data/portugal_to_korea.json" > "$RESULTS_FOLDER/json-render.bench"
|
||||
# echo "Running packedvector-bench"
|
||||
# $BENCHMARKS_FOLDER/packedvector-bench > "$RESULTS_FOLDER/packedvector.bench"
|
||||
# echo "Running rtree-bench"
|
||||
# $BENCHMARKS_FOLDER/rtree-bench "$FOLDER/test/data/monaco.osrm.ramIndex" "$FOLDER/test/data/monaco.osrm.fileIndex" "$FOLDER/test/data/monaco.osrm.nbg_nodes" > "$RESULTS_FOLDER/rtree.bench"
|
||||
|
||||
cp -rf $OSM_PBF $FOLDER/data.osm.pbf
|
||||
|
||||
@@ -83,19 +84,19 @@ function run_benchmarks_for_folder {
|
||||
measure_peak_ram_and_time "$BINARIES_FOLDER/osrm-contract $FOLDER/data.osrm" "$RESULTS_FOLDER/osrm_contract.bench"
|
||||
|
||||
|
||||
for ALGORITHM in ch mld; do
|
||||
for BENCH in nearest table trip route match; do
|
||||
echo "Running node $BENCH $ALGORITHM"
|
||||
START=$(date +%s.%N)
|
||||
node $SCRIPTS_FOLDER/scripts/ci/bench.js $FOLDER/lib/binding/node_osrm.node $FOLDER/data.osrm $ALGORITHM $BENCH $GPS_TRACES > "$RESULTS_FOLDER/node_${BENCH}_${ALGORITHM}.bench" 5
|
||||
END=$(date +%s.%N)
|
||||
DIFF=$(echo "$END - $START" | bc)
|
||||
echo "Took: ${DIFF}s"
|
||||
done
|
||||
done
|
||||
|
||||
for ALGORITHM in ch mld; do
|
||||
for BENCH in nearest table trip route match; do
|
||||
# for ALGORITHM in ch mld; do
|
||||
# for BENCH in nearest table trip route match; do
|
||||
# echo "Running node $BENCH $ALGORITHM"
|
||||
# START=$(date +%s.%N)
|
||||
# node $SCRIPTS_FOLDER/scripts/ci/bench.js $FOLDER/lib/binding/node_osrm.node $FOLDER/data.osrm $ALGORITHM $BENCH $GPS_TRACES > "$RESULTS_FOLDER/node_${BENCH}_${ALGORITHM}.bench" 5
|
||||
# END=$(date +%s.%N)
|
||||
# DIFF=$(echo "$END - $START" | bc)
|
||||
# echo "Took: ${DIFF}s"
|
||||
# done
|
||||
# done
|
||||
|
||||
for ALGORITHM in mld; do
|
||||
for BENCH in match; do
|
||||
echo "Running random $BENCH $ALGORITHM"
|
||||
START=$(date +%s.%N)
|
||||
$BENCHMARKS_FOLDER/bench "$FOLDER/data.osrm" $ALGORITHM $GPS_TRACES ${BENCH} > "$RESULTS_FOLDER/random_${BENCH}_${ALGORITHM}.bench" 5 || true
|
||||
@@ -106,28 +107,28 @@ function run_benchmarks_for_folder {
|
||||
done
|
||||
|
||||
|
||||
for ALGORITHM in ch mld; do
|
||||
$BINARIES_FOLDER/osrm-routed --algorithm $ALGORITHM $FOLDER/data.osrm > /dev/null 2>&1 &
|
||||
OSRM_ROUTED_PID=$!
|
||||
# for ALGORITHM in ch mld; do
|
||||
# $BINARIES_FOLDER/osrm-routed --algorithm $ALGORITHM $FOLDER/data.osrm > /dev/null 2>&1 &
|
||||
# OSRM_ROUTED_PID=$!
|
||||
|
||||
# wait for osrm-routed to start
|
||||
if ! curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true" > /dev/null 2>&1; then
|
||||
echo "osrm-routed failed to start for algorithm $ALGORITHM"
|
||||
kill -9 $OSRM_ROUTED_PID
|
||||
continue
|
||||
fi
|
||||
# # wait for osrm-routed to start
|
||||
# if ! curl --retry-delay 3 --retry 10 --retry-all-errors "http://127.0.0.1:5000/route/v1/driving/13.388860,52.517037;13.385983,52.496891?steps=true" > /dev/null 2>&1; then
|
||||
# echo "osrm-routed failed to start for algorithm $ALGORITHM"
|
||||
# kill -9 $OSRM_ROUTED_PID
|
||||
# continue
|
||||
# fi
|
||||
|
||||
for METHOD in route nearest trip table match; do
|
||||
echo "Running e2e benchmark for $METHOD $ALGORITHM"
|
||||
START=$(date +%s.%N)
|
||||
python3 $SCRIPTS_FOLDER/scripts/ci/e2e_benchmark.py --host http://localhost:5000 --method $METHOD --iterations 5 --num_requests 1000 --gps_traces_file_path $GPS_TRACES > $RESULTS_FOLDER/e2e_${METHOD}_${ALGORITHM}.bench
|
||||
END=$(date +%s.%N)
|
||||
DIFF=$(echo "$END - $START" | bc)
|
||||
echo "Took: ${DIFF}s"
|
||||
done
|
||||
# for METHOD in route nearest trip table match; do
|
||||
# echo "Running e2e benchmark for $METHOD $ALGORITHM"
|
||||
# START=$(date +%s.%N)
|
||||
# python3 $SCRIPTS_FOLDER/scripts/ci/e2e_benchmark.py --host http://localhost:5000 --method $METHOD --iterations 5 --num_requests 1000 --gps_traces_file_path $GPS_TRACES > $RESULTS_FOLDER/e2e_${METHOD}_${ALGORITHM}.bench
|
||||
# END=$(date +%s.%N)
|
||||
# DIFF=$(echo "$END - $START" | bc)
|
||||
# echo "Took: ${DIFF}s"
|
||||
# done
|
||||
|
||||
kill -9 $OSRM_ROUTED_PID
|
||||
done
|
||||
# kill -9 $OSRM_ROUTED_PID
|
||||
# done
|
||||
}
|
||||
|
||||
run_benchmarks_for_folder
|
||||
|
||||
@@ -45,7 +45,8 @@ unsigned getMedianSampleTime(const std::vector<unsigned> ×tamps)
|
||||
|
||||
template <typename Algorithm>
|
||||
inline void initializeHeap(SearchEngineData<Algorithm> &engine_working_data,
|
||||
const DataFacade<Algorithm> &facade)
|
||||
const DataFacade<Algorithm> &facade,
|
||||
size_t)
|
||||
{
|
||||
|
||||
const auto nodes_number = facade.GetNumberOfNodes();
|
||||
@@ -54,14 +55,92 @@ inline void initializeHeap(SearchEngineData<Algorithm> &engine_working_data,
|
||||
|
||||
template <>
|
||||
inline void initializeHeap<mld::Algorithm>(SearchEngineData<mld::Algorithm> &engine_working_data,
|
||||
const DataFacade<mld::Algorithm> &facade)
|
||||
const DataFacade<mld::Algorithm> &facade,
|
||||
size_t max_candidates)
|
||||
{
|
||||
|
||||
const auto nodes_number = facade.GetNumberOfNodes();
|
||||
const auto border_nodes_number = facade.GetMaxBorderNodeID() + 1;
|
||||
engine_working_data.InitializeOrClearMapMatchingThreadLocalStorage(nodes_number,
|
||||
border_nodes_number);
|
||||
engine_working_data.InitializeOrClearMapMatchingThreadLocalStorage(
|
||||
nodes_number, border_nodes_number, max_candidates);
|
||||
}
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
template <typename T> void saveVectorToFile(const std::vector<T> &data, const std::string &filename)
|
||||
{
|
||||
std::ofstream outFile(filename, std::ios::binary);
|
||||
if (!outFile)
|
||||
{
|
||||
std::cerr << "Error opening file for writing: " << filename << std::endl;
|
||||
return;
|
||||
}
|
||||
size_t size = data.size();
|
||||
outFile.write(reinterpret_cast<const char *>(&size), sizeof(size));
|
||||
outFile.write(reinterpret_cast<const char *>(data.data()), size * sizeof(T));
|
||||
outFile.close();
|
||||
if (!outFile.good())
|
||||
{
|
||||
std::cerr << "Error occurred at writing time!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> bool loadVectorFromFile(std::vector<T> &data, const std::string &filename)
|
||||
{
|
||||
std::ifstream inFile(filename, std::ios::binary);
|
||||
if (!inFile)
|
||||
{
|
||||
std::cerr << "Error opening file for reading: " << filename << std::endl;
|
||||
return false;
|
||||
}
|
||||
size_t size;
|
||||
inFile.read(reinterpret_cast<char *>(&size), sizeof(size));
|
||||
data.resize(size);
|
||||
inFile.read(reinterpret_cast<char *>(data.data()), size * sizeof(T));
|
||||
inFile.close();
|
||||
if (!inFile.good())
|
||||
{
|
||||
std::cerr << "Error occurred at reading time!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T> void saveStructToFile(const T &data, const std::string &filename)
|
||||
{
|
||||
std::ofstream outFile(filename, std::ios::binary);
|
||||
if (!outFile)
|
||||
{
|
||||
std::cerr << "Error opening file for writing: " << filename << std::endl;
|
||||
return;
|
||||
}
|
||||
outFile.write(reinterpret_cast<const char *>(&data), sizeof(T));
|
||||
outFile.close();
|
||||
if (!outFile.good())
|
||||
{
|
||||
std::cerr << "Error occurred at writing time!" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> bool loadStructFromFile(T &data, const std::string &filename)
|
||||
{
|
||||
std::ifstream inFile(filename, std::ios::binary);
|
||||
if (!inFile)
|
||||
{
|
||||
std::cerr << "Error opening file for reading: " << filename << std::endl;
|
||||
return false;
|
||||
}
|
||||
inFile.read(reinterpret_cast<char *>(&data), sizeof(T));
|
||||
inFile.close();
|
||||
if (!inFile.good())
|
||||
{
|
||||
std::cerr << "Error occurred at reading time!" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
template <typename Algorithm>
|
||||
@@ -144,9 +223,16 @@ SubMatchingList mapMatching(SearchEngineData<Algorithm> &engine_working_data,
|
||||
return sub_matchings;
|
||||
}
|
||||
|
||||
initializeHeap(engine_working_data, facade);
|
||||
size_t max_candidates = 0;
|
||||
for (const auto &candidates : candidates_list)
|
||||
{
|
||||
max_candidates = std::max(max_candidates, candidates.size());
|
||||
}
|
||||
|
||||
initializeHeap(engine_working_data, facade, max_candidates);
|
||||
auto &forward_heap = *engine_working_data.map_matching_forward_heap_1;
|
||||
auto &reverse_heap = *engine_working_data.map_matching_reverse_heap_1;
|
||||
const auto &reverse_heaps = engine_working_data.map_matching_reverse_heaps;
|
||||
|
||||
std::size_t breakage_begin = map_matching::INVALID_STATE;
|
||||
std::vector<std::size_t> split_points;
|
||||
@@ -225,6 +311,108 @@ SubMatchingList mapMatching(SearchEngineData<Algorithm> &engine_working_data,
|
||||
continue;
|
||||
}
|
||||
|
||||
// PhantomNode source;
|
||||
// loadStructFromFile<PhantomNode>(source, "source.bin");
|
||||
std::vector<PhantomNode> target_phantom_nodes;
|
||||
// loadVectorFromFile(target_phantom_nodes, "target.bin");
|
||||
// target_phantom_nodes.erase(target_phantom_nodes.begin());
|
||||
// target_phantom_nodes.erase(target_phantom_nodes.begin());
|
||||
// target_phantom_nodes.erase(target_phantom_nodes.begin());
|
||||
// target_phantom_nodes.erase(target_phantom_nodes.begin());
|
||||
// target_phantom_nodes.pop_back();
|
||||
// target_phantom_nodes.pop_back();
|
||||
// target_phantom_nodes.erase(target_phantom_nodes.begin() + 1);
|
||||
|
||||
// target_phantom_nodes.push_back(target);
|
||||
for (const auto s_prime : util::irange<std::size_t>(0UL, current_viterbi.size()))
|
||||
{
|
||||
const double emission_pr = emission_log_probabilities[t][s_prime];
|
||||
double new_value = prev_viterbi[s] + emission_pr;
|
||||
if (current_viterbi[s_prime] > new_value)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
target_phantom_nodes.push_back(current_timestamps_list[s_prime].phantom_node);
|
||||
}
|
||||
|
||||
// TIMER_START(NEW_DIST);
|
||||
|
||||
#define MODE 1
|
||||
|
||||
#if MODE == 0
|
||||
auto new_distances =
|
||||
getNetworkDistances(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heaps,
|
||||
prev_unbroken_timestamps_list[s].phantom_node,
|
||||
target_phantom_nodes,
|
||||
weight_upper_bound);
|
||||
std::vector<double> old_distances;
|
||||
|
||||
for (const auto &pn : target_phantom_nodes)
|
||||
{
|
||||
double network_distance =
|
||||
getNetworkDistance(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
prev_unbroken_timestamps_list[s].phantom_node,
|
||||
pn,
|
||||
weight_upper_bound);
|
||||
old_distances.push_back(network_distance);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < old_distances.size(); ++i)
|
||||
{
|
||||
if (std::abs(old_distances[i] - new_distances[i]) > 0.01)
|
||||
{
|
||||
// saveStructToFile(prev_unbroken_timestamps_list[s].phantom_node,
|
||||
// "source.bin");
|
||||
// saveVectorToFile(target_phantom_nodes, "target.bin");
|
||||
std::cerr << "OOPS " << old_distances[i] << " " << new_distances[i]
|
||||
<< std::endl;
|
||||
// std::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
auto distances = old_distances;
|
||||
#elif MODE == 1
|
||||
(void)reverse_heap;
|
||||
auto distances =
|
||||
getNetworkDistances(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heaps,
|
||||
prev_unbroken_timestamps_list[s].phantom_node,
|
||||
target_phantom_nodes,
|
||||
weight_upper_bound);
|
||||
// TIMER_STOP(NEW_DIST);
|
||||
#else
|
||||
// TIMER_START(OLD_DIST);
|
||||
(void)reverse_heaps;
|
||||
std::vector<double> distances;
|
||||
|
||||
for (const auto &pn : target_phantom_nodes)
|
||||
{
|
||||
double network_distance =
|
||||
getNetworkDistance(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
prev_unbroken_timestamps_list[s].phantom_node,
|
||||
pn,
|
||||
weight_upper_bound);
|
||||
distances.push_back(network_distance);
|
||||
}
|
||||
#endif
|
||||
// TIMER_STOP(OLD_DIST);
|
||||
|
||||
// std::cerr << "Old: " << TIMER_MSEC(OLD_DIST) << " New: " << TIMER_MSEC(NEW_DIST)
|
||||
// << std::endl;
|
||||
|
||||
|
||||
size_t distance_index = 0;
|
||||
for (const auto s_prime : util::irange<std::size_t>(0UL, current_viterbi.size()))
|
||||
{
|
||||
const double emission_pr = emission_log_probabilities[t][s_prime];
|
||||
@@ -234,14 +422,16 @@ SubMatchingList mapMatching(SearchEngineData<Algorithm> &engine_working_data,
|
||||
continue;
|
||||
}
|
||||
|
||||
double network_distance =
|
||||
getNetworkDistance(engine_working_data,
|
||||
facade,
|
||||
forward_heap,
|
||||
reverse_heap,
|
||||
prev_unbroken_timestamps_list[s].phantom_node,
|
||||
current_timestamps_list[s_prime].phantom_node,
|
||||
weight_upper_bound);
|
||||
double network_distance = distances[distance_index];
|
||||
++distance_index;
|
||||
// double network_distance =
|
||||
// getNetworkDistance(engine_working_data,
|
||||
// facade,
|
||||
// forward_heap,
|
||||
// reverse_heap,
|
||||
// prev_unbroken_timestamps_list[s].phantom_node,
|
||||
// current_timestamps_list[s_prime].phantom_node,
|
||||
// weight_upper_bound);
|
||||
|
||||
// get distance diff between loc1/2 and locs/s_prime
|
||||
const auto d_t = std::abs(network_distance - haversine_distance);
|
||||
|
||||
@@ -15,6 +15,8 @@ thread_local SearchEngineData<CH>::SearchEngineHeapPtr
|
||||
SearchEngineData<CH>::map_matching_forward_heap_1;
|
||||
thread_local SearchEngineData<CH>::SearchEngineHeapPtr
|
||||
SearchEngineData<CH>::map_matching_reverse_heap_1;
|
||||
thread_local std::vector<typename SearchEngineData<CH>::SearchEngineHeapPtr>
|
||||
SearchEngineData<CH>::map_matching_reverse_heaps;
|
||||
|
||||
thread_local SearchEngineData<CH>::ManyToManyHeapPtr SearchEngineData<CH>::many_to_many_heap;
|
||||
|
||||
@@ -123,9 +125,11 @@ thread_local SearchEngineData<MLD>::MapMatchingHeapPtr
|
||||
thread_local SearchEngineData<MLD>::MapMatchingHeapPtr
|
||||
SearchEngineData<MLD>::map_matching_reverse_heap_1;
|
||||
thread_local SearchEngineData<MLD>::ManyToManyHeapPtr SearchEngineData<MLD>::many_to_many_heap;
|
||||
thread_local std::vector<typename SearchEngineData<MLD>::MapMatchingHeapPtr>
|
||||
SearchEngineData<MLD>::map_matching_reverse_heaps;
|
||||
|
||||
void SearchEngineData<MLD>::InitializeOrClearMapMatchingThreadLocalStorage(
|
||||
unsigned number_of_nodes, unsigned number_of_boundary_nodes)
|
||||
unsigned number_of_nodes, unsigned number_of_boundary_nodes, size_t max_candidates)
|
||||
{
|
||||
if (map_matching_forward_heap_1.get())
|
||||
{
|
||||
@@ -146,6 +150,16 @@ void SearchEngineData<MLD>::InitializeOrClearMapMatchingThreadLocalStorage(
|
||||
map_matching_reverse_heap_1.reset(
|
||||
new MapMatchingQueryHeap(number_of_nodes, number_of_boundary_nodes));
|
||||
}
|
||||
|
||||
if (max_candidates > map_matching_reverse_heaps.size())
|
||||
{
|
||||
size_t to_add = max_candidates - map_matching_reverse_heaps.size();
|
||||
for (unsigned i = 0; i < to_add; ++i)
|
||||
{
|
||||
map_matching_reverse_heaps.emplace_back(
|
||||
new MapMatchingQueryHeap(number_of_nodes, number_of_boundary_nodes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SearchEngineData<MLD>::InitializeOrClearFirstThreadLocalStorage(
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
#include "util/pool_allocator.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(pool_allocator)
|
||||
|
||||
using namespace osrm;
|
||||
using namespace osrm::util;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_align_up)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(align_up(5, 4), 8);
|
||||
BOOST_CHECK_EQUAL(align_up(9, 8), 16);
|
||||
BOOST_CHECK_EQUAL(align_up(17, 16), 32);
|
||||
BOOST_CHECK_EQUAL(align_up(4, 4), 4);
|
||||
BOOST_CHECK_EQUAL(align_up(8, 8), 8);
|
||||
BOOST_CHECK_EQUAL(align_up(16, 16), 16);
|
||||
BOOST_CHECK_EQUAL(align_up(32, 16), 32);
|
||||
BOOST_CHECK_EQUAL(align_up(0, 4), 0);
|
||||
BOOST_CHECK_EQUAL(align_up(0, 8), 0);
|
||||
BOOST_CHECK_EQUAL(align_up(0, 16), 0);
|
||||
BOOST_CHECK_EQUAL(align_up(1000000, 256), 1000192);
|
||||
BOOST_CHECK_EQUAL(align_up(999999, 512), 1000448);
|
||||
BOOST_CHECK_EQUAL(align_up(123456789, 1024), 123457536);
|
||||
BOOST_CHECK_EQUAL(align_up(0, 1), 0);
|
||||
BOOST_CHECK_EQUAL(align_up(5, 1), 5);
|
||||
BOOST_CHECK_EQUAL(align_up(123456, 1), 123456);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_get_next_power_of_two_exponent)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(1), 0);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(2), 1);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(4), 2);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(8), 3);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(16), 4);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(3), 2);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(5), 3);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(9), 4);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(15), 4);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(17), 5);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(1), 0);
|
||||
BOOST_CHECK_EQUAL(get_next_power_of_two_exponent(SIZE_MAX), sizeof(size_t) * 8);
|
||||
}
|
||||
|
||||
// in many of these tests we hope on address sanitizer to alert in the case if we are doing
|
||||
// something wrong
|
||||
BOOST_AUTO_TEST_CASE(smoke)
|
||||
{
|
||||
PoolAllocator<int> pool;
|
||||
auto ptr = pool.allocate(1);
|
||||
*ptr = 42;
|
||||
BOOST_CHECK_NE(ptr, nullptr);
|
||||
pool.deallocate(ptr, 1);
|
||||
|
||||
ptr = pool.allocate(2);
|
||||
*ptr = 42;
|
||||
*(ptr + 1) = 43;
|
||||
BOOST_CHECK_NE(ptr, nullptr);
|
||||
pool.deallocate(ptr, 2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(a_lot_of_items)
|
||||
{
|
||||
PoolAllocator<int> pool;
|
||||
auto ptr = pool.allocate(2048);
|
||||
for (int i = 0; i < 2048; ++i)
|
||||
{
|
||||
ptr[i] = i;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2048; ++i)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(ptr[i], i);
|
||||
}
|
||||
|
||||
pool.deallocate(ptr, 2048);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(copy)
|
||||
{
|
||||
PoolAllocator<int> pool;
|
||||
auto ptr = pool.allocate(1);
|
||||
*ptr = 42;
|
||||
BOOST_CHECK_NE(ptr, nullptr);
|
||||
pool.deallocate(ptr, 1);
|
||||
|
||||
PoolAllocator<int> pool2(pool);
|
||||
ptr = pool2.allocate(1);
|
||||
*ptr = 42;
|
||||
BOOST_CHECK_NE(ptr, nullptr);
|
||||
pool2.deallocate(ptr, 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(move)
|
||||
{
|
||||
PoolAllocator<int> pool;
|
||||
auto ptr = pool.allocate(1);
|
||||
*ptr = 42;
|
||||
BOOST_CHECK_NE(ptr, nullptr);
|
||||
pool.deallocate(ptr, 1);
|
||||
|
||||
PoolAllocator<int> pool2(std::move(pool));
|
||||
ptr = pool2.allocate(1);
|
||||
*ptr = 42;
|
||||
BOOST_CHECK_NE(ptr, nullptr);
|
||||
pool2.deallocate(ptr, 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(unordered_map)
|
||||
{
|
||||
std::unordered_map<int,
|
||||
int,
|
||||
std::hash<int>,
|
||||
std::equal_to<int>,
|
||||
PoolAllocator<std::pair<const int, int>>>
|
||||
map;
|
||||
map[1] = 42;
|
||||
BOOST_CHECK_EQUAL(map[1], 42);
|
||||
|
||||
map.clear();
|
||||
|
||||
map[2] = 43;
|
||||
|
||||
BOOST_CHECK_EQUAL(map[2], 43);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(alignment)
|
||||
{
|
||||
PoolAllocator<char> pool_char;
|
||||
PoolAllocator<double> pool_double;
|
||||
|
||||
auto ptr_char = pool_char.allocate(1);
|
||||
auto ptr_double = pool_double.allocate(1);
|
||||
|
||||
BOOST_CHECK_NE(ptr_double, nullptr);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<uintptr_t>(ptr_double) % alignof(double), 0);
|
||||
BOOST_CHECK_NE(ptr_char, nullptr);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<uintptr_t>(ptr_char) % alignof(char), 0);
|
||||
|
||||
pool_char.deallocate(ptr_char, 1);
|
||||
pool_double.deallocate(ptr_double, 1);
|
||||
|
||||
ptr_char = pool_char.allocate(2);
|
||||
ptr_double = pool_double.allocate(1);
|
||||
|
||||
BOOST_CHECK_NE(ptr_double, nullptr);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<uintptr_t>(ptr_double) % alignof(double), 0);
|
||||
BOOST_CHECK_NE(ptr_char, nullptr);
|
||||
BOOST_CHECK_EQUAL(reinterpret_cast<uintptr_t>(ptr_char) % alignof(char), 0);
|
||||
|
||||
pool_char.deallocate(ptr_char, 2);
|
||||
pool_double.deallocate(ptr_double, 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
Reference in New Issue
Block a user