Merge branch 'master' into sandbox

This commit is contained in:
Emil Tin 2011-12-08 21:12:35 +01:00
commit 1f3421fc20
17 changed files with 363 additions and 240 deletions

View File

@ -66,8 +66,7 @@ public:
NodeID target; NodeID target;
struct EdgeData { struct EdgeData {
NodeID via; NodeID via;
unsigned nameID1; unsigned nameID;
unsigned nameID2;
int distance; int distance;
bool shortcut; bool shortcut;
bool forward; bool forward;
@ -91,7 +90,7 @@ public:
bool operator== ( const Edge& right ) const { bool operator== ( const Edge& right ) const {
return ( source == right.source && target == right.target && data.distance == right.data.distance && return ( source == right.source && target == right.target && data.distance == right.data.distance &&
data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward data.shortcut == right.data.shortcut && data.forward == right.data.forward && data.backward == right.data.backward
&& data.via == right.data.via && data.nameID1 == right.data.nameID1 && data.nameID2 == right.data.nameID2 && data.via == right.data.via && data.nameID == right.data.nameID
); );
} }
}; };
@ -145,7 +144,7 @@ private:
try { try {
_firstEdge.resize( _numNodes + 1 ); _firstEdge.resize( _numNodes + 1 );
} catch(...) { } catch(...) {
cerr << "Not enough RAM on machine" << endl; ERR("Not enough RAM on machine");
return; return;
} }
_firstEdge[0] = 0; _firstEdge[0] = 0;
@ -165,7 +164,7 @@ private:
threadData.push_back( new _ThreadData( _numNodes ) ); threadData.push_back( new _ThreadData( _numNodes ) );
} }
cout << "Scanning for useless shortcuts" << endl; INFO("Scanning for useless shortcuts");
BuildOutgoingGraph(); BuildOutgoingGraph();
#pragma omp parallel for #pragma omp parallel for
for ( int i = 0; i < ( int ) _graph.size(); i++ ) { for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
@ -203,7 +202,7 @@ private:
} }
} }
cout << "Removing edges" << endl; INFO("Removing edges");
int useful = 0; int useful = 0;
for ( int i = 0; i < ( int ) _graph.size(); i++ ) { for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut ) if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut )
@ -211,7 +210,7 @@ private:
_graph[useful] = _graph[i]; _graph[useful] = _graph[i];
useful++; useful++;
} }
cout << "Removed " << _graph.size() - useful << " useless shortcuts" << endl; INFO("Removed " << _graph.size() - useful << " useless shortcuts");
_graph.resize( useful ); _graph.resize( useful );
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) { for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
@ -224,6 +223,11 @@ private:
const NodeID node = heapForward->DeleteMin(); const NodeID node = heapForward->DeleteMin();
const int distance = heapForward->GetKey( node ); const int distance = heapForward->GetKey( node );
if ( distance > *targetDistance ) {
heapForward->DeleteAll();
return;
}
if ( heapBackward->WasInserted( node ) ) { if ( heapBackward->WasInserted( node ) ) {
const int newDistance = heapBackward->GetKey( node ) + distance; const int newDistance = heapBackward->GetKey( node ) + distance;
if ( newDistance < *targetDistance ) { if ( newDistance < *targetDistance ) {
@ -232,10 +236,6 @@ private:
} }
} }
if ( distance > *targetDistance ) {
heapForward->DeleteAll();
return;
}
for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) { for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) {
const NodeID to = _graph[edge].target; const NodeID to = _graph[edge].target;
const int edgeWeight = _graph[edge].data.distance; const int edgeWeight = _graph[edge].data.distance;
@ -257,15 +257,15 @@ private:
} }
} }
int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data, std::vector< NodeID >* path = NULL ) { int _ComputeDistance( NodeID source, NodeID target, _ThreadData * data ) {
data->_heapForward->Clear(); data->_heapForward->Clear();
data->_heapBackward->Clear(); data->_heapBackward->Clear();
//insert source into heap //insert source into heap
data->_heapForward->Insert( source, 0, source ); data->_heapForward->Insert( source, 0, source );
data->_heapBackward->Insert( target, 0, target ); data->_heapBackward->Insert( target, 0, target );
int targetDistance = (std::numeric_limits< int >::max)(); int targetDistance = std::numeric_limits< int >::max();
NodeID middle = (std::numeric_limits<NodeID>::max)(); NodeID middle = std::numeric_limits<NodeID>::max();
while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) { while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) {
if ( data->_heapForward->Size() > 0 ) { if ( data->_heapForward->Size() > 0 ) {

View File

@ -304,7 +304,7 @@ public:
newEdge.data.distance = data.distance; newEdge.data.distance = data.distance;
newEdge.data.shortcut = data.shortcut; newEdge.data.shortcut = data.shortcut;
newEdge.data.via = data.via; newEdge.data.via = data.via;
newEdge.data.nameID1 = data.nameID; newEdge.data.nameID = data.nameID;
newEdge.data.turnInstruction = data.turnInstruction; newEdge.data.turnInstruction = data.turnInstruction;
newEdge.data.forward = data.forward; newEdge.data.forward = data.forward;
newEdge.data.backward = data.backward; newEdge.data.backward = data.backward;
@ -495,6 +495,7 @@ private:
bool _UpdateNeighbours( std::vector< double >* priorities, std::vector< _PriorityData >* const nodeData, _ThreadData* const data, NodeID node ) { bool _UpdateNeighbours( std::vector< double >* priorities, std::vector< _PriorityData >* const nodeData, _ThreadData* const data, NodeID node ) {
std::vector< NodeID >& neighbours = data->neighbours; std::vector< NodeID >& neighbours = data->neighbours;
neighbours.clear(); neighbours.clear();
std::vector< NodeID>().swap(neighbours);
//find all neighbours //find all neighbours
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) { for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
@ -521,6 +522,7 @@ private:
std::vector< NodeID >& neighbours = data->neighbours; std::vector< NodeID >& neighbours = data->neighbours;
neighbours.clear(); neighbours.clear();
std::vector< NodeID>().swap(neighbours);
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) { for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
const NodeID target = _graph->GetTarget( e ); const NodeID target = _graph->GetTarget( e );

View File

@ -58,8 +58,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
edge.data.backward = i->isBackward(); edge.data.backward = i->isBackward();
edge.data.edgeBasedNodeID = edges.size(); edge.data.edgeBasedNodeID = edges.size();
edges.push_back( edge ); edges.push_back( edge );
std::swap( edge.source, edge.target );
if( edge.data.backward ) { if( edge.data.backward ) {
std::swap( edge.source, edge.target );
edge.data.forward = i->isBackward(); edge.data.forward = i->isBackward();
edge.data.backward = i->isForward(); edge.data.backward = i->isForward();
edge.data.edgeBasedNodeID = edges.size(); edge.data.edgeBasedNodeID = edges.size();
@ -99,40 +99,78 @@ void EdgeBasedGraphFactory::Run() {
Percent p(_nodeBasedGraph->GetNumberOfNodes()); Percent p(_nodeBasedGraph->GetNumberOfNodes());
int numberOfResolvedRestrictions(0); int numberOfResolvedRestrictions(0);
int nodeBasedEdgeCounter(0); int nodeBasedEdgeCounter(0);
NodeID onlyToNode(0);
//Loop over all nodes u. Three nested loop look super-linear, but we are dealing with a number linear in the turns only. //Loop over all nodes u. Three nested loop look super-linear, but we are dealing with a number linear in the turns only.
for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) { for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) {
//loop over all adjacent edge (u,v) //loop over all adjacent edge (u,v)
while(restrictionIterator->fromNode < u && inputRestrictions.end() != restrictionIterator) { while(inputRestrictions.end() != restrictionIterator && restrictionIterator->fromNode < u) {
++restrictionIterator; ++restrictionIterator;
} }
for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) { for(_NodeBasedDynamicGraph::EdgeIterator e1 = _nodeBasedGraph->BeginEdges(u); e1 < _nodeBasedGraph->EndEdges(u); ++e1) {
++nodeBasedEdgeCounter; ++nodeBasedEdgeCounter;
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1); _NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
//loop over all reachable edges (v,w) //loop over all reachable edges (v,w)
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { bool isOnlyAllowed(false);
_NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2);
//if (u,v,w) is a forbidden turn, continue //Check every turn restriction originating from this edge if it is an 'only_*'-turn.
bool isTurnProhibited = false; if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) {
if( u != w ) { //only add an edge if turn is not a U-turn
if(u == restrictionIterator->fromNode) {
std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator; std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator;
do { do {
if( v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) { if(v == secondRestrictionIterator->viaNode) {
isTurnProhibited = true; if(secondRestrictionIterator->flags.isOnly) {
isOnlyAllowed = true;
onlyToNode = secondRestrictionIterator->toNode;
}
} }
++secondRestrictionIterator; ++secondRestrictionIterator;
} while(u == secondRestrictionIterator->fromNode); } while(u == secondRestrictionIterator->fromNode);
} }
if( !isTurnProhibited ) { //only add an edge if turn is not prohibited if(_nodeBasedGraph->EndEdges(v) == _nodeBasedGraph->BeginEdges(v) + 1 && _nodeBasedGraph->GetEdgeData(e1).type != 14 ) {
EdgeBasedNode currentNode;
currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID;
currentNode.lat1 = inputNodeInfoList[u].lat;
currentNode.lon1 = inputNodeInfoList[u].lon;
currentNode.lat2 = inputNodeInfoList[v].lat;
currentNode.lon2 = inputNodeInfoList[v].lon;
currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;;
currentNode.weight = _nodeBasedGraph->GetEdgeData(e1).distance;
edgeBasedNodes.push_back(currentNode);
}
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) {
_NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2);
//if (u,v,w) is a forbidden turn, continue
bool isTurnRestricted(false);
if(isOnlyAllowed && w != onlyToNode) {
// INFO("skipped turn <" << u << "," << v << "," << w << ">, only allowing <" << u << "," << v << "," << onlyToNode << ">");
continue;
}
if( u != w ) { //only add an edge if turn is not a U-turn
if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) {
std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator;
do {
if(v == secondRestrictionIterator->viaNode) {
if(w == secondRestrictionIterator->toNode) {
isTurnRestricted = true;
}
}
++secondRestrictionIterator;
} while(u == secondRestrictionIterator->fromNode);
}
if( !isTurnRestricted || (isOnlyAllowed && w == onlyToNode) ) { //only add an edge if turn is not prohibited
if(isOnlyAllowed && w == onlyToNode) {
// INFO("Adding 'only_*'-turn <" << u << "," << v << "," << w << ">");
} else if(isOnlyAllowed && w != onlyToNode) {
assert(false);
}
//new costs for edge based edge (e1, e2) = cost (e1) + tc(e1,e2) //new costs for edge based edge (e1, e2) = cost (e1) + tc(e1,e2)
const _NodeBasedDynamicGraph::NodeIterator edgeBasedSource = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID; const _NodeBasedDynamicGraph::NodeIterator edgeBasedSource = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;
// INFO("edgeBasedSource: " << edgeBasedSource);
if(edgeBasedSource > _nodeBasedGraph->GetNumberOfEdges()) { if(edgeBasedSource > _nodeBasedGraph->GetNumberOfEdges()) {
ERR("edgeBasedTarget" << edgeBasedSource << ">" << _nodeBasedGraph->GetNumberOfEdges()); ERR("edgeBasedTarget" << edgeBasedSource << ">" << _nodeBasedGraph->GetNumberOfEdges());
} }
const _NodeBasedDynamicGraph::NodeIterator edgeBasedTarget = _nodeBasedGraph->GetEdgeData(e2).edgeBasedNodeID; const _NodeBasedDynamicGraph::NodeIterator edgeBasedTarget = _nodeBasedGraph->GetEdgeData(e2).edgeBasedNodeID;
// INFO("edgeBasedTarget: " << edgeBasedTarget);
if(edgeBasedTarget > _nodeBasedGraph->GetNumberOfEdges()) { if(edgeBasedTarget > _nodeBasedGraph->GetNumberOfEdges()) {
ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges()); ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges());
} }
@ -145,12 +183,12 @@ void EdgeBasedGraphFactory::Run() {
short turnInstruction = AnalyzeTurn(u, v, w); short turnInstruction = AnalyzeTurn(u, v, w);
//create edge-based graph edge //create edge-based graph edge
//EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty)
EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction); EdgeBasedEdge newEdge(edgeBasedSource, edgeBasedTarget, v, nameID, distance, true, false, turnInstruction);
edgeBasedEdges.push_back(newEdge); edgeBasedEdges.push_back(newEdge);
EdgeBasedNode currentNode;
if(_nodeBasedGraph->GetEdgeData(e1).type != 14 ) { if(_nodeBasedGraph->GetEdgeData(e1).type != 14 ) {
EdgeBasedNode currentNode;
currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID;
currentNode.lat1 = inputNodeInfoList[u].lat; currentNode.lat1 = inputNodeInfoList[u].lat;
currentNode.lon1 = inputNodeInfoList[u].lon; currentNode.lon1 = inputNodeInfoList[u].lon;

View File

@ -101,9 +101,9 @@ public:
std::string oneway( w.keyVals.Find("oneway")); std::string oneway( w.keyVals.Find("oneway"));
std::string junction( w.keyVals.Find("junction") ); std::string junction( w.keyVals.Find("junction") );
std::string route( w.keyVals.Find("route") ); std::string route( w.keyVals.Find("route") );
double maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) ); int maxspeed( atoi(w.keyVals.Find("maxspeed").c_str()) );
std::string access( w.keyVals.Find("access") ); std::string access( w.keyVals.Find("access") );
std::string accessClass( w.keyVals.Find(settings.accessTag) ); std::string accessTag( w.keyVals.Find(settings.accessTag) );
std::string man_made( w.keyVals.Find("man_made") ); std::string man_made( w.keyVals.Find("man_made") );
std::string barrier( w.keyVals.Find("barrier") ); std::string barrier( w.keyVals.Find("barrier") );
@ -119,12 +119,17 @@ public:
} }
//Is the highway tag listed as usable way? //Is the highway tag listed as usable way?
if(0 < settings[highway]) { if(0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) {
if(0 != maxspeed) if(0 < settings[highway]) {
w.speed = maxspeed; if(0 < maxspeed)
w.speed = std::min(maxspeed, settings[highway]);
else else
w.speed = settings[highway]; w.speed = settings[highway];
} else {
w.speed = settings.defaultSpeed;
highway = "default";
}
w.useful = true; w.useful = true;
//Okay, do we have access to that way? //Okay, do we have access to that way?
@ -135,10 +140,9 @@ public:
} }
} }
if("yes" == accessClass) if("no" == accessTag) {
w.access = true; return true;
else if("no" == accessClass) }
w.access = false;
//Let's process oneway property, if speed profile obeys to it //Let's process oneway property, if speed profile obeys to it
if(oneway != "no" && oneway != "false" && oneway != "0" && settings.obeyOneways) { if(oneway != "no" && oneway != "false" && oneway != "0" && settings.obeyOneways) {
@ -154,17 +158,21 @@ public:
//Is the route tag listed as usable way in the profile? //Is the route tag listed as usable way in the profile?
if(settings[route] > 0 || settings[man_made] > 0) { if(settings[route] > 0 || settings[man_made] > 0) {
w.useful = true; w.useful = true;
w.direction = _Way::oneway;
w.speed = settings[route]; w.speed = settings[route];
w.direction = _Way::bidirectional; w.direction = _Way::bidirectional;
if(0 < settings[route])
highway = route;
else if (0 < settings[man_made]) {
highway = man_made;
}
} }
} }
if ( w.useful && w.access && (1 < w.path.size()) ) { //Only true if the way is specified by the speed profile if ( w.useful && w.access && (1 < w.path.size()) ) { //Only true if the way is specified by the speed profile
//TODO: type is not set, perhaps use a bimap'ed speed profile to do set the type correctly? //TODO: type is not set, perhaps use a bimap'ed speed profile to do set the type correctly?
w.type = 1; w.type = settings.GetHighwayTypeID(highway);
//Get the unique identifier for the street name //Get the unique identifier for the street name
StringMap::const_iterator strit = stringMap->find(w.name); const StringMap::const_iterator strit = stringMap->find(w.name);
if(strit == stringMap->end()) { if(strit == stringMap->end()) {
w.nameID = externalMemory->nameVector.size(); w.nameID = externalMemory->nameVector.size();
externalMemory->nameVector.push_back(w.name); externalMemory->nameVector.push_back(w.name);
@ -173,8 +181,14 @@ public:
w.nameID = strit->second; w.nameID = strit->second;
} }
GUARANTEE(w.id != UINT_MAX, "found way with unknown type"); if(-1 == w.speed){
GUARANTEE(-1 != w.speed, "found way with unknown speed"); WARN("found way with bogus speed, id: " << w.id);
return true;
}
if(w.id == UINT_MAX) {
WARN("found way with unknown type: " << w.id);
return true;
}
if ( w.direction == _Way::opposite ){ if ( w.direction == _Way::opposite ){
std::reverse( w.path.begin(), w.path.end() ); std::reverse( w.path.begin(), w.path.end() );

View File

@ -36,6 +36,7 @@ struct _PathData {
}; };
typedef boost::unordered_map<std::string, NodeID > StringMap; typedef boost::unordered_map<std::string, NodeID > StringMap;
typedef boost::unordered_map<std::string, std::pair<int, int> > StringToIntPairMap;
struct _Node : NodeInfo{ struct _Node : NodeInfo{
_Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {} _Node(int _lat, int _lon, unsigned int _id) : NodeInfo(_lat, _lon, _id) {}
@ -64,6 +65,13 @@ struct _Coordinate {
bool isSet() const { bool isSet() const {
return (INT_MIN != lat) && (INT_MIN != lon); return (INT_MIN != lat) && (INT_MIN != lon);
} }
inline bool isValid() const {
if(lat > 90*100000 || lat < -90*100000 || lon > 180*100000 || lon <-180*100000) {
return false;
}
return true;
}
}; };
inline ostream & operator<<(ostream & out, const _Coordinate & c){ inline ostream & operator<<(ostream & out, const _Coordinate & c){
@ -177,10 +185,10 @@ struct _RawRestrictionContainer {
_Restriction restriction; _Restriction restriction;
EdgeID fromWay; EdgeID fromWay;
EdgeID toWay; EdgeID toWay;
unsigned viaWay; unsigned viaNode;
_RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaWay(vw) { restriction.viaNode = vn;} _RawRestrictionContainer(EdgeID f, EdgeID t, NodeID vn, unsigned vw) : fromWay(f), toWay(t), viaNode(vw) { restriction.viaNode = vn;}
_RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaWay(UINT_MAX) { restriction.flags.isOnly = isOnly;} _RawRestrictionContainer(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;}
static _RawRestrictionContainer min_value() { static _RawRestrictionContainer min_value() {
return _RawRestrictionContainer((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)()); return _RawRestrictionContainer((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)());
@ -233,7 +241,7 @@ struct _WayIDStartAndEndEdge {
} }
}; };
struct CmpWayStartAndEnd : public std::binary_function<_WayIDStartAndEndEdge, _WayIDStartAndEndEdge, bool> { struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDStartAndEndEdge, bool> {
typedef _WayIDStartAndEndEdge value_type; typedef _WayIDStartAndEndEdge value_type;
bool operator () (const _WayIDStartAndEndEdge & a, const _WayIDStartAndEndEdge & b) const { bool operator () (const _WayIDStartAndEndEdge & a, const _WayIDStartAndEndEdge & b) const {
return a.wayID < b.wayID; return a.wayID < b.wayID;
@ -247,19 +255,28 @@ struct CmpWayStartAndEnd : public std::binary_function<_WayIDStartAndEndEdge, _W
}; };
struct Settings { struct Settings {
Settings() : obeyPollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar") {} Settings() : obeyPollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar"), defaultSpeed(30), excludeFromGrid("ferry") {}
StringMap speedProfile; StringToIntPairMap speedProfile;
int operator[](const string & param) const { int operator[](const std::string & param) const {
if(speedProfile.find(param) == speedProfile.end()) if(speedProfile.find(param) == speedProfile.end())
return 0; return 0;
else else
return speedProfile.at(param); return speedProfile.at(param).first;
}
int GetHighwayTypeID(const std::string & param) const {
if(speedProfile.find(param) == speedProfile.end()) {
DEBUG("There is a bug with highway \"" << param << "\"");
return -1;
} else {
return speedProfile.at(param).second;
}
} }
bool obeyPollards; bool obeyPollards;
bool obeyOneways; bool obeyOneways;
bool useRestrictions; bool useRestrictions;
string accessTag; std::string accessTag;
int defaultSpeed;
std::string excludeFromGrid;
}; };
struct Cmp : public std::binary_function<NodeID, NodeID, bool> { struct Cmp : public std::binary_function<NodeID, NodeID, bool> {

View File

@ -29,6 +29,12 @@ struct _GridEdge {
int weight; int weight;
_Coordinate startCoord; _Coordinate startCoord;
_Coordinate targetCoord; _Coordinate targetCoord;
bool operator< ( const _GridEdge& right) const {
return edgeBasedNode < right.edgeBasedNode;
}
bool operator== ( const _GridEdge& right) const {
return edgeBasedNode == right.edgeBasedNode;
}
}; };
struct GridEntry { struct GridEntry {

View File

@ -304,22 +304,22 @@ public:
_GridEdge smallestEdge; _GridEdge smallestEdge;
_Coordinate tmp, newEndpoint; _Coordinate tmp, newEndpoint;
double dist = (numeric_limits<double>::max)(); double dist = numeric_limits<double>::max();
BOOST_FOREACH(_GridEdge candidate, candidates) { BOOST_FOREACH(_GridEdge candidate, candidates) {
double r = 0.; double r = 0.;
double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r); double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r);
if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs((int)candidate.edgeBasedNode-(int)resultNode.edgeBasedNode)) { if(DoubleEpsilonCompare(dist, tmpDist) && 1 == std::abs((int)candidate.edgeBasedNode-(int)resultNode.edgeBasedNode)) {
resultNode.weight2 = candidate.weight; resultNode.weight2 = candidate.weight;
/* if(resultNode.weight1 != resultNode.weight2) { // INFO("b) " << candidate.edgeBasedNode << ", dist: " << tmpDist);
ERR("w1: " << resultNode.weight1 << ", w2: " << resultNode.weight2);
assert(false);
}*/
if(candidate.edgeBasedNode < resultNode.edgeBasedNode) { if(candidate.edgeBasedNode < resultNode.edgeBasedNode) {
resultNode.edgeBasedNode = candidate.edgeBasedNode; resultNode.edgeBasedNode = candidate.edgeBasedNode;
std::swap(resultNode.weight1, resultNode.weight2); std::swap(resultNode.weight1, resultNode.weight2);
} }
// } else if(std::fabs(dist - tmpDist) < 1) {
// INFO("b) ignored " << candidate.edgeBasedNode << " at distance " << tmpDist);
} }
if(tmpDist < dist) { if(tmpDist < dist && !DoubleEpsilonCompare(dist, tmpDist)) {
// INFO("a) " << candidate.edgeBasedNode << ", dist: " << tmpDist);
resultNode.Reset(); resultNode.Reset();
resultNode.edgeBasedNode = candidate.edgeBasedNode; resultNode.edgeBasedNode = candidate.edgeBasedNode;
resultNode.nodeBasedEdgeNameID = candidate.nameID; resultNode.nodeBasedEdgeNameID = candidate.nameID;
@ -330,16 +330,18 @@ public:
foundNode = true; foundNode = true;
smallestEdge = candidate; smallestEdge = candidate;
newEndpoint = tmp; newEndpoint = tmp;
// } else if(tmpDist < dist) {
// INFO("a) ignored " << candidate.edgeBasedNode << " at distance " << std::fabs(dist - tmpDist));
} }
} }
// INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint); // INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint);
// INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord)); // INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord));
// INFO("Length of new edge: " << LengthOfVector(smallestEdge.startCoord, newEndpoint)); // INFO("Length of new edge: " << LengthOfVector(smallestEdge.startCoord, newEndpoint));
// assert(!resultNode.isBidirected || (resultNode.weight1 == resultNode.weight2)); // assert(!resultNode.isBidirected() || (resultNode.weight1 == resultNode.weight2));
// if(resultNode.weight1 != resultNode.weight2) { // if(resultNode.weight1 != resultNode.weight2) {
// INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2); // INFO("-> Weight1: " << resultNode.weight1 << ", weight2: " << resultNode.weight2);
// INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected ? "yes" : "no")); // INFO("-> node: " << resultNode.edgeBasedNode << ", bidir: " << (resultNode.isBidirected() ? "yes" : "no"));
// } // }
double ratio = std::min(1., LengthOfVector(smallestEdge.startCoord, newEndpoint)/LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord) ); double ratio = std::min(1., LengthOfVector(smallestEdge.startCoord, newEndpoint)/LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord) );
@ -350,6 +352,7 @@ public:
resultNode.weight2 *= (1-ratio); resultNode.weight2 *= (1-ratio);
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2); // INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2);
} }
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--")
return foundNode; return foundNode;
} }
@ -412,7 +415,7 @@ private:
} }
inline bool DoubleEpsilonCompare(const double d1, const double d2) { inline bool DoubleEpsilonCompare(const double d1, const double d2) {
return (std::fabs(d1 - d2) < 0.000000001); return (std::fabs(d1 - d2) < 0.0001);
} }
unsigned FillCell(std::vector<GridEntry>& entriesWithSameRAMIndex, unsigned fileOffset ) { unsigned FillCell(std::vector<GridEntry>& entriesWithSameRAMIndex, unsigned fileOffset ) {
@ -551,6 +554,11 @@ private:
if(!localStream.get() || !localStream->is_open()) { if(!localStream.get() || !localStream->is_open()) {
localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary)); localStream.reset(new std::ifstream(iif.c_str(), std::ios::in | std::ios::binary));
} }
if(!localStream->good()) {
localStream->clear(std::ios::goodbit);
DEBUG("Resetting stale filestream");
}
localStream->seekg(startIndexInFile); localStream->seekg(startIndexInFile);
localStream->read((char*) &cellIndex[0], 32*32*sizeof(unsigned)); localStream->read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
assert(cellMap.find(fileIndex) != cellMap.end()); assert(cellMap.find(fileIndex) != cellMap.end());

