This commit is contained in:
DennisOSRM 2012-04-16 17:42:49 +02:00
commit c4dc85f607
23 changed files with 196 additions and 212 deletions

View File

@ -29,7 +29,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
class PolylineCompressor {
private:
inline void encodeVectorSignedNumber(vector<int> & numbers, string & output) {
inline void encodeVectorSignedNumber(std::vector<int> & 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<char> (nextValue));
@ -57,8 +57,8 @@ private:
}
public:
inline void printEncodedString(const vector<SegmentInformation>& polyline, string &output) {
vector<int> deltaNumbers;
inline void printEncodedString(const std::vector<SegmentInformation>& polyline, std::string &output) {
std::vector<int> 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<int> deltaNumbers(2*polyline.size());
inline void printEncodedString(const std::vector<_Coordinate>& polyline, std::string &output) {
std::vector<int> 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<SegmentInformation> & polyline, string & output) {
inline void printUnencodedString(std::vector<SegmentInformation> & polyline, std::string & output) {
output += "[";
string tmp;
std::string tmp;
for(unsigned i = 0; i < polyline.size(); i++) {
if(!polyline[i].necessary)
continue;

View File

@ -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 <parallel/algorithm>
#else
#include <algorithm>
#endif
#ifndef _WIN32
#include <sys/time.h>
#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:

View File

@ -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() {

View File

@ -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.");

View File

@ -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 ) {

View File

@ -46,7 +46,7 @@ struct _Node : NodeInfo{
return _Node(0,0,0, false, false);
}
static _Node max_value() {
return _Node((numeric_limits<int>::max)(), (numeric_limits<int>::max)(), (numeric_limits<unsigned int>::max)(), false, false);
return _Node((std::numeric_limits<int>::max)(), (std::numeric_limits<int>::max)(), (std::numeric_limits<unsigned int>::max)(), false, false);
}
NodeID key() const {
return id;

View File

@ -100,6 +100,7 @@ public:
template<typename EdgeT>
void ConstructGrid(std::vector<EdgeT> & 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<double>::max)();
double dist = (std::numeric_limits<double>::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<double>::max)();
double dist = (std::numeric_limits<double>::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<GridEntry>& entriesWithSameRAMIndex, unsigned long fileOffset ) {
vector<char> tmpBuffer(32*32*4096,0);
unsigned FillCell(std::vector<GridEntry>& entriesWithSameRAMIndex, const unsigned long fileOffset ) {
std::vector<char> tmpBuffer(32*32*4096,0);
unsigned long indexIntoTmpBuffer = 0;
unsigned numberOfWrittenBytes = 0;
assert(indexOutFile.is_open());
vector<unsigned long> cellIndex(32*32,ULONG_MAX);
std::vector<unsigned long> 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<GridEntry> &vectorWithSameFileIndex, vector<char> & tmpBuffer, const unsigned long index) {
unsigned FlushEntriesWithSameFileIndexToBuffer( std::vector<GridEntry> &vectorWithSameFileIndex, std::vector<char> & 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<BresenhamPixel> 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<BresenhamPixel> &indexList) {
void GetListOfIndexesForEdgeAndGridSize(const _Coordinate& start, const _Coordinate& target, std::vector<BresenhamPixel> &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<GridEntry> entries;
#endif

View File

@ -39,13 +39,13 @@ struct NodeCoords {
NodeT id;
static NodeCoords<NodeT> min_value() {
return NodeCoords<NodeT>(-90*100000,-180*100000,numeric_limits<NodeT>::min());
return NodeCoords<NodeT>(-90*100000,-180*100000,std::numeric_limits<NodeT>::min());
}
static NodeCoords<NodeT> max_value() {
return NodeCoords<NodeT>(90*100000, 180*100000, numeric_limits<NodeT>::max());
return NodeCoords<NodeT>(90*100000, 180*100000, std::numeric_limits<NodeT>::max());
}
value_type operator[](size_t n) const {
value_type operator[](std::size_t n) const {
switch(n) {
case 1:
return lat;

View File

@ -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();
}

View File

@ -44,14 +44,14 @@ class SearchEngine {
private:
const GraphT * _graph;
NodeInformationHelpDesk * nodeHelpDesk;
std::vector<string> * _names;
std::vector<string> & _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<string> * n = new std::vector<string>()) : _graph(g), nodeHelpDesk(nh), _names(n) {}
SearchEngine(GraphT * g, NodeInformationHelpDesk * nh, std::vector<string> & 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 {

View File

@ -22,11 +22,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#define STATICGRAPH_H_INCLUDED
#include <vector>
#ifdef _GLIBCXX_PARALLEL
#include <parallel/algorithm>
#else
#include <algorithm>
#endif
#include "../typedefs.h"
#include "ImportEdge.h"

View File

@ -24,11 +24,7 @@ KD Tree coded by Christian Vetter, Monav Project
#define STATICKDTREE_H_INCLUDED
#include <vector>
#ifdef _GLIBCXX_PARALLEL
#include <parallel/algorithm>
#else
#include <algorithm>
#endif
#include <stack>
#include <limits>
@ -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 ) );
}

View File

@ -23,7 +23,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <fstream>
#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"); }

View File

@ -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);

View File

@ -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<vector>
#include<string>
#include "../DataStructures/StaticGraph.h"
#include "../Util/GraphLoader.h"
struct ObjectsForQueryStruct {
typedef StaticGraph<EdgeData> QueryGraph;
typedef QueryGraph::InputEdge InputEdge;
NodeInformationHelpDesk * nodeHelpDesk;
std::vector<std::string> * 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<std::string>();
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_ */

View File

@ -27,8 +27,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <string>
#include <vector>
#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<std::string> * names;
std::vector<std::string> & names;
StaticGraph<EdgeData> * graph;
HashTable<std::string, unsigned> descriptorTable;
std::string pluginDescriptorString;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * 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<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);

View File

@ -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()

View File

@ -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<std::string>();
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<std::string>(names).swap(names);
hsgrInStream.close();
namesInStream.close();
INFO("All query data structures loaded");
}
QueryObjectsStorage::~QueryObjectsStorage() {
// delete names;
delete graph;
delete nodeHelpDesk;
}

View File

@ -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<vector>
#include<string>
#include "../../DataStructures/StaticGraph.h"
struct QueryObjectsStorage {
typedef StaticGraph<EdgeData> QueryGraph;
typedef QueryGraph::InputEdge InputEdge;
NodeInformationHelpDesk * nodeHelpDesk;
std::vector<std::string> 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_ */

View File

@ -23,6 +23,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <cassert>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iomanip>
@ -30,12 +32,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/unordered_map.hpp>
#ifdef _GLIBCXX_PARALLEL
#include <parallel/algorithm>
#else
#include <algorithm>
#endif
#include "../DataStructures/ImportEdge.h"
#include "../typedefs.h"
@ -60,7 +56,7 @@ NodeID readBinaryOSRMGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeL
for (NodeID i=0; i<n; ++i) {
in.read((char*)&node, sizeof(_Node));
int2ExtNodeMap->push_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<EdgeT>& edgeL
return n;
}
template<typename EdgeT>
NodeID readDTMPGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeInfo> * int2ExtNodeMap) {
NodeID readDTMPGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeInfo> * 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<EdgeT>& edgeList, vector<Node
for (NodeID i=0; i<n;++i) {
in >> 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<EdgeT>& edgeList, vector<Node
edgeList.push_back(inputEdge);
}
ext2IntNodeMap.clear();
vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
cout << "ok" << endl;
std::vector<ImportEdge>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
std::cout << "ok" << std::endl;
return n;
}
template<typename EdgeT>
NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<NodeID> & int2ExtNodeMap) {
NodeID readDDSGGraphFromStream(std::istream &in, std::vector<EdgeT>& edgeList, std::vector<NodeID> & int2ExtNodeMap) {
ExternalNodeMap nodeMap;
NodeID n, source, target;
unsigned numberOfNodes = 0;
@ -323,32 +319,24 @@ NodeID readDDSGGraphFromStream(istream &in, vector<EdgeT>& edgeList, vector<Node
EdgeT inputEdge(source, target, 0, weight, forward, backward, 1 );
edgeList.push_back(inputEdge);
}
vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
std::vector<EdgeT>(edgeList.begin(), edgeList.end()).swap(edgeList); //remove excess candidates.
nodeMap.clear();
return numberOfNodes;
}
template<typename NodeT, typename EdgeT>
unsigned readHSGRFromStream(istream &in, vector<NodeT>& nodeList, vector<EdgeT> & edgeList, unsigned * checkSum) {
unsigned readHSGRFromStream(std::istream &in, std::vector<NodeT>& nodeList, std::vector<EdgeT> & 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*) &currentNode, 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*) &currentEdge, sizeof(EdgeT));
edgeList[edgeCounter] = currentEdge;
}
in.read((char*) &(edgeList[0]), numberOfEdges*sizeof(EdgeT));
return numberOfNodes;
}

View File

@ -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<<setfill('0')
ss<<std::setfill('0')
<< ROOT_PATH
<< "/"
<<NS
<<setw(2)<<abs(latitude)<<setw(0)
<<std::setw(2)<<std::abs(latitude)<<std::setw(0)
<<EW
<<setw(3)<<abs(longitude)<<setw(0)
<<std::setw(3)<<std::abs(longitude)<<std::setw(0)
<<'.'<<ext;
return ss.str();
}

View File

@ -59,7 +59,7 @@ typedef DynamicGraph<EdgeData>::InputEdge InputEdge;
typedef StaticGraph<EdgeData>::InputEdge StaticEdge;
typedef BaseConfiguration ContractorConfiguration;
std::vector<NodeInfo> internalToExternaleNodeMapping;
std::vector<NodeInfo> internalToExternalNodeMapping;
std::vector<_Restriction> inputRestrictions;
std::vector<NodeID> bollardNodes;
std::vector<NodeID> trafficLightNodes;
@ -111,7 +111,7 @@ int main (int argc, char *argv[]) {
char levelInfoOut[1024]; strcpy(levelInfoOut, argv[1]); strcat(levelInfoOut, ".levels");
std::vector<ImportEdge> 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<ImportEdge>().swap(edgeList);
edgeBasedGraphFactory->Run();
std::vector<_Restriction>().swap(inputRestrictions);
NodeID edgeBasedNodeNumber = edgeBasedGraphFactory->GetNumberOfNodes();
std::vector<EdgeBasedEdge> 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<EdgeBasedGraphFactory::EdgeBasedNode>().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<NodeInfo>().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<NodeInfo>().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<ContractionCleanup::Edge>().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;

View File

@ -24,14 +24,15 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#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"),