Merge branch 'master' of https://github.com/DennisOSRM/Project-OSRM
This commit is contained in:
commit
c1676a90d2
@ -144,7 +144,7 @@ private:
|
||||
try {
|
||||
_firstEdge.resize( _numNodes + 1 );
|
||||
} catch(...) {
|
||||
cerr << "Not enough RAM on machine" << endl;
|
||||
ERR("Not enough RAM on machine");
|
||||
return;
|
||||
}
|
||||
_firstEdge[0] = 0;
|
||||
@ -164,7 +164,7 @@ private:
|
||||
threadData.push_back( new _ThreadData( _numNodes ) );
|
||||
}
|
||||
|
||||
cout << "Scanning for useless shortcuts" << endl;
|
||||
INFO("Scanning for useless shortcuts");
|
||||
BuildOutgoingGraph();
|
||||
#pragma omp parallel for
|
||||
for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
|
||||
@ -202,7 +202,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Removing edges" << endl;
|
||||
INFO("Removing edges");
|
||||
int useful = 0;
|
||||
for ( int i = 0; i < ( int ) _graph.size(); i++ ) {
|
||||
if ( !_graph[i].data.forward && !_graph[i].data.backward && _graph[i].data.shortcut )
|
||||
@ -210,7 +210,7 @@ private:
|
||||
_graph[useful] = _graph[i];
|
||||
useful++;
|
||||
}
|
||||
cout << "Removed " << _graph.size() - useful << " useless shortcuts" << endl;
|
||||
INFO("Removed " << _graph.size() - useful << " useless shortcuts");
|
||||
_graph.resize( useful );
|
||||
|
||||
for ( int threadNum = 0; threadNum < maxThreads; ++threadNum ) {
|
||||
@ -223,6 +223,11 @@ private:
|
||||
const NodeID node = heapForward->DeleteMin();
|
||||
const int distance = heapForward->GetKey( node );
|
||||
|
||||
if ( distance > *targetDistance ) {
|
||||
heapForward->DeleteAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( heapBackward->WasInserted( node ) ) {
|
||||
const int newDistance = heapBackward->GetKey( node ) + distance;
|
||||
if ( newDistance < *targetDistance ) {
|
||||
@ -231,10 +236,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
if ( distance > *targetDistance ) {
|
||||
heapForward->DeleteAll();
|
||||
return;
|
||||
}
|
||||
for ( int edge = _firstEdge[node], endEdges = _firstEdge[node + 1]; edge != endEdges; ++edge ) {
|
||||
const NodeID to = _graph[edge].target;
|
||||
const int edgeWeight = _graph[edge].data.distance;
|
||||
@ -256,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->_heapBackward->Clear();
|
||||
//insert source into heap
|
||||
data->_heapForward->Insert( source, 0, source );
|
||||
data->_heapBackward->Insert( target, 0, target );
|
||||
|
||||
int targetDistance = (std::numeric_limits< int >::max)();
|
||||
NodeID middle = (std::numeric_limits<NodeID>::max)();
|
||||
int targetDistance = std::numeric_limits< int >::max();
|
||||
NodeID middle = std::numeric_limits<NodeID>::max();
|
||||
|
||||
while ( data->_heapForward->Size() + data->_heapBackward->Size() > 0 ) {
|
||||
if ( data->_heapForward->Size() > 0 ) {
|
||||
|
@ -99,6 +99,7 @@ void EdgeBasedGraphFactory::Run() {
|
||||
Percent p(_nodeBasedGraph->GetNumberOfNodes());
|
||||
int numberOfResolvedRestrictions(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.
|
||||
for(_NodeBasedDynamicGraph::NodeIterator u = 0; u < _nodeBasedGraph->GetNumberOfNodes(); ++u ) {
|
||||
@ -110,29 +111,56 @@ void EdgeBasedGraphFactory::Run() {
|
||||
++nodeBasedEdgeCounter;
|
||||
_NodeBasedDynamicGraph::NodeIterator v = _nodeBasedGraph->GetTarget(e1);
|
||||
//loop over all reachable edges (v,w)
|
||||
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 isTurnProhibited = false;
|
||||
if( u != w ) { //only add an edge if turn is not a U-turn
|
||||
bool isOnlyAllowed(false);
|
||||
|
||||
//Check every turn restriction originating from this edge if it is an 'only_*'-turn.
|
||||
if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) {
|
||||
std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator;
|
||||
do {
|
||||
if( v == secondRestrictionIterator->viaNode && w == secondRestrictionIterator->toNode) {
|
||||
isTurnProhibited = true;
|
||||
if(v == secondRestrictionIterator->viaNode) {
|
||||
if(secondRestrictionIterator->flags.isOnly) {
|
||||
isOnlyAllowed = true;
|
||||
onlyToNode = secondRestrictionIterator->toNode;
|
||||
}
|
||||
}
|
||||
++secondRestrictionIterator;
|
||||
} while(u == secondRestrictionIterator->fromNode);
|
||||
}
|
||||
if( !isTurnProhibited ) { //only add an edge if turn is not prohibited
|
||||
|
||||
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)
|
||||
const _NodeBasedDynamicGraph::NodeIterator edgeBasedSource = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;
|
||||
// INFO("edgeBasedSource: " << edgeBasedSource);
|
||||
if(edgeBasedSource > _nodeBasedGraph->GetNumberOfEdges()) {
|
||||
ERR("edgeBasedTarget" << edgeBasedSource << ">" << _nodeBasedGraph->GetNumberOfEdges());
|
||||
}
|
||||
const _NodeBasedDynamicGraph::NodeIterator edgeBasedTarget = _nodeBasedGraph->GetEdgeData(e2).edgeBasedNodeID;
|
||||
// INFO("edgeBasedTarget: " << edgeBasedTarget);
|
||||
if(edgeBasedTarget > _nodeBasedGraph->GetNumberOfEdges()) {
|
||||
ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges());
|
||||
}
|
||||
@ -145,7 +173,6 @@ void EdgeBasedGraphFactory::Run() {
|
||||
short turnInstruction = AnalyzeTurn(u, v, w);
|
||||
|
||||
//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);
|
||||
edgeBasedEdges.push_back(newEdge);
|
||||
EdgeBasedNode currentNode;
|
||||
|
@ -121,7 +121,7 @@ public:
|
||||
//Is the highway tag listed as usable way?
|
||||
if(0 < settings[highway]) {
|
||||
|
||||
if(0 != maxspeed)
|
||||
if(0 < maxspeed)
|
||||
w.speed = maxspeed;
|
||||
else
|
||||
w.speed = settings[highway];
|
||||
@ -154,7 +154,6 @@ public:
|
||||
//Is the route tag listed as usable way in the profile?
|
||||
if(settings[route] > 0 || settings[man_made] > 0) {
|
||||
w.useful = true;
|
||||
w.direction = _Way::oneway;
|
||||
w.speed = settings[route];
|
||||
w.direction = _Way::bidirectional;
|
||||
}
|
||||
@ -178,7 +177,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
if(w.id == UINT_MAX) {
|
||||
WARN("found way with unknown type" << w.id);
|
||||
WARN("found way with unknown type: " << w.id);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -177,10 +177,10 @@ struct _RawRestrictionContainer {
|
||||
_Restriction restriction;
|
||||
EdgeID fromWay;
|
||||
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(bool isOnly = false) : fromWay(UINT_MAX), toWay(UINT_MAX), viaWay(UINT_MAX) { restriction.flags.isOnly = isOnly;}
|
||||
_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), viaNode(UINT_MAX) { restriction.flags.isOnly = isOnly;}
|
||||
|
||||
static _RawRestrictionContainer min_value() {
|
||||
return _RawRestrictionContainer((numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)(), (numeric_limits<unsigned>::min)());
|
||||
@ -233,7 +233,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;
|
||||
bool operator () (const _WayIDStartAndEndEdge & a, const _WayIDStartAndEndEdge & b) const {
|
||||
return a.wayID < b.wayID;
|
||||
|
@ -332,10 +332,10 @@ public:
|
||||
// INFO("startcoord: " << smallestEdge.startCoord << ", tgtcoord" << smallestEdge.targetCoord << "result: " << newEndpoint);
|
||||
// INFO("length of old edge: " << LengthOfVector(smallestEdge.startCoord, smallestEdge.targetCoord));
|
||||
// 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) {
|
||||
// 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) );
|
||||
@ -547,6 +547,11 @@ private:
|
||||
if(!localStream.get() || !localStream->is_open()) {
|
||||
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->read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
|
||||
assert(cellMap.find(fileIndex) != cellMap.end());
|
||||
|
@ -270,9 +270,9 @@ private:
|
||||
if("from" == role || "to" == role) //Only via should be a node
|
||||
continue;
|
||||
assert("via" == role);
|
||||
if(UINT_MAX != currentRestrictionContainer.viaWay)
|
||||
currentRestrictionContainer.viaWay = UINT_MAX;
|
||||
assert(UINT_MAX == currentRestrictionContainer.viaWay);
|
||||
if(UINT_MAX != currentRestrictionContainer.viaNode)
|
||||
currentRestrictionContainer.viaNode = UINT_MAX;
|
||||
assert(UINT_MAX == currentRestrictionContainer.viaNode);
|
||||
currentRestrictionContainer.restriction.viaNode = lastRef;
|
||||
break;
|
||||
case 1: //way
|
||||
@ -285,7 +285,7 @@ private:
|
||||
}
|
||||
if ("via" == role) {
|
||||
assert(currentRestrictionContainer.restriction.toNode == UINT_MAX);
|
||||
currentRestrictionContainer.viaWay = lastRef;
|
||||
currentRestrictionContainer.viaNode = lastRef;
|
||||
}
|
||||
break;
|
||||
case 2: //relation, not used. relations relating to relations are evil.
|
||||
|
@ -31,7 +31,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
class XMLParser : public BaseParser<_Node, _RawRestrictionContainer, _Way> {
|
||||
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");
|
||||
inputReader = inputReaderFactory(filename);
|
||||
}
|
||||
@ -72,9 +72,12 @@ public:
|
||||
}
|
||||
}
|
||||
if ( xmlStrEqual( currentName, ( const xmlChar* ) "relation" ) == 1 ) {
|
||||
_Relation r;
|
||||
r.type = _Relation::unknown;
|
||||
//todo: parse relation
|
||||
_RawRestrictionContainer r = _ReadXMLRestriction();
|
||||
if(r.fromWay != UINT_MAX) {
|
||||
if(!(*restrictionCallback)(r)) {
|
||||
std::cerr << "[XMLParser] restriction not parsed" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
xmlFree( currentName );
|
||||
}
|
||||
@ -82,11 +85,69 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
_Relation _ReadXMLRelation ( ) {
|
||||
_Relation relation;
|
||||
relation.type = _Relation::unknown;
|
||||
_RawRestrictionContainer _ReadXMLRestriction ( ) {
|
||||
_RawRestrictionContainer restriction;
|
||||
|
||||
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( ) {
|
||||
@ -109,6 +170,9 @@ private:
|
||||
continue;
|
||||
|
||||
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 );
|
||||
break;
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
distance = searchEngine->ComputeRoute(segmentPhantomNodes, path);
|
||||
|
||||
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
|
||||
|
@ -208,7 +208,7 @@ int main (int argc, char *argv[]) {
|
||||
time = get_timestamp();
|
||||
|
||||
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 << "[extractor] Sorting restrctns. by from... " << flush;
|
||||
@ -255,8 +255,7 @@ int main (int argc, char *argv[]) {
|
||||
cout << "[extractor] Fixing restriction ends ... " << flush;
|
||||
restrictionsIT = externalMemory.restrictionsVector.begin();
|
||||
wayStartAndEndEdgeIT = externalMemory.wayStartEndVector.begin();
|
||||
while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() &&
|
||||
restrictionsIT != externalMemory.restrictionsVector.end()) {
|
||||
while(wayStartAndEndEdgeIT != externalMemory.wayStartEndVector.end() && restrictionsIT != externalMemory.restrictionsVector.end()) {
|
||||
if(wayStartAndEndEdgeIT->wayID < restrictionsIT->toWay){
|
||||
++wayStartAndEndEdgeIT;
|
||||
continue;
|
||||
@ -278,11 +277,13 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
if(UINT_MAX != restrictionsIT->restriction.fromNode && UINT_MAX != restrictionsIT->restriction.toNode) {
|
||||
++usableRestrictionsCounter;
|
||||
} else {
|
||||
INFO("Restriction from: " << restrictionsIT->restriction.fromNode << ", to: " << restrictionsIT->restriction.toNode);
|
||||
}
|
||||
++restrictionsIT;
|
||||
}
|
||||
|
||||
cout << "ok, after " << get_timestamp() - time << "s" << endl;
|
||||
INFO("usable restrictions: " << usableRestrictionsCounter);
|
||||
//serialize restrictions
|
||||
ofstream restrictionsOutstream;
|
||||
restrictionsOutstream.open(restrictionsFileName.c_str(), ios::binary);
|
||||
|
Loading…
Reference in New Issue
Block a user