View File

@ -270,9 +270,9 @@ private:
if("from" == role || "to" == role) //Only via should be a node if("from" == role || "to" == role) //Only via should be a node
continue; continue;
assert("via" == role); assert("via" == role);
if(UINT_MAX != currentRestrictionContainer.viaWay) if(UINT_MAX != currentRestrictionContainer.viaNode)
currentRestrictionContainer.viaWay = UINT_MAX; currentRestrictionContainer.viaNode = UINT_MAX;
assert(UINT_MAX == currentRestrictionContainer.viaWay); assert(UINT_MAX == currentRestrictionContainer.viaNode);
currentRestrictionContainer.restriction.viaNode = lastRef; currentRestrictionContainer.restriction.viaNode = lastRef;
break; break;
case 1: //way case 1: //way
@ -285,7 +285,7 @@ private:
} }
if ("via" == role) { if ("via" == role) {
assert(currentRestrictionContainer.restriction.toNode == UINT_MAX); assert(currentRestrictionContainer.restriction.toNode == UINT_MAX);
currentRestrictionContainer.viaWay = lastRef; currentRestrictionContainer.viaNode = lastRef;
} }
break; break;
case 2: //relation, not used. relations relating to relations are evil. case 2: //relation, not used. relations relating to relations are evil.

View File

