Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions features/testbot/distance_matrix.feature
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ Feature: Basic Distance Matrix

When I request a travel distance matrix I should get
| | f | g | h | i |
| f | 0 | 300+-2 | 0 | 300+-2 |
| g | 300+-2 | 0 | 300+-2 | 0 |
| h | 0 | 300+-2 | 0 | 300+-2 |
| i | 300+-2 | 0 | 300+-2 | 0 |
| f | 0 | 300+-3 | 0 | 300+-3 |
| g | 300+-3 | 0 | 300+-3 | 0 |
| h | 0 | 300+-3 | 0 | 300+-3 |
| i | 300+-3 | 0 | 300+-3 | 0 |

Scenario: Testbot - Travel distance matrix with loops
Given the node map
Expand All @@ -352,9 +352,9 @@ Feature: Basic Distance Matrix
When I request a travel distance matrix I should get
| | 1 | 2 | 3 | 4 |
| 1 | 0 | 100+-1 | 400+-1 | 500+-1 |
| 2 | 700+-1 | 0 | 300+-1 | 400+-1 |
| 2 | 700+-2 | 0 | 300+-2 | 400+-1 |
| 3 | 400+-1 | 500+-1 | 0 | 100+-1 |
| 4 | 300+-1 | 400+-1 | 700+-1 | 0 |
| 4 | 300+-2 | 400+-1 | 700+-3 | 0 |


Scenario: Testbot - Travel distance matrix based on segment durations
Expand Down Expand Up @@ -496,4 +496,4 @@ Feature: Basic Distance Matrix

When I request a travel distance matrix I should get
| | a | b | c | d |
| a | 0 | 1000+-3 | 2000+-3 | 3000+-3 |
| a | 0 | 1000+-3 | 2000+-3 | 3000+-3 |
6 changes: 4 additions & 2 deletions include/engine/data_watchdog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade, AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(
std::vector<storage::SharedRegionRegister::ShmKey>{
static_region.shm_key, updatable_region.shm_key}));
static_region.shm_key, updatable_region.shm_key}),
static_region.timestamp);
}

watcher = std::thread(&DataWatchdogImpl::Run, this);
Expand Down Expand Up @@ -115,7 +116,8 @@ class DataWatchdogImpl<AlgorithmT, datafacade::ContiguousInternalMemoryDataFacad
DataFacadeFactory<datafacade::ContiguousInternalMemoryDataFacade, AlgorithmT>(
std::make_shared<datafacade::SharedMemoryAllocator>(
std::vector<storage::SharedRegionRegister::ShmKey>{
static_region.shm_key, updatable_region.shm_key}));
static_region.shm_key, updatable_region.shm_key}),
static_region.timestamp);
}

util::Log() << "DataWatchdog thread stopped";
Expand Down
22 changes: 16 additions & 6 deletions include/engine/datafacade/contiguous_internalmem_datafacade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade

// allocator that keeps the allocation data
std::shared_ptr<ContiguousBlockAllocator> allocator;
std::size_t m_exclude_index;
unsigned m_timestamp;

void InitializeInternalPointers(const storage::SharedDataIndex &index,
const std::string &metric_name,
Expand All @@ -183,6 +185,8 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade

m_check_sum = *index.GetBlockPtr<std::uint32_t>("/common/connectivity_checksum");

m_exclude_index = exclude_index;

std::tie(m_coordinate_list, m_osmnodeid_list) =
make_nbn_data_view(index, "/common/nbn_data");

Expand Down Expand Up @@ -217,12 +221,16 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
}

public:
std::size_t GetTimestamp() const { return m_timestamp; }
std::size_t GetExcludeIndex() const { return m_exclude_index; }

// allows switching between process_memory/shared_memory datafacade, based on the type of
// allocator
ContiguousInternalMemoryDataFacadeBase(std::shared_ptr<ContiguousBlockAllocator> allocator_,
const std::string &metric_name,
const std::size_t exclude_index)
: allocator(std::move(allocator_))
const std::size_t exclude_index,
unsigned timestamp)
: allocator(std::move(allocator_)), m_timestamp(timestamp)
{
InitializeInternalPointers(allocator->GetIndex(), metric_name, exclude_index);
}
Expand Down Expand Up @@ -618,8 +626,9 @@ class ContiguousInternalMemoryDataFacade<CH>
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::string &metric_name,
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index),
const std::size_t exclude_index,
unsigned timestamp)
: ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index, timestamp),
ContiguousInternalMemoryAlgorithmDataFacade<CH>(allocator, metric_name, exclude_index)
{
}
Expand Down Expand Up @@ -735,8 +744,9 @@ class ContiguousInternalMemoryDataFacade<MLD> final
public:
ContiguousInternalMemoryDataFacade(std::shared_ptr<ContiguousBlockAllocator> allocator,
const std::string &metric_name,
const std::size_t exclude_index)
: ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index),
const std::size_t exclude_index,
unsigned timestamp)
: ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index, timestamp),
ContiguousInternalMemoryAlgorithmDataFacade<MLD>(allocator, metric_name, exclude_index)
{
}
Expand Down
13 changes: 7 additions & 6 deletions include/engine/datafacade_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
DataFacadeFactory() = default;

