diff --git a/include/contractor/contracted_metric.hpp b/include/contractor/contracted_metric.hpp new file mode 100644 index 00000000000..f44f49e8320 --- /dev/null +++ b/include/contractor/contracted_metric.hpp @@ -0,0 +1,25 @@ +#ifndef OSMR_CONTRACTOR_CONTRACTED_METRIC_HPP +#define OSMR_CONTRACTOR_CONTRACTED_METRIC_HPP + +#include "contractor/query_graph.hpp" + +namespace osrm +{ +namespace contractor +{ + +namespace detail +{ +template struct ContractedMetric +{ + detail::QueryGraph graph; + std::vector> edge_filter; +}; +} + +using ContractedMetric = detail::ContractedMetric; +using ContractedMetricView = detail::ContractedMetric; +} +} + +#endif diff --git a/include/contractor/files.hpp b/include/contractor/files.hpp index 39a15acaa9c..8dcade795d2 100644 --- a/include/contractor/files.hpp +++ b/include/contractor/files.hpp @@ -1,12 +1,9 @@ #ifndef OSRM_CONTRACTOR_FILES_HPP #define OSRM_CONTRACTOR_FILES_HPP -#include "contractor/query_graph.hpp" +#include "contractor/serialization.hpp" -#include "util/serialization.hpp" - -#include "storage/serialization.hpp" -#include "storage/tar.hpp" +#include namespace osrm { @@ -15,67 +12,45 @@ namespace contractor namespace files { // reads .osrm.hsgr file -template +template inline void readGraph(const boost::filesystem::path &path, - unsigned &checksum, - QueryGraphT &graph, - std::vector &edge_filter, + std::unordered_map &metrics, std::uint32_t &connectivity_checksum) { - static_assert(std::is_same::value || - std::is_same::value, - "graph must be of type QueryGraph<>"); - static_assert(std::is_same>::value || - std::is_same>::value, - "edge_filter must be a container of vector or vector_view"); + static_assert(std::is_same::value || + std::is_same::value, + "metric must be of type ContractedMetric<>"); const auto fingerprint = storage::tar::FileReader::VerifyFingerprint; storage::tar::FileReader reader{path, fingerprint}; - reader.ReadInto("/ch/checksum", checksum); - util::serialization::read(reader, "/ch/contracted_graph", graph); + reader.ReadInto("/ch/connectivity_checksum", connectivity_checksum); - auto count = reader.ReadElementCount64("/ch/edge_filter"); - edge_filter.resize(count); - for (const auto index : util::irange(0, count)) + for (auto &pair : metrics) { - storage::serialization::read( - reader, "/ch/edge_filter/" + std::to_string(index), edge_filter[index]); + serialization::read(reader, "/ch/metrics/" + pair.first, pair.second); } - - reader.ReadInto("/ch/connectivity_checksum", connectivity_checksum); } // writes .osrm.hsgr file -template +template inline void writeGraph(const boost::filesystem::path &path, - unsigned checksum, - const QueryGraphT &graph, - const std::vector &edge_filter, + const std::unordered_map &metrics, const std::uint32_t connectivity_checksum) { - static_assert(std::is_same::value || - std::is_same::value, - "graph must be of type QueryGraph<>"); - static_assert(std::is_same>::value || - std::is_same>::value, - "edge_filter must be a container of vector or vector_view"); + static_assert(std::is_same::value || + std::is_same::value, + "metric must be of type ContractedMetric<>"); const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint; storage::tar::FileWriter writer{path, fingerprint}; - writer.WriteElementCount64("/ch/checksum", 1); - writer.WriteFrom("/ch/checksum", checksum); - util::serialization::write(writer, "/ch/contracted_graph", graph); + writer.WriteElementCount64("/ch/connectivity_checksum", 1); + writer.WriteFrom("/ch/connectivity_checksum", connectivity_checksum); - writer.WriteElementCount64("/ch/edge_filter", edge_filter.size()); - for (const auto index : util::irange(0, edge_filter.size())) + for (const auto &pair : metrics) { - storage::serialization::write( - writer, "/ch/edge_filter/" + std::to_string(index), edge_filter[index]); + serialization::write(writer, "/ch/metrics/" + pair.first, pair.second); } - - writer.WriteElementCount64("/ch/connectivity_checksum", 1); - writer.WriteFrom("/ch/connectivity_checksum", connectivity_checksum); } } } diff --git a/include/contractor/serialization.hpp b/include/contractor/serialization.hpp new file mode 100644 index 00000000000..aa86592742d --- /dev/null +++ b/include/contractor/serialization.hpp @@ -0,0 +1,53 @@ +#ifndef OSRM_CONTRACTOR_SERIALIZATION_HPP +#define OSRM_CONTRACTOR_SERIALIZATION_HPP + +#include "contractor/contracted_metric.hpp" + +#include "util/serialization.hpp" + +#include "storage/serialization.hpp" +#include "storage/tar.hpp" + +namespace osrm +{ +namespace contractor +{ +namespace serialization +{ + +template +void write(storage::tar::FileWriter &writer, + const std::string &name, + const detail::ContractedMetric &metric) +{ + util::serialization::write(writer, name + "/contracted_graph", metric.graph); + + writer.WriteElementCount64(name + "/exclude", metric.edge_filter.size()); + for (const auto index : util::irange(0, metric.edge_filter.size())) + { + storage::serialization::write(writer, + name + "/exclude/" + std::to_string(index) + "/edge_filter", + metric.edge_filter[index]); + } +} + +template +void read(storage::tar::FileReader &reader, + const std::string &name, + detail::ContractedMetric &metric) +{ + util::serialization::read(reader, name + "/contracted_graph", metric.graph); + + metric.edge_filter.resize(reader.ReadElementCount64(name + "/exclude")); + for (const auto index : util::irange(0, metric.edge_filter.size())) + { + storage::serialization::read(reader, + name + "/exclude/" + std::to_string(index) + "/edge_filter", + metric.edge_filter[index]); + } +} +} +} +} + +#endif diff --git a/include/customizer/files.hpp b/include/customizer/files.hpp index 098752f9c9e..c89b5cb7607 100644 --- a/include/customizer/files.hpp +++ b/include/customizer/files.hpp @@ -7,6 +7,8 @@ #include "util/integer_range.hpp" +#include + namespace osrm { namespace customizer @@ -16,7 +18,8 @@ namespace files // reads .osrm.cell_metrics file template -inline void readCellMetrics(const boost::filesystem::path &path, std::vector &metrics) +inline void readCellMetrics(const boost::filesystem::path &path, + std::unordered_map> &metrics) { static_assert(std::is_same::value || std::is_same::value, @@ -25,20 +28,28 @@ inline void readCellMetrics(const boost::filesystem::path &path, std::vector -inline void writeCellMetrics(const boost::filesystem::path &path, - const std::vector &metrics) +inline void +writeCellMetrics(const boost::filesystem::path &path, + const std::unordered_map> &metrics) { static_assert(std::is_same::value || std::is_same::value, @@ -47,12 +58,19 @@ inline void writeCellMetrics(const boost::filesystem::path &path, const auto fingerprint = storage::tar::FileWriter::GenerateFingerprint; storage::tar::FileWriter writer{path, fingerprint}; - writer.WriteElementCount64("/mld/metrics", metrics.size()); - - auto id = 0; - for (const auto &metric : metrics) + for (const auto &pair : metrics) { - serialization::write(writer, "/mld/metrics/" + std::to_string(id++), metric); + const auto &metric_name = pair.first; + const auto &metric_exclude_classes = pair.second; + + auto prefix = "/mld/metrics/" + metric_name + "/exclude"; + writer.WriteElementCount64(prefix, metric_exclude_classes.size()); + + auto id = 0; + for (auto &exclude_metric : metric_exclude_classes) + { + serialization::write(writer, prefix + "/" + std::to_string(id++), exclude_metric); + } } } } diff --git a/include/engine/algorithm.hpp b/include/engine/algorithm.hpp index 751ef6b9b09..8f48b373005 100644 --- a/include/engine/algorithm.hpp +++ b/include/engine/algorithm.hpp @@ -30,6 +30,11 @@ template const char *name(); template <> inline const char *name() { return "CH"; } template <> inline const char *name() { return "MLD"; } +// Algorithm identifier +template const char *identifier(); +template <> inline const char *identifier() { return "ch"; } +template <> inline const char *identifier() { return "mld"; } + template struct HasAlternativePathSearch final : std::false_type { }; diff --git a/include/engine/datafacade/contiguous_block_allocator.hpp b/include/engine/datafacade/contiguous_block_allocator.hpp index 0a185202524..cc2dbca5a8d 100644 --- a/include/engine/datafacade/contiguous_block_allocator.hpp +++ b/include/engine/datafacade/contiguous_block_allocator.hpp @@ -16,7 +16,7 @@ class ContiguousBlockAllocator virtual ~ContiguousBlockAllocator() = default; // interface to give access to the datafacades - virtual storage::DataLayout &GetLayout() = 0; + virtual const storage::DataLayout &GetLayout() = 0; virtual char *GetMemory() = 0; }; diff --git a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp index c8785661d25..4281e295ef8 100644 --- a/include/engine/datafacade/contiguous_internalmem_datafacade.hpp +++ b/include/engine/datafacade/contiguous_internalmem_datafacade.hpp @@ -9,44 +9,13 @@ #include "engine/approach.hpp" #include "engine/geospatial_query.hpp" -#include "customizer/edge_based_graph.hpp" - -#include "extractor/datasources.hpp" -#include "extractor/edge_based_node.hpp" -#include "extractor/intersection_bearings_container.hpp" -#include "extractor/maneuver_override.hpp" -#include "extractor/name_table.hpp" -#include "extractor/node_data_container.hpp" -#include "extractor/packed_osm_ids.hpp" -#include "extractor/profile_properties.hpp" -#include "extractor/segment_data_container.hpp" -#include "extractor/turn_lane_types.hpp" - -#include "guidance/turn_bearing.hpp" -#include "guidance/turn_data_container.hpp" -#include "guidance/turn_instruction.hpp" - -#include "contractor/query_graph.hpp" - -#include "partitioner/cell_storage.hpp" -#include "partitioner/multi_level_partition.hpp" - #include "storage/shared_datatype.hpp" #include "storage/shared_memory_ownership.hpp" +#include "storage/view_factory.hpp" #include "util/exception.hpp" #include "util/exception_utils.hpp" -#include "util/filtered_graph.hpp" -#include "util/guidance/bearing_class.hpp" -#include "util/guidance/entry_class.hpp" -#include "util/guidance/turn_lanes.hpp" #include "util/log.hpp" -#include "util/packed_vector.hpp" -#include "util/range_table.hpp" -#include "util/rectangle.hpp" -#include "util/static_graph.hpp" -#include "util/static_rtree.hpp" -#include "util/typedefs.hpp" #include @@ -81,45 +50,24 @@ class ContiguousInternalMemoryAlgorithmDataFacade : public datafacade::Algor // allocator that keeps the allocation data std::shared_ptr allocator; - void InitializeGraphPointer(storage::DataLayout &data_layout, - char *memory_block, - const std::size_t exclude_index) - { - auto graph_nodes_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::CH_GRAPH_NODE_LIST); - - auto graph_edges_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::CH_GRAPH_EDGE_LIST); - - auto filter_block_id = static_cast( - storage::DataLayout::CH_EDGE_FILTER_0 + exclude_index); - - auto edge_filter_ptr = - data_layout.GetBlockPtr::Word>(memory_block, filter_block_id); - - util::vector_view node_list( - graph_nodes_ptr, data_layout.GetBlockEntries(storage::DataLayout::CH_GRAPH_NODE_LIST)); - util::vector_view edge_list( - graph_edges_ptr, data_layout.GetBlockEntries(storage::DataLayout::CH_GRAPH_EDGE_LIST)); - - util::vector_view edge_filter(edge_filter_ptr, - data_layout.GetBlockEntries(filter_block_id)); - m_query_graph = QueryGraph({node_list, edge_list}, edge_filter); - } - public: ContiguousInternalMemoryAlgorithmDataFacade( - std::shared_ptr allocator_, std::size_t exclude_index) + std::shared_ptr allocator_, + const std::string &metric_name, + std::size_t exclude_index) : allocator(std::move(allocator_)) { - InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index); + InitializeInternalPointers( + allocator->GetLayout(), allocator->GetMemory(), metric_name, exclude_index); } - void InitializeInternalPointers(storage::DataLayout &data_layout, + void InitializeInternalPointers(const storage::DataLayout &data_layout, char *memory_block, + const std::string &metric_name, const std::size_t exclude_index) { - InitializeGraphPointer(data_layout, memory_block, exclude_index); + m_query_graph = make_filtered_graph_view( + memory_block, data_layout, "/ch/metrics/" + metric_name, exclude_index); } // search graph access @@ -191,7 +139,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade extractor::ProfileProperties *m_profile_properties; extractor::Datasources *m_datasources; - unsigned m_check_sum; + std::uint32_t m_check_sum; util::vector_view m_coordinate_list; extractor::PackedOSMIDsView m_osmnodeid_list; util::vector_view m_lane_description_offsets; @@ -210,7 +158,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade util::vector_view m_maneuver_overrides; util::vector_view m_maneuver_override_node_sequences; - std::unique_ptr m_static_rtree; + SharedRTree m_static_rtree; std::unique_ptr m_geospatial_query; boost::filesystem::path file_index_path; @@ -224,336 +172,67 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade // allocator that keeps the allocation data std::shared_ptr allocator; - void InitializeProfilePropertiesPointer(storage::DataLayout &data_layout, - char *memory_block, - const std::size_t exclude_index) + void InitializeInternalPointers(const storage::DataLayout &layout, + char *memory_ptr, + const std::string &metric_name, + const std::size_t exclude_index) { - m_profile_properties = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::PROPERTIES); + // TODO: For multi-metric support we need to have separate exclude classes per metric + (void)metric_name; + + m_profile_properties = + layout.GetBlockPtr(memory_ptr, "/common/properties"); exclude_mask = m_profile_properties->excludable_classes[exclude_index]; - } - void InitializeChecksumPointer(storage::DataLayout &data_layout, char *memory_block) - { m_check_sum = - *data_layout.GetBlockPtr(memory_block, storage::DataLayout::HSGR_CHECKSUM); - util::Log() << "set checksum: " << m_check_sum; - } + *layout.GetBlockPtr(memory_ptr, "/common/connectivity_checksum"); - void InitializeRTreePointers(storage::DataLayout &data_layout, char *memory_block) - { - BOOST_ASSERT_MSG(!m_coordinate_list.empty(), "coordinates must be loaded before r-tree"); + std::tie(m_coordinate_list, m_osmnodeid_list) = + make_nbn_data_view(memory_ptr, layout, "/common/nbn_data"); - const auto file_index_ptr = - data_layout.GetBlockPtr(memory_block, storage::DataLayout::FILE_INDEX_PATH); - file_index_path = boost::filesystem::path(file_index_ptr); - if (!boost::filesystem::exists(file_index_path)) - { - util::Log(logDEBUG) << "Leaf file name " << file_index_path.string(); - throw util::exception("Could not load " + file_index_path.string() + - "Is any data loaded into shared memory?" + SOURCE_REF); - } - - const auto rtree_ptr = - data_layout.GetBlockPtr(memory_block, storage::DataLayout::R_SEARCH_TREE); - util::vector_view search_tree( - rtree_ptr, data_layout.GetBlockEntries(storage::DataLayout::R_SEARCH_TREE)); - - const auto rtree_levelstarts_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::R_SEARCH_TREE_LEVEL_STARTS); - util::vector_view rtree_level_starts( - rtree_levelstarts_ptr, - data_layout.GetBlockEntries(storage::DataLayout::R_SEARCH_TREE_LEVEL_STARTS)); - - m_static_rtree.reset(new SharedRTree{std::move(search_tree), - std::move(rtree_level_starts), - file_index_path, - m_coordinate_list}); + m_static_rtree = make_search_tree_view(memory_ptr, layout, "/common/rtree"); m_geospatial_query.reset( - new SharedGeospatialQuery(*m_static_rtree, m_coordinate_list, *this)); - } + new SharedGeospatialQuery(m_static_rtree, m_coordinate_list, *this)); - void InitializeNodeInformationPointers(storage::DataLayout &layout, char *memory_ptr) - { - const auto coordinate_list_ptr = - layout.GetBlockPtr(memory_ptr, storage::DataLayout::COORDINATE_LIST); - m_coordinate_list.reset(coordinate_list_ptr, - layout.GetBlockEntries(storage::DataLayout::COORDINATE_LIST)); + edge_based_node_data = make_ebn_data_view(memory_ptr, layout, "/common/ebg_node_data"); - const auto osmnodeid_ptr = layout.GetBlockPtr( - memory_ptr, storage::DataLayout::OSM_NODE_ID_LIST); - m_osmnodeid_list = extractor::PackedOSMIDsView( - util::vector_view( - osmnodeid_ptr, layout.GetBlockEntries(storage::DataLayout::OSM_NODE_ID_LIST)), - // We (ab)use the number of coordinates here because we know we have the same amount of - // ids - layout.GetBlockEntries(storage::DataLayout::COORDINATE_LIST)); - } + turn_data = make_turn_data_view(memory_ptr, layout, "/common/turn_data"); - void InitializeEdgeBasedNodeDataInformationPointers(storage::DataLayout &layout, - char *memory_ptr) - { - const auto edge_based_node_list_ptr = layout.GetBlockPtr( - memory_ptr, storage::DataLayout::EDGE_BASED_NODE_DATA_LIST); - util::vector_view edge_based_node_data_list( - edge_based_node_list_ptr, - layout.GetBlockEntries(storage::DataLayout::EDGE_BASED_NODE_DATA_LIST)); - - const auto annotation_data_list_ptr = - layout.GetBlockPtr( - memory_ptr, storage::DataLayout::ANNOTATION_DATA_LIST); - util::vector_view annotation_data( - annotation_data_list_ptr, - layout.GetBlockEntries(storage::DataLayout::ANNOTATION_DATA_LIST)); + m_name_table = make_name_table_view(memory_ptr, layout, "/common/names"); - edge_based_node_data = extractor::EdgeBasedNodeDataView( - std::move(edge_based_node_data_list), std::move(annotation_data)); - } - - void InitializeEdgeInformationPointers(storage::DataLayout &layout, char *memory_ptr) - { - const auto lane_data_id_ptr = - layout.GetBlockPtr(memory_ptr, storage::DataLayout::LANE_DATA_ID); - util::vector_view lane_data_ids( - lane_data_id_ptr, layout.GetBlockEntries(storage::DataLayout::LANE_DATA_ID)); + std::tie(m_lane_description_offsets, m_lane_description_masks) = + make_turn_lane_description_views(memory_ptr, layout, "/common/turn_lanes"); + m_lane_tupel_id_pairs = make_lane_data_view(memory_ptr, layout, "/common/turn_lanes"); - const auto turn_instruction_list_ptr = layout.GetBlockPtr( - memory_ptr, storage::DataLayout::TURN_INSTRUCTION); - util::vector_view turn_instructions( - turn_instruction_list_ptr, - layout.GetBlockEntries(storage::DataLayout::TURN_INSTRUCTION)); - - const auto entry_class_id_list_ptr = - layout.GetBlockPtr(memory_ptr, storage::DataLayout::ENTRY_CLASSID); - util::vector_view entry_class_ids( - entry_class_id_list_ptr, layout.GetBlockEntries(storage::DataLayout::ENTRY_CLASSID)); - - const auto pre_turn_bearing_ptr = layout.GetBlockPtr( - memory_ptr, storage::DataLayout::PRE_TURN_BEARING); - util::vector_view pre_turn_bearings( - pre_turn_bearing_ptr, layout.GetBlockEntries(storage::DataLayout::PRE_TURN_BEARING)); - - const auto post_turn_bearing_ptr = layout.GetBlockPtr( - memory_ptr, storage::DataLayout::POST_TURN_BEARING); - util::vector_view post_turn_bearings( - post_turn_bearing_ptr, layout.GetBlockEntries(storage::DataLayout::POST_TURN_BEARING)); - - turn_data = guidance::TurnDataView(std::move(turn_instructions), - std::move(lane_data_ids), - std::move(entry_class_ids), - std::move(pre_turn_bearings), - std::move(post_turn_bearings)); - } - - void InitializeNamePointers(storage::DataLayout &data_layout, char *memory_block) - { - const auto name_blocks_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::NAME_BLOCKS); - const auto name_values_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::NAME_VALUES); - - util::vector_view blocks( - name_blocks_ptr, data_layout.GetBlockEntries(storage::DataLayout::NAME_BLOCKS)); - util::vector_view values( - name_values_ptr, data_layout.GetBlockEntries(storage::DataLayout::NAME_VALUES)); - - extractor::NameTableView::IndexedData index_data_view{std::move(blocks), std::move(values)}; - m_name_table = extractor::NameTableView{std::move(index_data_view)}; - } - - void InitializeTurnLaneDescriptionsPointers(storage::DataLayout &data_layout, - char *memory_block) - { - auto offsets_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::LANE_DESCRIPTION_OFFSETS); - util::vector_view offsets( - offsets_ptr, - data_layout.GetBlockEntries(storage::DataLayout::LANE_DESCRIPTION_OFFSETS)); - m_lane_description_offsets = std::move(offsets); - - auto masks_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::LANE_DESCRIPTION_MASKS); - - util::vector_view masks( - masks_ptr, data_layout.GetBlockEntries(storage::DataLayout::LANE_DESCRIPTION_MASKS)); - m_lane_description_masks = std::move(masks); - - const auto lane_tupel_id_pair_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::TURN_LANE_DATA); - util::vector_view lane_tupel_id_pair( - lane_tupel_id_pair_ptr, - data_layout.GetBlockEntries(storage::DataLayout::TURN_LANE_DATA)); - m_lane_tupel_id_pairs = std::move(lane_tupel_id_pair); - } - - void InitializeTurnPenalties(storage::DataLayout &data_layout, char *memory_block) - { - auto turn_weight_penalties_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::TURN_WEIGHT_PENALTIES); - m_turn_weight_penalties = util::vector_view( - turn_weight_penalties_ptr, - data_layout.GetBlockEntries(storage::DataLayout::TURN_WEIGHT_PENALTIES)); - auto turn_duration_penalties_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::TURN_DURATION_PENALTIES); - m_turn_duration_penalties = util::vector_view( - turn_duration_penalties_ptr, - data_layout.GetBlockEntries(storage::DataLayout::TURN_DURATION_PENALTIES)); - } - - void InitializeGeometryPointers(storage::DataLayout &data_layout, char *memory_block) - { - auto geometries_index_ptr = - data_layout.GetBlockPtr(memory_block, storage::DataLayout::GEOMETRIES_INDEX); - util::vector_view geometry_begin_indices( - geometries_index_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_INDEX)); - - auto num_entries = data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_NODE_LIST); - auto geometries_node_list_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_NODE_LIST); - util::vector_view geometry_node_list(geometries_node_list_ptr, num_entries); - - auto geometries_fwd_weight_list_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST); - extractor::SegmentDataView::SegmentWeightVector geometry_fwd_weight_list( - util::vector_view( - geometries_fwd_weight_list_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_FWD_WEIGHT_LIST)), - num_entries); - - auto geometries_rev_weight_list_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST); - extractor::SegmentDataView::SegmentWeightVector geometry_rev_weight_list( - util::vector_view( - geometries_rev_weight_list_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_REV_WEIGHT_LIST)), - num_entries); - - auto geometries_fwd_duration_list_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST); - extractor::SegmentDataView::SegmentDurationVector geometry_fwd_duration_list( - util::vector_view( - geometries_fwd_duration_list_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_FWD_DURATION_LIST)), - num_entries); - - auto geometries_rev_duration_list_ptr = - data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_REV_DURATION_LIST); - extractor::SegmentDataView::SegmentDurationVector geometry_rev_duration_list( - util::vector_view( - geometries_rev_duration_list_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_REV_DURATION_LIST)), - num_entries); - - auto geometries_fwd_datasources_list_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_FWD_DATASOURCES_LIST); - util::vector_view geometry_fwd_datasources_list( - geometries_fwd_datasources_list_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_FWD_DATASOURCES_LIST)); - - auto geometries_rev_datasources_list_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::GEOMETRIES_REV_DATASOURCES_LIST); - util::vector_view geometry_rev_datasources_list( - geometries_rev_datasources_list_ptr, - data_layout.GetBlockEntries(storage::DataLayout::GEOMETRIES_REV_DATASOURCES_LIST)); - - segment_data = extractor::SegmentDataView{std::move(geometry_begin_indices), - std::move(geometry_node_list), - std::move(geometry_fwd_weight_list), - std::move(geometry_rev_weight_list), - std::move(geometry_fwd_duration_list), - std::move(geometry_rev_duration_list), - std::move(geometry_fwd_datasources_list), - std::move(geometry_rev_datasources_list)}; - - m_datasources = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::DATASOURCES_NAMES); - } - - void InitializeIntersectionClassPointers(storage::DataLayout &data_layout, char *memory_block) - { - auto bearing_class_id_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::BEARING_CLASSID); - util::vector_view bearing_class_id( - bearing_class_id_ptr, - data_layout.GetBlockEntries(storage::DataLayout::BEARING_CLASSID)); - - auto bearing_values_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::BEARING_VALUES); - util::vector_view bearing_values( - bearing_values_ptr, data_layout.GetBlockEntries(storage::DataLayout::BEARING_VALUES)); - - auto offsets_ptr = - data_layout.GetBlockPtr(memory_block, storage::DataLayout::BEARING_OFFSETS); - auto blocks_ptr = - data_layout.GetBlockPtr(memory_block, storage::DataLayout::BEARING_BLOCKS); - util::vector_view bearing_offsets( - offsets_ptr, data_layout.GetBlockEntries(storage::DataLayout::BEARING_OFFSETS)); - util::vector_view bearing_blocks( - blocks_ptr, data_layout.GetBlockEntries(storage::DataLayout::BEARING_BLOCKS)); - - util::RangeTable<16, storage::Ownership::View> bearing_range_table( - bearing_offsets, bearing_blocks, static_cast(bearing_values.size())); - - intersection_bearings_view = extractor::IntersectionBearingsView{ - std::move(bearing_values), std::move(bearing_class_id), std::move(bearing_range_table)}; - - auto entry_class_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::ENTRY_CLASS); - util::vector_view entry_class_table( - entry_class_ptr, data_layout.GetBlockEntries(storage::DataLayout::ENTRY_CLASS)); - m_entry_class_table = std::move(entry_class_table); - } - - void InitializeManeuverOverridePointers(storage::DataLayout &data_layout, char *memory_block) - { - auto maneuver_overrides_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MANEUVER_OVERRIDES); - m_maneuver_overrides = util::vector_view( - maneuver_overrides_ptr, - data_layout.GetBlockEntries(storage::DataLayout::MANEUVER_OVERRIDES)); - - auto maneuver_override_node_sequences_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MANEUVER_OVERRIDE_NODE_SEQUENCES); - m_maneuver_override_node_sequences = util::vector_view( - maneuver_override_node_sequences_ptr, - data_layout.GetBlockEntries(storage::DataLayout::MANEUVER_OVERRIDE_NODE_SEQUENCES)); - } - - void InitializeInternalPointers(storage::DataLayout &data_layout, - char *memory_block, - const std::size_t exclude_index) - { - InitializeChecksumPointer(data_layout, memory_block); - InitializeNodeInformationPointers(data_layout, memory_block); - InitializeEdgeBasedNodeDataInformationPointers(data_layout, memory_block); - InitializeEdgeInformationPointers(data_layout, memory_block); - InitializeTurnPenalties(data_layout, memory_block); - InitializeGeometryPointers(data_layout, memory_block); - InitializeNamePointers(data_layout, memory_block); - InitializeTurnLaneDescriptionsPointers(data_layout, memory_block); - InitializeProfilePropertiesPointer(data_layout, memory_block, exclude_index); - InitializeRTreePointers(data_layout, memory_block); - InitializeIntersectionClassPointers(data_layout, memory_block); - InitializeManeuverOverridePointers(data_layout, memory_block); + m_turn_weight_penalties = make_turn_weight_view(memory_ptr, layout, "/common/turn_penalty"); + m_turn_duration_penalties = + make_turn_duration_view(memory_ptr, layout, "/common/turn_penalty"); + + segment_data = make_segment_data_view(memory_ptr, layout, "/common/segment_data"); + + m_datasources = + layout.GetBlockPtr(memory_ptr, "/common/data_sources_names"); + + intersection_bearings_view = + make_intersection_bearings_view(memory_ptr, layout, "/common/intersection_bearings"); + + m_entry_class_table = make_entry_classes_view(memory_ptr, layout, "/common/entry_classes"); + + std::tie(m_maneuver_overrides, m_maneuver_override_node_sequences) = + make_maneuver_overrides_views(memory_ptr, layout, "/common/maneuver_overrides"); } public: // allows switching between process_memory/shared_memory datafacade, based on the type of // allocator ContiguousInternalMemoryDataFacadeBase(std::shared_ptr allocator_, + const std::string &metric_name, const std::size_t exclude_index) : allocator(std::move(allocator_)) { - InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index); + InitializeInternalPointers( + allocator->GetLayout(), allocator->GetMemory(), metric_name, exclude_index); } // node and edge information access @@ -772,7 +451,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade input_coordinate, bearing, bearing_range, approach); } - unsigned GetCheckSum() const override final { return m_check_sum; } + std::uint32_t GetCheckSum() const override final { return m_check_sum; } GeometryID GetGeometryIndex(const NodeID id) const override final { @@ -961,9 +640,10 @@ class ContiguousInternalMemoryDataFacade { public: ContiguousInternalMemoryDataFacade(std::shared_ptr allocator, + const std::string &metric_name, const std::size_t exclude_index) - : ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index), - ContiguousInternalMemoryAlgorithmDataFacade(allocator, exclude_index) + : ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index), + ContiguousInternalMemoryAlgorithmDataFacade(allocator, metric_name, exclude_index) { } @@ -981,122 +661,16 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade : public Algo QueryGraph query_graph; - void InitializeInternalPointers(storage::DataLayout &data_layout, - char *memory_block, + void InitializeInternalPointers(const storage::DataLayout &layout, + char *memory_ptr, + const std::string &metric_name, const std::size_t exclude_index) { - InitializeMLDDataPointers(data_layout, memory_block, exclude_index); - InitializeGraphPointer(data_layout, memory_block); - } - - void InitializeMLDDataPointers(storage::DataLayout &data_layout, - char *memory_block, - const std::size_t exclude_index) - { - if (data_layout.GetBlockSize(storage::DataLayout::MLD_PARTITION) > 0) - { - 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( - memory_block, storage::DataLayout::MLD_LEVEL_DATA); - - auto mld_partition_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_PARTITION); - auto partition_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_PARTITION); - util::vector_view partition(mld_partition_ptr, partition_entries_count); - - auto mld_chilren_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_CELL_TO_CHILDREN); - auto children_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_TO_CHILDREN); - util::vector_view cell_to_children(mld_chilren_ptr, children_entries_count); - - mld_partition = - partitioner::MultiLevelPartitionView{level_data, partition, cell_to_children}; - } - - const auto weights_block_id = static_cast( - storage::DataLayout::MLD_CELL_WEIGHTS_0 + exclude_index); - const auto durations_block_id = static_cast( - storage::DataLayout::MLD_CELL_DURATIONS_0 + exclude_index); - - if (data_layout.GetBlockSize(weights_block_id) > 0) - { - auto mld_cell_weights_ptr = - data_layout.GetBlockPtr(memory_block, weights_block_id); - auto mld_cell_durations_ptr = - data_layout.GetBlockPtr(memory_block, durations_block_id); - auto weight_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_WEIGHTS_0); - auto duration_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_DURATIONS_0); - BOOST_ASSERT(weight_entries_count == duration_entries_count); - util::vector_view weights(mld_cell_weights_ptr, weight_entries_count); - util::vector_view durations(mld_cell_durations_ptr, - duration_entries_count); - - mld_cell_metric = customizer::CellMetricView{std::move(weights), std::move(durations)}; - } - - if (data_layout.GetBlockSize(storage::DataLayout::MLD_CELLS) > 0) - { - - auto mld_source_boundary_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_CELL_SOURCE_BOUNDARY); - auto mld_destination_boundary_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_CELL_DESTINATION_BOUNDARY); - auto mld_cells_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_CELLS); - auto mld_cell_level_offsets_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_CELL_LEVEL_OFFSETS); - - auto source_boundary_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_SOURCE_BOUNDARY); - auto destination_boundary_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_DESTINATION_BOUNDARY); - auto cells_entries_counts = data_layout.GetBlockEntries(storage::DataLayout::MLD_CELLS); - auto cell_level_offsets_entries_count = - data_layout.GetBlockEntries(storage::DataLayout::MLD_CELL_LEVEL_OFFSETS); - - util::vector_view source_boundary(mld_source_boundary_ptr, - source_boundary_entries_count); - util::vector_view destination_boundary(mld_destination_boundary_ptr, - destination_boundary_entries_count); - util::vector_view cells(mld_cells_ptr, - cells_entries_counts); - util::vector_view level_offsets(mld_cell_level_offsets_ptr, - cell_level_offsets_entries_count); - - mld_cell_storage = partitioner::CellStorageView{std::move(source_boundary), - std::move(destination_boundary), - std::move(cells), - std::move(level_offsets)}; - } - } - void InitializeGraphPointer(storage::DataLayout &data_layout, char *memory_block) - { - auto graph_nodes_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_GRAPH_NODE_LIST); - - auto graph_edges_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_GRAPH_EDGE_LIST); - - auto graph_node_to_offset_ptr = data_layout.GetBlockPtr( - memory_block, storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET); - - util::vector_view node_list( - graph_nodes_ptr, data_layout.GetBlockEntries(storage::DataLayout::MLD_GRAPH_NODE_LIST)); - util::vector_view edge_list( - graph_edges_ptr, data_layout.GetBlockEntries(storage::DataLayout::MLD_GRAPH_EDGE_LIST)); - util::vector_view node_to_offset( - graph_node_to_offset_ptr, - data_layout.GetBlockEntries(storage::DataLayout::MLD_GRAPH_NODE_TO_OFFSET)); - - query_graph = - QueryGraph(std::move(node_list), std::move(edge_list), std::move(node_to_offset)); + mld_partition = make_partition_view(memory_ptr, layout, "/mld/multilevelpartition"); + mld_cell_metric = make_filtered_cell_metric_view( + memory_ptr, layout, "/mld/metrics/" + metric_name, exclude_index); + mld_cell_storage = make_cell_storage_view(memory_ptr, layout, "/mld/cellstorage"); + query_graph = make_multi_level_graph_view(memory_ptr, layout, "/mld/multilevelgraph"); } // allocator that keeps the allocation data @@ -1104,10 +678,13 @@ template <> class ContiguousInternalMemoryAlgorithmDataFacade : public Algo public: ContiguousInternalMemoryAlgorithmDataFacade( - std::shared_ptr allocator_, const std::size_t exclude_index) + std::shared_ptr allocator_, + const std::string &metric_name, + const std::size_t exclude_index) : allocator(std::move(allocator_)) { - InitializeInternalPointers(allocator->GetLayout(), allocator->GetMemory(), exclude_index); + InitializeInternalPointers( + allocator->GetLayout(), allocator->GetMemory(), metric_name, exclude_index); } const partitioner::MultiLevelPartitionView &GetMultiLevelPartition() const override @@ -1161,9 +738,10 @@ class ContiguousInternalMemoryDataFacade final private: public: ContiguousInternalMemoryDataFacade(std::shared_ptr allocator, + const std::string &metric_name, const std::size_t exclude_index) - : ContiguousInternalMemoryDataFacadeBase(allocator, exclude_index), - ContiguousInternalMemoryAlgorithmDataFacade(allocator, exclude_index) + : ContiguousInternalMemoryDataFacadeBase(allocator, metric_name, exclude_index), + ContiguousInternalMemoryAlgorithmDataFacade(allocator, metric_name, exclude_index) { } diff --git a/include/engine/datafacade/datafacade_base.hpp b/include/engine/datafacade/datafacade_base.hpp index 46d8e335020..ed40533c81e 100644 --- a/include/engine/datafacade/datafacade_base.hpp +++ b/include/engine/datafacade/datafacade_base.hpp @@ -53,7 +53,7 @@ class BaseDataFacade BaseDataFacade() {} virtual ~BaseDataFacade() {} - virtual unsigned GetCheckSum() const = 0; + virtual std::uint32_t GetCheckSum() const = 0; // node and edge information access virtual util::Coordinate GetCoordinateOfNode(const NodeID id) const = 0; diff --git a/include/engine/datafacade/process_memory_allocator.hpp b/include/engine/datafacade/process_memory_allocator.hpp index aa41dd6e4e8..705ab935e1b 100644 --- a/include/engine/datafacade/process_memory_allocator.hpp +++ b/include/engine/datafacade/process_memory_allocator.hpp @@ -27,12 +27,12 @@ class ProcessMemoryAllocator : public ContiguousBlockAllocator ~ProcessMemoryAllocator() override final; // interface to give access to the datafacades - storage::DataLayout &GetLayout() override final; + const storage::DataLayout &GetLayout() override final; char *GetMemory() override final; private: + storage::DataLayout internal_layout; std::unique_ptr internal_memory; - std::unique_ptr internal_layout; }; } // namespace datafacade diff --git a/include/engine/datafacade/shared_memory_allocator.hpp b/include/engine/datafacade/shared_memory_allocator.hpp index f69c6f09edf..e201e4ee483 100644 --- a/include/engine/datafacade/shared_memory_allocator.hpp +++ b/include/engine/datafacade/shared_memory_allocator.hpp @@ -27,10 +27,12 @@ class SharedMemoryAllocator : public ContiguousBlockAllocator ~SharedMemoryAllocator() override final; // interface to give access to the datafacades - storage::DataLayout &GetLayout() override final; + const storage::DataLayout &GetLayout() override final; char *GetMemory() override final; private: + std::size_t layout_size; + storage::DataLayout data_layout; std::unique_ptr m_large_memory; }; diff --git a/include/engine/datafacade_factory.hpp b/include/engine/datafacade_factory.hpp index 92efcf7ee9e..44e1a1f85c7 100644 --- a/include/engine/datafacade_factory.hpp +++ b/include/engine/datafacade_factory.hpp @@ -33,6 +33,7 @@ template