@ -91,13 +91,17 @@ public:
//insert start and/or target node of start edge //insert start and/or target node of start edge
_forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode, -phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.edgeBasedNode); _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode, -phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.edgeBasedNode);
// INFO("a) forw insert " << phantomNodes.startPhantom.edgeBasedNode << ", weight: " << -phantomNodes.startPhantom.weight1);
if(phantomNodes.startPhantom.isBidirected() ) { if(phantomNodes.startPhantom.isBidirected() ) {
// INFO("b) forw insert " << phantomNodes.startPhantom.edgeBasedNode+1 << ", weight: " << -phantomNodes.startPhantom.weight2);
_forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode+1, -phantomNodes.startPhantom.weight2, phantomNodes.startPhantom.edgeBasedNode+1); _forwardHeap->Insert(phantomNodes.startPhantom.edgeBasedNode+1, -phantomNodes.startPhantom.weight2, phantomNodes.startPhantom.edgeBasedNode+1);
} }
//insert start and/or target node of target edge id //insert start and/or target node of target edge id
_backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode, -phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.edgeBasedNode); _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode, -phantomNodes.targetPhantom.weight2, phantomNodes.targetPhantom.edgeBasedNode);
// INFO("c) back insert " << phantomNodes.targetPhantom.edgeBasedNode << ", weight: " << -phantomNodes.targetPhantom.weight2);
if(phantomNodes.targetPhantom.isBidirected() ) { if(phantomNodes.targetPhantom.isBidirected() ) {
_backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode+1, -phantomNodes.targetPhantom.weight2, phantomNodes.targetPhantom.edgeBasedNode+1); _backwardHeap->Insert(phantomNodes.targetPhantom.edgeBasedNode+1, -phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.edgeBasedNode+1);
// INFO("d) back insert " << phantomNodes.targetPhantom.edgeBasedNode+1 << ", weight: " << -phantomNodes.targetPhantom.weight1);
} }
while(_forwardHeap->Size() + _backwardHeap->Size() > 0){ while(_forwardHeap->Size() + _backwardHeap->Size() > 0){
@ -256,7 +260,7 @@ private:
return false; return false;
} else { } else {
assert(!ed.shortcut); assert(!ed.shortcut);
path.push_back(_PathData(ed.via, ed.nameID1, ed.turnInstruction, ed.distance) ); path.push_back(_PathData(ed.via, ed.nameID, ed.turnInstruction, ed.distance) );
return true; return true;
} }
} }

