From abbdc17be27f77c52bfab9f04b0f9eac074fe1de Mon Sep 17 00:00:00 2001 From: Denis Koronchik Date: Mon, 20 Oct 2014 15:59:59 +0300 Subject: [PATCH] Revert "Merge pull request #2866 from vng/routing-beta" This reverts commit 7f52ed17e0b473bb98ce106e3982ca6d3785e4ea, reversing changes made to efcc4ddb2d653a5e627d0d2ea62cc56b863ee785. --- .../RoutingAlgorithms/BasicRoutingInterface.h | 34 +- .../Server/DataStructures/BaseDataFacade.h | 2 + .../osrm/osrm-backend/mapsme/CMakeLists.txt | 11 +- 3party/osrm/osrm-backend/mapsme/converter.cpp | 365 ++++++++++++++---- 3party/osrm/osrm-backend/mapsme/converter.hpp | 11 +- 3party/osrm/osrm-backend/mapsme/main.cpp | 4 +- base/bits.hpp | 2 + defines.hpp | 8 +- routing/osrm_data_facade.hpp | 54 ++- routing/routing.pro | 1 + 10 files changed, 357 insertions(+), 135 deletions(-) diff --git a/3party/osrm/osrm-backend/RoutingAlgorithms/BasicRoutingInterface.h b/3party/osrm/osrm-backend/RoutingAlgorithms/BasicRoutingInterface.h index f830d2717a..8e806787fd 100644 --- a/3party/osrm/osrm-backend/RoutingAlgorithms/BasicRoutingInterface.h +++ b/3party/osrm/osrm-backend/RoutingAlgorithms/BasicRoutingInterface.h @@ -98,7 +98,7 @@ template class BasicRoutingInterface // Stalling for (const auto edge : facade->GetAdjacentEdgeRange(node)) { - const EdgeData &data = facade->GetEdgeData(edge); + const EdgeData &data = facade->GetEdgeData(edge, node); const bool reverse_flag = ((!forward_direction) ? data.forward : data.backward); if (reverse_flag) { @@ -119,7 +119,7 @@ template class BasicRoutingInterface for (const auto edge : facade->GetAdjacentEdgeRange(node)) { - const EdgeData &data = facade->GetEdgeData(edge); + const EdgeData &data = facade->GetEdgeData(edge, node); bool forward_directionFlag = (forward_direction ? data.forward : data.backward); if (forward_directionFlag) { @@ -181,14 +181,17 @@ template class BasicRoutingInterface // facade->FindEdge does not suffice here in case of shortcuts. // The above explanation unclear? Think! EdgeID smaller_edge_id = SPECIAL_EDGEID; + NodeID smaller_node_id = SPECIAL_NODEID; int edge_weight = std::numeric_limits::max(); for (const auto edge_id : facade->GetAdjacentEdgeRange(edge.first)) { - const int weight = facade->GetEdgeData(edge_id).distance; + auto const & edgeData = facade->GetEdgeData(edge_id, edge.first); + const int weight = edgeData.distance; if ((facade->GetTarget(edge_id) == edge.second) && (weight < edge_weight) && - facade->GetEdgeData(edge_id).forward) + edgeData.forward) { smaller_edge_id = edge_id; + smaller_node_id = edge.first; edge_weight = weight; } } @@ -204,18 +207,20 @@ template class BasicRoutingInterface { for (const auto edge_id : facade->GetAdjacentEdgeRange(edge.second)) { - const int weight = facade->GetEdgeData(edge_id).distance; + auto const & edgeData = facade->GetEdgeData(edge_id, edge.second); + const int weight = edgeData.distance; if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && - facade->GetEdgeData(edge_id).backward) + edgeData.backward) { smaller_edge_id = edge_id; + smaller_node_id = edge.second; edge_weight = weight; } } } BOOST_ASSERT_MSG(edge_weight != INVALID_EDGE_WEIGHT, "edge id invalid"); - const EdgeData &ed = facade->GetEdgeData(smaller_edge_id); + const EdgeData &ed = facade->GetEdgeData(smaller_edge_id, smaller_node_id); if (ed.shortcut) { // unpack const NodeID middle_node_id = ed.id; @@ -344,14 +349,17 @@ template class BasicRoutingInterface recursion_stack.pop(); EdgeID smaller_edge_id = SPECIAL_EDGEID; + NodeID smaller_node_id = SPECIAL_NODEID; int edge_weight = std::numeric_limits::max(); for (const auto edge_id : facade->GetAdjacentEdgeRange(edge.first)) { - const int weight = facade->GetEdgeData(edge_id).distance; + auto const & edgeData = facade->GetEdgeData(edge_id, edge.first); + const int weight = edgeData.distance; if ((facade->GetTarget(edge_id) == edge.second) && (weight < edge_weight) && - facade->GetEdgeData(edge_id).forward) + edgeData.forward) { smaller_edge_id = edge_id; + smaller_node_id = edge.first; edge_weight = weight; } } @@ -360,18 +368,20 @@ template class BasicRoutingInterface { for (const auto edge_id : facade->GetAdjacentEdgeRange(edge.second)) { - const int weight = facade->GetEdgeData(edge_id).distance; + auto const & edgeData = facade->GetEdgeData(edge_id, edge.second); + const int weight = edgeData.distance; if ((facade->GetTarget(edge_id) == edge.first) && (weight < edge_weight) && - facade->GetEdgeData(edge_id).backward) + edgeData.backward) { smaller_edge_id = edge_id; + smaller_node_id = edge.second; edge_weight = weight; } } } BOOST_ASSERT_MSG(edge_weight != std::numeric_limits::max(), "edge weight invalid"); - const EdgeData &ed = facade->GetEdgeData(smaller_edge_id); + const EdgeData &ed = facade->GetEdgeData(smaller_edge_id, smaller_node_id); if (ed.shortcut) { // unpack const NodeID middle_node_id = ed.id; diff --git a/3party/osrm/osrm-backend/Server/DataStructures/BaseDataFacade.h b/3party/osrm/osrm-backend/Server/DataStructures/BaseDataFacade.h index e0113c6fe6..0869cdc307 100644 --- a/3party/osrm/osrm-backend/Server/DataStructures/BaseDataFacade.h +++ b/3party/osrm/osrm-backend/Server/DataStructures/BaseDataFacade.h @@ -64,6 +64,8 @@ template class BaseDataFacade virtual EdgeDataT &GetEdgeData(const EdgeID e) = 0; + virtual EdgeDataT &GetEdgeData(const EdgeID e, NodeID node) { static EdgeDataT edge; return edge; } + // virtual const EdgeDataT &GetEdgeData( const EdgeID e ) const = 0; virtual EdgeID BeginEdges(const NodeID n) const = 0; diff --git a/3party/osrm/osrm-backend/mapsme/CMakeLists.txt b/3party/osrm/osrm-backend/mapsme/CMakeLists.txt index ab4df3944c..09fe32e968 100644 --- a/3party/osrm/osrm-backend/mapsme/CMakeLists.txt +++ b/3party/osrm/osrm-backend/mapsme/CMakeLists.txt @@ -1,5 +1,12 @@ file(GLOB_RECURSE SOURCES "*.cpp") file(GLOB_RECURSE HEADERS "*.hpp") -add_executable(osrm-mapsme ${SOURCES} ${HEADERS}) -target_link_libraries(osrm-mapsme ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB) + +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DNDEBUG") + +add_executable(osrm-mapsme ${SOURCES} ${HEADERS} "${CMAKE_SOURCE_DIR}/../../succinct/rs_bit_vector.cpp") +target_link_libraries(osrm-mapsme ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB + debug "${CMAKE_SOURCE_DIR}/../../../../omim-build-debug/out/debug/libcoding.a" + "${CMAKE_SOURCE_DIR}/../../../../omim-build-debug/out/debug/libbase.a" + general "${CMAKE_SOURCE_DIR}/../../../../omim-build-release/out/release/libcoding.a" + "${CMAKE_SOURCE_DIR}/../../../../omim-build-release/out/release/libbase.a") diff --git a/3party/osrm/osrm-backend/mapsme/converter.cpp b/3party/osrm/osrm-backend/mapsme/converter.cpp index dc67df2243..af3b0dbffc 100644 --- a/3party/osrm/osrm-backend/mapsme/converter.cpp +++ b/3party/osrm/osrm-backend/mapsme/converter.cpp @@ -2,78 +2,186 @@ #include -#include "../Server/DataStructures/InternalDataFacade.h" -#include "../DataStructures/QueryEdge.h" + +#include "../../../../base/bits.hpp" +#include "../../../../base/logging.hpp" +#include "../../../../base/scope_guard.hpp" #include "../../../../coding/matrix_traversal.hpp" -//#include "../../../../routing/osrm_data_facade.hpp" +#include "../../../../coding/internal/file_data.hpp" + +#include "../../../../routing/osrm_data_facade.hpp" #include "../../../succinct/elias_fano.hpp" #include "../../../succinct/elias_fano_compressed_list.hpp" #include "../../../succinct/gamma_vector.hpp" +#include "../../../succinct/rs_bit_vector.hpp" #include "../../../succinct/mapper.hpp" +#include "../Server/DataStructures/InternalDataFacade.h" namespace mapsme { +struct EdgeLess +{ + bool operator () (QueryEdge::EdgeData const & e1, QueryEdge::EdgeData const & e2) const + { + + if (e1.distance != e2.distance) + return e1.distance < e2.distance; + + if (e1.shortcut != e2.shortcut) + return e1.shortcut < e2.shortcut; + + if (e1.forward != e2.forward) + return e1.forward < e2.forward; + + if (e1.backward != e2.backward) + return e1.backward < e2.backward; + + if (e1.id != e2.id) + return e1.id < e2.id; + + return false; + } +}; + void PrintStatus(bool b) { std::cout << (b ? "[Ok]" : "[Fail]") << std::endl; } -Converter::Converter() +string EdgeDataToString(QueryEdge::EdgeData const & d) { - + stringstream ss; + ss << "[" << d.distance << ", " << d.shortcut << ", " << d.forward << ", " << d.backward << ", " << d.id << "]"; + return ss.str(); } -void Converter::run(const std::string & name) + + +void GenerateRoutingIndex(const std::string & fPath) { ServerPaths server_paths; - server_paths["hsgrdata"] = boost::filesystem::path(name + ".hsgr"); - server_paths["ramindex"] = boost::filesystem::path(name + ".ramIndex"); - server_paths["fileindex"] = boost::filesystem::path(name + ".fileIndex"); - server_paths["geometries"] = boost::filesystem::path(name + ".geometry"); - server_paths["nodesdata"] = boost::filesystem::path(name + ".nodes"); - server_paths["edgesdata"] = boost::filesystem::path(name + ".edges"); - server_paths["namesdata"] = boost::filesystem::path(name + ".names"); - server_paths["timestamp"] = boost::filesystem::path(name + ".timestamp"); + server_paths["hsgrdata"] = boost::filesystem::path(fPath + ".hsgr"); + server_paths["ramindex"] = boost::filesystem::path(fPath + ".ramIndex"); + server_paths["fileindex"] = boost::filesystem::path(fPath + ".fileIndex"); + server_paths["geometries"] = boost::filesystem::path(fPath + ".geometry"); + server_paths["nodesdata"] = boost::filesystem::path(fPath + ".nodes"); + server_paths["edgesdata"] = boost::filesystem::path(fPath + ".edges"); + server_paths["namesdata"] = boost::filesystem::path(fPath + ".names"); + server_paths["timestamp"] = boost::filesystem::path(fPath + ".timestamp"); - std::cout << "Create internal data facade for file: " << name << "..."; + std::cout << "Create internal data facade for file: " << fPath << "..."; InternalDataFacade facade(server_paths); PrintStatus(true); - uint64_t const nodeCount = facade.GetNumberOfNodes(); + uint32_t const nodeCount = facade.GetNumberOfNodes(); std::vector edges; std::vector edgesData; std::vector shortcuts; - std::vector edgeId; + std::vector edgeId; - std::cout << "Repack graph..."; + std::cout << "Repack graph..." << std::endl; - for (uint64_t node = 0; node < nodeCount; ++node) + typedef pair EdgeInfoT; + typedef vector EdgeInfoVecT; + + uint64_t copiedEdges = 0, ignoredEdges = 0; + for (uint32_t node = 0; node < nodeCount; ++node) { + EdgeInfoVecT edgesInfo; for (auto edge : facade.GetAdjacentEdgeRange(node)) { uint64_t target = facade.GetTarget(edge); auto const & data = facade.GetEdgeData(edge); + edgesInfo.push_back(EdgeInfoT(target, data)); + } + + sort(edgesInfo.begin(), edgesInfo.end(), [](EdgeInfoT const & a, EdgeInfoT const & b) + { + if (a.first != b.first) + return a.first < b.first; + + if (a.second.forward != b.second.forward) + return a.second.forward > b.second.forward; + + return a.second.id < b.second.id; + }); + + uint64_t lastTarget = 0; + for (auto edge : edgesInfo) + { + uint64_t const target = edge.first; + auto const & data = edge.second; + + if (target < lastTarget) + LOG(LCRITICAL, ("Invalid order of target nodes", target, lastTarget)); + + lastTarget = target; assert(data.forward || data.backward); - uint32_t d = data.distance; - d = d << 1; - d += data.forward ? 1 : 0; - d = d << 1; - d += data.backward ? 1 : 0; + auto addDataFn = [&](bool b) + { + uint64_t const e = TraverseMatrixInRowOrder(nodeCount, node, target, b); - edges.push_back(TraverseMatrixInRowOrder(nodeCount, node, target, data.backward)); - edgesData.push_back(d); - shortcuts.push_back(data.shortcut); - edgeId.push_back(data.id); + auto compressId = [&](uint64_t id) + { + return bits::ZigZagEncode(int64_t(node) - int64_t(id)); + }; + + if (!edges.empty()) + CHECK_GREATER_OR_EQUAL(e, edges.back(), ()); + + if (!edges.empty() && (edges.back() == e)) + { + LOG(LWARNING, ("Invalid order of edges", e, edges.back(), nodeCount, node, target, b)); + CHECK(data.shortcut == shortcuts.back(), ()); + + auto const last = edgesData.back(); + if (data.distance <= last) + { + if (!edgeId.empty() && data.shortcut) + { + CHECK(shortcuts.back(), ()); + unsigned oldId = node - bits::ZigZagDecode(edgeId.back()); + + if (data.distance == last) + edgeId.back() = compressId(min(oldId, data.id)); + else + edgeId.back() = compressId(data.id); + } + + edgesData.back() = data.distance; + } + + ++ignoredEdges; + return; + } + + edges.push_back(e); + edgesData.push_back(data.distance); + shortcuts.push_back(data.shortcut); + + if (data.shortcut) + edgeId.push_back(compressId(data.id)); + }; + + if (data.forward && data.backward) + { + addDataFn(false); + addDataFn(true); + copiedEdges++; + } + else + addDataFn(data.backward); } } + std::cout << "Edges count: " << edgeId.size() << std::endl; PrintStatus(true); @@ -90,78 +198,179 @@ void Converter::run(const std::string & name) builder.push_back(e); succinct::elias_fano matrix(&builder); - std::string fileName = name + ".matrix"; - succinct::mapper::freeze(matrix, fileName.c_str()); - + std::string fileName = fPath + "." + ROUTING_MATRIX_FILE_TAG; + std::ofstream fout(fileName, std::ios::binary); + fout.write((const char*)&nodeCount, sizeof(nodeCount)); + succinct::mapper::freeze(matrix, fout); + fout.close(); std::cout << "--- Save edge data" << std::endl; succinct::elias_fano_compressed_list edgeVector(edgesData); - fileName = name + ".edgedata"; + fileName = fPath + "." + ROUTING_EDGEDATA_FILE_TAG; succinct::mapper::freeze(edgeVector, fileName.c_str()); succinct::elias_fano_compressed_list edgeIdVector(edgeId); - fileName = name + ".edgeid"; + fileName = fPath + "." + ROUTING_EDGEID_FILE_TAG; succinct::mapper::freeze(edgeIdVector, fileName.c_str()); std::cout << "--- Save edge shortcuts" << std::endl; - succinct::bit_vector shortcutsVector(shortcuts); - fileName = name + ".shortcuts"; + succinct::rs_bit_vector shortcutsVector(shortcuts); + fileName = fPath + "." + ROUTING_SHORTCUTS_FILE_TAG; succinct::mapper::freeze(shortcutsVector, fileName.c_str()); - /// @todo Restore this checking. Now data facade depends on mwm libraries. - /* - std::cout << "--- Test packed data" << std::endl; - routing::OsrmDataFacade facadeNew(name); + if (edgeId.size() != shortcutsVector.num_ones()) + LOG(LCRITICAL, ("Invalid data")); - std::cout << "Check node count " << facade.GetNumberOfNodes() << " == " << facadeNew.GetNumberOfNodes() << "..."; - PrintStatus(facade.GetNumberOfNodes() == facadeNew.GetNumberOfNodes()); - std::cout << "Check edges count " << facade.GetNumberOfEdges() << " == " << facadeNew.GetNumberOfEdges() << "..."; - PrintStatus(facade.GetNumberOfEdges() == facadeNew.GetNumberOfEdges()); + std::cout << "--- Test packed data" << std::endl; + std::string path = fPath + ".test"; + + { + FilesContainerW routingCont(path); + + auto appendFile = [&] (string const & tag) + { + string const fileName = fPath + "." + tag; + routingCont.Write(fileName, tag); + }; + + appendFile(ROUTING_SHORTCUTS_FILE_TAG); + appendFile(ROUTING_EDGEDATA_FILE_TAG); + appendFile(ROUTING_MATRIX_FILE_TAG); + appendFile(ROUTING_EDGEID_FILE_TAG); + + routingCont.Finish(); + } + + MY_SCOPE_GUARD(testFileGuard, bind(&my::DeleteFileX, cref(path))); + + FilesMappingContainer container; + container.Open(path); + typedef routing::OsrmDataFacade DataFacadeT; + DataFacadeT facadeNew; + facadeNew.Load(container); + + uint64_t edgesCount = facadeNew.GetNumberOfEdges() - copiedEdges + ignoredEdges; + std::cout << "Check node count " << facade.GetNumberOfNodes() << " == " << facadeNew.GetNumberOfNodes() << "..." << std::endl; + CHECK_EQUAL(facade.GetNumberOfNodes(), facadeNew.GetNumberOfNodes(), ()); + std::cout << "Check edges count " << facade.GetNumberOfEdges() << " == " << edgesCount << "..." << std::endl; + CHECK_EQUAL(facade.GetNumberOfEdges(), edgesCount, ()); std::cout << "Check edges data ..."; bool error = false; + + typedef vector EdgeDataT; assert(facade.GetNumberOfEdges() == facadeNew.GetNumberOfEdges()); - for (uint32_t e = 0; e < facade.GetNumberOfEdges(); ++e) + for (uint32_t i = 0; i < facade.GetNumberOfNodes(); ++i) { - QueryEdge::EdgeData d1 = facade.GetEdgeData(e); - QueryEdge::EdgeData d2 = facadeNew.GetEdgeData(e); + EdgeDataT v1, v2; - if (d1.backward != d2.backward || - d1.forward != d2.forward || - d1.distance != d2.distance || - d1.id != d2.id || - d1.shortcut != d2.shortcut) + // get all edges from osrm datafacade and store just minimal weights for duplicates + typedef pair EdgeOsrmT; + vector edgesOsrm; + for (auto e : facade.GetAdjacentEdgeRange(i)) + edgesOsrm.push_back(EdgeOsrmT(facade.GetTarget(e), facade.GetEdgeData(e))); + + sort(edgesOsrm.begin(), edgesOsrm.end(), [](EdgeOsrmT const & a, EdgeOsrmT const & b) { - std::cout << "Edge num: " << e << std::endl; - std::cout << "d1 (backward: " << (uint32_t)d1.backward << ", forward: " << (uint32_t)d1.forward << ", distance: " - << (uint32_t)d1.distance << ", id: " << (uint32_t)d1.id << ", shortcut: " << (uint32_t)d1.shortcut << std::endl; - std::cout << "d2 (backward: " << (uint32_t)d2.backward << ", forward: " << (uint32_t)d2.forward << ", distance: " - << (uint32_t)d2.distance << ", id: " << (uint32_t)d2.id << ", shortcut: " << (uint32_t)d2.shortcut << std::endl; - error = true; - break; + if (a.first != b.first) + return a.first < b.first; + + if (a.second.forward != b.second.forward) + return a.second.forward < b.second.forward; + + if (a.second.backward != b.second.backward) + return a.second.backward < b.second.backward; + + if (a.second.distance != b.second.distance) + return a.second.distance < b.second.distance; + + return a.second.id < b.second.id; + }); + + for (size_t k = 1; k < edgesOsrm.size();) + { + auto const & e1 = edgesOsrm[k - 1]; + auto const & e2 = edgesOsrm[k]; + + if (e1.first != e2.first || + e1.second.forward != e2.second.forward || + e1.second.backward != e2.second.backward) + { + ++k; + continue; + } + + if (e1.second.distance > e2.second.distance) + edgesOsrm.erase(edgesOsrm.begin() + k - 1); + else + edgesOsrm.erase(edgesOsrm.begin() + k); } + + for (auto e : edgesOsrm) + { + QueryEdge::EdgeData d = e.second; + if (d.forward && d.backward) + { + d.backward = false; + v1.push_back(d); + d.forward = false; + d.backward = true; + } + + v1.push_back(d); + } + + for (auto e : facadeNew.GetAdjacentEdgeRange(i)) + v2.push_back(facadeNew.GetEdgeData(e, i)); + + if (v1.size() != v2.size()) + { + auto printV = [](EdgeDataT const & v, stringstream & ss) + { + for (auto i : v) + ss << EdgeDataToString(i) << std::endl; + }; + + sort(v1.begin(), v1.end(), EdgeLess()); + sort(v2.begin(), v2.end(), EdgeLess()); + + stringstream ss; + ss << "File name: " << fPath << std::endl; + ss << "Not equal edges count for node: " << i << std::endl; + ss << "v1: " << v1.size() << " v2: " << v2.size() << std::endl; + ss << "--- v1 ---" << std::endl; + printV(v1, ss); + ss << "--- v2 ---" << std::endl; + printV(v2, ss); + + LOG(LCRITICAL, (ss.str())); + } + + sort(v1.begin(), v1.end(), EdgeLess()); + sort(v2.begin(), v2.end(), EdgeLess()); + + // compare vectors + for (size_t k = 0; k < v1.size(); ++k) + { + QueryEdge::EdgeData const & d1 = v1[k]; + QueryEdge::EdgeData const & d2 = v2[k]; + + if (d1.backward != d2.backward || + d1.forward != d2.forward || + d1.distance != d2.distance || + (d1.id != d2.id && (d1.shortcut || d2.shortcut)) || + d1.shortcut != d2.shortcut) + { + std::cout << "--- " << std::endl; + for (size_t j = 0; j < v1.size(); ++j) + std::cout << EdgeDataToString(v1[j]) << " - " << EdgeDataToString(v2[j]) << std::endl; + + LOG(LCRITICAL, ("File:", fPath, "Node:", i, EdgeDataToString(d1), EdgeDataToString(d2))); + } + } + } PrintStatus(!error); - - std::cout << "Check graph structure..."; - error = false; - for (uint32_t node = 0; node < facade.GetNumberOfNodes(); ++node) - { - EdgeRange r1 = facade.GetAdjacentEdgeRange(node); - EdgeRange r2 = facadeNew.GetAdjacentEdgeRange(node); - - if ((r1.front() != r2.front()) || (r1.back() != r2.back())) - { - std::cout << "Node num: " << node << std::endl; - std::cout << "r1 (" << r1.front() << ", " << r1.back() << ")" << std::endl; - std::cout << "r2 (" << r2.front() << ", " << r2.back() << ")" << std::endl; - - error = true; - break; - } - } - PrintStatus(!error); - */ } } diff --git a/3party/osrm/osrm-backend/mapsme/converter.hpp b/3party/osrm/osrm-backend/mapsme/converter.hpp index f434c9a5ca..77961dd3ca 100644 --- a/3party/osrm/osrm-backend/mapsme/converter.hpp +++ b/3party/osrm/osrm-backend/mapsme/converter.hpp @@ -2,17 +2,12 @@ #include +#include "../DataStructures/QueryEdge.h" + namespace mapsme { -class Converter -{ -public: - Converter(); - void run(const std::string & name); - - -}; +void GenerateRoutingIndex(const std::string & fPath); } diff --git a/3party/osrm/osrm-backend/mapsme/main.cpp b/3party/osrm/osrm-backend/mapsme/main.cpp index f0f5dc7330..5d626a9e61 100644 --- a/3party/osrm/osrm-backend/mapsme/main.cpp +++ b/3party/osrm/osrm-backend/mapsme/main.cpp @@ -22,8 +22,8 @@ int main(int argc, char **argv) return 0; } - mapsme::Converter conv; - conv.run(vm["input"].as()); + + mapsme::GenerateRoutingIndex(vm["input"].as()); return 0; } diff --git a/base/bits.hpp b/base/bits.hpp index 2b04b8b9c3..f0e5c13345 100644 --- a/base/bits.hpp +++ b/base/bits.hpp @@ -1,6 +1,8 @@ #pragma once #include "assert.hpp" +#include "assert.hpp" + #include "../std/type_traits.hpp" diff --git a/defines.hpp b/defines.hpp index 6c45396574..399eb8364a 100644 --- a/defines.hpp +++ b/defines.hpp @@ -12,10 +12,10 @@ #define SEARCH_INDEX_FILE_TAG "sdx" #define HEADER_FILE_TAG "header" #define VERSION_FILE_TAG "version" -#define ROUTING_MATRIX_FILE_TAG "matrix" -#define ROUTING_EDGEDATA_FILE_TAG "edgedata" -#define ROUTING_EDGEID_FILE_TAG "edgeid" -#define ROUTING_SHORTCUTS_FILE_TAG "shortcuts" +#define ROUTING_MATRIX_FILE_TAG "mercedes" +#define ROUTING_EDGEDATA_FILE_TAG "daewoo" +#define ROUTING_EDGEID_FILE_TAG "infinity" +#define ROUTING_SHORTCUTS_FILE_TAG "skoda" #define ROUTING_FTSEG_FILE_TAG "ftseg" #define ROUTING_NODEIND_TO_FTSEGIND_FILE_TAG "node2ftseg" diff --git a/routing/osrm_data_facade.hpp b/routing/osrm_data_facade.hpp index f652cf2e57..6c166d1e57 100644 --- a/routing/osrm_data_facade.hpp +++ b/routing/osrm_data_facade.hpp @@ -4,12 +4,14 @@ #include "../std/string.hpp" +#include "../base/bits.hpp" + #include "../coding/file_container.hpp" #include "../3party/succinct/elias_fano.hpp" #include "../3party/succinct/elias_fano_compressed_list.hpp" #include "../3party/succinct/gamma_vector.hpp" -#include "../3party/succinct/bit_vector.hpp" +#include "../3party/succinct/rs_bit_vector.hpp" #include "../3party/succinct/mapper.hpp" #include "../3party/osrm/osrm-backend/Server/DataStructures/BaseDataFacade.h" @@ -23,16 +25,17 @@ template class OsrmDataFacade : public BaseDataFacade super; succinct::elias_fano_compressed_list m_edgeData; - succinct::bit_vector m_shortcuts; - succinct::elias_fano m_fanoMatrix; + succinct::rs_bit_vector m_shortcuts; + succinct::elias_fano m_matrix; succinct::elias_fano_compressed_list m_edgeId; FilesMappingContainer::Handle m_handleEdgeData; FilesMappingContainer::Handle m_handleEdgeId; + FilesMappingContainer::Handle m_handleEdgeIdFano; FilesMappingContainer::Handle m_handleShortcuts; FilesMappingContainer::Handle m_handleFanoMatrix; - unsigned m_numberOfNodes; + uint32_t m_numberOfNodes; template void ClearContainer(T & t) { @@ -62,9 +65,9 @@ public: m_handleFanoMatrix.Assign(container.Map(ROUTING_MATRIX_FILE_TAG)); ASSERT(m_handleFanoMatrix.IsValid(), ()); - succinct::mapper::map(m_fanoMatrix, m_handleFanoMatrix.GetData()); - m_numberOfNodes = (unsigned)sqrt(m_fanoMatrix.size() / 2) + 1; + m_numberOfNodes = *m_handleFanoMatrix.GetData(); + succinct::mapper::map(m_matrix, m_handleFanoMatrix.GetData() + sizeof(m_numberOfNodes)); } void Clear() @@ -78,7 +81,7 @@ public: ClearContainer(m_shortcuts); m_handleShortcuts.Unmap(); - ClearContainer(m_fanoMatrix); + ClearContainer(m_matrix); m_handleFanoMatrix.Unmap(); } @@ -99,23 +102,26 @@ public: NodeID GetTarget(const EdgeID e) const { - return (m_fanoMatrix.select(e) / 2) % GetNumberOfNodes(); + return (m_matrix.select(e) / 2) % GetNumberOfNodes(); } - //! TODO: Remove static variable EdgeDataT & GetEdgeData(const EdgeID e) + { + static EdgeDataT res; + return res; + } + + //! TODO: Remove static variable + EdgeDataT & GetEdgeData(const EdgeID e, NodeID node) { static EdgeDataT res; - uint64_t data = m_edgeData[e]; - res.id = m_edgeId[e]; - res.backward = data & 0x1; - data >>= 1; - res.forward = data & 0x1; - data >>= 1; - res.distance = data; res.shortcut = m_shortcuts[e]; + res.id = res.shortcut ? (node - bits::ZigZagDecode(m_edgeId[m_shortcuts.rank(e)])) : 0; + res.backward = (m_matrix.select(e) % 2 == 1); + res.forward = !res.backward; + res.distance = m_edgeData[e]; return res; } @@ -124,29 +130,19 @@ public: EdgeDataT const & GetEdgeData(const EdgeID e) const { static EdgeDataT res; - - uint64_t data = m_edgeData[e]; - - res.id = m_edgeId[e]; - res.backward = data & 0x1; - data >>= 1; - res.forward = data & 0x1; - data >>= 1; - res.distance = data; - res.shortcut = m_shortcuts[e]; - return res; } EdgeID BeginEdges(const NodeID n) const { - return n == 0 ? 0 : m_fanoMatrix.rank(2 * n * (uint64_t)GetNumberOfNodes()); + uint64_t idx = 2 * n * (uint64_t)GetNumberOfNodes(); + return n == 0 ? 0 : m_matrix.rank(min(idx, m_matrix.size())); } EdgeID EndEdges(const NodeID n) const { uint64_t const idx = 2 * (n + 1) * (uint64_t)GetNumberOfNodes(); - return m_fanoMatrix.rank(std::min(idx, m_fanoMatrix.size())); + return m_matrix.rank(min(idx, m_matrix.size())); } EdgeRange GetAdjacentEdgeRange(const NodeID node) const diff --git a/routing/routing.pro b/routing/routing.pro index ec4005a8cc..cc381f6871 100644 --- a/routing/routing.pro +++ b/routing/routing.pro @@ -17,6 +17,7 @@ SOURCES += \ osrm_online_router.cpp \ osrm2feature_map.cpp \ vehicle_model.cpp \ + ../3party/succinct/rs_bit_vector.cpp \ HEADERS += \ route.hpp \