Moved MultiLevelPartition and CellStorage to partition namespace

This commit is contained in:
Patrick Niklaus 2017-03-04 18:54:06 +00:00 committed by Patrick Niklaus
parent 694bf9d8b1
commit 00d01946cd
9 changed files with 105 additions and 101 deletions

View File

@ -3,9 +3,11 @@
#include "contractor/query_edge.hpp"
#include "engine/algorithm.hpp"
#include "util/cell_storage.hpp"
#include "partition/multi_level_partition.hpp"
#include "partition/cell_storage.hpp"
#include "util/integer_range.hpp"
#include "util/multi_level_partition.hpp"
namespace osrm
{
@ -64,9 +66,9 @@ template <> class AlgorithmDataFacade<algorithm::CoreCH>
template <> class AlgorithmDataFacade<algorithm::MLD>
{
public:
virtual const util::MultiLevelPartitionView &GetMultiLevelPartition() const = 0;
virtual const partition::MultiLevelPartitionView &GetMultiLevelPartition() const = 0;
virtual const util::CellStorageView &GetCellStorage() const = 0;
virtual const partition::CellStorageView &GetCellStorage() const = 0;
};
}
}

View File

@ -5,23 +5,26 @@
#include "engine/datafacade/contiguous_block_allocator.hpp"
#include "engine/datafacade/datafacade_base.hpp"
#include "engine/algorithm.hpp"
#include "engine/geospatial_query.hpp"
#include "extractor/compressed_edge_container.hpp"
#include "extractor/guidance/turn_instruction.hpp"
#include "extractor/guidance/turn_lane_types.hpp"
#include "extractor/profile_properties.hpp"
#include "storage/shared_datatype.hpp"
#include "util/guidance/bearing_class.hpp"
#include "util/guidance/entry_class.hpp"
#include "util/guidance/turn_lanes.hpp"
#include "engine/algorithm.hpp"
#include "engine/geospatial_query.hpp"
#include "util/cell_storage.hpp"
#include "partition/cell_storage.hpp"
#include "partition/multi_level_partition.hpp"
#include "storage/shared_datatype.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/guidance/bearing_class.hpp"
#include "util/guidance/entry_class.hpp"
#include "util/guidance/turn_bearing.hpp"
#include "util/guidance/turn_lanes.hpp"
#include "util/log.hpp"
#include "util/multi_level_partition.hpp"
#include "util/name_table.hpp"
#include "util/packed_vector.hpp"
#include "util/range_table.hpp"
@ -1088,8 +1091,8 @@ class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
: public datafacade::AlgorithmDataFacade<algorithm::MLD>
{
// MLD data
util::MultiLevelPartitionView mld_partition;
util::CellStorageView mld_cell_storage;
partition::MultiLevelPartitionView mld_partition;
partition::CellStorageView mld_cell_storage;
void InitializeInternalPointers(storage::DataLayout &data_layout, char *memory_block)
{
@ -1103,24 +1106,26 @@ class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
BOOST_ASSERT(data_layout.GetBlockSize(storage::DataLayout::MLD_LEVEL_DATA) > 0);
BOOST_ASSERT(data_layout.GetBlockSize(storage::DataLayout::MLD_CELL_TO_CHILDREN) > 0);
auto level_data = *data_layout.GetBlockPtr<util::MultiLevelPartitionView::LevelData>(
memory_block, storage::DataLayout::MLD_PARTITION);
auto level_data =
*data_layout.GetBlockPtr<partition::MultiLevelPartitionView::LevelData>(
memory_block, storage::DataLayout::MLD_PARTITION);
auto mld_partition_ptr = data_layout.GetBlockPtr<util::PartitionID>(
auto mld_partition_ptr = data_layout.GetBlockPtr<partition::PartitionID>(
memory_block, storage::DataLayout::MLD_PARTITION);
auto partition_entries_count =
data_layout.GetBlockEntries(storage::DataLayout::MLD_PARTITION);
util::ShM<util::PartitionID, true>::vector partition(mld_partition_ptr,
partition_entries_count);
util::ShM<partition::PartitionID, true>::vector partition(mld_partition_ptr,
partition_entries_count);
auto mld_chilren_ptr = data_layout.GetBlockPtr<util::CellID>(
auto mld_chilren_ptr = data_layout.GetBlockPtr<partition::CellID>(
memory_block, storage::DataLayout::MLD_CELL_TO_CHILDREN);
auto children_entries_count =
data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_TO_CHILDREN);
util::ShM<util::CellID, true>::vector cell_to_children(mld_chilren_ptr,
children_entries_count);
util::ShM<partition::CellID, true>::vector cell_to_children(mld_chilren_ptr,
children_entries_count);
mld_partition = util::MultiLevelPartitionView{level_data, partition, cell_to_children};
mld_partition =
partition::MultiLevelPartitionView{level_data, partition, cell_to_children};
}
if (data_layout.GetBlockSize(storage::DataLayout::MLD_CELL_WEIGHTS) > 0)
@ -1138,7 +1143,7 @@ class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
memory_block, storage::DataLayout::MLD_CELL_SOURCE_BOUNDARY);
auto mld_destination_boundary_ptr = data_layout.GetBlockPtr<NodeID>(
memory_block, storage::DataLayout::MLD_CELL_DESTINATION_BOUNDARY);
auto mld_cells_ptr = data_layout.GetBlockPtr<util::CellStorageView::CellData>(
auto mld_cells_ptr = data_layout.GetBlockPtr<partition::CellStorageView::CellData>(
memory_block, storage::DataLayout::MLD_CELLS);
auto mld_cell_level_offsets_ptr = data_layout.GetBlockPtr<std::uint64_t>(
memory_block, storage::DataLayout::MLD_CELL_LEVEL_OFFSETS);
@ -1158,16 +1163,16 @@ class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
source_boundary_entries_count);
util::ShM<NodeID, true>::vector destination_boundary(
mld_destination_boundary_ptr, destination_boundary_entries_count);
util::ShM<util::CellStorageView::CellData, true>::vector cells(mld_cells_ptr,
cells_entries_counts);
util::ShM<partition::CellStorageView::CellData, true>::vector cells(
mld_cells_ptr, cells_entries_counts);
util::ShM<std::uint64_t, true>::vector level_offsets(mld_cell_level_offsets_ptr,
cell_level_offsets_entries_count);
mld_cell_storage = util::CellStorageView{std::move(weights),
std::move(source_boundary),
std::move(destination_boundary),
std::move(cells),
std::move(level_offsets)};
mld_cell_storage = partition::CellStorageView{std::move(weights),
std::move(source_boundary),
std::move(destination_boundary),
std::move(cells),
std::move(level_offsets)};
}
}
@ -1182,9 +1187,12 @@ class ContiguousInternalMemoryAlgorithmDataFacade<algorithm::MLD>
InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory());
}
const util::MultiLevelPartitionView &GetMultiLevelPartition() const { return mld_partition; }
const partition::MultiLevelPartitionView &GetMultiLevelPartition() const
{
return mld_partition;
}
const util::CellStorageView &GetCellStorage() const { return mld_cell_storage; }
const partition::CellStorageView &GetCellStorage() const { return mld_cell_storage; }
};
template <>