View File

@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> { class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
public: public:
XMLParser(const char * filename) { XMLParser(const char * filename) : nodeCallback(NULL), wayCallback(NULL), restrictionCallback(NULL){
WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf"); WARN("Parsing plain .osm/.osm.bz2 is deprecated. Switch to .pbf");
inputReader = inputReaderFactory(filename); inputReader = inputReaderFactory(filename);
} }
@ -72,9 +72,12 @@ public:
} }
} }
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) { if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
_Relation r; _RawRestrictionContainer r = _ReadXMLRestriction();
r.type = _Relation::unknown; if(r.fromWay != UINT_MAX) {
//todo: parse relation if(!(*restrictionCallback)(r)) {
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
}
}
} }
xmlFree( currentName ); xmlFree( currentName );
} }
@ -82,11 +85,69 @@ public:
} }
private: private:
_Relation _ReadXMLRelation ( ) { _RawRestrictionContainer _ReadXMLRestriction ( ) {
_Relation relation; _RawRestrictionContainer restriction;
relation.type = _Relation::unknown;
return relation; if ( xmlTextReaderIsEmptyElement( inputReader ) != 1 ) {
const int depth = xmlTextReaderDepth( inputReader );while ( xmlTextReaderRead( inputReader ) == 1 ) {
const int childType = xmlTextReaderNodeType( inputReader );
if ( childType != 1 && childType != 15 )
continue;
const int childDepth = xmlTextReaderDepth( inputReader );
xmlChar* childName = xmlTextReaderName( inputReader );
if ( childName == NULL )
continue;
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "relation" ) == 1 ) {
xmlFree( childName );
break;
}
if ( childType != 1 ) {
xmlFree( childName );
continue;
}
if ( xmlStrEqual( childName, ( const xmlChar* ) "tag" ) == 1 ) {
xmlChar* k = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "k" );
xmlChar* value = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "v" );
if ( k != NULL && value != NULL ) {
if(xmlStrEqual(k, ( const xmlChar* ) "restriction" )){
if(0 == std::string((const char *) value).find("only_"))
restriction.restriction.flags.isOnly = true;
}
}
if ( k != NULL )
xmlFree( k );
if ( value != NULL )
xmlFree( value );
} else if ( xmlStrEqual( childName, ( const xmlChar* ) "member" ) == 1 ) {
xmlChar* ref = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "ref" );
if ( ref != NULL ) {
xmlChar * role = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "role" );
xmlChar * type = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "type" );
if(xmlStrEqual(role, (const xmlChar *) "to") && xmlStrEqual(type, (const xmlChar *) "way")) {
restriction.toWay = atoi((const char*) ref);
}
if(xmlStrEqual(role, (const xmlChar *) "from") && xmlStrEqual(type, (const xmlChar *) "way")) {
restriction.fromWay = atoi((const char*) ref);
}
if(xmlStrEqual(role, (const xmlChar *) "via") && xmlStrEqual(type, (const xmlChar *) "node")) {
restriction.restriction.viaNode = atoi((const char*) ref);
}
if(NULL != type)
xmlFree( type );
if(NULL != role)
xmlFree( role );
if(NULL != ref)
xmlFree( ref );
}
}
xmlFree( childName );
}
}
return restriction;
} }
_Way _ReadXMLWay( ) { _Way _ReadXMLWay( ) {
@ -109,6 +170,9 @@ private:
continue; continue;
if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) { if ( depth == childDepth && childType == 15 && xmlStrEqual( childName, ( const xmlChar* ) "way" ) == 1 ) {
xmlChar* id = xmlTextReaderGetAttribute( inputReader, ( const xmlChar* ) "id" );
way.id = atoi((char*)id);
xmlFree(id);
xmlFree( childName ); xmlFree( childName );
break; break;
} }

View File

@ -58,7 +58,7 @@ struct ObjectsForQueryStruct {
names = new std::vector<std::string>(); names = new std::vector<std::string>();
char buf[1024]; char buf[1024];
for(unsigned i = 0; i < size; i++) { for(unsigned i = 0; i < size; ++i) {
unsigned sizeOfString = 0; unsigned sizeOfString = 0;
namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); namesInStream.read((char *)&sizeOfString, sizeof(unsigned));
memset(buf, 0, 1024*sizeof(char)); memset(buf, 0, 1024*sizeof(char));

View File

@ -140,7 +140,7 @@ public:
distance = searchEngine->ComputeRoute(segmentPhantomNodes, path); distance = searchEngine->ComputeRoute(segmentPhantomNodes, path);
if(INT_MAX == distance ) { if(INT_MAX == distance ) {
INFO( "Error occurred, single path not found" ); DEBUG( "Error occurred, single path not found" );
} }
//put segments at correct position of routes raw data //put segments at correct position of routes raw data

View File

@ -77,11 +77,12 @@ preprocessing runs in three steps, all done by seperate programs.
necessary, because the osm data is not made to support fast routing out of the necessary, because the osm data is not made to support fast routing out of the
box. The output of the step is a file called 'file.osrm' box. The output of the step is a file called 'file.osrm'
'osrm-prepare file.osrm' preprocesses the road network and computes additional 'osrm-prepare file.osrm file.restrictions' preprocesses the road network and
information that is exploited later to speed up the path computation. The output computes additional information that is exploited later to speed up the path
of this step consists of two file 'file.osrm.hsgr' and 'file.osrm.nodes'. The first computation. The output of this step consists of two file 'file.osrm.hsgr' and
file is the so-called hierarchy that speeds up the path computation while the 'file.osrm.nodes'. The first file is the so-called hierarchy that speeds up the
latter one carries (among other things) geographical information. path computation while the latter one carries (among other things) geographical
information.
'osrm-routed' starts the server on TCP Port 5000. The 'osrm-routed' starts the server on TCP Port 5000. The
server communicates over http and can be queried by any browser or http-capable server communicates over http and can be queried by any browser or http-capable

View File

@ -48,17 +48,17 @@ NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
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 ext2IntNodeMap;
in >> n; in >> n;
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) DEBUG("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(make_pair(id, i)); ext2IntNodeMap.insert(make_pair(id, i));
} }
in >> m; in >> m;
VERBOSE(cout << " and " << m << " edges ..." << flush;) DEBUG(" and " << m << " edges ...");
edgeList.reserve(m); edgeList.reserve(m);
for (EdgeID i=0; i<m; i++) { for (EdgeID i=0; i<m; ++i) {
EdgeWeight weight; EdgeWeight weight;
short type; short type;
NodeID nameID; NodeID nameID;
@ -73,23 +73,19 @@ NodeID readOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
if (1 == dir) backward = false; if (1 == dir) backward = false;
if (2 == dir) forward = false; if (2 == dir) forward = false;
if(length == 0) if(length == 0) { ERR("loaded null length edge"); }
{ cerr << "loaded null length edge" << endl; exit(1); }
// translate the external NodeIDs to internal IDs // translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
{ ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source );
cerr << "after " << edgeList.size() << " edges" << endl;
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
cerr << "unresolved source NodeID: " << source << endl; exit(0);
} }
source = intNodeID->second; source = intNodeID->second;
intNodeID = ext2IntNodeMap.find(target); intNodeID = ext2IntNodeMap.find(target);
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); } if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); }
target = intNodeID->second; target = intNodeID->second;
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } if(source == UINT_MAX || target == UINT_MAX) { ERR( "nonexisting source or target" ); }
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type ); EdgeT inputEdge(source, target, nameID, weight, forward, backward, type );
edgeList.push_back(inputEdge); edgeList.push_back(inputEdge);
@ -107,8 +103,8 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) int xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open)
ExternalNodeMap ext2IntNodeMap; ExternalNodeMap ext2IntNodeMap;
in.read((char*)&n, sizeof(NodeID)); in.read((char*)&n, sizeof(NodeID));
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) DEBUG("Importing n = " << n << " nodes ");
for (NodeID i=0; i<n;i++) { for (NodeID i=0; i<n; ++i) {
in.read((char*)&id, sizeof(unsigned)); in.read((char*)&id, sizeof(unsigned));
in.read((char*)&ycoord, sizeof(int)); in.read((char*)&ycoord, sizeof(int));
in.read((char*)&xcoord, sizeof(int)); in.read((char*)&xcoord, sizeof(int));
@ -116,26 +112,26 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
ext2IntNodeMap.insert(make_pair(id, i)); ext2IntNodeMap.insert(make_pair(id, i));
} }
in.read((char*)&m, sizeof(unsigned)); in.read((char*)&m, sizeof(unsigned));
VERBOSE(cout << " and " << m << " edges ..." << flush;) DEBUG(" 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); ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(inputRestrictions[i].fromNode);
if( intNodeID == ext2IntNodeMap.end()) { if( intNodeID == ext2IntNodeMap.end()) {
DEBUG("Unmapped restriction") DEBUG("Unmapped from Node of restriction");
continue; continue;
} }
inputRestrictions[i].fromNode = intNodeID->second; inputRestrictions[i].fromNode = intNodeID->second;
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode); intNodeID = ext2IntNodeMap.find(inputRestrictions[i].viaNode);
if( intNodeID == ext2IntNodeMap.end()) { if( intNodeID == ext2IntNodeMap.end()) {
DEBUG("Unmapped restriction") DEBUG("Unmapped via node of restriction");
continue; continue;
} }
inputRestrictions[i].viaNode = intNodeID->second; inputRestrictions[i].viaNode = intNodeID->second;
intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode); intNodeID = ext2IntNodeMap.find(inputRestrictions[i].toNode);
if( intNodeID == ext2IntNodeMap.end()) { if( intNodeID == ext2IntNodeMap.end()) {
DEBUG("Unmapped restriction") DEBUG("Unmapped to node of restriction");
continue; continue;
} }
inputRestrictions[i].toNode = intNodeID->second; inputRestrictions[i].toNode = intNodeID->second;
@ -148,7 +144,7 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
int length; int length;
bool isRoundabout; bool isRoundabout;
for (EdgeID i=0; i<m; i++) { for (EdgeID i=0; i<m; ++i) {
in.read((char*)&source, sizeof(unsigned)); in.read((char*)&source, sizeof(unsigned));
in.read((char*)&target, sizeof(unsigned)); in.read((char*)&target, sizeof(unsigned));
in.read((char*)&length, sizeof(int)); in.read((char*)&length, sizeof(int));
@ -158,22 +154,20 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
in.read((char*)&nameID, sizeof(unsigned)); in.read((char*)&nameID, sizeof(unsigned));
in.read((char*)&isRoundabout, sizeof(bool)); in.read((char*)&isRoundabout, sizeof(bool));
assert(length > 0); GUARANTEE(length > 0, "loaded null length edge" );
assert(weight > 0); GUARANTEE(weight > 0, "loaded null weight");
assert(0<=dir && dir<=2); GUARANTEE(0<=dir && dir<=2, "loaded bogus direction");
bool forward = true; bool forward = true;
bool backward = true; bool backward = true;
if (1 == dir) { backward = false; } if (1 == dir) { backward = false; }
if (2 == dir) { forward = false; } if (2 == dir) { forward = false; }
if(length == 0) { cerr << "loaded null length edge" << endl; exit(1); }
// translate the external NodeIDs to internal IDs // translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
#ifndef NDEBUG #ifndef NDEBUG
cerr << "[warning] unresolved source NodeID: " << source << endl; WARN(" unresolved source NodeID: " << source );
#endif #endif
continue; continue;
} }
@ -181,20 +175,19 @@ NodeID readBinaryOSRMGraphFromStream(istream &in, vector<EdgeT>& edgeList, vecto
intNodeID = ext2IntNodeMap.find(target); intNodeID = ext2IntNodeMap.find(target);
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) {
#ifndef NDEBUG #ifndef NDEBUG
cerr << "unresolved target NodeID : " << target << endl; WARN("unresolved target NodeID : " << target );
#endif #endif
continue; continue;
} }
target = intNodeID->second; target = intNodeID->second;
GUARANTEE(source != UINT_MAX && target != UINT_MAX, "nonexisting source or target");
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); }
EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout ); EdgeT inputEdge(source, target, nameID, weight, forward, backward, type, isRoundabout );
edgeList.push_back(inputEdge); edgeList.push_back(inputEdge);
} }
ext2IntNodeMap.clear(); ext2IntNodeMap.clear();
vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
cout << "ok" << endl; INFO("Graph loaded ok");
return n; return n;
} }
template<typename EdgeT> template<typename EdgeT>
@ -204,17 +197,17 @@ NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
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 ext2IntNodeMap;
in >> n; in >> n;
VERBOSE(cout << "Importing n = " << n << " nodes ..." << flush;) DEBUG("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(make_pair(id, i)); ext2IntNodeMap.insert(make_pair(id, i));
} }
in >> m; in >> m;
VERBOSE(cout << " and " << m << " edges ..." << flush;) DEBUG(" and " << m << " edges");
edgeList.reserve(m); edgeList.reserve(m);
for (EdgeID i=0; i<m; i++) { for (EdgeID i=0; i<m; ++i) {
EdgeWeight weight; EdgeWeight weight;
unsigned speedType(0); unsigned speedType(0);
short type(0); short type(0);
@ -279,7 +272,7 @@ NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
assert(length > 0); assert(length > 0);
assert(weight > 0); assert(weight > 0);
if(dir <0 || dir > 2) if(dir <0 || dir > 2)
std::cerr << "[error] direction bogus: " << dir << std::endl; WARN("direction bogus: " << dir);
assert(0<=dir && dir<=2); assert(0<=dir && dir<=2);
bool forward = true; bool forward = true;
@ -287,23 +280,19 @@ NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
if (dir == 1) backward = false; if (dir == 1) backward = false;
if (dir == 2) forward = false; if (dir == 2) forward = false;
if(length == 0) if(length == 0) { ERR("loaded null length edge"); }
{ cerr << "loaded null length edge" << endl; exit(1); }
// translate the external NodeIDs to internal IDs // translate the external NodeIDs to internal IDs
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) {
{ ERR("after " << edgeList.size() << " edges" << "\n->" << source << "," << target << "," << length << "," << dir << "," << weight << "\n->unresolved source NodeID: " << source);
cerr << "after " << edgeList.size() << " edges" << endl;
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
cerr << "unresolved source NodeID: " << source << endl; exit(0);
} }
source = intNodeID->second; source = intNodeID->second;
intNodeID = ext2IntNodeMap.find(target); intNodeID = ext2IntNodeMap.find(target);
if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); } if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { ERR("unresolved target NodeID : " << target); }
target = intNodeID->second; target = intNodeID->second;
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } if(source == UINT_MAX || target == UINT_MAX) { ERR("nonexisting source or target" ); }
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);
@ -333,12 +322,9 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
EdgeWeight weight; EdgeWeight weight;
in >> source >> target >> weight >> dir; in >> source >> target >> weight >> dir;
// if(dir == 3)
// dir = 0;
assert(weight > 0); assert(weight > 0);
if(dir <0 || dir > 3) if(dir <0 || dir > 3)
std::cerr << "[error] direction bogus: " << dir << std::endl; ERR( "[error] direction bogus: " << dir );
assert(0<=dir && dir<=3); assert(0<=dir && dir<=3);
bool forward = true; bool forward = true;
@ -347,8 +333,7 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
if (dir == 2) forward = false; if (dir == 2) forward = false;
if (dir == 3) {backward = true; forward = true;} if (dir == 3) {backward = true; forward = true;}
if(weight == 0) if(weight == 0) { ERR("loaded null length edge"); }
{ cerr << "loaded null length edge" << endl; exit(1); }
if( nodeMap.find(source) == nodeMap.end()) { if( nodeMap.find(source) == nodeMap.end()) {
nodeMap.insert(std::make_pair(source, numberOfNodes )); nodeMap.insert(std::make_pair(source, numberOfNodes ));
@ -365,8 +350,6 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
} }
vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
// cout << "ok" << endl;
// std::cout << "imported " << numberOfNodes << " nodes and " << edgeList.size() << " edges" << std::endl;
nodeMap.clear(); nodeMap.clear();
return numberOfNodes; return numberOfNodes;
} }

