Skip to content

Commit

Permalink
Merge branch 'master' of https://DennisOSRM@github.com/DennisOSRM/Pro…
Browse files Browse the repository at this point in the history
…ject-OSRM.git
  • Loading branch information
DennisOSRM committed Apr 16, 2012
2 parents 7e8de26 + 3c62aa0 commit c4dc85f
Show file tree
Hide file tree
Showing 23 changed files with 196 additions and 212 deletions.
20 changes: 10 additions & 10 deletions Algorithms/PolylineCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -41,7 +41,7 @@ class PolylineCompressor {
}
}

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));
Expand All @@ -57,8 +57,8 @@ class PolylineCompressor {
}

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;
Expand All @@ -77,8 +77,8 @@ class PolylineCompressor {

}

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;
Expand All @@ -92,9 +92,9 @@ class PolylineCompressor {
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 += "[";
Expand All @@ -110,9 +110,9 @@ class PolylineCompressor {
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;
Expand Down
8 changes: 0 additions & 8 deletions Contractor/ContractionCleanup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,11 +116,7 @@ class ContractionCleanup {
edges.push_back( newEdge );
}
}
#ifdef _GLIBCXX_PARALLEL
__gnu_parallel::sort( edges.begin(), edges.end() );
#else
sort( edges.begin(), edges.end() );
#endif
}

private:
Expand Down
9 changes: 6 additions & 3 deletions Contractor/Contractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ class Contractor {
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(); ) {
Expand Down Expand Up @@ -168,8 +169,10 @@ class Contractor {
}
}
}
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;
Expand All @@ -188,10 +191,10 @@ class Contractor {
// INFO(" ->(" << highestNode << "," << _graph->GetTarget(i) << "); via: " << _graph->GetEdgeData(i).via);
// }


//Create temporary file

GetTemporaryFileName(temporaryEdgeStorageFilename);
std::cout << "contractor finished initalization" << std::endl;
}

~Contractor() {
Expand Down
4 changes: 4 additions & 0 deletions Contractor/EdgeBasedGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
6 changes: 3 additions & 3 deletions DataStructures/DynamicGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion DataStructures/ExtractorStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 12 additions & 11 deletions DataStructures/NNGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class NNGrid {

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) {
Expand Down Expand Up @@ -240,7 +241,7 @@ class NNGrid {
}
}
_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);
Expand All @@ -264,7 +265,7 @@ class NNGrid {
}
}
_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);
Expand Down Expand Up @@ -298,13 +299,13 @@ class NNGrid {
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;
Expand Down Expand Up @@ -354,7 +355,7 @@ class NNGrid {
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;

Expand All @@ -373,7 +374,7 @@ class NNGrid {
++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];
Expand Down Expand Up @@ -419,7 +420,7 @@ class NNGrid {
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);
Expand Down Expand Up @@ -468,7 +469,7 @@ class NNGrid {
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.;

Expand Down Expand Up @@ -523,8 +524,8 @@ class NNGrid {

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
Expand Down
6 changes: 3 additions & 3 deletions DataStructures/NodeCoords.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions DataStructures/NodeInformationHelpDesk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions DataStructures/SearchEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -377,7 +377,7 @@ class SearchEngine {
}

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 {
Expand Down
4 changes: 0 additions & 4 deletions DataStructures/StaticGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 0 additions & 8 deletions DataStructures/StaticKDTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -119,11 +115,7 @@ class StaticKDTree {
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 ) );
}
Expand Down
4 changes: 2 additions & 2 deletions Plugins/LocatePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"); }
Expand Down
Loading

0 comments on commit c4dc85f

Please sign in to comment.