View File

@ -1,10 +1,11 @@
#ifndef OSRM_UTIL_CELL_STORAGE_HPP
#define OSRM_UTIL_CELL_STORAGE_HPP
#include "partition/multi_level_partition.hpp"
#include "util/assert.hpp"
#include "util/for_each_range.hpp"
#include "util/log.hpp"
#include "util/multi_level_partition.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
#include "util/typedefs.hpp"
@ -20,23 +21,22 @@
namespace osrm
{
namespace util
namespace partition
{
namespace detail
{
namespace detail {
template <bool UseShareMemory> class CellStorageImpl;
}
using CellStorage = detail::CellStorageImpl<false>;
using CellStorageView = detail::CellStorageImpl<true>;
}
namespace partition {
namespace io {
namespace io
{
template <bool UseShareMemory>
inline void write(const boost::filesystem::path &path, const util::detail::CellStorageImpl<UseShareMemory> &storage);
}
inline void write(const boost::filesystem::path &path,
const detail::CellStorageImpl<UseShareMemory> &storage);
}
namespace util
{
namespace detail
{
template <bool UseShareMemory> class CellStorageImpl
@ -301,10 +301,10 @@ template <bool UseShareMemory> class CellStorageImpl
template <typename = std::enable_if<UseShareMemory>>
CellStorageImpl(Vector<EdgeWeight> weights_,
Vector<NodeID> source_boundary_,
Vector<NodeID> destination_boundary_,
Vector<CellData> cells_,
Vector<std::uint64_t> level_to_cell_offset_)
Vector<NodeID> source_boundary_,
Vector<NodeID> destination_boundary_,
Vector<CellData> cells_,
Vector<std::uint64_t> level_to_cell_offset_)
: weights(std::move(weights_)), source_boundary(std::move(source_boundary_)),
destination_boundary(std::move(destination_boundary_)), cells(std::move(cells_)),
level_to_cell_offset(std::move(level_to_cell_offset_))
@ -322,8 +322,7 @@ template <bool UseShareMemory> class CellStorageImpl
cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()};
}
template <typename = std::enable_if<!UseShareMemory>>
Cell GetCell(LevelID level, CellID id)
template <typename = std::enable_if<!UseShareMemory>> Cell GetCell(LevelID level, CellID id)
{
const auto level_index = LevelIDToIndex(level);
BOOST_ASSERT(level_index < level_to_cell_offset.size());
@ -334,7 +333,8 @@ template <bool UseShareMemory> class CellStorageImpl
cells[cell_index], weights.data(), source_boundary.data(), destination_boundary.data()};
}
friend void partition::io::write<UseShareMemory>(const boost::filesystem::path &path, const util::detail::CellStorageImpl<UseShareMemory> &storage);
friend void io::write<UseShareMemory>(const boost::filesystem::path &path,
const detail::CellStorageImpl<UseShareMemory> &storage);
private:
Vector<EdgeWeight> weights;

View File

@ -1,9 +1,10 @@
#ifndef OSRM_PARTITION_IO_HPP
#define OSRM_PARTITION_IO_HPP
#include "partition/multi_level_partition.hpp"
#include "partition/cell_storage.hpp"
#include "storage/io.hpp"
#include "util/multi_level_partition.hpp"
#include "util/cell_storage.hpp"
namespace osrm
{
@ -13,7 +14,7 @@ namespace io
{
template <>
inline void write(const boost::filesystem::path &path, const util::MultiLevelPartition &mlp)
inline void write(const boost::filesystem::path &path, const partition::MultiLevelPartition &mlp)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};
@ -24,7 +25,7 @@ inline void write(const boost::filesystem::path &path, const util::MultiLevelPar
}
template <>
inline void write(const boost::filesystem::path &path, const util::CellStorage &storage)
inline void write(const boost::filesystem::path &path, const partition::CellStorage &storage)
{
const auto fingerprint = storage::io::FileWriter::GenerateFingerprint;
storage::io::FileWriter writer{path, fingerprint};

View File

@ -20,8 +20,7 @@
namespace osrm
{
namespace util
namespace partition
{
namespace detail
{
@ -29,20 +28,14 @@ template <bool UseShareMemory> class MultiLevelPartitionImpl;
}
using MultiLevelPartition = detail::MultiLevelPartitionImpl<false>;
using MultiLevelPartitionView = detail::MultiLevelPartitionImpl<true>;
}
namespace partition
{
namespace io
{
template <bool UseShareMemory>
void write(const boost::filesystem::path &file,
const util::detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
}
const detail::MultiLevelPartitionImpl<UseShareMemory> &mlp);
}
namespace util
{
namespace detail
{
// get the msb of an integer
@ -168,8 +161,8 @@ template <bool UseShareMemory> class MultiLevelPartitionImpl final
return cell_to_children[offset + cell + 1];
}
friend void partition::io::write<UseShareMemory>(const boost::filesystem::path &file,
const MultiLevelPartitionImpl &mlp);
friend void io::write<UseShareMemory>(const boost::filesystem::path &file,
const MultiLevelPartitionImpl &mlp);
private:
auto MakeLevelData(const std::vector<std::uint32_t> &lidx_to_num_cells)

View File

@ -6,15 +6,14 @@
#include "partition/io.hpp"
#include "partition/node_based_graph_to_edge_based_graph_mapping_reader.hpp"
#include "partition/recursive_bisection.hpp"
#include "partition/multi_level_partition.hpp"
#include "util/cell_storage.hpp"
#include "util/coordinate.hpp"
#include "util/geojson_debug_logger.hpp"
#include "util/geojson_debug_policies.hpp"
#include "util/integer_range.hpp"
#include "util/json_container.hpp"
#include "util/log.hpp"
#include "util/multi_level_partition.hpp"
#include <algorithm>
#include <iterator>
@ -218,15 +217,15 @@ int Partitioner::Run(const PartitionConfig &config)
std::cout << std::setw(8) << std::hex << x << std::dec << "\n";
// collect cell ids as masked bisection ids
std::vector<std::vector<osrm::util::CellID>> partitions(
level_masks.size(), std::vector<osrm::util::CellID>(edge_based_partition_ids.size()));
std::vector<std::unordered_set<osrm::util::CellID>> partition_sets(level_masks.size());
std::vector<std::vector<CellID>> partitions(
level_masks.size(), std::vector<CellID>(edge_based_partition_ids.size()));
std::vector<std::unordered_set<CellID>> partition_sets(level_masks.size());
for (std::size_t index = 0; index < edge_based_partition_ids.size(); ++index)
{
auto bisection_id = edge_based_partition_ids[index];
for (std::size_t level = 0; level < level_masks.size(); ++level)
{
osrm::util::CellID cell_id =
CellID cell_id =
bisection_id & level_masks[level_masks.size() - 1 - level];
partitions[level][index] = cell_id;
partition_sets[level].insert(cell_id);
@ -237,7 +236,7 @@ int Partitioner::Run(const PartitionConfig &config)
std::transform(partition_sets.begin(),
partition_sets.end(),
std::back_inserter(level_to_num_cells),
[](const std::unordered_set<osrm::util::CellID> &partition_set) {
[](const std::unordered_set<CellID> &partition_set) {
return partition_set.size();
});
std::cout << "# of cell on levels\n";
@ -250,13 +249,13 @@ int Partitioner::Run(const PartitionConfig &config)
}
TIMER_START(packed_mlp);
osrm::util::MultiLevelPartition mlp{partitions, level_to_num_cells};
MultiLevelPartition mlp{partitions, level_to_num_cells};
TIMER_STOP(packed_mlp);
util::Log() << "MultiLevelPartition constructed in " << TIMER_SEC(packed_mlp)
<< " seconds";
TIMER_START(cell_storage);
osrm::util::CellStorage storage(mlp, *edge_based_graph);
CellStorage storage(mlp, *edge_based_graph);
TIMER_STOP(cell_storage);
util::Log() << "CellStorage constructed in " << TIMER_SEC(cell_storage) << " seconds";

View File

@ -6,20 +6,20 @@
#include "extractor/profile_properties.hpp"
#include "extractor/query_node.hpp"
#include "extractor/travel_mode.hpp"
#include "partition/cell_storage.hpp"
#include "partition/multi_level_partition.hpp"
#include "storage/io.hpp"
#include "storage/serialization.hpp"
#include "storage/shared_datatype.hpp"
#include "storage/shared_memory.hpp"
#include "storage/shared_monitor.hpp"
#include "engine/datafacade/datafacade_base.hpp"
#include "util/cell_storage.hpp"
#include "util/coordinate.hpp"
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/fingerprint.hpp"
#include "util/io.hpp"
#include "util/log.hpp"
#include "util/multi_level_partition.hpp"
#include "util/packed_vector.hpp"
#include "util/range_table.hpp"
#include "util/shared_memory_vector_wrapper.hpp"
@ -402,22 +402,22 @@ void Storage::PopulateLayout(DataLayout &layout)
{
io::FileReader reader(config.mld_partition_path, io::FileReader::VerifyFingerprint);
reader.Skip<util::MultiLevelPartition::LevelData>(1);
layout.SetBlockSize<util::MultiLevelPartition::LevelData>(DataLayout::MLD_LEVEL_DATA,
1);
const auto partition_entries_count = reader.ReadVectorSize<util::PartitionID>();
layout.SetBlockSize<util::PartitionID>(DataLayout::MLD_PARTITION,
partition_entries_count);
const auto children_entries_count = reader.ReadVectorSize<util::CellID>();
layout.SetBlockSize<util::CellID>(DataLayout::MLD_CELL_TO_CHILDREN,
children_entries_count);
reader.Skip<partition::MultiLevelPartition::LevelData>(1);
layout.SetBlockSize<partition::MultiLevelPartition::LevelData>(
DataLayout::MLD_LEVEL_DATA, 1);
const auto partition_entries_count = reader.ReadVectorSize<partition::PartitionID>();
layout.SetBlockSize<partition::PartitionID>(DataLayout::MLD_PARTITION,
partition_entries_count);
const auto children_entries_count = reader.ReadVectorSize<partition::CellID>();
layout.SetBlockSize<partition::CellID>(DataLayout::MLD_CELL_TO_CHILDREN,
children_entries_count);
}
else
{
layout.SetBlockSize<util::MultiLevelPartition::LevelData>(DataLayout::MLD_LEVEL_DATA,
0);
layout.SetBlockSize<util::PartitionID>(DataLayout::MLD_PARTITION, 0);
layout.SetBlockSize<util::CellID>(DataLayout::MLD_CELL_TO_CHILDREN, 0);
layout.SetBlockSize<partition::MultiLevelPartition::LevelData>(
DataLayout::MLD_LEVEL_DATA, 0);
layout.SetBlockSize<partition::PartitionID>(DataLayout::MLD_PARTITION, 0);
layout.SetBlockSize<partition::CellID>(DataLayout::MLD_CELL_TO_CHILDREN, 0);
}
if (boost::filesystem::exists(config.mld_storage_path))
@ -431,8 +431,9 @@ void Storage::PopulateLayout(DataLayout &layout)
const auto destination_node_count = reader.ReadVectorSize<NodeID>();
layout.SetBlockSize<NodeID>(DataLayout::MLD_CELL_DESTINATION_BOUNDARY,
destination_node_count);
const auto cell_count = reader.ReadVectorSize<util::CellStorage::CellData>();
layout.SetBlockSize<util::CellStorage::CellData>(DataLayout::MLD_CELLS, cell_count);
const auto cell_count = reader.ReadVectorSize<partition::CellStorage::CellData>();
layout.SetBlockSize<partition::CellStorage::CellData>(DataLayout::MLD_CELLS,
cell_count);
const auto level_offsets_count = reader.ReadVectorSize<std::uint64_t>();
layout.SetBlockSize<std::uint64_t>(DataLayout::MLD_CELL_LEVEL_OFFSETS,
level_offsets_count);
@ -899,11 +900,11 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
if (boost::filesystem::exists(config.mld_partition_path))
{
auto mld_level_data_ptr =
layout.GetBlockPtr<util::MultiLevelPartition::LevelData, true>(
layout.GetBlockPtr<partition::MultiLevelPartition::LevelData, true>(
memory_ptr, DataLayout::MLD_LEVEL_DATA);
auto mld_partition_ptr =
layout.GetBlockPtr<util::PartitionID, true>(memory_ptr, DataLayout::MLD_PARTITION);
auto mld_chilren_ptr = layout.GetBlockPtr<util::CellID, true>(
auto mld_partition_ptr = layout.GetBlockPtr<partition::PartitionID, true>(
memory_ptr, DataLayout::MLD_PARTITION);
auto mld_chilren_ptr = layout.GetBlockPtr<partition::CellID, true>(
memory_ptr, DataLayout::MLD_CELL_TO_CHILDREN);
io::FileReader reader(config.mld_partition_path, io::FileReader::VerifyFingerprint);
@ -923,7 +924,7 @@ void Storage::PopulateData(const DataLayout &layout, char *memory_ptr)
layout.GetBlockPtr<NodeID, true>(memory_ptr, DataLayout::MLD_CELL_SOURCE_BOUNDARY);
auto mld_destination_boundary_ptr = layout.GetBlockPtr<NodeID, true>(
memory_ptr, DataLayout::MLD_CELL_DESTINATION_BOUNDARY);
auto mld_cells_ptr = layout.GetBlockPtr<util::CellStorage::CellData, true>(
auto mld_cells_ptr = layout.GetBlockPtr<partition::CellStorage::CellData, true>(
memory_ptr, DataLayout::MLD_CELLS);
auto mld_cell_level_offsets_ptr = layout.GetBlockPtr<std::uint64_t, true>(
memory_ptr, DataLayout::MLD_CELL_LEVEL_OFFSETS);

View File

@ -1,7 +1,7 @@
#include <boost/numeric/conversion/cast.hpp>
#include <boost/test/unit_test.hpp>
#include "util/cell_storage.hpp"
#include "partition/cell_storage.hpp"
#include "util/static_graph.hpp"
#define CHECK_SIZE_RANGE(range, ref) BOOST_CHECK_EQUAL(range.end() - range.begin(), ref)
@ -14,7 +14,7 @@
} while (0)
using namespace osrm;
using namespace osrm::util;
using namespace osrm::partition;
struct MockEdge
{
@ -29,7 +29,7 @@ auto makeGraph(const std::vector<MockEdge> &mock_edges)
bool forward;
bool backward;
};
using Edge = static_graph_details::SortableEdgeWithData<EdgeData>;
using Edge = util::static_graph_details::SortableEdgeWithData<EdgeData>;
std::vector<Edge> edges;
std::size_t max_id = 0;
for (const auto &m : mock_edges)

View File

@ -1,7 +1,7 @@
#include <boost/numeric/conversion/cast.hpp>
#include <boost/test/unit_test.hpp>
#include "util/multi_level_partition.hpp"
#include "partition/multi_level_partition.hpp"
#define CHECK_SIZE_RANGE(range, ref) BOOST_CHECK_EQUAL(range.second - range.first, ref)
#define CHECK_EQUAL_RANGE(range, ref) \
@ -13,7 +13,7 @@
} while (0)
using namespace osrm;
using namespace osrm::util;
using namespace osrm::partition;
BOOST_AUTO_TEST_SUITE(multi_level_partition_tests)