Bugfixes, plus safe delete, less pointers and speed back on track

This commit is contained in:
Dennis Luxen 2011-07-12 14:03:31 +00:00
parent 77ae0d8ef4
commit ae81a8d118
14 changed files with 334 additions and 223 deletions

View File

@ -103,6 +103,7 @@ public:
std::string maxspeed( w.keyVals.Find("maxspeed") );
std::string access( w.keyVals.Find("access") );
std::string motorcar( w.keyVals.Find("motorcar") );
std::string man_made( w.keyVals.Find("man_made") );
if ( ref != "" ) {
w.name = ref;
@ -130,9 +131,9 @@ public:
if(w.type == -1)
w.type = 9;
}
if ( route == "ferry") {
if ( route == "ferry" || man_made == "pier" ) {
for ( unsigned i = 0; i < settings.speedProfile.names.size(); i++ ) {
if ( route == settings.speedProfile.names[i] ) {
if ( "ferry" == settings.speedProfile.names[i] ) {
w.type = i;
w.maximumSpeed = settings.speedProfile.speed[i];
w.useful = true;

View File

@ -88,7 +88,7 @@ ostream & operator<<(ostream & out, const _Coordinate & c){
}
struct _Way {
_Way() : id(UINT_MAX) {
_Way() : id(UINT_MAX), nameID(UINT_MAX) {
direction = _Way::notSure;
maximumSpeed = -1;

128
DataStructures/LRUCache.h Normal file
View File

@ -0,0 +1,128 @@
#include <climits>
#include <google/sparse_hash_map>
#include <iostream>
#include <list>
#include <vector>
template < class T >
struct Countfn {
unsigned long operator()( const T &x ) { return 1; }
};
template< class Key, class Data, class Sizefn = Countfn< Data > > class LRUCache {
public:
typedef std::list< std::pair< Key, Data > > List; ///< Main cache storage typedef
typedef typename List::iterator List_Iter; ///< Main cache iterator
typedef typename List::const_iterator List_cIter; ///< Main cache iterator (const)
typedef std::vector< Key > Key_List; ///< List of keys
typedef typename Key_List::iterator Key_List_Iter; ///< Main cache iterator
typedef typename Key_List::const_iterator Key_List_cIter; ///< Main cache iterator (const)
typedef google::sparse_hash_map< Key, List_Iter > Map; ///< Index typedef
typedef std::pair< Key, List_Iter > Pair; ///< Pair of Map elements
typedef typename Map::iterator Map_Iter; ///< Index iterator
typedef typename Map::const_iterator Map_cIter; ///< Index iterator (const)
private:
List _list; ///< Main cache storage
Map _index; ///< Cache storage index
unsigned long _max_size; ///< Maximum abstract size of the cache
unsigned long _curr_size; ///< Current abstract size of the cache
public:
LRUCache( const unsigned long Size ) : _max_size( Size ), _curr_size( 0 ) {
_index.set_deleted_key(UINT_MAX);
}
~LRUCache() { clear(); }
inline const unsigned long size( void ) const { return _curr_size; }
inline const unsigned long max_size( void ) const { return _max_size; }
/// Clears all storage and indices.
void clear( void ) {
_list.clear();
_index.clear();
};
inline bool exists( const Key &key ) const {
return _index.find( key ) != _index.end();
}
inline void remove( const Key &key ) {
Map_Iter miter = _index.find( key );
if( miter == _index.end() ) return;
_remove( miter );
}
inline void touch( const Key &key ) {
_touch( key );
}
inline Data *fetch_ptr( const Key &key, bool touch = true ) {
Map_Iter miter = _index.find( key );
if( miter == _index.end() ) return NULL;
_touch( key );
return &(miter->second->second);
}
inline bool fetch( const Key &key, Data &data, bool touch_data = true ) {
Map_Iter miter = _index.find( key );
if( miter == _index.end() ) return false;
if( touch_data )
_touch( key );
data = miter->second->second;
return true;
}
inline void insert( const Key &key, const Data data ) {
// Touch the key, if it exists, then replace the content.
Map_Iter miter = _touch( key );
if( miter != _index.end() )
_remove( miter );
// Ok, do the actual insert at the head of the list
_list.push_front( std::make_pair( key, data ) );
List_Iter liter = _list.begin();
// Store the index
_index.insert( std::make_pair( key, liter ) );
_curr_size += Sizefn()( data );
// Check to see if we need to remove an element due to exceeding max_size
while( _curr_size > _max_size ) {
std::cout << "removing element " << std::endl;
// Remove the last element.
liter = _list.end();
--liter;
_remove( liter->first );
}
}
inline const Key_List get_all_keys( void ) {
Key_List ret;
for( List_cIter liter = _list.begin(); liter != _list.end(); liter++ )
ret.push_back( liter->first );
return ret;
}
private:
inline Map_Iter _touch( const Key &key ) {
Map_Iter miter = _index.find( key );
if( miter == _index.end() ) return miter;
// Move the found node to the head of the list.
_list.splice( _list.begin(), _list, miter->second );
return miter;
}
inline void _remove( const Map_Iter &miter ) {
_curr_size -= Sizefn()( miter->second->second );
_list.erase( miter->second );
_index.erase( miter );
}
inline void _remove( const Key &key ) {
Map_Iter miter = _index.find( key );
_remove( miter );
}
};

View File

@ -34,6 +34,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "ExtractorStructs.h"
#include "GridEdge.h"
#include "LRUCache.h"
#include "Percent.h"
#include "PhantomNodes.h"
#include "Util.h"
@ -140,10 +141,25 @@ static void GetListOfIndexesForEdgeAndGridSize(_Coordinate& start, _Coordinate&
template<bool WriteAccess = false>
class NNGrid {
public:
NNGrid() { ramIndexTable.resize((1024*1024), UINT_MAX); if( WriteAccess) { entries = new stxxl::vector<GridEntry>(); }}
private:
struct DiskEdge {
NodeID start;
NodeID target;
int slat;
int slon;
int tlat;
int tlon;
};
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()) {
public:
NNGrid() : cellCache(500), fileCache(500) {
ramIndexTable.resize((1024*1024), UINT_MAX);
if( WriteAccess) {
entries = new stxxl::vector<GridEntry>();
}
}
NNGrid(const char* rif, const char* _i, unsigned numberOfThreads = omp_get_num_procs()): cellCache(500), fileCache(500) {
iif = _i;
ramIndexTable.resize((1024*1024), UINT_MAX);
ramInFile.open(rif, std::ios::in | std::ios::binary);
@ -282,7 +298,7 @@ public:
/** search for point on edge close to source */
unsigned fileIndex = GetFileIndexForLatLon(startCoord.lat, startCoord.lon);
std::vector<_Edge> candidates;
double timestamp = get_timestamp();
// double timestamp = get_timestamp();
for(int j = -32768; j < (32768+1); j+=32768) {
for(int i = -1; i < 2; i++){
@ -292,7 +308,7 @@ public:
_Coordinate tmp;
double dist = numeric_limits<double>::max();
timestamp = get_timestamp();
// timestamp = get_timestamp();
for(std::vector<_Edge>::iterator it = candidates.begin(); it != candidates.end(); it++) {
double r = 0.;
double tmpDist = ComputeDistance(startCoord, it->startCoord, it->targetCoord, tmp, &r);
@ -310,10 +326,10 @@ public:
return foundNode;
}
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes * routingStarts) {
routingStarts->Reset();
return (FindPhantomNodeForCoordinate( start, routingStarts->startPhantom) &&
FindPhantomNodeForCoordinate( target, routingStarts->targetPhantom) );
bool FindRoutingStarts(const _Coordinate& start, const _Coordinate& target, PhantomNodes & routingStarts) {
routingStarts.Reset();
return (FindPhantomNodeForCoordinate( start, routingStarts.startPhantom) &&
FindPhantomNodeForCoordinate( target, routingStarts.targetPhantom) );
}
void FindNearestNodeInGraph(const _Coordinate& inputCoordinate, _Coordinate& outputCoordinate) {
@ -526,8 +542,8 @@ private:
std::vector<unsigned> cellIndex;
cellIndex.resize(32*32);
google::dense_hash_map< unsigned, unsigned > * cellMap = new google::dense_hash_map< unsigned, unsigned >(1024);
cellMap->set_empty_key(UINT_MAX);
google::dense_hash_map< unsigned, unsigned > cellMap(1024);
cellMap.set_empty_key(UINT_MAX);
unsigned lineBase = ramIndex/1024;
lineBase = lineBase*32*32768;
@ -536,77 +552,56 @@ private:
for(int i = 0; i < 32; i++) {
for(int j = 0; j < 32; j++) {
assert(cellMap->size() >= 0);
unsigned fileIndex = lineBase + i*32768 + columnBase+j;
unsigned cellIndex = i*32+j;
cellMap->insert(std::make_pair(fileIndex, cellIndex));
cellMap.insert(std::make_pair(fileIndex, cellIndex));
}
}
{
// if(cellCache.Holds(startIndexInFile)) {
// cellIndex = cellCache.Find(startIndexInFile);
// } else {
std::ifstream localStream(iif, std::ios::in | std::ios::binary);
localStream.seekg(startIndexInFile);
unsigned numOfElementsInCell = 0;
for(int i = 0; i < 32*32; i++) {
localStream.read((char *)&cellIndex[i], sizeof(unsigned));
numOfElementsInCell += cellIndex[i];
if(cellCache.exists(startIndexInFile)) {
cellCache.fetch(startIndexInFile, cellIndex);
} else {
std::ifstream localStream(iif, std::ios::in | std::ios::binary);
localStream.seekg(startIndexInFile);
localStream.read((char*) &cellIndex[0], 32*32*sizeof(unsigned));
localStream.close();
assert(cellMap.find(fileIndex) != cellMap.end());
if(cellIndex[cellMap.find(fileIndex)->second] == UINT_MAX) {
return;
}
#pragma omp critical
{
cellCache.insert(startIndexInFile, cellIndex);
}
}
localStream.close();
assert(cellMap->find(fileIndex) != cellMap->end());
if(cellIndex[cellMap->find(fileIndex)->second] == UINT_MAX) {
delete cellMap;
return;
// }
// if(cellCache.Size() > MAX_CACHE_ELEMENTS) {
// std::cout << "fixme: cell cache full" << std::endl;
// }
// std::cout << "Adding cache entry for cell position: " << startIndexInFile << std::endl;
//#pragma omp critical
// {
// cellCache.Add(startIndexInFile, cellIndex);
}
}
unsigned position = cellIndex[cellMap->find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
// if(fileCache.Find(position).size() > 0) {
// result = fileCache.Find(position);
const unsigned position = cellIndex[cellMap.find(fileIndex)->second] + 32*32*sizeof(unsigned) ;
// if(fileCache.exists(position)) {
// fileCache.fetch(position, result);
// } else {
std::ifstream localStream(iif, std::ios::in | std::ios::binary);
localStream.seekg(position);
unsigned numberOfEdgesInFileBucket = 0;
NodeID start, target; int slat, slon, tlat, tlon;
DiskEdge diskEdge;
do {
localStream.read((char *)&(start), sizeof(NodeID));
if(localStream.eof() || start == UINT_MAX)
localStream.read((char *)&(diskEdge), sizeof(DiskEdge));
if(localStream.eof() || diskEdge.start == UINT_MAX)
break;
localStream.read((char *)&(target), sizeof(NodeID));
localStream.read((char *)&(slat), sizeof(int));
localStream.read((char *)&(slon), sizeof(int));
localStream.read((char *)&(tlat), sizeof(int));
localStream.read((char *)&(tlon), sizeof(int));
_Edge e(start, target);
e.startCoord.lat = slat;
e.startCoord.lon = slon;
e.targetCoord.lat = tlat;
e.targetCoord.lon = tlon;
_Edge e(diskEdge.start, diskEdge.target);
e.startCoord.lat = diskEdge.slat;
e.startCoord.lon = diskEdge.slon;
e.targetCoord.lat = diskEdge.tlat;
e.targetCoord.lon = diskEdge.tlon;
result.push_back(e);
numberOfEdgesInFileBucket++;
} while(true);
localStream.close();
// if(fileCache.Size() > MAX_CACHE_ELEMENTS) {
// std::cout << "fixme: file cache full" << std::endl;
// }
// std::cout << "Adding cache entry for file position: " << position << std::endl;
//#pragma omp critical
// {
// fileCache.Add(position, result);
// fileCache.insert(position, result);
// }
// }
delete cellMap;
}
void AddEdge(_GridEdge edge) {
@ -661,8 +656,8 @@ private:
stxxl::vector<GridEntry> * entries;
std::vector<unsigned> ramIndexTable; //4 MB for first level index in RAM
const char * iif;
// HashTable<unsigned, std::vector<_Edge> > fileCache;
// HashTable<unsigned, std::vector<unsigned> > cellCache;
LRUCache<int,std::vector<unsigned> > cellCache;
LRUCache<int,std::vector<_Edge> > fileCache;
};
}

View File

@ -65,7 +65,7 @@ public:
return readOnlyGrid->FindPhantomNodeForCoordinate(location, resultNode);
}
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes * phantomNodes) {
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & phantomNodes) {
readOnlyGrid->FindRoutingStarts(start, target, phantomNodes);
return true;
}

View File

@ -62,7 +62,7 @@ private:
public:
inline void printEncodedString(vector<_Coordinate>& polyline, string &output) {
output += "\"";
if(polyline.size() > 0) {
if(!polyline.empty()) {
output += encodeSignedNumber(polyline[0].lat);
output += encodeSignedNumber(polyline[0].lon);
}

View File

@ -85,7 +85,7 @@ struct _InsertedNodes {
};
typedef BinaryHeap< NodeID, int, int, _HeapData/*, ArrayS< NodeID, unsigned >*/ > _Heap;
typedef BinaryHeap< NodeID, int, int, _HeapData, ArrayStorage<NodeID, NodeID, false> > _Heap;
template<typename EdgeData, typename GraphT, typename NodeHelperT = NodeInformationHelpDesk>
class SearchEngine {
@ -107,8 +107,8 @@ public:
return nodeHelpDesk->getNumberOfNodes();
}
unsigned int ComputeRoute(PhantomNodes * phantomNodes, vector<_PathData > * path) {
bool onSameEdge = false;
unsigned int ComputeRoute(PhantomNodes &phantomNodes, vector<_PathData > & path) {
bool onSameEdge = false;
bool onSameEdgeReversed = false;
bool startReverse = false;
bool targetReverse = false;
@ -120,16 +120,16 @@ public:
NodeID middle = ( NodeID ) 0;
unsigned int _upperbound = std::numeric_limits<unsigned int>::max();
if(phantomNodes->startPhantom.startNode == UINT_MAX || phantomNodes->startPhantom.targetNode == UINT_MAX || phantomNodes->targetPhantom.startNode == UINT_MAX || phantomNodes->targetPhantom.targetNode == UINT_MAX)
if(phantomNodes.startPhantom.startNode == UINT_MAX || phantomNodes.startPhantom.targetNode == UINT_MAX || phantomNodes.targetPhantom.startNode == UINT_MAX || phantomNodes.targetPhantom.targetNode == UINT_MAX)
return _upperbound;
if( (phantomNodes->startPhantom.startNode == phantomNodes->startPhantom.targetNode && phantomNodes->targetPhantom.startNode == phantomNodes->targetPhantom.targetNode ) ||
(phantomNodes->startPhantom.startNode == phantomNodes->targetPhantom.targetNode && phantomNodes->targetPhantom.startNode == phantomNodes->startPhantom.targetNode) )
if( (phantomNodes.startPhantom.startNode == phantomNodes.startPhantom.targetNode && phantomNodes.targetPhantom.startNode == phantomNodes.targetPhantom.targetNode ) ||
(phantomNodes.startPhantom.startNode == phantomNodes.targetPhantom.targetNode && phantomNodes.targetPhantom.startNode == phantomNodes.startPhantom.targetNode) )
{
bool reverse = false;
EdgeID currentEdge = _graph->FindEdge( phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode );
EdgeID currentEdge = _graph->FindEdge( phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode );
if(currentEdge == UINT_MAX){
currentEdge = _graph->FindEdge( phantomNodes->startPhantom.targetNode, phantomNodes->startPhantom.startNode );
currentEdge = _graph->FindEdge( phantomNodes.startPhantom.targetNode, phantomNodes.startPhantom.startNode );
reverse = true;
}
@ -137,34 +137,34 @@ public:
return _upperbound;
}
if(phantomNodes->startPhantom.ratio < phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward) {
if(phantomNodes.startPhantom.ratio < phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward) {
onSameEdge = true;
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
} else if(phantomNodes->startPhantom.ratio > phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward && !reverse)
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
} else if(phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward && !reverse)
{
onSameEdge = true;
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
} else if(phantomNodes->startPhantom.ratio < phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward) {
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
} else if(phantomNodes.startPhantom.ratio < phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).backward) {
onSameEdge = true;
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
} else if(phantomNodes->startPhantom.ratio > phantomNodes->targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward && _graph->GetEdgeData(currentEdge).backward) {
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
} else if(phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio && _graph->GetEdgeData(currentEdge).forward && _graph->GetEdgeData(currentEdge).backward) {
onSameEdge = true;
_upperbound = 10 * ApproximateDistance(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon, phantomNodes->targetPhantom.location.lat, phantomNodes->targetPhantom.location.lon);
} else if(phantomNodes->startPhantom.ratio > phantomNodes->targetPhantom.ratio) {
_upperbound = 10 * ApproximateDistance(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon, phantomNodes.targetPhantom.location.lat, phantomNodes.targetPhantom.location.lon);
} else if(phantomNodes.startPhantom.ratio > phantomNodes.targetPhantom.ratio) {
onSameEdgeReversed = true;
EdgeWeight w = _graph->GetEdgeData( currentEdge ).distance;
_forwardHeap.Insert(phantomNodes->targetPhantom.startNode, absDouble( w*phantomNodes->startPhantom.ratio), phantomNodes->targetPhantom.startNode);
_insertedNodes.ForwInsert(phantomNodes->targetPhantom.startNode);
_backwardHeap.Insert(phantomNodes->startPhantom.startNode, absDouble( w-w*phantomNodes->targetPhantom.ratio), phantomNodes->startPhantom.startNode);
_insertedNodes.BackInsert(phantomNodes->startPhantom.startNode);
_forwardHeap.Insert(phantomNodes.targetPhantom.startNode, absDouble( w*phantomNodes.startPhantom.ratio), phantomNodes.targetPhantom.startNode);
_insertedNodes.ForwInsert(phantomNodes.targetPhantom.startNode);
_backwardHeap.Insert(phantomNodes.startPhantom.startNode, absDouble( w-w*phantomNodes.targetPhantom.ratio), phantomNodes.startPhantom.startNode);
_insertedNodes.BackInsert(phantomNodes.startPhantom.startNode);
}
}
if(phantomNodes->startPhantom.startNode != UINT_MAX) {
EdgeID edge = _graph->FindEdge( phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
if(phantomNodes.startPhantom.startNode != UINT_MAX) {
EdgeID edge = _graph->FindEdge( phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode);
if(edge == UINT_MAX){
edge = _graph->FindEdge( phantomNodes->startPhantom.targetNode, phantomNodes->startPhantom.startNode );
edge = _graph->FindEdge( phantomNodes.startPhantom.targetNode, phantomNodes.startPhantom.startNode );
if(edge == UINT_MAX){
return _upperbound;
}
@ -174,18 +174,18 @@ public:
EdgeWeight w = ed.distance;
if( (ed.backward && !startReverse) || (ed.forward && startReverse) ){
_forwardHeap.Insert(phantomNodes->startPhantom.startNode, absDouble( w*phantomNodes->startPhantom.ratio), phantomNodes->startPhantom.startNode);
_insertedNodes.ForwInsert(phantomNodes->startPhantom.startNode);
_forwardHeap.Insert(phantomNodes.startPhantom.startNode, absDouble( w*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.startNode);
_insertedNodes.ForwInsert(phantomNodes.startPhantom.startNode);
}
if( (ed.backward && startReverse) || (ed.forward && !startReverse) ) {
_forwardHeap.Insert(phantomNodes->startPhantom.targetNode, absDouble(w-w*phantomNodes->startPhantom.ratio), phantomNodes->startPhantom.targetNode);
_insertedNodes.ForwInsert(phantomNodes->startPhantom.targetNode);
_forwardHeap.Insert(phantomNodes.startPhantom.targetNode, absDouble(w-w*phantomNodes.startPhantom.ratio), phantomNodes.startPhantom.targetNode);
_insertedNodes.ForwInsert(phantomNodes.startPhantom.targetNode);
}
}
if(phantomNodes->startPhantom.targetNode!= UINT_MAX && !onSameEdgeReversed) {
EdgeID edge = _graph->FindEdge( phantomNodes->targetPhantom.startNode, phantomNodes->targetPhantom.targetNode);
if(phantomNodes.startPhantom.targetNode!= UINT_MAX && !onSameEdgeReversed) {
EdgeID edge = _graph->FindEdge( phantomNodes.targetPhantom.startNode, phantomNodes.targetPhantom.targetNode);
if(edge == UINT_MAX){
edge = _graph->FindEdge( phantomNodes->targetPhantom.targetNode, phantomNodes->targetPhantom.startNode);
edge = _graph->FindEdge( phantomNodes.targetPhantom.targetNode, phantomNodes.targetPhantom.startNode);
targetReverse = true;
}
if(edge == UINT_MAX){
@ -196,15 +196,14 @@ public:
EdgeWeight w = ed.distance;
if( (ed.backward && !targetReverse) || (ed.forward && targetReverse) ) {
_backwardHeap.Insert(phantomNodes->targetPhantom.targetNode, absDouble( w*phantomNodes->targetPhantom.ratio), phantomNodes->targetPhantom.targetNode);
_insertedNodes.BackInsert(phantomNodes->targetPhantom.targetNode);
_backwardHeap.Insert(phantomNodes.targetPhantom.targetNode, absDouble( w*phantomNodes.targetPhantom.ratio), phantomNodes.targetPhantom.targetNode);
_insertedNodes.BackInsert(phantomNodes.targetPhantom.targetNode);
}
if( (ed.backward && targetReverse) || (ed.forward && !targetReverse) ) {
_backwardHeap.Insert(phantomNodes->targetPhantom.startNode, absDouble(w-w*phantomNodes->targetPhantom.ratio), phantomNodes->targetPhantom.startNode);
_insertedNodes.BackInsert(phantomNodes->targetPhantom.startNode);
_backwardHeap.Insert(phantomNodes.targetPhantom.startNode, absDouble(w-w*phantomNodes.targetPhantom.ratio), phantomNodes.targetPhantom.startNode);
_insertedNodes.BackInsert(phantomNodes.targetPhantom.startNode);
}
}
// double time = get_timestamp();
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
if ( _forwardHeap.Size() > 0 ) {
@ -215,8 +214,6 @@ public:
}
}
// std::cout << "[debug] computing distance took " << get_timestamp() - time << std::endl;
// time = get_timestamp();
if ( _upperbound == std::numeric_limits< unsigned int >::max() || onSameEdge ) {
return _upperbound;
@ -238,7 +235,7 @@ public:
packedPath.push_back( pathNode );
}
path->push_back( _PathData(packedPath[0]) );
path.push_back( _PathData(packedPath[0]) );
for(deque<NodeID>::size_type i = 0; i < packedPath.size()-1; i++) {
_UnpackEdge(packedPath[i], packedPath[i+1], path);
}
@ -302,7 +299,7 @@ public:
}
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes * routingStarts) {
inline bool FindRoutingStarts(const _Coordinate &start, const _Coordinate &target, PhantomNodes & routingStarts) {
nodeHelpDesk->FindRoutingStarts(start, target, routingStarts);
return true;
}
@ -490,7 +487,7 @@ private:
}
}
bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< _PathData >* path ) {
bool _UnpackEdge( const NodeID source, const NodeID target, std::vector< _PathData >& path ) {
assert(source != target);
//find edge first.
bool forward = true;
@ -532,7 +529,7 @@ private:
return false;
} else {
assert(!ed.shortcut);
path->push_back(_PathData(target) );
path.push_back(_PathData(target) );
return true;
}
}

View File

@ -118,7 +118,7 @@ public:
BaseDescriptor() { }
//Maybe someone can explain the pure virtual destructor thing to me (dennis)
virtual ~BaseDescriptor() { }
virtual void Run(http::Reply& reply, RawRouteData * route, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) = 0;
virtual void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) = 0;
virtual void SetConfig(const _DescriptorConfig & config) = 0;
};

View File

@ -31,26 +31,26 @@ private:
_Coordinate current;
public:
void SetConfig(const _DescriptorConfig& c) { config = c; }
void Run(http::Reply& reply, RawRouteData * route, PhantomNodes * phantomNodes, SearchEngineT * sEngine, unsigned distance) {
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
reply.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
reply.content += "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" "
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 gpx.xsd"
"\">";
reply.content += "<rte>";
if(distance != UINT_MAX && route->routeSegments.size()) {
if(distance != UINT_MAX && rawRoute.routeSegments.size()) {
convertInternalLatLonToString(phantomNodes->startPhantom.location.lat, tmp);
convertInternalLatLonToString(phantomNodes.startPhantom.location.lat, tmp);
reply.content += "<rtept lat=\"" + tmp + "\" ";
convertInternalLatLonToString(phantomNodes->startPhantom.location.lon, tmp);
convertInternalLatLonToString(phantomNodes.startPhantom.location.lon, tmp);
reply.content += "lon=\"" + tmp + "\"></rtept>";
for(unsigned segmentIdx = 0; segmentIdx < route->routeSegments.size(); segmentIdx++) {
const std::vector< _PathData > & path = route->routeSegments[segmentIdx];
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
if( ! path.size() )
continue;
for(vector< _PathData >::const_iterator it = path.begin(); it != path.end(); it++) {
sEngine->getCoordinatesForNodeID(it->node, current);
sEngine.getCoordinatesForNodeID(it->node, current);
convertInternalLatLonToString(current.lat, tmp);
reply.content += "<rtept lat=\"" + tmp + "\" ";
@ -60,9 +60,9 @@ public:
reply.content +="</rtept>";
}
}
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lat, tmp);
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lat, tmp);
reply.content += "<rtept lat=\"" + tmp + "\" ";
convertInternalLatLonToString(phantomNodes->targetPhantom.location.lon, tmp);
convertInternalLatLonToString(phantomNodes.targetPhantom.location.lon, tmp);
reply.content += "lon=\"" + tmp + "\"></rtept>";
}
reply.content += "</rte></gpx>";

View File

@ -38,44 +38,46 @@ public:
JSONDescriptor() {}
void SetConfig(const _DescriptorConfig & c) { config = c; }
void Run(http::Reply & reply, RawRouteData *rawRoute, PhantomNodes *phantomNodes, SearchEngineT *sEngine, unsigned distance) {
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
WriteHeaderToOutput(reply.content);
//We do not need to do much, if there is no route ;-)
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
if(distance != UINT_MAX && rawRoute.routeSegments.size() > 0) {
reply.content += "0,"
"\"status_message\": \"Found route between points\",";
//Put first segment of route into geometry
polyline.push_back(phantomNodes->startPhantom.location);
polyline.push_back(phantomNodes.startPhantom.location);
descriptorState.geometryCounter++;
descriptorState.startOfSegmentCoordinate = phantomNodes->startPhantom.location;
descriptorState.startOfSegmentCoordinate = phantomNodes.startPhantom.location;
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startPhantom.startNode, phantomNodes->startPhantom.targetNode);
summary.startName = sEngine.GetEscapedNameForOriginDestinationNodeID(phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode);
descriptorState.lastNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.startPhantom.startNode, phantomNodes.startPhantom.targetNode);
//If we have a route, i.e. start and dest not on same edge, than get it
if(rawRoute->routeSegments[0].size() > 0)
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
if(rawRoute.routeSegments[0].size() > 0)
sEngine.getCoordinatesForNodeID(rawRoute.routeSegments[0].begin()->node, descriptorState.tmpCoord);
else
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
descriptorState.tmpCoord = phantomNodes.targetPhantom.location;
descriptorState.previousCoordinate = phantomNodes->startPhantom.location;
descriptorState.previousCoordinate = phantomNodes.startPhantom.location;
descriptorState.currentCoordinate = descriptorState.tmpCoord;
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
if(config.instructions) {
//Get Heading
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
getDirectionOfInstruction(angle, directionOfInstruction);
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
}
NodeID lastNodeID = UINT_MAX;
for(unsigned segmentIdx = 0; segmentIdx < rawRoute->routeSegments.size(); segmentIdx++) {
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
if(path.empty())
continue;
if ( UINT_MAX == lastNodeID) {
lastNodeID = (phantomNodes->startPhantom.startNode == (*path.begin()).node ? phantomNodes->startPhantom.targetNode : phantomNodes->startPhantom.startNode);
lastNodeID = (phantomNodes.startPhantom.startNode == (*path.begin()).node ? phantomNodes.startPhantom.targetNode : phantomNodes.startPhantom.startNode);
}
//Check, if there is overlap between current and previous route segment
//if not, than we are fine and can route over this edge without paying any special attention.
@ -83,34 +85,34 @@ public:
// appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
polyline.push_back(descriptorState.currentCoordinate);
descriptorState.geometryCounter++;
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode);
lastNodeID = (lastNodeID == rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode);
//output of the via nodes coordinates
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
polyline.push_back(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
descriptorState.geometryCounter++;
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
//Make a special announement to do a U-Turn.
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
descriptorState.routeInstructionString += ",";
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
descriptorState.routeInstructionString += ",";
tmp = "U-turn at via point";
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
double tmpDistance = descriptorState.distanceOfInstruction;
descriptorState.SetStartOfSegment(); //Set start of segment but save distance information.
descriptorState.distanceOfInstruction = tmpDistance;
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
assert(segmentIdx != 0);
//routeInstructionString += "reaching via node: ";
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location;
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
descriptorState.nextCoordinate = rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location;
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.targetNode);
polyline.push_back(descriptorState.currentCoordinate);
descriptorState.geometryCounter++;
polyline.push_back(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
polyline.push_back(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
descriptorState.geometryCounter++;
if(config.instructions) {
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
@ -119,12 +121,12 @@ public:
descriptorState.routeInstructionString += ",";
getTurnDirectionOfInstruction(turnAngle, tmp);
tmp += " and reach via point";
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
//instruction to continue on the segment
appendInstructionLengthToString(ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate), descriptorState.routeInstructionString);
descriptorState.routeInstructionString += ",";
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
//note the new segment starting coordinates
descriptorState.SetStartOfSegment();
@ -133,8 +135,8 @@ public:
}
}
for(vector< _PathData >::const_iterator it = path.begin(); it != path.end(); it++) {
sEngine->getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
sEngine.getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
double area = fabs(0.5*( descriptorState.startOfSegmentCoordinate.lon*(descriptorState.nextCoordinate.lat - descriptorState.currentCoordinate.lat) + descriptorState.nextCoordinate.lon*(descriptorState.currentCoordinate.lat - descriptorState.startOfSegmentCoordinate.lat) + descriptorState.currentCoordinate.lon*(descriptorState.startOfSegmentCoordinate.lat - descriptorState.nextCoordinate.lat) ) );
//if route is generalization does not skip this point, add it to description
@ -147,7 +149,7 @@ public:
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
descriptorState.routeInstructionString += ",";
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
//note the new segment starting coordinates
descriptorState.SetStartOfSegment();
@ -161,8 +163,9 @@ public:
}
}
}
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->targetPhantom.targetNode);
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.targetPhantom.startNode, phantomNodes.targetPhantom.targetNode);
descriptorState.nextCoordinate = phantomNodes.targetPhantom.location;
polyline.push_back(descriptorState.currentCoordinate);
descriptorState.geometryCounter++;
@ -171,13 +174,13 @@ public:
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
descriptorState.routeInstructionString += ",";
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
descriptorState.distanceOfInstruction = 0;
descriptorState.SetStartOfSegment();
}
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
summary.destName = sEngine.GetEscapedNameForNameID(descriptorState.currentNameID);
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
polyline.push_back(phantomNodes->targetPhantom.location);
polyline.push_back(phantomNodes.targetPhantom.location);
descriptorState.geometryCounter++;
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
summary.BuildDurationAndLengthStrings(descriptorState.entireDistance, distance);
@ -221,23 +224,20 @@ public:
reply.content += "],";
//list all viapoints so that the client may display it
reply.content += "\"via_points\":[";
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute->segmentEndCoordinates.size()); segmentIdx++) {
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute.segmentEndCoordinates.size()); segmentIdx++) {
if(segmentIdx > 1)
reply.content += ",";
reply.content += "[";
if(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location.isSet())
convertInternalReversedCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, tmp);
if(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location.isSet())
convertInternalReversedCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, tmp);
else
convertInternalReversedCoordinateToString(rawRoute->rawViaNodeCoordinates[segmentIdx], tmp);
// INFO(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
// INFO(rawRoute->rawViaNodeCoordinates[segmentIdx]);
convertInternalReversedCoordinateToString(rawRoute.rawViaNodeCoordinates[segmentIdx], tmp);
reply.content += tmp;
reply.content += "]";
}
reply.content += "],"
"\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.2)\"";
reply.content += "}";
// std::cout << reply.content << std::endl;
}
private:
void appendInstructionNameToString(const std::string & nameOfStreet, const std::string & instructionOrDirection, std::string &output, bool firstAdvice = false) {

View File

@ -36,83 +36,83 @@ public:
KMLDescriptor() {}
void SetConfig(const _DescriptorConfig & c) { config = c; }
void Run(http::Reply & reply, RawRouteData *rawRoute, PhantomNodes *phantomNodes, SearchEngineT *sEngine, unsigned distance) {
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, unsigned distance) {
WriteHeaderToOutput(reply.content);
//We do not need to do much, if there is no route ;-)
if(distance != UINT_MAX && rawRoute->routeSegments.size() > 0) {
if(distance != UINT_MAX && rawRoute.routeSegments.size() > 0) {
//Put first segment of route into geometry
appendCoordinateToString(phantomNodes->startPhantom.location, descriptorState.routeGeometryString);
descriptorState.startOfSegmentCoordinate = phantomNodes->startPhantom.location;
appendCoordinateToString(phantomNodes.startPhantom.location, descriptorState.routeGeometryString);
descriptorState.startOfSegmentCoordinate = phantomNodes.startPhantom.location;
//Generate initial instruction for start of route (order of NodeIDs does not matter, its the same name anyway)
summary.startName = sEngine->GetEscapedNameForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->startPhantom.startNode);
descriptorState.lastNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->targetPhantom.startNode, phantomNodes->startPhantom.startNode);
summary.startName = sEngine.GetEscapedNameForOriginDestinationNodeID(phantomNodes.targetPhantom.startNode, phantomNodes.startPhantom.startNode);
descriptorState.lastNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.targetPhantom.startNode, phantomNodes.startPhantom.startNode);
//If we have a route, i.e. start and dest not on same edge, than get it
if(rawRoute->routeSegments[0].size() > 0)
sEngine->getCoordinatesForNodeID(rawRoute->routeSegments[0].begin()->node, descriptorState.tmpCoord);
if(rawRoute.routeSegments[0].size() > 0)
sEngine.getCoordinatesForNodeID(rawRoute.routeSegments[0].begin()->node, descriptorState.tmpCoord);
else
descriptorState.tmpCoord = phantomNodes->targetPhantom.location;
descriptorState.tmpCoord = phantomNodes.targetPhantom.location;
descriptorState.previousCoordinate = phantomNodes->startPhantom.location;
descriptorState.previousCoordinate = phantomNodes.startPhantom.location;
descriptorState.currentCoordinate = descriptorState.tmpCoord;
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.previousCoordinate, descriptorState.currentCoordinate);
if(config.instructions) {
//Get Heading
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes->startPhantom.location.lat, phantomNodes->startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
double angle = GetAngleBetweenTwoEdges(_Coordinate(phantomNodes.startPhantom.location.lat, phantomNodes.startPhantom.location.lon), descriptorState.tmpCoord, _Coordinate(descriptorState.tmpCoord.lat, descriptorState.tmpCoord.lon-1000));
getDirectionOfInstruction(angle, directionOfInstruction);
appendInstructionNameToString(summary.startName, directionOfInstruction.direction, descriptorState.routeInstructionString, true);
}
NodeID lastNodeID = UINT_MAX;
for(unsigned segmentIdx = 0; segmentIdx < rawRoute->routeSegments.size(); segmentIdx++) {
const std::vector< _PathData > & path = rawRoute->routeSegments[segmentIdx];
for(unsigned segmentIdx = 0; segmentIdx < rawRoute.routeSegments.size(); segmentIdx++) {
const std::vector< _PathData > & path = rawRoute.routeSegments[segmentIdx];
if( ! path.size() )
continue;
if ( UINT_MAX == lastNodeID) {
lastNodeID = (phantomNodes->startPhantom.startNode == (*path.begin()).node ? phantomNodes->targetPhantom.startNode : phantomNodes->startPhantom.startNode);
lastNodeID = (phantomNodes.startPhantom.startNode == (*path.begin()).node ? phantomNodes.targetPhantom.startNode : phantomNodes.startPhantom.startNode);
}
//Check, if there is overlap between current and previous route segment
//if not, than we are fine and can route over this edge without paying any special attention.
if(lastNodeID == (*path.begin()).node) {
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
lastNodeID = (lastNodeID == rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode);
lastNodeID = (lastNodeID == rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode ? rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode : rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode);
//output of the via nodes coordinates
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
appendCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
//Make a special announement to do a U-Turn.
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location);
descriptorState.distanceOfInstruction = ApproximateDistance(descriptorState.currentCoordinate, rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location);
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
tmp = "U-turn at via point";
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
double tmpDistance = descriptorState.distanceOfInstruction;
descriptorState.SetStartOfSegment(); //Set start of segment but save distance information.
descriptorState.distanceOfInstruction = tmpDistance;
} else if(segmentIdx > 0) { //We are going straight through an edge which is carrying the via point.
assert(segmentIdx != 0);
//routeInstructionString += "\nreaching via node: \n";
descriptorState.nextCoordinate = rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location;
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute->segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
descriptorState.nextCoordinate = rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location;
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.startNode, rawRoute.segmentEndCoordinates[segmentIdx].targetPhantom.startNode);
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
appendCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, descriptorState.routeGeometryString);
if(config.instructions) {
double turnAngle = descriptorState.GetAngleBetweenCoordinates();
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
getTurnDirectionOfInstruction(turnAngle, tmp);
tmp += " and reach via point";
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
//instruction to continue on the segment
appendInstructionLengthToString(ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate), descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), "Continue on", descriptorState.routeInstructionString);
//note the new segment starting coordinates
descriptorState.SetStartOfSegment();
@ -124,8 +124,8 @@ public:
}
for(vector< _PathData >::const_iterator it = path.begin(); it != path.end(); it++) {
sEngine->getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
sEngine.getCoordinatesForNodeID(it->node, descriptorState.nextCoordinate);
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(lastNodeID, it->node);
double area = fabs(0.5*( descriptorState.startOfSegmentCoordinate.lon*(descriptorState.nextCoordinate.lat - descriptorState.currentCoordinate.lat) + descriptorState.nextCoordinate.lon*(descriptorState.currentCoordinate.lat - descriptorState.startOfSegmentCoordinate.lat) + descriptorState.currentCoordinate.lon*(descriptorState.startOfSegmentCoordinate.lat - descriptorState.nextCoordinate.lat) ) );
//if route is generalization does not skip this point, add it to description
@ -135,7 +135,7 @@ public:
if( ( false == descriptorState.CurrentAndPreviousNameIDsEqual() ) && config.instructions) {
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
//note the new segment starting coordinates
descriptorState.SetStartOfSegment();
@ -149,19 +149,19 @@ public:
}
}
}
descriptorState.currentNameID = sEngine->GetNameIDForOriginDestinationNodeID(phantomNodes->startPhantom.targetNode, phantomNodes->targetPhantom.targetNode);
descriptorState.nextCoordinate = phantomNodes->targetPhantom.location;
descriptorState.currentNameID = sEngine.GetNameIDForOriginDestinationNodeID(phantomNodes.startPhantom.targetNode, phantomNodes.targetPhantom.targetNode);
descriptorState.nextCoordinate = phantomNodes.targetPhantom.location;
appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
if((false == descriptorState.CurrentAndPreviousNameIDsEqual()) && config.instructions) {
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
getTurnDirectionOfInstruction(descriptorState.GetAngleBetweenCoordinates(), tmp);
appendInstructionNameToString(sEngine->GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
appendInstructionNameToString(sEngine.GetEscapedNameForNameID(descriptorState.currentNameID), tmp, descriptorState.routeInstructionString);
descriptorState.distanceOfInstruction = 0;
}
summary.destName = sEngine->GetEscapedNameForNameID(descriptorState.currentNameID);
summary.destName = sEngine.GetEscapedNameForNameID(descriptorState.currentNameID);
descriptorState.distanceOfInstruction += ApproximateDistance(descriptorState.currentCoordinate, descriptorState.nextCoordinate);
appendCoordinateToString(phantomNodes->targetPhantom.location, descriptorState.routeGeometryString);
appendCoordinateToString(phantomNodes.targetPhantom.location, descriptorState.routeGeometryString);
appendInstructionLengthToString(descriptorState.distanceOfInstruction, descriptorState.routeInstructionString);
descriptorState.SetStartOfSegment();
//compute distance/duration for route summary
@ -191,13 +191,13 @@ public:
reply.content += "</Placemark>";
//list all viapoints so that the client may display it
std::cout << "number of segment endpoints in route: " << rawRoute->segmentEndCoordinates.size() << std::endl;
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute->segmentEndCoordinates.size()); segmentIdx++) {
std::cout << "number of segment endpoints in route: " << rawRoute.segmentEndCoordinates.size() << std::endl;
for(unsigned segmentIdx = 1; (true == config.geometry) && (segmentIdx < rawRoute.segmentEndCoordinates.size()); segmentIdx++) {
reply.content += "<Placemark>";
reply.content += "<name>Via Point 1</name>";
reply.content += "<Point>";
reply.content += "<coordinates>";
appendCoordinateToString(rawRoute->segmentEndCoordinates[segmentIdx].startPhantom.location, reply.content);
appendCoordinateToString(rawRoute.segmentEndCoordinates[segmentIdx].startPhantom.location, reply.content);
reply.content += "</coordinates>";
reply.content += "</Point>";
reply.content += "</Placemark>";

View File

@ -94,12 +94,12 @@ public:
_Coordinate startCoord(lat1, lon1);
_Coordinate targetCoord(lat2, lon2);
vector< _PathData > * path = new vector< _PathData >();
RawRouteData * rawRoute = new RawRouteData();
PhantomNodes * phantomNodes = new PhantomNodes();
vector< _PathData > path;
RawRouteData rawRoute;
PhantomNodes phantomNodes;
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
unsigned int distance = sEngine->ComputeRoute(phantomNodes, path);
rawRoute->routeSegments.push_back(*path);
rawRoute.routeSegments.push_back(path);
reply.status = http::Reply::ok;
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
std::string JSONParameter = routeParameters.options.Find("jsonp");
@ -145,7 +145,7 @@ public:
break;
}
desc->SetConfig(descriptorConfig);
desc->Run(reply, rawRoute, phantomNodes, sEngine, distance);
desc->Run(reply, rawRoute, phantomNodes, *sEngine, distance);
if("" != JSONParameter) {
reply.content += ")\n";
}
@ -193,15 +193,12 @@ public:
break;
}
delete desc;
delete path;
delete rawRoute;
delete phantomNodes;
DELETE( desc );
return;
}
private:
NodeInformationHelpDesk * nodeHelpDesk;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine;
SearchEngine<EdgeData, StaticGraph<EdgeData> > *sEngine;
std::vector<std::string> * names;
StaticGraph<EdgeData> * graph;
HashTable<std::string, unsigned> descriptorTable;

