fixing regression in osrm-components

This commit is contained in:
Dennis Luxen 2013-08-19 13:42:34 +02:00
parent b584ba9149
commit da98900e3a
3 changed files with 55 additions and 28 deletions

View File

@ -111,7 +111,10 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con
restrictionsIT->restriction.toNode = wayStartAndEndEdgeIT->firstStart; 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; ++usableRestrictionsCounter;
} }
++restrictionsIT; ++restrictionsIT;
@ -123,8 +126,15 @@ void ExtractionContainers::PrepareData(const std::string & output_file_name, con
restrictionsOutstream.open(restrictionsFileName.c_str(), std::ios::binary); restrictionsOutstream.open(restrictionsFileName.c_str(), std::ios::binary);
restrictionsOutstream.write((char*)&uuid, sizeof(UUID)); restrictionsOutstream.write((char*)&uuid, sizeof(UUID));
restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned)); restrictionsOutstream.write((char*)&usableRestrictionsCounter, sizeof(unsigned));
for(restrictionsIT = restrictionsVector.begin(); restrictionsIT != restrictionsVector.end(); ++restrictionsIT) { for(
if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) { 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)); restrictionsOutstream.write((char *)&(restrictionsIT->restriction), sizeof(TurnRestriction));
} }
} }

View File

@ -30,6 +30,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "../Util/InputFileUtil.h" #include "../Util/InputFileUtil.h"
#include "../Util/OSRMException.h" #include "../Util/OSRMException.h"
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/UUID.h"
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <fstream> #include <fstream>
@ -58,6 +59,16 @@ int main (int argc, char * argv[]) {
SimpleLogger().Write() << SimpleLogger().Write() <<
"Using restrictions from file: " << argv[2]; "Using restrictions from file: " << argv[2];
std::ifstream restriction_ifstream(argv[2], std::ios::binary); 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()) { if(!restriction_ifstream.good()) {
throw OSRMException("Could not access <osrm-restrictions> files"); throw OSRMException("Could not access <osrm-restrictions> files");
} }
@ -92,6 +103,11 @@ int main (int argc, char * argv[]) {
); );
input_stream.close(); input_stream.close();
BOOST_ASSERT_MSG(
restrictions_vector.size() == usable_restriction_count,
"size of restrictions_vector changed"
);
SimpleLogger().Write() << SimpleLogger().Write() <<
restrictions_vector.size() << " restrictions, " << restrictions_vector.size() << " restrictions, " <<
bollard_node_IDs_vector.size() << " bollard nodes, " << bollard_node_IDs_vector.size() << " bollard nodes, " <<

View File

