diff --git a/Algorithms/PolylineCompressor.h b/Algorithms/PolylineCompressor.h index a05c4a3d1..836fdb868 100644 --- a/Algorithms/PolylineCompressor.h +++ b/Algorithms/PolylineCompressor.h @@ -29,7 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt. class PolylineCompressor { private: - inline void encodeVectorSignedNumber(vector & numbers, string & output) { + inline void encodeVectorSignedNumber(std::vector & numbers, std::string & output) { for(unsigned i = 0; i < numbers.size(); ++i) { numbers[i] <<= 1; if (numbers[i] < 0) { @@ -41,7 +41,7 @@ private: } } - inline void encodeNumber(int numberToEncode, string & output) { + inline void encodeNumber(int numberToEncode, std::string & output) { while (numberToEncode >= 0x20) { int nextValue = (0x20 | (numberToEncode & 0x1f)) + 63; output += (static_cast (nextValue)); @@ -57,8 +57,8 @@ private: } public: - inline void printEncodedString(const vector& polyline, string &output) { - vector deltaNumbers; + inline void printEncodedString(const std::vector& polyline, std::string &output) { + std::vector deltaNumbers; output += "\""; if(!polyline.empty()) { _Coordinate lastCoordinate = polyline[0].location; @@ -77,8 +77,8 @@ public: } - inline void printEncodedString(const vector<_Coordinate>& polyline, string &output) { - vector deltaNumbers(2*polyline.size()); + inline void printEncodedString(const std::vector<_Coordinate>& polyline, std::string &output) { + std::vector deltaNumbers(2*polyline.size()); output += "\""; if(!polyline.empty()) { deltaNumbers[0] = polyline[0].lat; @@ -92,9 +92,9 @@ public: output += "\""; } - inline void printUnencodedString(vector<_Coordinate> & polyline, string & output) { + inline void printUnencodedString(std::vector<_Coordinate> & polyline, std::string & output) { output += "["; - string tmp; + std::string tmp; for(unsigned i = 0; i < polyline.size(); i++) { convertInternalLatLonToString(polyline[i].lat, tmp); output += "["; @@ -110,9 +110,9 @@ public: output += "]"; } - inline void printUnencodedString(vector & polyline, string & output) { + inline void printUnencodedString(std::vector & polyline, std::string & output) { output += "["; - string tmp; + std::string tmp; for(unsigned i = 0; i < polyline.size(); i++) { if(!polyline[i].necessary) continue; diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h index 4786e58ca..c1f08b081 100644 --- a/Contractor/ContractionCleanup.h +++ b/Contractor/ContractionCleanup.h @@ -21,11 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef CONTRACTIONCLEANUP_H_INCLUDED #define CONTRACTIONCLEANUP_H_INCLUDED -#ifdef _GLIBCXX_PARALLEL -#include -#else #include -#endif #ifndef _WIN32 #include #endif @@ -120,11 +116,7 @@ public: edges.push_back( newEdge ); } } -#ifdef _GLIBCXX_PARALLEL - __gnu_parallel::sort( edges.begin(), edges.end() ); -#else sort( edges.begin(), edges.end() ); -#endif } private: diff --git a/Contractor/Contractor.h b/Contractor/Contractor.h index 63bfa58c7..e63cd48aa 100644 --- a/Contractor/Contractor.h +++ b/Contractor/Contractor.h @@ -119,8 +119,9 @@ public: edge.data.backward = currentEdge.isForward(); edges.push_back( edge ); } - //remove data from memory + //clear input vector and trim the current set of edges with the well-known swap trick std::vector< InputEdge >().swap( inputEdges ); + sort( edges.begin(), edges.end() ); NodeID edge = 0; for ( NodeID i = 0; i < edges.size(); ) { @@ -168,8 +169,10 @@ public: } } } - std::cout << "ok" << std::endl << "merged " << edges.size() - edge << " edges out of " << edges.size() << std::endl; + std::cout << "ok" << "merged " << edges.size() - edge << " edges out of " << edges.size() << std::endl; edges.resize( edge ); + std::vector<_ImportEdge>(edges).swap(edges); + _graph.reset( new _DynamicGraph( nodes, edges ) ); std::vector< _ImportEdge >().swap( edges ); // unsigned maxdegree = 0; @@ -188,10 +191,10 @@ public: // INFO(" ->(" << highestNode << "," << _graph->GetTarget(i) << "); via: " << _graph->GetEdgeData(i).via); // } - //Create temporary file GetTemporaryFileName(temporaryEdgeStorageFilename); + std::cout << "contractor finished initalization" << std::endl; } ~Contractor() { diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index a2d69e245..bfa09d84d 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -260,8 +260,12 @@ void EdgeBasedGraphFactory::Run() { } p.printIncrement(); } + INFO("Sorting edge-based Nodes"); std::sort(edgeBasedNodes.begin(), edgeBasedNodes.end()); + INFO("Removing duplicate nodes (if any)"); edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() ); + INFO("Applying vector self-swap trick to free up memory"); + edgeBasedNodes.swap(edgeBasedNodes); INFO("Node-based graph contains " << nodeBasedEdgeCounter << " edges"); INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << (double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter); INFO("Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << numberOfTurnRestrictions << " restrictions."); diff --git a/DataStructures/DynamicGraph.h b/DataStructures/DynamicGraph.h index 404c6028c..1ee24b134 100644 --- a/DataStructures/DynamicGraph.h +++ b/DataStructures/DynamicGraph.h @@ -49,7 +49,7 @@ class DynamicGraph { m_nodes.reserve( m_numNodes ); m_nodes.resize( m_numNodes ); - m_edges.reserve( m_numNodes * 1.2 ); + m_edges.reserve( m_numNodes * 1.1 ); m_edges.resize( m_numNodes ); } DynamicGraph( int nodes, const std::vector< InputEdge > &graph ) @@ -69,7 +69,7 @@ class DynamicGraph { m_nodes[node].edges = edge - lastEdge; position += m_nodes[node].edges; } - m_edges.reserve( position * 1.2 ); + m_edges.reserve( position * 1.1 ); m_edges.resize( position ); edge = 0; for ( NodeIterator node = 0; node < m_numNodes; ++node ) { @@ -136,7 +136,7 @@ class DynamicGraph { m_edges[node.firstEdge] = m_edges[node.firstEdge + node.edges]; } else { EdgeIterator newFirstEdge = ( EdgeIterator ) m_edges.size(); - unsigned newSize = node.edges * 1.2 + 2; + unsigned newSize = node.edges * 1.1 + 2; EdgeIterator requiredCapacity = newSize + m_edges.size(); EdgeIterator oldCapacity = m_edges.capacity(); if ( requiredCapacity >= oldCapacity ) { diff --git a/DataStructures/ExtractorStructs.h b/DataStructures/ExtractorStructs.h index ad0b1f411..dc4488be0 100644 --- a/DataStructures/ExtractorStructs.h +++ b/DataStructures/ExtractorStructs.h @@ -46,7 +46,7 @@ struct _Node : NodeInfo{ return _Node(0,0,0, false, false); } static _Node max_value() { - return _Node((numeric_limits::max)(), (numeric_limits::max)(), (numeric_limits::max)(), false, false); + return _Node((std::numeric_limits::max)(), (std::numeric_limits::max)(), (std::numeric_limits::max)(), false, false); } NodeID key() const { return id; diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index 3054c176f..a7bdca071 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -100,6 +100,7 @@ public: template void ConstructGrid(std::vector & edgeList, char * ramIndexOut, char * fileIndexOut) { + //TODO: Implement this using STXXL-Streams #ifndef ROUTED Percent p(edgeList.size()); BOOST_FOREACH(EdgeT & edge, edgeList) { @@ -240,7 +241,7 @@ public: } } _Coordinate tmp; - double dist = (numeric_limits::max)(); + double dist = (std::numeric_limits::max)(); BOOST_FOREACH(_GridEdge candidate, candidates) { double r = 0.; double tmpDist = ComputeDistance(inputCoordinate, candidate.startCoord, candidate.targetCoord, tmp, &r); @@ -264,7 +265,7 @@ public: } } _Coordinate tmp; - double dist = (numeric_limits::max)(); + double dist = (std::numeric_limits::max)(); BOOST_FOREACH(_GridEdge candidate, candidates) { double r = 0.; double tmpDist = ComputeDistance(startCoord, candidate.startCoord, candidate.targetCoord, tmp, &r); @@ -298,13 +299,13 @@ private: return (std::fabs(d1 - d2) < 0.0001); } - unsigned FillCell(std::vector& entriesWithSameRAMIndex, unsigned long fileOffset ) { - vector tmpBuffer(32*32*4096,0); + unsigned FillCell(std::vector& entriesWithSameRAMIndex, const unsigned long fileOffset ) { + std::vector tmpBuffer(32*32*4096,0); unsigned long indexIntoTmpBuffer = 0; unsigned numberOfWrittenBytes = 0; assert(indexOutFile.is_open()); - vector cellIndex(32*32,ULONG_MAX); + std::vector cellIndex(32*32,ULONG_MAX); boost::unordered_map< unsigned, unsigned, IdenticalHashFunction > cellMap(1024); unsigned ramIndex = entriesWithSameRAMIndex.begin()->ramIndex; @@ -354,7 +355,7 @@ private: return numberOfWrittenBytes; } - unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector &vectorWithSameFileIndex, vector & tmpBuffer, const unsigned long index) { + unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector &vectorWithSameFileIndex, std::vector & tmpBuffer, const unsigned long index) { tmpBuffer.resize(tmpBuffer.size()+(sizeof(_GridEdge)*vectorWithSameFileIndex.size()) + sizeof(unsigned) ); unsigned counter = 0; @@ -373,7 +374,7 @@ private: ++counter; } - BOOST_FOREACH(GridEntry entry, vectorWithSameFileIndex) { + BOOST_FOREACH(const GridEntry & entry, vectorWithSameFileIndex) { char * data = (char *)&(entry.edge); for(unsigned i = 0; i < sizeof(_GridEdge); ++i) { tmpBuffer[index+counter] = data[i]; @@ -419,7 +420,7 @@ private: localStream->read((char *)&result[currentSizeOfResult], lengthOfBucket*sizeof(_GridEdge)); } - void AddEdge(_GridEdge edge) { + void AddEdge(const _GridEdge & edge) { #ifndef ROUTED std::vector indexList; GetListOfIndexesForEdgeAndGridSize(edge.startCoord, edge.targetCoord, indexList); @@ -468,7 +469,7 @@ private: return (p-x)*(p-x) + (q-y)*(q-y); } - void GetListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate& target, std::vector &indexList) { + void GetListOfIndexesForEdgeAndGridSize(const _Coordinate& start, const _Coordinate& target, std::vector &indexList) { double lat1 = start.lat/100000.; double lon1 = start.lon/100000.; @@ -523,8 +524,8 @@ private: const static unsigned long END_OF_BUCKET_DELIMITER = UINT_MAX; - ofstream indexOutFile; - ifstream ramInFile; + std::ofstream indexOutFile; + std::ifstream ramInFile; #ifndef ROUTED stxxl::vector entries; #endif diff --git a/DataStructures/NodeCoords.h b/DataStructures/NodeCoords.h index f36699fcc..7f1d964b3 100644 --- a/DataStructures/NodeCoords.h +++ b/DataStructures/NodeCoords.h @@ -39,13 +39,13 @@ struct NodeCoords { NodeT id; static NodeCoords min_value() { - return NodeCoords(-90*100000,-180*100000,numeric_limits::min()); + return NodeCoords(-90*100000,-180*100000,std::numeric_limits::min()); } static NodeCoords max_value() { - return NodeCoords(90*100000, 180*100000, numeric_limits::max()); + return NodeCoords(90*100000, 180*100000, std::numeric_limits::max()); } - value_type operator[](size_t n) const { + value_type operator[](std::size_t n) const { switch(n) { case 1: return lat; diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index 5d8fbdc25..51eb2bad2 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -33,25 +33,26 @@ class NodeInformationHelpDesk{ public: NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned _numberOfNodes, const unsigned crc) : numberOfNodes(_numberOfNodes), checkSum(crc) { readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); - coordinateVector.reserve(numberOfNodes); assert(0 == coordinateVector.size()); } //Todo: Shared memory mechanism - NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) { - readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); - } +// NodeInformationHelpDesk(const char* ramIndexInput, const char* fileIndexInput, const unsigned crc) : checkSum(crc) { +// readOnlyGrid = new ReadOnlyGrid(ramIndexInput,fileIndexInput); +// } ~NodeInformationHelpDesk() { delete readOnlyGrid; } - void initNNGrid(ifstream& in) { + void initNNGrid(std::ifstream& in) { + NodeInfo b; while(!in.eof()) { - NodeInfo b; - in.read((char *)&b, sizeof(b)); + in.read((char *)&b, sizeof(NodeInfo)); coordinateVector.push_back(_Coordinate(b.lat, b.lon)); } - in.close(); + std::vector<_Coordinate>(coordinateVector).swap(coordinateVector); + numberOfNodes = coordinateVector.size(); + in.close(); readOnlyGrid->OpenIndexFiles(); } diff --git a/DataStructures/SearchEngine.h b/DataStructures/SearchEngine.h index a73a98e77..719f01457 100644 --- a/DataStructures/SearchEngine.h +++ b/DataStructures/SearchEngine.h @@ -44,14 +44,14 @@ class SearchEngine { private: const GraphT * _graph; NodeInformationHelpDesk * nodeHelpDesk; - std::vector * _names; + std::vector & _names; static HeapPtr _forwardHeap; static HeapPtr _backwardHeap; static HeapPtr _forwardHeap2; static HeapPtr _backwardHeap2; inline double absDouble(double input) { if(input < 0) return input*(-1); else return input;} public: - SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector * n = new std::vector()) : _graph(g), nodeHelpDesk(nh), _names(n) {} + SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector & n) : _graph(g), nodeHelpDesk(nh), _names(n) {} ~SearchEngine() {} inline const void GetCoordinatesForNodeID(NodeID id, _Coordinate& result) const { @@ -377,7 +377,7 @@ public: } inline std::string GetEscapedNameForNameID(const NodeID nameID) const { - return ((nameID >= _names->size() || nameID == 0) ? std::string("") : HTMLEntitize(_names->at(nameID))); + return ((nameID >= _names.size() || nameID == 0) ? std::string("") : HTMLEntitize(_names.at(nameID))); } inline std::string GetEscapedNameForEdgeBasedEdgeID(const unsigned edgeID) const { diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 7e278f42f..c817495a2 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -22,11 +22,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #define STATICGRAPH_H_INCLUDED #include -#ifdef _GLIBCXX_PARALLEL -#include -#else #include -#endif #include "../typedefs.h" #include "ImportEdge.h" diff --git a/DataStructures/StaticKDTree.h b/DataStructures/StaticKDTree.h index bfc5e24b0..87f2dcf49 100644 --- a/DataStructures/StaticKDTree.h +++ b/DataStructures/StaticKDTree.h @@ -24,11 +24,7 @@ KD Tree coded by Christian Vetter, Monav Project #define STATICKDTREE_H_INCLUDED #include -#ifdef _GLIBCXX_PARALLEL -#include -#else #include -#endif #include #include @@ -119,11 +115,7 @@ public: continue; Iterator middle = tree.left + ( tree.right - tree.left ) / 2; -#ifdef _GLIBCXX_PARALLEL - __gnu_parallel::nth_element( kdtree + tree.left, kdtree + middle, kdtree + tree.right, Less( tree.dimension ) ); -#else std::nth_element( kdtree + tree.left, kdtree + middle, kdtree + tree.right, Less( tree.dimension ) ); -#endif s.push( Tree( tree.left, middle, ( tree.dimension + 1 ) % k ) ); s.push( Tree( middle + 1, tree.right, ( tree.dimension + 1 ) % k ) ); } diff --git a/Plugins/LocatePlugin.h b/Plugins/LocatePlugin.h index 47dc29d54..dbf2dbf0e 100644 --- a/Plugins/LocatePlugin.h +++ b/Plugins/LocatePlugin.h @@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#include "ObjectForPluginStruct.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" #include "BasePlugin.h" #include "RouteParameters.h" #include "../Util/StringUtil.h" @@ -34,7 +34,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ class LocatePlugin : public BasePlugin { public: - LocatePlugin(ObjectsForQueryStruct * objects) { + LocatePlugin(QueryObjectsStorage * objects) { nodeHelpDesk = objects->nodeHelpDesk; } std::string GetDescriptor() const { return std::string("locate"); } diff --git a/Plugins/NearestPlugin.h b/Plugins/NearestPlugin.h index 21fb935b9..8f50dbed2 100644 --- a/Plugins/NearestPlugin.h +++ b/Plugins/NearestPlugin.h @@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "BasePlugin.h" #include "RouteParameters.h" -#include "ObjectForPluginStruct.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" #include "../DataStructures/NodeInformationHelpDesk.h" #include "../DataStructures/HashTable.h" @@ -37,7 +37,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ class NearestPlugin : public BasePlugin { public: - NearestPlugin(ObjectsForQueryStruct * objects) { + NearestPlugin(QueryObjectsStorage * objects) { nodeHelpDesk = objects->nodeHelpDesk; descriptorTable.Set("", 0); //default descriptor descriptorTable.Set("kml", 0); diff --git a/Plugins/ObjectForPluginStruct.h b/Plugins/ObjectForPluginStruct.h deleted file mode 100644 index c8610cce2..000000000 --- a/Plugins/ObjectForPluginStruct.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - open source routing machine - Copyright (C) Dennis Luxen, others 2010 - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU AFFERO General Public License as published by -the Free Software Foundation; either version 3 of the License, or -any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU Affero General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -or see http://www.gnu.org/licenses/agpl.txt. - */ - - -#ifndef OBJECTSFORQUERYSTRUCT_H_ -#define OBJECTSFORQUERYSTRUCT_H_ - -#include -#include - -#include "../DataStructures/StaticGraph.h" -#include "../Util/GraphLoader.h" - - -struct ObjectsForQueryStruct { - typedef StaticGraph QueryGraph; - typedef QueryGraph::InputEdge InputEdge; - - NodeInformationHelpDesk * nodeHelpDesk; - std::vector * names; - QueryGraph * graph; - unsigned checkSum; - - ObjectsForQueryStruct(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route") { - INFO("loading graph data"); - std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary); - //Deserialize road network graph - std::vector< QueryGraph::_StrNode> nodeList; - std::vector< QueryGraph::_StrEdge> edgeList; - const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList, &checkSum); - INFO("Data checksum is " << checkSum); - graph = new QueryGraph(nodeList, edgeList); - assert(0 == nodeList.size()); - assert(0 == edgeList.size()); - INFO("Loading nearest neighbor indices"); - //Init nearest neighbor data structure - std::ifstream nodesInStream(nodesPath.c_str(), ios::binary); - nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum); - nodeHelpDesk->initNNGrid(nodesInStream); - - //deserialize street name list - INFO("Loading names index"); - std::ifstream namesInStream(namesPath.c_str(), ios::binary); - unsigned size(0); - namesInStream.read((char *)&size, sizeof(unsigned)); - names = new std::vector(); - - char buf[1024]; - for(unsigned i = 0; i < size; ++i) { - unsigned sizeOfString = 0; - namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); - memset(buf, 0, 1024*sizeof(char)); - namesInStream.read(buf, sizeOfString); - std::string currentStreetName(buf); - names->push_back(currentStreetName); - } - hsgrInStream.close(); - namesInStream.close(); - INFO("All query data structures loaded"); - } - - ~ObjectsForQueryStruct() { - delete names; - delete graph; - delete nodeHelpDesk; - } -}; - -#endif /* OBJECTSFORQUERYSTRUCT_H_ */ diff --git a/Plugins/ViaRoutePlugin.h b/Plugins/ViaRoutePlugin.h index 317ee2593..d9b8d93e7 100644 --- a/Plugins/ViaRoutePlugin.h +++ b/Plugins/ViaRoutePlugin.h @@ -27,8 +27,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include -#include "ObjectForPluginStruct.h" - #include "BasePlugin.h" #include "RouteParameters.h" @@ -44,20 +42,21 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../Util/StringUtil.h" +#include "../Server/DataStructures/QueryObjectsStorage.h" + class ViaRoutePlugin : public BasePlugin { private: NodeInformationHelpDesk * nodeHelpDesk; - std::vector * names; + std::vector & names; StaticGraph * graph; HashTable descriptorTable; std::string pluginDescriptorString; SearchEngine > * searchEngine; public: - ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : pluginDescriptorString(psd) { + ViaRoutePlugin(QueryObjectsStorage * objects, std::string psd = "viaroute") : names(objects->names), pluginDescriptorString(psd) { nodeHelpDesk = objects->nodeHelpDesk; graph = objects->graph; - names = objects->names; searchEngine = new SearchEngine >(graph, nodeHelpDesk, names); diff --git a/SConstruct b/SConstruct index 8a5aec097..e9326cb47 100644 --- a/SConstruct +++ b/SConstruct @@ -258,6 +258,6 @@ if sys.platform != 'darwin': env.Program(target = 'osrm-extract', source = ["extractor.cpp", Glob('DataStructures/pbf-proto/*.pb.cc'), Glob('Util/*.cpp')], depends=['osm1', 'osm2']) env.Program(target = 'osrm-prepare', source = ["createHierarchy.cpp", 'Contractor/EdgeBasedGraphFactory.cpp', Glob('Util/SRTMLookup/*.cpp'), Glob('Algorithms/*.cpp')]) -env.Program(target = 'osrm-routed', source = ["routed.cpp", 'Descriptors/DescriptionFactory.cpp', Glob('ThirdParty/*.cc')], CCFLAGS = env['CCFLAGS'] + ['-DROUTED']) +env.Program(target = 'osrm-routed', source = ["routed.cpp", 'Descriptors/DescriptionFactory.cpp', Glob('ThirdParty/*.cc'), Glob('Server/DataStructures/*.cpp')], CCFLAGS = env['CCFLAGS'] + ['-DROUTED']) env = conf.Finish() diff --git a/Server/DataStructures/QueryObjectsStorage.cpp b/Server/DataStructures/QueryObjectsStorage.cpp new file mode 100644 index 000000000..7938c697f --- /dev/null +++ b/Server/DataStructures/QueryObjectsStorage.cpp @@ -0,0 +1,68 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + + +#include "QueryObjectsStorage.h" +#include "../../Util/GraphLoader.h" + +QueryObjectsStorage::QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd) { + INFO("loading graph data"); + std::ifstream hsgrInStream(hsgrPath.c_str(), ios::binary); + //Deserialize road network graph + std::vector< QueryGraph::_StrNode> nodeList; + std::vector< QueryGraph::_StrEdge> edgeList; + const int n = readHSGRFromStream(hsgrInStream, nodeList, edgeList, &checkSum); + + INFO("Data checksum is " << checkSum); + graph = new QueryGraph(nodeList, edgeList); + assert(0 == nodeList.size()); + assert(0 == edgeList.size()); + INFO("Loading nearest neighbor indices"); + //Init nearest neighbor data structure + std::ifstream nodesInStream(nodesPath.c_str(), ios::binary); + nodeHelpDesk = new NodeInformationHelpDesk(ramIndexPath.c_str(), fileIndexPath.c_str(), n, checkSum); + nodeHelpDesk->initNNGrid(nodesInStream); + + //deserialize street name list + INFO("Loading names index"); + std::ifstream namesInStream(namesPath.c_str(), ios::binary); + unsigned size(0); + namesInStream.read((char *)&size, sizeof(unsigned)); + // names = new std::vector(); + + char buf[1024]; + for(unsigned i = 0; i < size; ++i) { + unsigned sizeOfString = 0; + namesInStream.read((char *)&sizeOfString, sizeof(unsigned)); + buf[sizeOfString] = '\0'; // instead of memset + namesInStream.read(buf, sizeOfString); + names.push_back(buf); + } + std::vector(names).swap(names); + hsgrInStream.close(); + namesInStream.close(); + INFO("All query data structures loaded"); +} + +QueryObjectsStorage::~QueryObjectsStorage() { + // delete names; + delete graph; + delete nodeHelpDesk; +} diff --git a/Server/DataStructures/QueryObjectsStorage.h b/Server/DataStructures/QueryObjectsStorage.h new file mode 100644 index 000000000..72695bd86 --- /dev/null +++ b/Server/DataStructures/QueryObjectsStorage.h @@ -0,0 +1,44 @@ +/* + open source routing machine + Copyright (C) Dennis Luxen, others 2010 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU AFFERO General Public License as published by +the Free Software Foundation; either version 3 of the License, or +any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +or see http://www.gnu.org/licenses/agpl.txt. + */ + + +#ifndef QUERYOBJECTSSTORAGE_H_ +#define QUERYOBJECTSSTORAGE_H_ + +#include +#include + +#include "../../DataStructures/StaticGraph.h" + +struct QueryObjectsStorage { + typedef StaticGraph QueryGraph; + typedef QueryGraph::InputEdge InputEdge; + + NodeInformationHelpDesk * nodeHelpDesk; + std::vector names; + QueryGraph * graph; + unsigned checkSum; + + QueryObjectsStorage(std::string hsgrPath, std::string ramIndexPath, std::string fileIndexPath, std::string nodesPath, std::string namesPath, std::string psd = "route"); + + ~QueryObjectsStorage(); +}; + +#endif /* QUERYOBJECTSSTORAGE_H_ */ diff --git a/Util/GraphLoader.h b/Util/GraphLoader.h index 2b81206f8..74cb0975d 100644 --- a/Util/GraphLoader.h +++ b/Util/GraphLoader.h @@ -23,6 +23,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include + +#include #include #include #include @@ -30,12 +32,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include -#ifdef _GLIBCXX_PARALLEL -#include -#else -#include -#endif - #include "../DataStructures/ImportEdge.h" #include "../typedefs.h" @@ -60,7 +56,7 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector& edgeL for (NodeID i=0; ipush_back(NodeInfo(node.lat, node.lon, node.id)); - ext2IntNodeMap.insert(make_pair(node.id, i)); + ext2IntNodeMap.insert(std::make_pair(node.id, i)); if(node.bollard) bollardNodes.push_back(i); if(node.trafficLight) @@ -166,7 +162,7 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector& edgeL return n; } template -NodeID readDTMPGraphFromStream(istream &in, vector& edgeList, vector * int2ExtNodeMap) { +NodeID readDTMPGraphFromStream(std::istream &in, std::vector& edgeList, std::vector * int2ExtNodeMap) { NodeID n, source, target, id; EdgeID m; int dir, xcoord, ycoord;// direction (0 = open, 1 = forward, 2+ = open) @@ -176,7 +172,7 @@ NodeID readDTMPGraphFromStream(istream &in, vector& edgeList, vector> id >> ycoord >> xcoord; int2ExtNodeMap->push_back(NodeInfo(xcoord, ycoord, id)); - ext2IntNodeMap.insert(make_pair(id, i)); + ext2IntNodeMap.insert(std::make_pair(id, i)); } in >> m; DEBUG(" and " << m << " edges"); @@ -273,13 +269,13 @@ NodeID readDTMPGraphFromStream(istream &in, vector& edgeList, vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. - cout << "ok" << endl; + std::vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. + std::cout << "ok" << std::endl; return n; } template -NodeID readDDSGGraphFromStream(istream &in, vector& edgeList, vector & int2ExtNodeMap) { +NodeID readDDSGGraphFromStream(std::istream &in, std::vector& edgeList, std::vector & int2ExtNodeMap) { ExternalNodeMap nodeMap; NodeID n, source, target; unsigned numberOfNodes = 0; @@ -323,32 +319,24 @@ NodeID readDDSGGraphFromStream(istream &in, vector& edgeList, vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. + std::vector(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates. nodeMap.clear(); return numberOfNodes; } template -unsigned readHSGRFromStream(istream &in, vector& nodeList, vector & edgeList, unsigned * checkSum) { +unsigned readHSGRFromStream(std::istream &in, std::vector& nodeList, std::vector & edgeList, unsigned * checkSum) { unsigned numberOfNodes = 0; in.read((char*) checkSum, sizeof(unsigned)); in.read((char*) & numberOfNodes, sizeof(unsigned)); nodeList.resize(numberOfNodes + 1); - NodeT currentNode; - for(unsigned nodeCounter = 0; nodeCounter < numberOfNodes; ++nodeCounter ) { - in.read((char*) ¤tNode, sizeof(NodeT)); - nodeList[nodeCounter] = currentNode; - } + in.read((char*) &(nodeList[0]), numberOfNodes*sizeof(NodeT)); unsigned numberOfEdges = 0; in.read((char*) &numberOfEdges, sizeof(unsigned)); edgeList.resize(numberOfEdges); - EdgeT currentEdge; - for(unsigned edgeCounter = 0; edgeCounter < numberOfEdges; ++edgeCounter) { - in.read((char*) ¤tEdge, sizeof(EdgeT)); - edgeList[edgeCounter] = currentEdge; - } + in.read((char*) &(edgeList[0]), numberOfEdges*sizeof(EdgeT)); return numberOfNodes; } diff --git a/Util/NASAGridSquare.cpp b/Util/NASAGridSquare.cpp index 49a5169e2..112ed0b70 100644 --- a/Util/NASAGridSquare.cpp +++ b/Util/NASAGridSquare.cpp @@ -29,13 +29,13 @@ std::string NasaGridSquare::make_filename(const char* ext) const { char EW =(longitude>=0 ? 'E' : 'W' ); char NS =(latitude >=0 ? 'N' : 'S'); std::stringstream ss; - ss<::InputEdge InputEdge; typedef StaticGraph::InputEdge StaticEdge; typedef BaseConfiguration ContractorConfiguration; -std::vector internalToExternaleNodeMapping; +std::vector internalToExternalNodeMapping; std::vector<_Restriction> inputRestrictions; std::vector bollardNodes; std::vector trafficLightNodes; @@ -111,7 +111,7 @@ int main (int argc, char *argv[]) { char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels"); std::vector edgeList; - NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternaleNodeMapping, inputRestrictions); + NodeID nodeBasedNodeNumber = readBinaryOSRMGraphFromStream(in, edgeList, bollardNodes, trafficLightNodes, &internalToExternalNodeMapping, inputRestrictions); in.close(); INFO("Loaded " << inputRestrictions.size() << " restrictions, " << bollardNodes.size() << " bollard nodes, " << trafficLightNodes.size() << " traffic lights"); @@ -120,11 +120,11 @@ int main (int argc, char *argv[]) { } boost::property_tree::ptree speedProfile; boost::property_tree::ini_parser::read_ini("speedprofile.ini", speedProfile); - EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternaleNodeMapping, speedProfile, SRTM_ROOT); - edgeList.clear(); + EdgeBasedGraphFactory * edgeBasedGraphFactory = new EdgeBasedGraphFactory (nodeBasedNodeNumber, edgeList, bollardNodes, trafficLightNodes, inputRestrictions, internalToExternalNodeMapping, speedProfile, SRTM_ROOT); std::vector().swap(edgeList); edgeBasedGraphFactory->Run(); + std::vector<_Restriction>().swap(inputRestrictions); NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes(); std::vector edgeBasedEdgeList; edgeBasedGraphFactory->GetEdgeBasedEdges(edgeBasedEdgeList); @@ -140,23 +140,15 @@ int main (int argc, char *argv[]) { delete writeableGrid; CRC32 crc32; unsigned crc32OfNodeBasedEdgeList = crc32((char *)&(nodeBasedEdgeList[0]), nodeBasedEdgeList.size()*sizeof(EdgeBasedGraphFactory::EdgeBasedNode)); -// INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList); - nodeBasedEdgeList.clear(); std::vector().swap(nodeBasedEdgeList); INFO("writing node map ..."); std::ofstream mapOutFile(nodeOut, ios::binary); - mapOutFile.write((char *)&(internalToExternaleNodeMapping[0]), internalToExternaleNodeMapping.size()*sizeof(NodeInfo)); + mapOutFile.write((char *)&(internalToExternalNodeMapping[0]), internalToExternalNodeMapping.size()*sizeof(NodeInfo)); mapOutFile.close(); - - std::vector().swap(internalToExternaleNodeMapping); - inputRestrictions.clear(); - std::vector<_Restriction>().swap(inputRestrictions); - -// unsigned crc32OfNodeBasedEdgeList = crc32((char*)&edgeBasedEdgeList[0], edgeBasedEdgeList.size()); -// INFO("CRC32 of data is " << crc32OfNodeBasedEdgeList); + std::vector().swap(internalToExternalNodeMapping); INFO("initializing contractor"); Contractor* contractor = new Contractor( edgeBasedNodeNumber, edgeBasedEdgeList ); @@ -168,15 +160,6 @@ int main (int argc, char *argv[]) { contractor->GetEdges( contractedEdgeList ); delete contractor; -// ContractionCleanup * cleanup = new ContractionCleanup(edgeBasedNodeNumber, contractedEdges); -// contractedEdges.clear(); -// std::vector().swap(contractedEdges); -// cleanup->Run(); -// -// std::vector< InputEdge> cleanedEdgeList; -// cleanup->GetData(cleanedEdgeList); -// delete cleanup; - INFO("Building Node Array"); sort(contractedEdgeList.begin(), contractedEdgeList.end()); unsigned numberOfNodes = 0; diff --git a/routed.cpp b/routed.cpp index ee3138ba3..b970905e2 100644 --- a/routed.cpp +++ b/routed.cpp @@ -24,14 +24,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include +#include "Server/DataStructures/QueryObjectsStorage.h" #include "Server/ServerConfiguration.h" #include "Server/ServerFactory.h" #include "Plugins/HelloWorldPlugin.h" #include "Plugins/LocatePlugin.h" #include "Plugins/NearestPlugin.h" -#include "Plugins/ObjectForPluginStruct.h" #include "Plugins/ViaRoutePlugin.h" + #include "Util/InputFileUtil.h" #include "Util/OpenMPReplacement.h" @@ -39,8 +40,6 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "Util/LinuxStackTrace.h" #endif -using namespace std; - typedef http::RequestHandler RequestHandler; #ifdef _WIN32 @@ -89,7 +88,7 @@ int main (int argc, char *argv[]) { Server * s = ServerFactory::CreateServer(serverConfig); RequestHandler & h = s->GetRequestHandlerPtr(); - ObjectsForQueryStruct * objects = new ObjectsForQueryStruct(serverConfig.GetParameter("hsgrData"), + QueryObjectsStorage * objects = new QueryObjectsStorage(serverConfig.GetParameter("hsgrData"), serverConfig.GetParameter("ramIndex"), serverConfig.GetParameter("fileIndex"), serverConfig.GetParameter("nodesData"),