View File

@ -151,8 +151,6 @@ public:
unsigned distance = 0;
bool errorOccurredFlag = false;
double time = get_timestamp();
//#pragma omp parallel for reduction(+:distance)
for(unsigned i = 0; i < phantomNodeVector.size()-1 && !errorOccurredFlag; i++) {
@ -160,15 +158,15 @@ public:
segmentPhantomNodes.startPhantom = phantomNodeVector[i];
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
std::vector< _PathData > path;
threadData[omp_get_thread_num()]->distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(&segmentPhantomNodes, &path);
int distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(segmentPhantomNodes, path);
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment) {
if(UINT_MAX == threadData[omp_get_thread_num()]->distanceOfSegment || path.empty()) {
errorOccurredFlag = true;
cout << "Error occurred, path not found" << endl;
distance = UINT_MAX;
break;
} else {
distance += threadData[omp_get_thread_num()]->distanceOfSegment;
distance += distanceOfSegment;
}
//put segments at correct position of routes raw data
@ -176,9 +174,6 @@ public:
rawRoute.routeSegments[i] = path;
}
double time2 = get_timestamp();
// std::cout << "Finished routing after " << (time2-time) << "s" << std::endl;
time = get_timestamp();
reply.status = http::Reply::ok;
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
@ -225,14 +220,15 @@ public:
break;
}
PhantomNodes phantomNodes;
threadData[0]->sEngine->FindRoutingStarts(startCoord, targetCoord, &phantomNodes);
phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom;
phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom;
desc->SetConfig(descriptorConfig);
desc->Run(reply, &rawRoute, &phantomNodes, threadData[0]->sEngine, distance);
desc->Run(reply, rawRoute, phantomNodes, *threadData[0]->sEngine, distance);
if("" != JSONParameter) {
reply.content += ")\n";
}
reply.headers.resize(3);
reply.headers[0].name = "Content-Length";
std::string tmp;
@ -276,9 +272,6 @@ public:
break;
}
time2 = get_timestamp();
// std::cout << "Finished everything after " << (time2-time) << "s" << std::endl;
delete desc;
return;
}

View File

@ -51,7 +51,7 @@ public:
void handle_request(const Request& req, Reply& rep){
//parse command
std::string request(req.uri);
std::cout << "[r] " << request << std::endl;
//std::cout << "[r] " << request << std::endl;
std::string command;
std::size_t firstAmpPosition = request.find_first_of("&");
command = request.substr(1,firstAmpPosition-1);