From 8d008f9dccace8c38dd4903a3fbe0f7ba68e9d64 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Fri, 25 Nov 2011 12:02:52 +0100 Subject: [PATCH] Space requirements are better now --- Contractor/EdgeBasedGraphFactory.cpp | 39 ++++++---------- Contractor/EdgeBasedGraphFactory.h | 21 +++------ DataStructures/ImportEdge.h | 19 ++++---- createHierarchy.cpp | 70 +++++++++++----------------- 4 files changed, 56 insertions(+), 93 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 4cd26e56e..bb9b06554 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -51,7 +51,7 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector 0 ); edge.data.shortcut = false; edge.data.roundabout = i->isRoundabout(); - edge.data.middleName.nameID = i->name(); + edge.data.nameID = i->name(); edge.data.type = i->type(); edge.data.forward = i->isForward(); edge.data.backward = i->isBackward(); @@ -66,7 +66,6 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & nodes) { @@ -97,8 +94,6 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nod void EdgeBasedGraphFactory::Run() { INFO("Generating Edge based representation of input data"); - _edgeBasedGraph.reset(new _EdgeBasedDynamicGraph(_nodeBasedGraph->GetNumberOfEdges() ) ); - std::vector<_Restriction>::iterator restrictionIterator = inputRestrictions.begin(); Percent p(_nodeBasedGraph->GetNumberOfNodes()); int numberOfResolvedRestrictions(0); @@ -141,25 +136,21 @@ void EdgeBasedGraphFactory::Run() { ERR("edgeBasedTarget" << edgeBasedTarget << ">" << _nodeBasedGraph->GetNumberOfEdges()); } - _EdgeBasedEdge newEdge; - newEdge.source = edgeBasedSource; - newEdge.target = edgeBasedTarget; - //incorporate turn costs, this is just a simple model and can (read: must) be extended double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); - newEdge.data.distance = (int)( _nodeBasedGraph->GetEdgeData(e1).distance *(1+std::abs((angle-180.)/180.))); - newEdge.data.forward = true; - newEdge.data.backward = false; - newEdge.data.via = v; - newEdge.data.nameID = _nodeBasedGraph->GetEdgeData(e2).middleName.nameID; - newEdge.data.turnInstruction = AnalyzeTurn(u, v, w); - //create Edge for NearestNeighborlookup + unsigned distance = (int)( _nodeBasedGraph->GetEdgeData(e1).distance *(1+std::abs((angle-180.)/180.))); + unsigned nameID = _nodeBasedGraph->GetEdgeData(e2).nameID; + 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; if(_nodeBasedGraph->GetEdgeData(e1).type != 14) { - currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).middleName.nameID; + currentNode.nameID = _nodeBasedGraph->GetEdgeData(e1).nameID; currentNode.lat1 = inputNodeInfoList[u].lat; currentNode.lon1 = inputNodeInfoList[u].lon; currentNode.lat2 = inputNodeInfoList[v].lat; @@ -188,8 +179,8 @@ short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const N _NodeBasedDynamicGraph::EdgeIterator edge1 = _nodeBasedGraph->FindEdge(u, v); _NodeBasedDynamicGraph::EdgeIterator edge2 = _nodeBasedGraph->FindEdge(v, w); - _NodeBasedDynamicGraph::EdgeData data1 = _nodeBasedGraph->GetEdgeData(edge1); - _NodeBasedDynamicGraph::EdgeData data2 = _nodeBasedGraph->GetEdgeData(edge2); + _NodeBasedDynamicGraph::EdgeData & data1 = _nodeBasedGraph->GetEdgeData(edge1); + _NodeBasedDynamicGraph::EdgeData & data2 = _nodeBasedGraph->GetEdgeData(edge2); double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); @@ -214,7 +205,7 @@ short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const N } //If street names stay the same and if we are certain that it is not a roundabout, we skip it. - if(data1.middleName.nameID == data2.middleName.nameID) + if(data1.nameID == data2.nameID) return TurnInstructions.NoTurn; return TurnInstructions.GetTurnDirectionOfInstruction(angle); diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 5fa1007fa..05825faf1 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -37,21 +37,15 @@ class EdgeBasedGraphFactory { private: - union _MiddleName { - unsigned middle; - unsigned nameID; - }; - struct _NodeBasedEdgeData { int distance; unsigned edgeBasedNodeID; - unsigned originalEdges; - bool shortcut; - bool forward; - bool backward; - bool roundabout; + unsigned nameID; + bool shortcut:1; + bool forward:1; + bool backward:1; + bool roundabout:1; short type; - _MiddleName middleName; } data; struct _EdgeBasedEdgeData { @@ -83,16 +77,13 @@ public: unsigned weight; }; - typedef DynamicGraph< _EdgeBasedEdgeData> _EdgeBasedDynamicGraph; - typedef _EdgeBasedDynamicGraph::InputEdge _EdgeBasedEdge; private: boost::shared_ptr<_NodeBasedDynamicGraph> _nodeBasedGraph; - boost::shared_ptr<_EdgeBasedDynamicGraph> _edgeBasedGraph; std::vector<_Restriction> & inputRestrictions; std::vector & inputNodeInfoList; - std::vector<_EdgeBasedEdge> edgeBasedEdges; + std::vector edgeBasedEdges; std::vector edgeBasedNodes; template diff --git a/DataStructures/ImportEdge.h b/DataStructures/ImportEdge.h index 14ae31463..24e777826 100644 --- a/DataStructures/ImportEdge.h +++ b/DataStructures/ImportEdge.h @@ -92,24 +92,24 @@ public: _via(myEdge.data.via), _nameID1(myEdge.data.nameID), _weight(myEdge.data.distance), - forward(myEdge.data.forward), - backward(myEdge.data.backward), + _forward(myEdge.data.forward), + _backward(myEdge.data.backward), _turnInstruction(myEdge.data.turnInstruction) { } /** Default constructor. target and weight are set to 0.*/ EdgeBasedEdge() : - _source(0), _target(0), _via(0), _nameID1(0), _weight(0), forward(0), backward(0), _turnInstruction(0) { assert(false); } //shall not be used. + _source(0), _target(0), _via(0), _nameID1(0), _weight(0), _forward(0), _backward(0), _turnInstruction(0) { assert(false); } //shall not be used. - explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, unsigned n2, EdgeWeight w, bool f, bool b, short ty) : - _source(s), _target(t), _via(v), _nameID1(n1), _weight(w), forward(f), backward(b), _turnInstruction(ty) { assert(ty >= 0); } + explicit EdgeBasedEdge(NodeID s, NodeID t, NodeID v, unsigned n1, EdgeWeight w, bool f, bool b, short ty) : + _source(s), _target(t), _via(v), _nameID1(n1), _weight(w), _forward(f), _backward(b), _turnInstruction(ty) { assert(ty >= 0); } NodeID target() const {return _target; } NodeID source() const {return _source; } EdgeWeight weight() const {return _weight; } NodeID via() const { return _via; } short turnInstruction() const { assert(_turnInstruction >= 0); return _turnInstruction; } - bool isBackward() const { return backward; } - bool isForward() const { return forward; } + bool isBackward() const { return _backward; } + bool isForward() const { return _forward; } unsigned getNameIDOfTurnTarget() const { return _nameID1; } @@ -117,10 +117,9 @@ public: NodeID _target; NodeID _via; unsigned _nameID1; -// unsigned _nameID2; EdgeWeight _weight; - bool forward; - bool backward; + bool _forward; + bool _backward; short _turnInstruction; }; diff --git a/createHierarchy.cpp b/createHierarchy.cpp index f9287ee28..7b7e233ff 100644 --- a/createHierarchy.cpp +++ b/createHierarchy.cpp @@ -51,7 +51,6 @@ void omp_set_num_threads(int i) {} #include "Contractor/EdgeBasedGraphFactory.h" #include "DataStructures/BinaryHeap.h" #include "DataStructures/ExtractorStructs.h" -#include "DataStructures/LevelInformation.h" #include "DataStructures/NNGrid.h" #include "Util/BaseConfiguration.h" #include "Util/InputFileUtil.h" @@ -63,12 +62,12 @@ typedef DynamicGraph::InputEdge InputEdge; typedef StaticGraph::InputEdge StaticEdge; typedef BaseConfiguration ContractorConfiguration; -vector int2ExtNodeMap; -vector<_Restriction> inputRestrictions; +std::vector internalToExternaleNodeMapping; +std::vector<_Restriction> inputRestrictions; int main (int argc, char *argv[]) { if(argc < 3) { - cerr << "usage: " << endl << argv[0] << " " << endl; + cerr << "usage: " << std::endl << argv[0] << " " << std::endl; exit(-1); } INFO("Using restrictions from file: " << argv[2]); @@ -91,17 +90,17 @@ int main (int argc, char *argv[]) { } omp_set_num_threads(numberOfThreads); - cout << "preprocessing data from input file " << argv[1]; + std::cout << "preprocessing data from input file " << argv[1]; #ifdef _GLIBCXX_PARALLEL - cout << " using STL parallel mode" << std::endl; + std::cout << " using STL parallel mode" << std::endl; #else - cout << " using STL serial mode" << std::endl; + std::cout << " using STL serial mode" << std::endl; #endif ifstream in; in.open (argv[1], ifstream::in | ifstream::binary); if (!in.is_open()) { - cerr << "Cannot open " << argv[1] << endl; exit(-1); + cerr << "Cannot open " << argv[1] << std::endl; exit(-1); } char nodeOut[1024]; @@ -122,11 +121,14 @@ int main (int argc, char *argv[]) { strcat(fileIndexOut, ".fileIndex"); strcat(levelInfoOut, ".levels"); - vector edgeList; - NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &int2ExtNodeMap, inputRestrictions); + std::vector edgeList; + NodeID n = readBinaryOSRMGraphFromStream(in, edgeList, &internalToExternaleNodeMapping, inputRestrictions); in.close(); - EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, inputRestrictions, int2ExtNodeMap); + EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (n, edgeList, inputRestrictions, internalToExternaleNodeMapping); + edgeList.clear(); + std::vector().swap(edgeList); + edgeBasedGraphFactory->Run(); n = edgeBasedGraphFactory->GetNumberOfNodes(); std::vector edgeBasedEdgeList; @@ -134,52 +136,32 @@ int main (int argc, char *argv[]) { std::vector nodeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedNodes(nodeBasedEdgeList); - INFO("size of nodeBasedEdgeList: " << nodeBasedEdgeList.size()); DELETE(edgeBasedGraphFactory); WritableGrid * writeableGrid = new WritableGrid(); - cout << "building grid ..." << flush; - writeableGrid->ConstructGrid(nodeBasedEdgeList, &int2ExtNodeMap, ramIndexOut, fileIndexOut); - delete writeableGrid; + std::cout << "building grid ..." << std::flush; + writeableGrid->ConstructGrid(nodeBasedEdgeList, &internalToExternaleNodeMapping, ramIndexOut, fileIndexOut); + DELETE( writeableGrid ); std::cout << "writing node map ..." << std::flush; ofstream mapOutFile(nodeOut, ios::binary); - for(NodeID i = 0; i < int2ExtNodeMap.size(); i++) { - mapOutFile.write((char *)&(int2ExtNodeMap.at(i)), sizeof(NodeInfo)); + for(NodeID i = 0; i < internalToExternaleNodeMapping.size(); i++) { + mapOutFile.write((char *)&(internalToExternaleNodeMapping.at(i)), sizeof(NodeInfo)); } mapOutFile.close(); std::cout << "ok" << std::endl; - int2ExtNodeMap.clear(); + internalToExternaleNodeMapping.clear(); + std::vector().swap(internalToExternaleNodeMapping); + inputRestrictions.clear(); + std::vector<_Restriction>().swap(inputRestrictions); - cout << "initializing contractor ..." << flush; + std::cout << "initializing contractor ..." << std::flush; Contractor* contractor = new Contractor( n, edgeBasedEdgeList ); double contractionStartedTimestamp(get_timestamp()); contractor->Run(); INFO("Contraction took " << get_timestamp() - contractionStartedTimestamp << " sec"); - LevelInformation * levelInfo = contractor->GetLevelInformation(); - std::cout << "sorting level info" << std::endl; - for(unsigned currentLevel = levelInfo->GetNumberOfLevels(); currentLevel>0; currentLevel--) { - std::vector & level = levelInfo->GetLevel(currentLevel-1); - std::sort(level.begin(), level.end()); - } - - std::cout << "writing level info" << std::endl; - ofstream levelOutFile(levelInfoOut, ios::binary); - unsigned numberOfLevels = levelInfo->GetNumberOfLevels(); - levelOutFile.write((char *)&numberOfLevels, sizeof(unsigned)); - for(unsigned currentLevel = 0; currentLevel < levelInfo->GetNumberOfLevels(); currentLevel++ ) { - std::vector & level = levelInfo->GetLevel(currentLevel); - unsigned sizeOfLevel = level.size(); - levelOutFile.write((char *)&sizeOfLevel, sizeof(unsigned)); - for(unsigned currentLevelEntry = 0; currentLevelEntry < sizeOfLevel; currentLevelEntry++) { - unsigned node = level[currentLevelEntry]; - levelOutFile.write((char *)&node, sizeof(unsigned)); - assert(node < n); - } - } - levelOutFile.close(); std::vector< ContractionCleanup::Edge > contractedEdges; contractor->GetEdges( contractedEdges ); @@ -189,9 +171,9 @@ int main (int argc, char *argv[]) { std::vector< InputEdge> cleanedEdgeList; cleanup->GetData(cleanedEdgeList); - delete cleanup; + DELETE( cleanup ); - cout << "Serializing edges " << flush; + std::cout << "Serializing edges " << std::flush; ofstream edgeOutFile(edgeOut, ios::binary); Percent p(cleanedEdgeList.size()); for(std::vector< InputEdge>::iterator it = cleanedEdgeList.begin(); it != cleanedEdgeList.end(); it++) { @@ -203,6 +185,6 @@ int main (int argc, char *argv[]) { edgeOutFile.close(); cleanedEdgeList.clear(); - cout << "finished" << endl; + std::cout << "finished" << std::endl; return 0; }