View File

@ -28,7 +28,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
#undef VERBOSE2 #undef VERBOSE2
#endif #endif
#include <climits> #include <boost/foreach.hpp>
#include <fstream> #include <fstream>
#include <istream> #include <istream>
#include <iostream> #include <iostream>
@ -60,11 +61,10 @@ std::vector<_Restriction> inputRestrictions;
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
if(argc < 3) { if(argc < 3) {
cerr << "usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>" << std::endl; ERR("usage: " << std::endl << argv[0] << " <osrm-data> <osrm-restrictions>");
exit(-1);
} }
INFO("Using restrictions from file: " << argv[2]); INFO("Using restrictions from file: " << argv[2]);
ifstream restrictionsInstream(argv[2], ios::binary); std::ifstream restrictionsInstream(argv[2], ios::binary);
_Restriction restriction; _Restriction restriction;
unsigned usableRestrictionsCounter(0); unsigned usableRestrictionsCounter(0);
restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned)); restrictionsInstream.read((char*)&usableRestrictionsCounter, sizeof(unsigned));
@ -83,36 +83,24 @@ int main (int argc, char *argv[]) {
} }
omp_set_num_threads(numberOfThreads); omp_set_num_threads(numberOfThreads);
std::cout << "preprocessing data from input file " << argv[1]; INFO("preprocessing data from input file " << argv[1] << " using STL "
#ifdef _GLIBCXX_PARALLEL #ifdef _GLIBCXX_PARALLEL
std::cout << " using STL parallel mode" << std::endl; "parallel (GCC)"
#else #else
std::cout << " using STL serial mode" << std::endl; "serial"
#endif #endif
" mode");
ifstream in; ifstream in;
in.open (argv[1], ifstream::in | ifstream::binary); in.open (argv[1], ifstream::in | ifstream::binary);
if (!in.is_open()) { if (!in.is_open()) {
cerr << "Cannot open " << argv[1] << std::endl; exit(-1); ERR("Cannot open " << argv[1]);
} }
char nodeOut[1024]; char nodeOut[1024]; strcpy(nodeOut, argv[1]); strcat(nodeOut, ".nodes");
char edgeOut[1024]; char edgeOut[1024]; strcpy(edgeOut, argv[1]); strcat(edgeOut, ".hsgr");
char ramIndexOut[1024]; char ramIndexOut[1024]; strcpy(ramIndexOut, argv[1]); strcat(ramIndexOut, ".ramIndex");
char fileIndexOut[1024]; char fileIndexOut[1024]; strcpy(fileIndexOut, argv[1]); strcat(fileIndexOut, ".fileIndex");
char levelInfoOut[1024]; char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels");
strcpy(nodeOut, argv[1]);
strcpy(edgeOut, argv[1]);
strcpy(ramIndexOut, argv[1]);
strcpy(fileIndexOut, argv[1]);
strcpy(levelInfoOut, argv[1]);
strcat(nodeOut, ".nodes");
strcat(edgeOut, ".hsgr");
strcat(ramIndexOut, ".ramIndex");
strcat(fileIndexOut, ".fileIndex");
strcat(levelInfoOut, ".levels");
std::vector<ImportEdge> edgeList; std::vector<ImportEdge> edgeList;
NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions); NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions);
@ -132,24 +120,24 @@ int main (int argc, char *argv[]) {
DELETE(edgeBasedGraphFactory); DELETE(edgeBasedGraphFactory);
WritableGrid * writeableGrid = new WritableGrid(); WritableGrid * writeableGrid = new WritableGrid();
std::cout << "building grid ..." << std::flush; INFO("building grid ...");
writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut); writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut);
DELETE( writeableGrid ); DELETE( writeableGrid );
std::cout << "writing node map ..." << std::flush; nodeBasedEdgeList.clear();
ofstream mapOutFile(nodeOut, ios::binary); std::vector<EdgeBasedGraphFactory::EdgeBasedNode>().swap(nodeBasedEdgeList);
for(NodeID i = 0; i < internalToExternaleNodeMapping.size(); i++) { INFO("writing node map ...");
mapOutFile.write((char *)&(internalToExternaleNodeMapping.at(i)), sizeof(NodeInfo)); std::ofstream mapOutFile(nodeOut, ios::binary);
BOOST_FOREACH(NodeInfo & info, internalToExternaleNodeMapping) {
mapOutFile.write((char *)&(info), sizeof(NodeInfo));
} }
mapOutFile.close(); mapOutFile.close();
std::cout << "ok" << std::endl;
internalToExternaleNodeMapping.clear(); internalToExternaleNodeMapping.clear();
std::vector<NodeInfo>().swap(internalToExternaleNodeMapping); std::vector<NodeInfo>().swap(internalToExternaleNodeMapping);
inputRestrictions.clear(); inputRestrictions.clear();
std::vector<_Restriction>().swap(inputRestrictions); std::vector<_Restriction>().swap(inputRestrictions);
std::cout << "initializing contractor ..." << std::flush; INFO("initializing contractor");
Contractor* contractor = new Contractor( n, edgeBasedEdgeList ); Contractor* contractor = new Contractor( n, edgeBasedEdgeList );
double contractionStartedTimestamp(get_timestamp()); double contractionStartedTimestamp(get_timestamp());
contractor->Run(); contractor->Run();
@ -160,24 +148,25 @@ int main (int argc, char *argv[]) {
ContractionCleanup * cleanup = new ContractionCleanup(n, contractedEdges); ContractionCleanup * cleanup = new ContractionCleanup(n, contractedEdges);
contractedEdges.clear(); contractedEdges.clear();
std::vector<ContractionCleanup::Edge>().swap(contractedEdges);
cleanup->Run(); cleanup->Run();
std::vector< InputEdge> cleanedEdgeList; std::vector< InputEdge> cleanedEdgeList;
cleanup->GetData(cleanedEdgeList); cleanup->GetData(cleanedEdgeList);
DELETE( cleanup ); DELETE( cleanup );
std::cout << "Serializing edges " << std::flush; INFO("Serializing edges ");
ofstream edgeOutFile(edgeOut, ios::binary); ofstream edgeOutFile(edgeOut, ios::binary);
Percent p(cleanedEdgeList.size()); Percent p(cleanedEdgeList.size());
for(std::vector< InputEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++) { BOOST_FOREACH(InputEdge & edge, cleanedEdgeList) {
p.printIncrement(); p.printIncrement();
edgeOutFile.write((char *)&(it->data), sizeof(EdgeData)); edgeOutFile.write((char *)&(edge.data), sizeof(EdgeData));
edgeOutFile.write((char *)&(it->source), sizeof(NodeID)); edgeOutFile.write((char *)&(edge.source), sizeof(NodeID));
edgeOutFile.write((char *)&(it->target), sizeof(NodeID)); edgeOutFile.write((char *)&(edge.target), sizeof(NodeID));
} }
edgeOutFile.close(); edgeOutFile.close();
cleanedEdgeList.clear(); cleanedEdgeList.clear();
std::cout << "finished" << std::endl; INFO("finished preprocessing");
return 0; return 0;
} }

