From 1ba915cbed0b55560337432b80216ee21ac7bda0 Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Thu, 2 Sep 2010 15:47:55 +0000 Subject: [PATCH] BREAKING CHANGE, REPROCESS YOUR OSM FILES Ferry egdes are now ignores by nearest neighbor grid --- Contractor/Contractor.h | 59 +----------------- Contractor/GraphLoader.h | 5 +- Contractor/SearchEngine.h | 2 +- {Contractor => DataStructures}/DynamicGraph.h | 0 DataStructures/ImportEdge.h | 7 ++- createHierarchy.cpp | 4 +- extractLargeNetwork.cpp | 9 +-- routed.cpp | 61 +++++++++---------- typedefs.h | 2 +- 9 files changed, 48 insertions(+), 101 deletions(-) rename {Contractor => DataStructures}/DynamicGraph.h (100%) diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index cb4428713..2e7b0168e 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -25,7 +25,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #else #include #endif -#include "DynamicGraph.h" +#include "../DataStructures/DynamicGraph.h" #include #include #include @@ -460,65 +460,8 @@ public: } } - NodeID GetNumberOfComponents() - { - NodeID unique = 1; - NodeID largestRun = 0; - NodeID tmp = 1; - _components = new std::vector(_graph->GetNumberOfNodes(), 0); - for(NodeID i = 0; i < _graph->GetNumberOfNodes(); i++) - { - BFSAtNode(i); - } -#ifdef _GLIBCXX_PARALLEL - __gnu_parallel::sort( _components->begin(), _components->end() ); -#else - std::sort(_components->begin(), _components->end()); -#endif - - for(NodeID i = 0; i < _graph->GetNumberOfNodes()-1; i++) - { - if( _components->at(i) != _components->at(i+1)){ - if(tmp > largestRun) - { - largestRun = tmp; - } - tmp = 1; - unique++; - } - else - tmp++; - } - if(tmp > largestRun) - largestRun = tmp; - _components->clear(); - cout << "Largest component has size: " << largestRun << endl; - return unique; - } - private: - void BFSAtNode(const NodeID n){ - std::stack * bfsStack = new std::stack(); - if(_components->at(n) != 0) - return; - _components->at(n) = n+1; - bfsStack->push(n); - while(!bfsStack->empty()) - { - NodeID node = bfsStack->top(); - bfsStack->pop(); - for(_DynamicGraph::EdgeIterator e = _graph->BeginEdges(node); e < _graph->EndEdges(node); e++) - { - if(_components->at(_graph->GetTarget(e))!=0) - continue; - _components->at(_graph->GetTarget(e)) = n+1; - bfsStack->push(_graph->GetTarget(e)); - } - } - delete bfsStack; - } - double _Timestamp() { return time(NULL); } diff --git a/Contractor/GraphLoader.h b/Contractor/GraphLoader.h index 1b0073021..754ec8550 100644 --- a/Contractor/GraphLoader.h +++ b/Contractor/GraphLoader.h @@ -45,6 +45,7 @@ template inline NodeID readOSMRGraphFromStream(istream &in, vector& edgeList, vector * int2ExtNodeMap) { NodeID n, source, target, id; EdgeID m; + bool locatable; int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) ExternalNodeMap ext2IntNodeMap; ext2IntNodeMap.set_empty_key(UINT_MAX); @@ -62,7 +63,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector& edgeList, vect for (EdgeID i=0; i> source >> target >> length >> dir >> weight; + in >> source >> target >> length >> dir >> weight >> locatable; assert(length > 0); assert(weight > 0); @@ -91,7 +92,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector& edgeList, vect if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } - EdgeT inputEdge(source, target, weight, forward, backward); + EdgeT inputEdge(source, target, weight, forward, backward, locatable); edgeList.push_back(inputEdge); } ext2IntNodeMap.clear(); diff --git a/Contractor/SearchEngine.h b/Contractor/SearchEngine.h index a4da2610f..b51d004a7 100644 --- a/Contractor/SearchEngine.h +++ b/Contractor/SearchEngine.h @@ -73,7 +73,7 @@ public: currentEdge = _graph->FindEdge( phantomNodes->startNode2, phantomNodes->startNode1 ); if(currentEdge != UINT_MAX && _graph->GetEdgeData(currentEdge).forward && phantomNodes->startRatio < phantomNodes->targetRatio) { //upperbound auf kantenlänge setzen - cout << "start and target on same edge" << endl; +// cout << "start and target on same edge" << endl; onSameEdge = true; _upperbound = 10 * ApproximateDistance(phantomNodes->startCoord.lat, phantomNodes->startCoord.lon, phantomNodes->targetCoord.lat, phantomNodes->targetCoord.lon); } else if (currentEdge != UINT_MAX && !_graph->GetEdgeData(currentEdge).backward) { diff --git a/Contractor/DynamicGraph.h b/DataStructures/DynamicGraph.h similarity index 100% rename from Contractor/DynamicGraph.h rename to DataStructures/DynamicGraph.h diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 920acd748..954527b0f 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -44,7 +44,7 @@ public: /** Default constructor. target and weight are set to 0.*/ Edge() { assert(false); } //shall not be used. - explicit Edge(NodeID s, NodeID t, EdgeWeight w, bool f, bool b) : _source(s), _target(t), _weight(w), forward(f), backward(b) { } + explicit Edge(NodeID s, NodeID t, EdgeWeight w, bool f, bool b, bool l) : _source(s), _target(t), _weight(w), forward(f), backward(b), locatable(l) { } NodeID target() const {return _target; } NodeID source() const {return _source;} @@ -54,12 +54,15 @@ public: bool isForward() const { return forward; } + bool isLocatable() const { return locatable; } + private: NodeID _source; NodeID _target; - EdgeWeight _weight:30; + EdgeWeight _weight:29; bool forward:1; bool backward:1; + bool locatable:1; }; typedef Edge ImportEdge; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index a71c10602..e6f603f01 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -45,8 +45,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Contractor/BinaryHeap.h" #include "Contractor/Contractor.h" #include "Contractor/ContractionCleanup.h" -#include "Contractor/DynamicGraph.h" - #include "DataStructures/NNGrid.h" using namespace std; @@ -95,6 +93,8 @@ int main (int argc, char *argv[]) Percent p(edgeList.size()); for(NodeID i = 0; i < edgeList.size(); i++) { + if(!edgeList[i].isLocatable()) + continue; p.printIncrement(); int slat = int2ExtNodeMap->at(edgeList[i].source()).lat; int slon = int2ExtNodeMap->at(edgeList[i].source()).lon; diff --git a/extractLargeNetwork.cpp b/extractLargeNetwork.cpp index 15e34aca5..9b49da3c8 100644 --- a/extractLargeNetwork.cpp +++ b/extractLargeNetwork.cpp @@ -246,20 +246,21 @@ int main (int argc, char *argv[]) double weight = ( distance * 10. ) / (eit->speed / 3.6); int intWeight = max(1, (int) weight); int intDist = max(1, (int)distance); + int ferryIndex = settings.indexInAccessListOf("ferry"); switch(eit->direction) { case _Way::notSure: - fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n"; break; case _Way::oneway: - fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n"; break; case _Way::bidirectional: - fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n"; break; case _Way::opposite: - fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << " " << (eit->type == ferryIndex ? false :true ) << "\n"; break; default: assert(false); diff --git a/routed.cpp b/routed.cpp index c9edcdf4f..a6d31e6f8 100644 --- a/routed.cpp +++ b/routed.cpp @@ -47,7 +47,6 @@ typedef http::server > server; /* * TODO: Description of command line arguments */ - int main (int argc, char *argv[]) { double time; @@ -99,38 +98,38 @@ int main (int argc, char *argv[]) cout << "deserializing node map and building nearest neighbor grid ..." << flush; nodeInfoHelper->initNNGrid(in2); cout << "in " << get_timestamp() - time << "s" << endl; - time = get_timestamp(); +// time = get_timestamp(); StaticGraph * graph = new StaticGraph(nodeInfoHelper->getNumberOfNodes()-1, *edgelist); delete edgelist; - cout << "checking data sanity ..." << flush; - NodeID numberOfNodes = graph->GetNumberOfNodes(); - for ( NodeID node = 0; node < numberOfNodes; ++node ) { - for ( StaticGraph::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) { - const NodeID start = node; - const NodeID target = graph->GetTarget( edge ); - const EdgeData& data = graph->GetEdgeData( edge ); - const NodeID middle = data.middle; - assert(start != target); - if(data.shortcut) - { - if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID) - { - assert(false); - cerr << "hierarchy broken" << endl; exit(-1); - } - if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID) - { - assert(false); - cerr << "hierarchy broken" << endl; exit(-1); - } - } - } - if(graph->GetOutDegree(node) == 0) - { - cerr << "found node with degree 0: " << node << endl; - } - } - cout << "in " << get_timestamp() - time << "s" << endl; +// cout << "checking data sanity ..." << flush; +// NodeID numberOfNodes = graph->GetNumberOfNodes(); +// for ( NodeID node = 0; node < numberOfNodes; ++node ) { +// for ( StaticGraph::EdgeIterator edge = graph->BeginEdges( node ), endEdges = graph->EndEdges( node ); edge != endEdges; ++edge ) { +// const NodeID start = node; +// const NodeID target = graph->GetTarget( edge ); +// const EdgeData& data = graph->GetEdgeData( edge ); +// const NodeID middle = data.middle; +// assert(start != target); +// if(data.shortcut) +// { +// if(graph->FindEdge(start, middle) == SPECIAL_EDGEID && graph->FindEdge(middle, start) == SPECIAL_EDGEID) +// { +// assert(false); +// cerr << "hierarchy broken" << endl; exit(-1); +// } +// if(graph->FindEdge(middle, target) == SPECIAL_EDGEID && graph->FindEdge(target, middle) == SPECIAL_EDGEID) +// { +// assert(false); +// cerr << "hierarchy broken" << endl; exit(-1); +// } +// } +// } +// if(graph->GetOutDegree(node) == 0) +// { +// cerr << "found node with degree 0: " << node << endl; +// } +// } +// cout << "in " << get_timestamp() - time << "s" << endl; time = get_timestamp(); cout << "building search graph ..." << flush; diff --git a/typedefs.h b/typedefs.h index 5f9772884..e66a832c1 100644 --- a/typedefs.h +++ b/typedefs.h @@ -52,7 +52,7 @@ typedef NodeCoords NodeInfo; #include "Contractor/Contractor.h" #include "Contractor/ContractionCleanup.h" typedef ContractionCleanup::Edge::EdgeData EdgeData; -#include "Contractor/DynamicGraph.h" +#include "DataStructures/DynamicGraph.h" #include "Contractor/SearchEngine.h" #endif /* TYPEDEFS_H_ */