Bugfixes, plus safe delete, less pointers and speed back on track
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
};
|
||||
+59
-64
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user