View File

@ -70,19 +70,16 @@ bool removeIfUnused(ClassT n) { return (false == n.used); }
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
if(argc <= 1) { GUARANTEE((argc > 1) ,"usage: \n" << argv[0] << " <file.osm/.osm.bz2/.osm.pbf>");
cerr << "usage: " << endl << argv[0] << " <file.osm/.osm.bz2/.osm.pbf>" << endl;
exit(-1);
}
cout << "[extractor] extracting data from input file " << argv[1] << endl; INFO("extracting data from input file " << argv[1]);
bool isPBF = false; bool isPBF(false);
string outputFileName(argv[1]); std::string outputFileName(argv[1]);
string restrictionsFileName(argv[1]); std::string restrictionsFileName(argv[1]);
string::size_type pos = outputFileName.find(".osm.bz2"); std::string::size_type pos = outputFileName.find(".osm.bz2");
if(pos==string::npos) { if(pos==std::string::npos) {
pos = outputFileName.find(".osm.pbf"); pos = outputFileName.find(".osm.pbf");
if(pos!=string::npos) { if(pos!=std::string::npos) {
isPBF = true; isPBF = true;
} }
} }
@ -99,7 +96,7 @@ int main (int argc, char *argv[]) {
restrictionsFileName.append(".osrm.restrictions"); restrictionsFileName.append(".osrm.restrictions");
} }
} }
string adressFileName(outputFileName); std::string adressFileName(outputFileName);
Settings settings; Settings settings;
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
@ -109,15 +106,15 @@ int main (int argc, char *argv[]) {
INFO("Found the following speed profiles: "); INFO("Found the following speed profiles: ");
int profileCounter(0); int profileCounter(0);
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) { BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child("")) {
string name = v.first; std::string name = v.first;
cout << " [" << profileCounter << "]" << name << endl; cout << " [" << profileCounter << "]" << name << endl;
++profileCounter; ++profileCounter;
} }
string usedSpeedProfile(pt.get_child("").begin()->first); std::string usedSpeedProfile(pt.get_child("").begin()->first);
INFO("Using profile \"" << usedSpeedProfile << "\"") INFO("Using profile \"" << usedSpeedProfile << "\"")
BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(usedSpeedProfile)) { BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt.get_child(usedSpeedProfile)) {
string name = v.first; std::string name = v.first;
string value = v.second.get<string>(""); std::string value = v.second.get<std::string>("");
DEBUG("inserting " << name << "=" << value); DEBUG("inserting " << name << "=" << value);
if(name == "obeyOneways") { if(name == "obeyOneways") {
if(value == "no") if(value == "no")
@ -137,11 +134,20 @@ int main (int argc, char *argv[]) {
if(name == "accessTag") { if(name == "accessTag") {
settings.accessTag = value; settings.accessTag = value;
continue; continue;
} else {
if(name == "excludeFromGrid") {
settings.excludeFromGrid = value;
} else {
if(name == "defaultSpeed") {
settings.defaultSpeed = atoi(value.c_str());
settings.speedProfile["default"] = std::make_pair(settings.defaultSpeed, settings.speedProfile.size() );
} }
} }
} }
} }
settings.speedProfile[name] = atoi(value.c_str()); }
settings.speedProfile[name] = std::make_pair(std::atoi(value.c_str()), settings.speedProfile.size() );
}
} }
} catch(std::exception& e) { } catch(std::exception& e) {
ERR("caught: " << e.what() ); ERR("caught: " << e.what() );
@ -150,23 +156,21 @@ int main (int argc, char *argv[]) {
unsigned amountOfRAM = 1; unsigned amountOfRAM = 1;
unsigned installedRAM = GetPhysicalmemory(); unsigned installedRAM = GetPhysicalmemory();
if(installedRAM < 2048264) { if(installedRAM < 2048264) {
cout << "[Warning] Machine has less than 2GB RAM." << endl; WARN("Machine has less than 2GB RAM.");
} }
if(testDataFile("extractor.ini")) { if(testDataFile("extractor.ini")) {
ExtractorConfiguration extractorConfig("extractor.ini"); ExtractorConfiguration extractorConfig("extractor.ini");
unsigned memoryAmountFromFile = atoi(extractorConfig.GetParameter("Memory").c_str()); unsigned memoryAmountFromFile = atoi(extractorConfig.GetParameter("Memory").c_str());
if( memoryAmountFromFile != 0 && memoryAmountFromFile <= installedRAM/(1024*1024)) if( memoryAmountFromFile != 0 && memoryAmountFromFile <= installedRAM/(1024*1024))
amountOfRAM = memoryAmountFromFile; amountOfRAM = memoryAmountFromFile;
cout << "[extractor] using " << amountOfRAM << " GB of RAM for buffers" << endl; INFO("Using " << amountOfRAM << " GB of RAM for buffers");
} }
StringMap stringMap;
STXXLContainers externalMemory; STXXLContainers externalMemory;
unsigned usedNodeCounter = 0; unsigned usedNodeCounter = 0;
unsigned usedEdgeCounter = 0; unsigned usedEdgeCounter = 0;
StringMap stringMap;
double time = get_timestamp(); double time = get_timestamp();
stringMap[""] = 0; stringMap[""] = 0;
@ -178,13 +182,9 @@ int main (int argc, char *argv[]) {
parser = new XMLParser(argv[1]); parser = new XMLParser(argv[1]);
} }
parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction, &adressFunction); parser->RegisterCallbacks(&nodeFunction, &restrictionFunction, &wayFunction, &adressFunction);
if(parser->Init()) { GUARANTEE(parser->Init(), "Parser not initialized!");
parser->Parse(); parser->Parse();
} else { DELETE(parser);
cerr << "[error] parser not initialized!" << endl;
exit(-1);
}
delete parser;
stringMap.clear(); stringMap.clear();
try { try {
@ -217,7 +217,7 @@ int main (int argc, char *argv[]) {
time = get_timestamp(); time = get_timestamp();
cout << "[extractor] Sorting used ways ... " << flush; cout << "[extractor] Sorting used ways ... " << flush;
stxxl::sort(externalMemory.wayStartEndVector.begin(), externalMemory.wayStartEndVector.end(), CmpWayStartAndEnd(), memory_to_use); stxxl::sort(externalMemory.wayStartEndVector.begin(), externalMemory.wayStartEndVector.end(), CmpWayByID(), memory_to_use);
cout << "ok, after " << get_timestamp() - time << "s" << endl; cout << "ok, after " << get_timestamp() - time << "s" << endl;
cout << "[extractor] Sorting restrctns. by from... " << flush; cout << "[extractor] Sorting restrctns. by from... " << flush;
@ -264,8 +264,7 @@ int main (int argc, char *argv[]) {
cout << "[extractor] Fixing restriction ends ... " << flush; cout << "[extractor] Fixing restriction ends ... " << flush;
restrictionsIT = externalMemory.restrictionsVector.begin(); restrictionsIT = externalMemory.restrictionsVector.begin();
wayStartAndEndEdgeIT = externalMemory.wayStartEndVector.begin(); wayStartAndEndEdgeIT = externalMemory.wayStartEndVector.begin();
while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) {
restrictionsIT != externalMemory.restrictionsVector.end()) {
if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){ if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){
++wayStartAndEndEdgeIT; ++wayStartAndEndEdgeIT;
continue; continue;
@ -290,8 +289,8 @@ int main (int argc, char *argv[]) {
} }
++restrictionsIT; ++restrictionsIT;
} }
cout << "ok, after " << get_timestamp() - time << "s" << endl; cout << "ok, after " << get_timestamp() - time << "s" << endl;
INFO("usable restrictions: " << usableRestrictionsCounter);
//serialize restrictions //serialize restrictions
ofstream restrictionsOutstream; ofstream restrictionsOutstream;
restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary); restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary);

