From da98900e3aae7458108a90dd1b3391b9f8c2f561 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 19 Aug 2013 13:42:34 +0200 Subject: [PATCH] fixing regression in osrm-components --- Extractor/ExtractionContainers.cpp | 16 ++++++++-- Tools/componentAnalysis.cpp | 16 ++++++++++ Util/GraphLoader.h | 51 +++++++++++++++--------------- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/Extractor/ExtractionContainers.cpp b/Extractor/ExtractionContainers.cpp index 515c78b84..e93723a65 100644 --- a/Extractor/ExtractionContainers.cpp +++ b/Extractor/ExtractionContainers.cpp @@ -111,7 +111,10 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con restrictionsIT->restriction.toNode = wayStartAndEndEdgeIT->firstStart; } - if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { + if( + UINT_MAX != restrictionsIT->restriction.fromNode && + UINT_MAX != restrictionsIT->restriction.toNode + ) { ++usableRestrictionsCounter; } ++restrictionsIT; @@ -123,8 +126,15 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con restrictionsOutstream.open(restrictionsFileName.c_str(), std::ios::binary); restrictionsOutstream.write((char*)&uuid, sizeof(UUID)); restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned)); - for(restrictionsIT = restrictionsVector.begin(); restrictionsIT != restrictionsVector.end(); ++restrictionsIT) { - if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { + for( + restrictionsIT = restrictionsVector.begin(); + restrictionsIT != restrictionsVector.end(); + ++restrictionsIT + ) { + if( + UINT_MAX != restrictionsIT->restriction.fromNode && + UINT_MAX != restrictionsIT->restriction.toNode + ) { restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(TurnRestriction)); } } diff --git a/Tools/componentAnalysis.cpp b/Tools/componentAnalysis.cpp index 12d0a1d64..74d7104d2 100644 --- a/Tools/componentAnalysis.cpp +++ b/Tools/componentAnalysis.cpp @@ -30,6 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/InputFileUtil.h" #include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" +#include "../Util/UUID.h" #include #include @@ -58,6 +59,16 @@ int main (int argc, char * argv[]) { SimpleLogger().Write() << "Using restrictions from file: " << argv[2]; std::ifstream restriction_ifstream(argv[2], std::ios::binary); + const UUID uuid_orig; + UUID uuid_loaded; + restriction_ifstream.read((char *) &uuid_loaded, sizeof(UUID)); + + if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { + SimpleLogger().Write(logWARNING) << + argv[2] << " was prepared with a different build. " + "Reprocess to get rid of this warning."; + } + if(!restriction_ifstream.good()) { throw OSRMException("Could not access files"); } @@ -92,6 +103,11 @@ int main (int argc, char * argv[]) { ); input_stream.close(); + BOOST_ASSERT_MSG( + restrictions_vector.size() == usable_restriction_count, + "size of restrictions_vector changed" + ); + SimpleLogger().Write() << restrictions_vector.size() << " restrictions, " << bollard_node_IDs_vector.size() << " bollard nodes, " << diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 7a674da01..4c9621302 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -68,21 +68,21 @@ NodeID readBinaryOSRMGraphFromStream( if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { SimpleLogger().Write(logWARNING) << - ".osrm was prepared with different build.\n" + ".osrm was prepared with different build." "Reprocess to get rid of this warning."; } NodeID n, source, target; EdgeID m; short dir;// direction (0 = open, 1 = forward, 2+ = open) - ExternalNodeMap ext2IntNodeMap; + ExternalNodeMap ext_to_int_id_map; in.read((char*)&n, sizeof(NodeID)); SimpleLogger().Write() << "Importing n = " << n << " nodes "; _Node node; for (NodeID i=0; ipush_back(NodeInfo(node.lat, node.lon, node.id)); - ext2IntNodeMap.insert(std::make_pair(node.id, i)); + ext_to_int_id_map.emplace(node.id, i); if(node.bollard) { bollardNodes.push_back(i); } @@ -97,28 +97,29 @@ NodeID readBinaryOSRMGraphFromStream( in.read((char*)&m, sizeof(unsigned)); SimpleLogger().Write() << " and " << m << " edges "; - for(unsigned i = 0; i < inputRestrictions.size(); ++i) { - ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode); - if( intNodeID == ext2IntNodeMap.end()) { + // for(unsigned i = 0; i < inputRestrictions.size(); ++i) { + BOOST_FOREACH(TurnRestriction & current_restriction, inputRestrictions) { + ExternalNodeMap::iterator intNodeID = ext_to_int_id_map.find(current_restriction.fromNode); + if( intNodeID == ext_to_int_id_map.end()) { SimpleLogger().Write(logDEBUG) << "Unmapped from Node of restriction"; continue; } - inputRestrictions[i].fromNode = intNodeID->second; + current_restriction.fromNode = intNodeID->second; - intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode); - if( intNodeID == ext2IntNodeMap.end()) { + intNodeID = ext_to_int_id_map.find(current_restriction.viaNode); + if( intNodeID == ext_to_int_id_map.end()) { SimpleLogger().Write(logDEBUG) << "Unmapped via node of restriction"; continue; } - inputRestrictions[i].viaNode = intNodeID->second; + current_restriction.viaNode = intNodeID->second; - intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode); - if( intNodeID == ext2IntNodeMap.end()) { + intNodeID = ext_to_int_id_map.find(current_restriction.toNode); + if( intNodeID == ext_to_int_id_map.end()) { SimpleLogger().Write(logDEBUG) << "Unmapped to node of restriction"; continue; } - inputRestrictions[i].toNode = intNodeID->second; + current_restriction.toNode = intNodeID->second; } edgeList.reserve(m); @@ -153,8 +154,8 @@ NodeID readBinaryOSRMGraphFromStream( assert(type >= 0); // translate the external NodeIDs to internal IDs - ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); - if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { + ExternalNodeMap::iterator intNodeID = ext_to_int_id_map.find(source); + if( ext_to_int_id_map.find(source) == ext_to_int_id_map.end()) { #ifndef NDEBUG SimpleLogger().Write(logWARNING) << " unresolved source NodeID: " << source; @@ -162,8 +163,8 @@ NodeID readBinaryOSRMGraphFromStream( continue; } source = intNodeID->second; - intNodeID = ext2IntNodeMap.find(target); - if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { + intNodeID = ext_to_int_id_map.find(target); + if(ext_to_int_id_map.find(target) == ext_to_int_id_map.end()) { #ifndef NDEBUG SimpleLogger().Write(logWARNING) << "unresolved target NodeID : " << target; @@ -215,7 +216,7 @@ NodeID readBinaryOSRMGraphFromStream( } } typename std::vector::iterator newEnd = std::remove_if(edgeList.begin(), edgeList.end(), _ExcessRemover()); - ext2IntNodeMap.clear(); + ext_to_int_id_map.clear(); std::vector(edgeList.begin(), newEnd).swap(edgeList); //remove excess candidates. SimpleLogger().Write() << "Graph loaded ok and has " << edgeList.size() << " edges"; return n; @@ -225,13 +226,13 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s NodeID n, source, target, id; EdgeID m; int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) - ExternalNodeMap ext2IntNodeMap; + ExternalNodeMap ext_to_int_id_map; in >> n; SimpleLogger().Write(logDEBUG) << "Importing n = " << n << " nodes "; for (NodeID i=0; i> id >> ycoord >> xcoord; int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); - ext2IntNodeMap.insert(std::make_pair(id, i)); + ext_to_int_id_map.insert(std::make_pair(id, i)); } in >> m; SimpleLogger().Write(logDEBUG) << " and " << m << " edges"; @@ -321,13 +322,13 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s } // translate the external NodeIDs to internal IDs - ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); - if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { + ExternalNodeMap::iterator intNodeID = ext_to_int_id_map.find(source); + if( ext_to_int_id_map.find(source) == ext_to_int_id_map.end()) { throw OSRMException("unresolvable source Node ID"); } source = intNodeID->second; - intNodeID = ext2IntNodeMap.find(target); - if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { + intNodeID = ext_to_int_id_map.find(target); + if(ext_to_int_id_map.find(target) == ext_to_int_id_map.end()) { throw OSRMException("unresolvable target Node ID"); } target = intNodeID->second; @@ -339,7 +340,7 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, s EdgeT inputEdge(source, target, 0, weight, forward, backward, type ); edgeList.push_back(inputEdge); } - ext2IntNodeMap.clear(); + ext_to_int_id_map.clear(); std::vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. std::cout << "ok" << std::endl; return n;