template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator)
: DataFacadeFactory(allocator, has_exclude_flags)
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, unsigned timestamp)
: DataFacadeFactory(allocator, has_exclude_flags, timestamp)
{
BOOST_ASSERT_MSG(facades.size() >= 1, "At least one datafacade is needed");
}
Expand All @@ -44,7 +44,7 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
private:
// Algorithm with exclude flags
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::true_type)
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::true_type, unsigned timestamp)
{
const auto &index = allocator->GetIndex();
properties = index.template GetBlockPtr<extractor::ProfileProperties>("/common/properties");
Expand All @@ -71,7 +71,8 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa
std::size_t index =
std::stoi(exclude_prefix.substr(index_begin + 1, exclude_prefix.size()));
BOOST_ASSERT(index >= 0 && index < facades.size());
facades[index] = std::make_shared<const Facade>(allocator, metric_name, index);
facades[index] =
std::make_shared<const Facade>(allocator, metric_name, index, timestamp);
}

for (const auto index : util::irange<std::size_t>(0, properties->class_names.size()))
Expand All @@ -86,12 +87,12 @@ template <template <typename A> class FacadeT, typename AlgorithmT> class DataFa

// Algorithm without exclude flags
template <typename AllocatorT>
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::false_type)
DataFacadeFactory(std::shared_ptr<AllocatorT> allocator, std::false_type, unsigned timestamp)
{
const auto &index = allocator->GetIndex();
properties = index.template GetBlockPtr<extractor::ProfileProperties>("/common/properties");
const auto &metric_name = properties->GetWeightName();
facades.push_back(std::make_shared<const Facade>(allocator, metric_name, 0));
facades.push_back(std::make_shared<const Facade>(allocator, metric_name, 0, timestamp));
}

std::shared_ptr<const Facade> Get(const api::TileParameters &, std::false_type) const
Expand Down
5 changes: 3 additions & 2 deletions include/engine/datafacade_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class ExternalProvider final : public DataFacadeProvider<AlgorithmT, FacadeT>

ExternalProvider(const storage::StorageConfig &config,
const boost::filesystem::path &memory_file)
: facade_factory(std::make_shared<datafacade::MMapMemoryAllocator>(config, memory_file))
: facade_factory(std::make_shared<datafacade::MMapMemoryAllocator>(config, memory_file),
0) // is it ok to add timestamp as zero here?
{
}

Expand All @@ -58,7 +59,7 @@ class ImmutableProvider final : public DataFacadeProvider<AlgorithmT, FacadeT>
using Facade = typename DataFacadeProvider<AlgorithmT, FacadeT>::Facade;

ImmutableProvider(const storage::StorageConfig &config)
: facade_factory(std::make_shared<datafacade::ProcessMemoryAllocator>(config))
: facade_factory(std::make_shared<datafacade::ProcessMemoryAllocator>(config), 0)
{
}

Expand Down
25 changes: 25 additions & 0 deletions include/engine/routing_algorithms/routing_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,31 @@ template <typename FacadeT> EdgeDistance computeEdgeDistance(const FacadeT &faca
return total_distance;
}

template <typename FacadeT>
EdgeDuration computeEdgeDuration(const FacadeT &facade, NodeID node_id, NodeID turn_id)
{
const auto geometry_index = facade.GetGeometryIndex(node_id);

// datastructures to hold extracted data from geometry
EdgeDuration total_duration;

if (geometry_index.forward)
{
auto duration_range = facade.GetUncompressedForwardDurations(geometry_index.id);
total_duration = std::accumulate(duration_range.begin(), duration_range.end(), 0);
}
else
{
auto duration_range = facade.GetUncompressedReverseDurations(geometry_index.id);
total_duration = std::accumulate(duration_range.begin(), duration_range.end(), 0);
}

const auto turn_duration = facade.GetDurationPenaltyForEdgeID(turn_id);
total_duration += turn_duration;

return total_duration;
}

} // namespace routing_algorithms
} // namespace engine
} // namespace osrm
Expand Down
Loading