Better statistics for osrm-partition and osrm-custimize
This commit is contained in:
committed by
Patrick Niklaus
parent
600ca06166
commit
7edf0f218c
@@ -0,0 +1,54 @@
|
||||
#ifndef OSRM_PARTITIONER_CELL_STATISTICS_HPP
|
||||
#define OSRM_PARTITIONER_CELL_STATISTICS_HPP
|
||||
|
||||
#include "util/log.hpp"
|
||||
#include "util/typedefs.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace partitioner
|
||||
{
|
||||
template <typename Partition, typename CellStorage>
|
||||
void printCellStatistics(const Partition &partition, const CellStorage &storage)
|
||||
{
|
||||
util::Log() << "Cells statistics per level";
|
||||
|
||||
for (std::size_t level = 1; level < partition.GetNumberOfLevels(); ++level)
|
||||
{
|
||||
auto num_cells = partition.GetNumberOfCells(level);
|
||||
std::size_t source = 0, destination = 0;
|
||||
std::size_t boundary_nodes = 0;
|
||||
std::size_t entries = 0;
|
||||
for (std::uint32_t cell_id = 0; cell_id < num_cells; ++cell_id)
|
||||
{
|
||||
std::unordered_set<NodeID> boundary;
|
||||
const auto &cell = storage.GetUnfilledCell(level, cell_id);
|
||||
source += cell.GetSourceNodes().size();
|
||||
destination += cell.GetDestinationNodes().size();
|
||||
for (auto node : cell.GetSourceNodes())
|
||||
{
|
||||
boundary.insert(node);
|
||||
}
|
||||
for (auto node : cell.GetDestinationNodes())
|
||||
{
|
||||
boundary.insert(node);
|
||||
}
|
||||
boundary_nodes += boundary.size();
|
||||
entries += cell.GetSourceNodes().size() * cell.GetDestinationNodes().size();
|
||||
}
|
||||
|
||||
source /= num_cells;
|
||||
destination /= num_cells;
|
||||
|
||||
util::Log() << "Level " << level << " #cells " << num_cells << " #boundary nodes "
|
||||
<< boundary_nodes << ", sources: avg. " << source << ", destinations: avg. "
|
||||
<< destination << ", entries: " << entries << " ("
|
||||
<< (2 * entries * sizeof(EdgeWeight)) << " bytes)";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -193,6 +193,20 @@ template <storage::Ownership Ownership> class CellStorageImpl
|
||||
BOOST_ASSERT(num_source_nodes == 0 || all_sources != nullptr);
|
||||
BOOST_ASSERT(num_destination_nodes == 0 || all_destinations != nullptr);
|
||||
}
|
||||
|
||||
// Consturcts an emptry cell without weights. Useful when only access
|
||||
// to the cell structure is needed, without a concrete metric.
|
||||
CellImpl(const CellData &data,
|
||||
const NodeID *const all_sources,
|
||||
const NodeID *const all_destinations)
|
||||
: num_source_nodes{data.num_source_nodes},
|
||||
num_destination_nodes{data.num_destination_nodes}, weights{nullptr},
|
||||
durations{nullptr}, source_boundary{all_sources + data.source_boundary_offset},
|
||||
destination_boundary{all_destinations + data.destination_boundary_offset}
|
||||
{
|
||||
BOOST_ASSERT(num_source_nodes == 0 || all_sources != nullptr);
|
||||
BOOST_ASSERT(num_destination_nodes == 0 || all_destinations != nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
std::size_t LevelIDToIndex(LevelID level) const { return level - 1; }
|
||||
@@ -378,6 +392,18 @@ template <storage::Ownership Ownership> class CellStorageImpl
|
||||
destination_boundary.empty() ? nullptr : destination_boundary.data()};
|
||||
}
|
||||
|
||||
ConstCell GetUnfilledCell(LevelID level, CellID id) const
|
||||
{
|
||||
const auto level_index = LevelIDToIndex(level);
|
||||
BOOST_ASSERT(level_index < level_to_cell_offset.size());
|
||||
const auto offset = level_to_cell_offset[level_index];
|
||||
const auto cell_index = offset + id;
|
||||
BOOST_ASSERT(cell_index < cells.size());
|
||||
return ConstCell{cells[cell_index],
|
||||
source_boundary.empty() ? nullptr : source_boundary.data(),
|
||||
destination_boundary.empty() ? nullptr : destination_boundary.data()};
|
||||
}
|
||||
|
||||
template <typename = std::enable_if<Ownership == storage::Ownership::Container>>
|
||||
Cell GetCell(customizer::CellMetric &metric, LevelID level, CellID id) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user