performance fixes

This commit is contained in:
Dennis Luxen 2011-08-07 10:56:37 +00:00
parent a5c94c4630
commit bcb39b9e69
5 changed files with 380 additions and 401 deletions

View File

@ -32,7 +32,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <google/sparse_hash_map> #include <google/sparse_hash_map>
#include <google/sparsetable> #include <google/sparsetable>
template< typename NodeID, typename Key, bool initialize = true > template< typename NodeID, typename Key, bool initialize = false >
class ArrayStorage { class ArrayStorage {
public: public:

View File

@ -108,6 +108,7 @@ public:
} }
unsigned int ComputeRoute(PhantomNodes &phantomNodes, vector<_PathData > & path) { unsigned int ComputeRoute(PhantomNodes &phantomNodes, vector<_PathData > & path) {
bool startEdgeIsReversedInGraph = false; bool startEdgeIsReversedInGraph = false;
bool targetEdgeIsReversed = false; bool targetEdgeIsReversed = false;
@ -127,10 +128,11 @@ public:
} }
_InsertedNodes _insertedNodes; _InsertedNodes _insertedNodes;
_Heap _forwardHeap(nodeHelpDesk->getNumberOfNodes()); _Heap _forwardHeap(nodeHelpDesk->getNumberOfNodes());
_Heap _backwardHeap(nodeHelpDesk->getNumberOfNodes()); _Heap _backwardHeap(nodeHelpDesk->getNumberOfNodes());
NodeID middle = ( NodeID ) 0; NodeID middle = ( NodeID ) UINT_MAX;
if( phantomNodes.PhantomsAreOnSameEdge() ) { if( phantomNodes.PhantomsAreOnSameEdge() ) {
const EdgeData& currentEdgeData = _graph->GetEdgeData(sourceEdgeID); const EdgeData& currentEdgeData = _graph->GetEdgeData(sourceEdgeID);
@ -179,7 +181,6 @@ public:
_insertedNodes.BackInsert(phantomNodes.targetPhantom.startNode); _insertedNodes.BackInsert(phantomNodes.targetPhantom.startNode);
} }
while(_forwardHeap.Size() + _backwardHeap.Size() > 0) { while(_forwardHeap.Size() + _backwardHeap.Size() > 0) {
if ( _forwardHeap.Size() > 0 ) { if ( _forwardHeap.Size() > 0 ) {
_RoutingStep( _forwardHeap, _backwardHeap, true, &middle, &_upperbound ); _RoutingStep( _forwardHeap, _backwardHeap, true, &middle, &_upperbound );

View File

@ -140,7 +140,7 @@ public:
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) ) ); 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 //if route is generalization does not skip this point, add it to description
if( it==path.end()-1 || config.z == 19 || area >= areaThresholds[config.z] || (false == descriptorState.CurrentAndPreviousNameIDsEqual()) ) { if( config.z == 19 || area >= areaThresholds[config.z] || (false == descriptorState.CurrentAndPreviousNameIDsEqual()) ) {
//mark the beginning of the segment thats announced //mark the beginning of the segment thats announced
// appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString); // appendCoordinateToString(descriptorState.currentCoordinate, descriptorState.routeGeometryString);
polyline.push_back(descriptorState.currentCoordinate); polyline.push_back(descriptorState.currentCoordinate);

View File

@ -50,22 +50,7 @@ private:
HashTable<std::string, unsigned> descriptorTable; HashTable<std::string, unsigned> descriptorTable;
std::string pluginDescriptorString; std::string pluginDescriptorString;
struct _ThreadData { SearchEngine<EdgeData, StaticGraph<EdgeData> > * searchEngine;
SearchEngine<EdgeData, StaticGraph<EdgeData> > * sEngine;
std::vector< _PathData > * path;
unsigned distanceOfSegment;
PhantomNodes phantomNodesOfSegment;
_ThreadData(SearchEngine<EdgeData, StaticGraph<EdgeData> > * s) : sEngine(s), distanceOfSegment(0) {
path = new std::vector< _PathData >();
}
~_ThreadData() {
DELETE( path );
DELETE( sEngine );
}
};
std::vector<_ThreadData *> threadData;
public: public:
ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : pluginDescriptorString(psd) { ViaRoutePlugin(ObjectsForQueryStruct * objects, std::string psd = "viaroute") : pluginDescriptorString(psd) {
@ -73,10 +58,7 @@ public:
graph = objects->graph; graph = objects->graph;
names = objects->names; names = objects->names;
unsigned maxThreads = omp_get_max_threads(); searchEngine = new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names);
for ( unsigned threadNum = 0; threadNum < maxThreads; ++threadNum ) {
threadData.push_back( new _ThreadData( new SearchEngine<EdgeData, StaticGraph<EdgeData> >(graph, nodeHelpDesk, names)) );
}
descriptorTable.Set("", 0); //default descriptor descriptorTable.Set("", 0); //default descriptor
descriptorTable.Set("kml", 0); descriptorTable.Set("kml", 0);
@ -85,9 +67,7 @@ public:
} }
virtual ~ViaRoutePlugin() { virtual ~ViaRoutePlugin() {
for ( unsigned threadNum = 0; threadNum < threadData.size(); threadNum++ ) { DELETE( searchEngine );
DELETE( threadData[threadNum] );
}
} }
std::string GetDescriptor() { return pluginDescriptorString; } std::string GetDescriptor() { return pluginDescriptorString; }
@ -144,25 +124,22 @@ public:
vector<PhantomNode> phantomNodeVector(rawRoute.rawViaNodeCoordinates.size()); vector<PhantomNode> phantomNodeVector(rawRoute.rawViaNodeCoordinates.size());
bool errorOccurredFlag = false; bool errorOccurredFlag = false;
#pragma omp parallel for
for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); i++) { for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); i++) {
threadData[omp_get_thread_num()]->sEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]); searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
if(!rawRoute.rawViaNodeCoordinates[i].isSet()) { if(!rawRoute.rawViaNodeCoordinates[i].isSet()) {
errorOccurredFlag = true; errorOccurredFlag = true;
} }
} }
rawRoute.Resize(); rawRoute.Resize();
unsigned distance = 0; unsigned distance = 0;
//#pragma omp parallel for reduction(+:distance)
for(unsigned i = 0; i < phantomNodeVector.size()-1 && !errorOccurredFlag; i++) { for(unsigned i = 0; i < phantomNodeVector.size()-1 && !errorOccurredFlag; i++) {
PhantomNodes & segmentPhantomNodes = threadData[omp_get_thread_num()]->phantomNodesOfSegment; PhantomNodes segmentPhantomNodes;
segmentPhantomNodes.startPhantom = phantomNodeVector[i]; segmentPhantomNodes.startPhantom = phantomNodeVector[i];
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1]; segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
std::vector< _PathData > path; std::vector< _PathData > path;
unsigned distanceOfSegment = threadData[omp_get_thread_num()]->sEngine->ComputeRoute(segmentPhantomNodes, path); unsigned distanceOfSegment = searchEngine->ComputeRoute(segmentPhantomNodes, path);
if(UINT_MAX == distanceOfSegment ) { if(UINT_MAX == distanceOfSegment ) {
errorOccurredFlag = true; errorOccurredFlag = true;
@ -229,7 +206,9 @@ public:
phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom; phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom;
phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom; phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom;
desc->SetConfig(descriptorConfig); desc->SetConfig(descriptorConfig);
desc->Run(reply, rawRoute, phantomNodes, *threadData[0]->sEngine, distance);
desc->Run(reply, rawRoute, phantomNodes, *searchEngine, distance);
if("" != JSONParameter) { if("" != JSONParameter) {
reply.content += ")\n"; reply.content += ")\n";
} }

View File

@ -46,7 +46,6 @@ public:
BasePlugin * tempPointer = _pluginVector[i]; BasePlugin * tempPointer = _pluginVector[i];
DELETE( tempPointer ); DELETE( tempPointer );
} }
} }
void handle_request(const Request& req, Reply& rep){ void handle_request(const Request& req, Reply& rep){