Refactor cell weights and durations to own file and allow for multiple metrics
This commit is contained in:
committed by
Patrick Niklaus
parent
21686ee8a9
commit
303a8fae32
@@ -1,6 +1,7 @@
|
||||
#include "customizer/customizer.hpp"
|
||||
#include "customizer/cell_customizer.hpp"
|
||||
#include "customizer/edge_based_graph.hpp"
|
||||
#include "customizer/files.hpp"
|
||||
|
||||
#include "partition/cell_storage.hpp"
|
||||
#include "partition/edge_based_graph_reader.hpp"
|
||||
@@ -22,7 +23,8 @@ namespace customizer
|
||||
template <typename Graph, typename Partition, typename CellStorage>
|
||||
void CellStorageStatistics(const Graph &graph,
|
||||
const Partition &partition,
|
||||
const CellStorage &storage)
|
||||
const CellStorage &storage,
|
||||
const CellMetric &metric)
|
||||
{
|
||||
util::Log() << "Cells statistics per level";
|
||||
|
||||
@@ -38,7 +40,7 @@ void CellStorageStatistics(const Graph &graph,
|
||||
std::size_t invalid_sources = 0, invalid_destinations = 0;
|
||||
for (std::uint32_t cell_id = 0; cell_id < partition.GetNumberOfCells(level); ++cell_id)
|
||||
{
|
||||
const auto &cell = storage.GetCell(level, cell_id);
|
||||
const auto &cell = storage.GetCell(metric, level, cell_id);
|
||||
source += cell.GetSourceNodes().size();
|
||||
destination += cell.GetDestinationNodes().size();
|
||||
total += cell_nodes[cell_id];
|
||||
@@ -109,12 +111,13 @@ int Customizer::Run(const CustomizationConfig &config)
|
||||
|
||||
TIMER_START(cell_customize);
|
||||
CellCustomizer customizer(mlp);
|
||||
customizer.Customize(*edge_based_graph, storage);
|
||||
auto metric = storage.MakeMetric();
|
||||
customizer.Customize(*edge_based_graph, storage, metric);
|
||||
TIMER_STOP(cell_customize);
|
||||
util::Log() << "Cells customization took " << TIMER_SEC(cell_customize) << " seconds";
|
||||
|
||||
TIMER_START(writing_mld_data);
|
||||
partition::files::writeCells(config.GetPath(".osrm.cells"), storage);
|
||||
files::writeCellMetrics(config.GetPath(".osrm.cell_metrics"), std::vector<CellMetric>{metric});
|
||||
TIMER_STOP(writing_mld_data);
|
||||
util::Log() << "MLD customization writing took " << TIMER_SEC(writing_mld_data) << " seconds";
|
||||
|
||||
@@ -123,7 +126,7 @@ int Customizer::Run(const CustomizationConfig &config)
|
||||
TIMER_STOP(writing_graph);
|
||||
util::Log() << "Graph writing took " << TIMER_SEC(writing_graph) << " seconds";
|
||||
|
||||
CellStorageStatistics(*edge_based_graph, mlp, storage);
|
||||
CellStorageStatistics(*edge_based_graph, mlp, storage, metric);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -112,6 +112,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
|
||||
{
|
||||
const auto &partition = facade.GetMultiLevelPartition();
|
||||
const auto &cells = facade.GetCellStorage();
|
||||
const auto &metric = facade.GetCellMetric();
|
||||
|
||||
auto highest_diffrent_level = [&partition, node](const SegmentID &phantom_node) {
|
||||
if (phantom_node.enabled)
|
||||
@@ -125,7 +126,7 @@ void relaxOutgoingEdges(const DataFacade<mld::Algorithm> &facade,
|
||||
|
||||
if (level >= 1 && !node_data.from_clique_arc)
|
||||
{
|
||||
const auto &cell = cells.GetCell(level, partition.GetCell(level, node));
|
||||
const auto &cell = cells.GetCell(metric, level, partition.GetCell(level, node));
|
||||
if (DIRECTION == FORWARD_DIRECTION)
|
||||
{ // Shortcuts in forward direction
|
||||
auto destination = cell.GetDestinationNodes().begin();
|
||||
|
||||
+73
-37
@@ -10,6 +10,7 @@
|
||||
#include "contractor/query_graph.hpp"
|
||||
|
||||
#include "customizer/edge_based_graph.hpp"
|
||||
#include "customizer/files.hpp"
|
||||
|
||||
#include "extractor/class_data.hpp"
|
||||
#include "extractor/compressed_edge_container.hpp"
|
||||
@@ -64,6 +65,8 @@ namespace osrm
|
||||
namespace storage
|
||||
{
|
||||
|
||||
static constexpr std::size_t NUM_METRICS = 8;
|
||||
|
||||
using RTreeLeaf = engine::datafacade::BaseDataFacade::RTreeLeaf;
|
||||
using RTreeNode = util::StaticRTree<RTreeLeaf, storage::Ownership::View>::TreeNode;
|
||||
using QueryGraph = util::StaticGraph<contractor::QueryEdge::EdgeData>;
|
||||
@@ -453,10 +456,6 @@ void Storage::PopulateLayout(DataLayout &layout)
|
||||
{
|
||||
io::FileReader reader(config.GetPath(".osrm.cells"), io::FileReader::VerifyFingerprint);
|
||||
|
||||
const auto weights_count = reader.ReadVectorSize<EdgeWeight>();
|
||||
layout.SetBlockSize<EdgeWeight>(DataLayout::MLD_CELL_WEIGHTS_0, weights_count);
|
||||
const auto durations_count = reader.ReadVectorSize<EdgeDuration>();
|
||||
layout.SetBlockSize<EdgeDuration>(DataLayout::MLD_CELL_DURATIONS_0, durations_count);
|
||||
const auto source_node_count = reader.ReadVectorSize<NodeID>();
|
||||
layout.SetBlockSize<NodeID>(DataLayout::MLD_CELL_SOURCE_BOUNDARY, source_node_count);
|
||||
const auto destination_node_count = reader.ReadVectorSize<NodeID>();
|
||||
@@ -468,22 +467,45 @@ void Storage::PopulateLayout(DataLayout &layout)
|
||||
const auto level_offsets_count = reader.ReadVectorSize<std::uint64_t>();
|
||||
layout.SetBlockSize<std::uint64_t>(DataLayout::MLD_CELL_LEVEL_OFFSETS,
|
||||
level_offsets_count);
|
||||
}
|
||||
else
|
||||
{
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_SOURCE_BOUNDARY, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DESTINATION_BOUNDARY, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELLS, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_LEVEL_OFFSETS, 0);
|
||||
}
|
||||
|
||||
// FIXME these need to be filled with actual weight values
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_1, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_2, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_3, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_4, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_5, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_6, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_WEIGHTS_7, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_1, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_2, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_3, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_4, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_5, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_6, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_7, 0);
|
||||
if (boost::filesystem::exists(config.GetPath(".osrm.cell_metrics")))
|
||||
{
|
||||
io::FileReader reader(config.GetPath(".osrm.cell_metrics"),
|
||||
io::FileReader::VerifyFingerprint);
|
||||
auto num_metric = reader.ReadElementCount64();
|
||||
|
||||
if (num_metric > NUM_METRICS)
|
||||
{
|
||||
throw util::exception("Only " + std::to_string(NUM_METRICS) +
|
||||
" metrics are supported at the same time.");
|
||||
}
|
||||
|
||||
for (const auto index : util::irange<std::size_t>(0, num_metric))
|
||||
{
|
||||
const auto weights_count = reader.ReadVectorSize<EdgeWeight>();
|
||||
layout.SetBlockSize<EdgeWeight>(
|
||||
static_cast<DataLayout::BlockID>(DataLayout::MLD_CELL_WEIGHTS_0 + index),
|
||||
weights_count);
|
||||
const auto durations_count = reader.ReadVectorSize<EdgeDuration>();
|
||||
layout.SetBlockSize<EdgeDuration>(
|
||||
static_cast<DataLayout::BlockID>(DataLayout::MLD_CELL_DURATIONS_0 + index),
|
||||
durations_count);
|
||||
}
|
||||
for (const auto index : util::irange<std::size_t>(num_metric, NUM_METRICS))
|
||||
{
|
||||
layout.SetBlockSize<EdgeWeight>(
|
||||
static_cast<DataLayout::BlockID>(DataLayout::MLD_CELL_WEIGHTS_0 + index), 0);
|
||||
layout.SetBlockSize<EdgeDuration>(
|
||||
static_cast<DataLayout::BlockID>(DataLayout::MLD_CELL_DURATIONS_0 + index), 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -503,10 +525,6 @@ void Storage::PopulateLayout(DataLayout &layout)
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_5, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_6, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DURATIONS_7, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_SOURCE_BOUNDARY, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_DESTINATION_BOUNDARY, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELLS, 0);
|
||||
layout.SetBlockSize<char>(DataLayout::MLD_CELL_LEVEL_OFFSETS, 0);
|
||||
}
|
||||
|
||||
if (boost::filesystem::exists(config.GetPath(".osrm.mldgr")))
|
||||
@@ -941,10 +959,6 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
|
||||
BOOST_ASSERT(layout.GetBlockSize(storage::DataLayout::MLD_CELLS) > 0);
|
||||
BOOST_ASSERT(layout.GetBlockSize(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS) > 0);
|
||||
|
||||
auto mld_cell_weights_ptr = layout.GetBlockPtr<EdgeWeight, true>(
|
||||
memory_ptr, storage::DataLayout::MLD_CELL_WEIGHTS_0);
|
||||
auto mld_cell_duration_ptr = layout.GetBlockPtr<EdgeDuration, true>(
|
||||
memory_ptr, storage::DataLayout::MLD_CELL_DURATIONS_0);
|
||||
auto mld_source_boundary_ptr = layout.GetBlockPtr<NodeID, true>(
|
||||
memory_ptr, storage::DataLayout::MLD_CELL_SOURCE_BOUNDARY);
|
||||
auto mld_destination_boundary_ptr = layout.GetBlockPtr<NodeID, true>(
|
||||
@@ -954,10 +968,6 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
|
||||
auto mld_cell_level_offsets_ptr = layout.GetBlockPtr<std::uint64_t, true>(
|
||||
memory_ptr, storage::DataLayout::MLD_CELL_LEVEL_OFFSETS);
|
||||
|
||||
auto weight_entries_count =
|
||||
layout.GetBlockEntries(storage::DataLayout::MLD_CELL_WEIGHTS_0);
|
||||
auto duration_entries_count =
|
||||
layout.GetBlockEntries(storage::DataLayout::MLD_CELL_DURATIONS_0);
|
||||
auto source_boundary_entries_count =
|
||||
layout.GetBlockEntries(storage::DataLayout::MLD_CELL_SOURCE_BOUNDARY);
|
||||
auto destination_boundary_entries_count =
|
||||
@@ -966,9 +976,6 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
|
||||
auto cell_level_offsets_entries_count =
|
||||
layout.GetBlockEntries(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS);
|
||||
|
||||
util::vector_view<EdgeWeight> weights(mld_cell_weights_ptr, weight_entries_count);
|
||||
util::vector_view<EdgeDuration> durations(mld_cell_duration_ptr,
|
||||
duration_entries_count);
|
||||
util::vector_view<NodeID> source_boundary(mld_source_boundary_ptr,
|
||||
source_boundary_entries_count);
|
||||
util::vector_view<NodeID> destination_boundary(mld_destination_boundary_ptr,
|
||||
@@ -978,15 +985,44 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
|
||||
util::vector_view<std::uint64_t> level_offsets(mld_cell_level_offsets_ptr,
|
||||
cell_level_offsets_entries_count);
|
||||
|
||||
partition::CellStorageView storage{std::move(weights),
|
||||
std::move(durations),
|
||||
std::move(source_boundary),
|
||||
partition::CellStorageView storage{std::move(source_boundary),
|
||||
std::move(destination_boundary),
|
||||
std::move(cells),
|
||||
std::move(level_offsets)};
|
||||
partition::files::readCells(config.GetPath(".osrm.cells"), storage);
|
||||
}
|
||||
|
||||
if (boost::filesystem::exists(config.GetPath(".osrm.cell_metrics")))
|
||||
{
|
||||
BOOST_ASSERT(layout.GetBlockSize(storage::DataLayout::MLD_CELLS) > 0);
|
||||
BOOST_ASSERT(layout.GetBlockSize(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS) > 0);
|
||||
|
||||
std::vector<customizer::CellMetricView> metrics;
|
||||
|
||||
for (auto index : util::irange<std::size_t>(0, NUM_METRICS))
|
||||
{
|
||||
auto weights_block_id = static_cast<DataLayout::BlockID>(
|
||||
storage::DataLayout::MLD_CELL_WEIGHTS_0 + index);
|
||||
auto durations_block_id = static_cast<DataLayout::BlockID>(
|
||||
storage::DataLayout::MLD_CELL_DURATIONS_0 + index);
|
||||
|
||||
auto weight_entries_count = layout.GetBlockEntries(weights_block_id);
|
||||
auto duration_entries_count = layout.GetBlockEntries(durations_block_id);
|
||||
auto mld_cell_weights_ptr =
|
||||
layout.GetBlockPtr<EdgeWeight, true>(memory_ptr, weights_block_id);
|
||||
auto mld_cell_duration_ptr =
|
||||
layout.GetBlockPtr<EdgeDuration, true>(memory_ptr, durations_block_id);
|
||||
util::vector_view<EdgeWeight> weights(mld_cell_weights_ptr, weight_entries_count);
|
||||
util::vector_view<EdgeDuration> durations(mld_cell_duration_ptr,
|
||||
duration_entries_count);
|
||||
|
||||
metrics.push_back(
|
||||
customizer::CellMetricView{std::move(weights), std::move(durations)});
|
||||
}
|
||||
|
||||
customizer::files::readCellMetrics(config.GetPath(".osrm.cell_metrics"), metrics);
|
||||
}
|
||||
|
||||
if (boost::filesystem::exists(config.GetPath(".osrm.mldgr")))
|
||||
{
|
||||
|
||||
|
||||
@@ -169,14 +169,12 @@ int main(int argc, char *argv[]) try
|
||||
<< "! This setting may have performance side-effects.";
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(contractor_config.GetPath(".osrm")))
|
||||
if (!contractor_config.IsValid())
|
||||
{
|
||||
util::Log(logERROR) << "Input file " << contractor_config.GetPath(".osrm").string()
|
||||
<< " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
util::Log() << "Input file: " << contractor_config.GetPath(".osrm").filename().string();
|
||||
util::Log() << "Input file: " << contractor_config.base_path.string() << ".osrm";
|
||||
util::Log() << "Threads: " << contractor_config.requested_num_threads;
|
||||
|
||||
tbb::task_scheduler_init init(contractor_config.requested_num_threads);
|
||||
|
||||
@@ -153,10 +153,8 @@ int main(int argc, char *argv[]) try
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (!boost::filesystem::is_regular_file(customization_config.GetPath(".osrm")))
|
||||
if (!customization_config.IsValid())
|
||||
{
|
||||
util::Log(logERROR) << "Input file " << customization_config.GetPath(".osrm").string()
|
||||
<< " not found!";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user