@ -68,21 +68,21 @@ NodeID readBinaryOSRMGraphFromStream(
if( !uuid_loaded.TestGraphUtil(uuid_orig) ) { if( !uuid_loaded.TestGraphUtil(uuid_orig) ) {
SimpleLogger().Write(logWARNING) << SimpleLogger().Write(logWARNING) <<
".osrm was prepared with different build.\n" ".osrm was prepared with different build."
"Reprocess to get rid of this warning."; "Reprocess to get rid of this warning.";
} }
NodeID n, source, target; NodeID n, source, target;
EdgeID m; EdgeID m;
short dir;// direction (0 = open, 1 = forward, 2+ = open) short dir;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext_to_int_id_map;
in.read((char*)&n, sizeof(NodeID)); in.read((char*)&n, sizeof(NodeID));
SimpleLogger().Write() << "Importing n = " << n << " nodes "; SimpleLogger().Write() << "Importing n = " << n << " nodes ";
_Node node; _Node node;
for (NodeID i=0; i<n; ++i) { for (NodeID i=0; i<n; ++i) {
in.read((char*)&node, sizeof(_Node)); in.read((char*)&node, sizeof(_Node));
int2ExtNodeMap->push_back(NodeInfo(node.lat, node.lon, node.id)); int2ExtNodeMap->push_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) { if(node.bollard) {
bollardNodes.push_back(i); bollardNodes.push_back(i);
} }
@ -97,28 +97,29 @@ NodeID readBinaryOSRMGraphFromStream(
in.read((char*)&m, sizeof(unsigned)); in.read((char*)&m, sizeof(unsigned));
SimpleLogger().Write() << " and " << m << " edges "; SimpleLogger().Write() << " and " << m << " edges ";
for(unsigned i = 0; i < inputRestrictions.size(); ++i) { // for(unsigned i = 0; i < inputRestrictions.size(); ++i) {
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode); BOOST_FOREACH(TurnRestriction & current_restriction, inputRestrictions) {
if( intNodeID == ext2IntNodeMap.end()) { 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"; SimpleLogger().Write(logDEBUG) << "Unmapped from Node of restriction";
continue; continue;
} }
inputRestrictions[i].fromNode = intNodeID->second; current_restriction.fromNode = intNodeID->second;
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode); intNodeID = ext_to_int_id_map.find(current_restriction.viaNode);
if( intNodeID == ext2IntNodeMap.end()) { if( intNodeID == ext_to_int_id_map.end()) {
SimpleLogger().Write(logDEBUG) << "Unmapped via node of restriction"; SimpleLogger().Write(logDEBUG) << "Unmapped via node of restriction";
continue; continue;
} }
inputRestrictions[i].viaNode = intNodeID->second; current_restriction.viaNode = intNodeID->second;
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode); intNodeID = ext_to_int_id_map.find(current_restriction.toNode);
if( intNodeID == ext2IntNodeMap.end()) { if( intNodeID == ext_to_int_id_map.end()) {
SimpleLogger().Write(logDEBUG) << "Unmapped to node of restriction"; SimpleLogger().Write(logDEBUG) << "Unmapped to node of restriction";
continue; continue;
} }
inputRestrictions[i].toNode = intNodeID->second; current_restriction.toNode = intNodeID->second;
} }
edgeList.reserve(m); edgeList.reserve(m);
@ -153,8 +154,8 @@ NodeID readBinaryOSRMGraphFromStream(
assert(type >= 0); assert(type >= 0);
// translate the external NodeIDs to internal IDs // translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); ExternalNodeMap::iterator intNodeID = ext_to_int_id_map.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { if( ext_to_int_id_map.find(source) == ext_to_int_id_map.end()) {
#ifndef NDEBUG #ifndef NDEBUG
SimpleLogger().Write(logWARNING) << SimpleLogger().Write(logWARNING) <<
" unresolved source NodeID: " << source; " unresolved source NodeID: " << source;
@ -162,8 +163,8 @@ NodeID readBinaryOSRMGraphFromStream(
continue; continue;
} }
source = intNodeID->second; source = intNodeID->second;
intNodeID = ext2IntNodeMap.find(target); intNodeID = ext_to_int_id_map.find(target);
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { if(ext_to_int_id_map.find(target) == ext_to_int_id_map.end()) {
#ifndef NDEBUG #ifndef NDEBUG
SimpleLogger().Write(logWARNING) << SimpleLogger().Write(logWARNING) <<
"unresolved target NodeID : " << target; "unresolved target NodeID : " << target;
@ -215,7 +216,7 @@ NodeID readBinaryOSRMGraphFromStream(
} }
} }
typename std::vector<EdgeT>::iterator newEnd = std::remove_if(edgeList.begin(), edgeList.end(), _ExcessRemover<EdgeT>()); typename std::vector<EdgeT>::iterator newEnd = std::remove_if(edgeList.begin(), edgeList.end(), _ExcessRemover<EdgeT>());
ext2IntNodeMap.clear(); ext_to_int_id_map.clear();
std::vector<EdgeT>(edgeList.begin(), newEnd).swap(edgeList); //remove excess candidates. std::vector<EdgeT>(edgeList.begin(), newEnd).swap(edgeList); //remove excess candidates.
SimpleLogger().Write() << "Graph loaded ok and has " << edgeList.size() << " edges"; SimpleLogger().Write() << "Graph loaded ok and has " << edgeList.size() << " edges";
return n; return n;
@ -225,13 +226,13 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
NodeID n, source, target, id; NodeID n, source, target, id;
EdgeID m; EdgeID m;
int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext_to_int_id_map;
in >> n; in >> n;
SimpleLogger().Write(logDEBUG) << "Importing n = " << n << " nodes "; SimpleLogger().Write(logDEBUG) << "Importing n = " << n << " nodes ";
for (NodeID i=0; i<n; ++i) { for (NodeID i=0; i<n; ++i) {
in >> id >> ycoord >> xcoord; in >> id >> ycoord >> xcoord;
int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); 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; in >> m;
SimpleLogger().Write(logDEBUG) << " and " << m << " edges"; SimpleLogger().Write(logDEBUG) << " and " << m << " edges";
@ -321,13 +322,13 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
} }
// translate the external NodeIDs to internal IDs // translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); ExternalNodeMap::iterator intNodeID = ext_to_int_id_map.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { if( ext_to_int_id_map.find(source) == ext_to_int_id_map.end()) {
throw OSRMException("unresolvable source Node ID"); throw OSRMException("unresolvable source Node ID");
} }
source = intNodeID->second; source = intNodeID->second;
intNodeID = ext2IntNodeMap.find(target); intNodeID = ext_to_int_id_map.find(target);
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { if(ext_to_int_id_map.find(target) == ext_to_int_id_map.end()) {
throw OSRMException("unresolvable target Node ID"); throw OSRMException("unresolvable target Node ID");
} }
target = intNodeID->second; target = intNodeID->second;
@ -339,7 +340,7 @@ NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, s
EdgeT inputEdge(source, target, 0, weight, forward, backward, type ); EdgeT inputEdge(source, target, 0, weight, forward, backward, type );
edgeList.push_back(inputEdge); edgeList.push_back(inputEdge);
} }
ext2IntNodeMap.clear(); ext_to_int_id_map.clear();
std::vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. std::vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
std::cout << "ok" << std::endl; std::cout << "ok" << std::endl;
return n; return n;