diff --git a/.gitignore b/.gitignore index 564292449..5e8c12d8b 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ stxxl.errlog /osrm-prepare /osrm-unlock-all /osrm-cli +/osrm-check-hsgr /nohup.out # Sandbox folder # diff --git a/CMakeLists.txt b/CMakeLists.txt index 154edaeac..d60a7e27c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -304,10 +304,13 @@ if(WITH_TOOLS OR BUILD_TOOLS) if(UNIX AND NOT APPLE) target_link_libraries(osrm-unlock-all rt) endif() + add_executable(osrm-check-hsgr Tools/check-hsgr.cpp) + target_link_libraries(osrm-check-hsgr ${Boost_LIBRARIES} GITDESCRIPTION FINGERPRINT) install(TARGETS osrm-cli DESTINATION bin) install(TARGETS osrm-io-benchmark DESTINATION bin) install(TARGETS osrm-unlock-all DESTINATION bin) + install(TARGETS osrm-check-hsgr DESTINATION bin) endif() file(GLOB InstallGlob Include/osrm/*.h Library/OSRM.h) diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index c57d936af..1589d1d38 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -127,39 +127,6 @@ template class StaticGraph node_array.swap(nodes); edge_array.swap(edges); - -#ifndef NDEBUG - Percent p(GetNumberOfNodes()); - for (const auto u : boost::irange(0u, GetNumberOfNodes())) - { - for (auto eid : GetAdjacentEdgeRange(u)) - { - const EdgeData &data = GetEdgeData(eid); - if (!data.shortcut) - { - continue; - } - const unsigned v = GetTarget(eid); - const EdgeID first_edge_id = FindEdgeInEitherDirection(u, data.id); - if (SPECIAL_EDGEID == first_edge_id) - { - SimpleLogger().Write(logWARNING) << "cannot find first segment of edge (" - << u << "," << data.id << "," << v - << "), eid: " << eid; - BOOST_ASSERT(false); - } - const EdgeID second_edge_id = FindEdgeInEitherDirection(data.id, v); - if (SPECIAL_EDGEID == second_edge_id) - { - SimpleLogger().Write(logWARNING) << "cannot find second segment of edge (" - << u << "," << data.id << "," << v - << "), eid: " << eid; - BOOST_ASSERT(false); - } - } - p.printIncrement(); - } -#endif } unsigned GetNumberOfNodes() const { return number_of_nodes; } diff --git a/Tools/check-hsgr.cpp b/Tools/check-hsgr.cpp new file mode 100644 index 000000000..75e5782b6 --- /dev/null +++ b/Tools/check-hsgr.cpp @@ -0,0 +1,105 @@ +/* + +Copyright (c) 2013, Project OSRM, Dennis Luxen, others +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list +of conditions and the following disclaimer. +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*/ +#include "../DataStructures/DeallocatingVector.h" +#include "../DataStructures/Percent.h" +#include "../DataStructures/QueryEdge.h" +#include "../DataStructures/StaticGraph.h" +#include "../Util/GraphLoader.h" +#include "../Util/SimpleLogger.h" + +#include +#include + +#include +#include + +typedef QueryEdge::EdgeData EdgeData; +typedef StaticGraph QueryGraph; + +int main(int argc, char *argv[]) +{ + LogPolicy::GetInstance().Unmute(); + if (argc != 2) + { + SimpleLogger().Write(logWARNING) << "usage: " << argv[0] << " "; + return 1; + } + + boost::filesystem::path hsgr_path(argv[1]); + + std::vector node_list; + std::vector edge_list; + + SimpleLogger().Write() << "loading graph from " << hsgr_path.string(); + + unsigned m_check_sum = 0; + unsigned m_number_of_nodes = readHSGRFromStream(hsgr_path, node_list, edge_list, &m_check_sum); + SimpleLogger().Write() << "announced " << m_number_of_nodes + << " nodes, checksum: " << m_check_sum; + BOOST_ASSERT_MSG(0 != node_list.size(), "node list empty"); + // BOOST_ASSERT_MSG(0 != edge_list.size(), "edge list empty"); + SimpleLogger().Write() << "loaded " << node_list.size() << " nodes and " << edge_list.size() + << " edges"; + std::shared_ptr m_query_graph = std::make_shared(node_list, edge_list); + + BOOST_ASSERT_MSG(0 == node_list.size(), "node list not flushed"); + BOOST_ASSERT_MSG(0 == edge_list.size(), "edge list not flushed"); + + Percent p(m_query_graph->GetNumberOfNodes()); + for (const auto u : boost::irange(0u, m_query_graph->GetNumberOfNodes())) + { + for (const auto eid : m_query_graph->GetAdjacentEdgeRange(u)) + { + const EdgeData &data = m_query_graph->GetEdgeData(eid); + if (!data.shortcut) + { + continue; + } + const unsigned v = m_query_graph->GetTarget(eid); + const EdgeID first_edge_id = m_query_graph->FindEdgeInEitherDirection(u, data.id); + if (SPECIAL_EDGEID == first_edge_id) + { + SimpleLogger().Write(logWARNING) << "cannot find first segment of edge (" << u + << "," << data.id << "," << v << "), eid: " << eid; + BOOST_ASSERT(false); + return 1; + } + const EdgeID second_edge_id = m_query_graph->FindEdgeInEitherDirection(data.id, v); + if (SPECIAL_EDGEID == second_edge_id) + { + SimpleLogger().Write(logWARNING) << "cannot find second segment of edge (" << u + << "," << data.id << "," << v << "), eid: " << eid; + BOOST_ASSERT(false); + return 1; + } + } + p.printIncrement(); + } + m_query_graph.reset(); + SimpleLogger().Write() << "Data file " << argv[0] << " appears to be OK"; + return 0; +}