View File

@ -31,8 +31,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
using namespace std; using namespace std;
#define VERBOSE(x) x
#define VERBOSE2(x)
#ifdef STXXL_VERBOSE_LEVEL #ifdef STXXL_VERBOSE_LEVEL
#undef STXXL_VERBOSE_LEVEL #undef STXXL_VERBOSE_LEVEL
#endif #endif
@ -41,12 +39,12 @@ using namespace std;
#define INFO(x) do {std::cout << "[info " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); #define INFO(x) do {std::cout << "[info " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0);
#define ERR(x) do {std::cerr << "[error " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl; exit(-1);} while(0); #define ERR(x) do {std::cerr << "[error " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl; exit(-1);} while(0);
#define WARN(x) do {std::cerr << "[warn " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); #define WARN(x) do {std::cerr << "[warn " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0);
#define GUARANTEE(x,y) do { {do{ if(false == (x)) { ERR(y) } } while(0);} } while(0);
#ifdef NDEBUG #ifdef NDEBUG
#define DEBUG(x) #define DEBUG(x)
#define GUARANTEE(x,y)
#else #else
#define DEBUG(x) do {std::cout << "[debug " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0); #define DEBUG(x) do {std::cout << "[debug " << __FILE__ << ":" << __LINE__ << "] " << x << std::endl;} while(0);
#define GUARANTEE(x,y) do { {do{ if(false == (x)) { ERR(y) } } while(0);} } while(0);
#endif #endif
#define DELETE(x) do { if(NULL != x) { delete x; x = NULL; } }while(0); #define DELETE(x) do { if(NULL != x) { delete x; x = NULL; } }while(0);