This commit is contained in:
DennisOSRM 2011-12-31 16:19:00 +01:00
commit 44c07e9504
9 changed files with 475 additions and 485 deletions

View File

@ -81,9 +81,7 @@ private:
int edgesAdded; int edgesAdded;
int originalEdgesDeleted; int originalEdgesDeleted;
int originalEdgesAdded; int originalEdgesAdded;
_ContractionInformation() { _ContractionInformation() : edgesDeleted(0), edgesAdded(0), originalEdgesDeleted(0), originalEdgesAdded(0) {}
edgesAdded = edgesDeleted = originalEdgesAdded = originalEdgesDeleted = 0;
}
}; };
struct _NodePartitionor { struct _NodePartitionor {
@ -199,7 +197,7 @@ public:
} }
std::cout << "Contractor is using " << maxThreads << " threads" << std::endl; std::cout << "Contractor is using " << maxThreads << " threads" << std::endl;
NodeID levelID = 0; NodeID numberOfContractedNodes = 0;
std::vector< std::pair< NodeID, bool > > remainingNodes( numberOfNodes ); std::vector< std::pair< NodeID, bool > > remainingNodes( numberOfNodes );
std::vector< double > nodePriority( numberOfNodes ); std::vector< double > nodePriority( numberOfNodes );
std::vector< _PriorityData > nodeData( numberOfNodes ); std::vector< _PriorityData > nodeData( numberOfNodes );
@ -223,7 +221,7 @@ public:
} }
std::cout << "ok" << std::endl << "preprocessing ..." << std::flush; std::cout << "ok" << std::endl << "preprocessing ..." << std::flush;
while ( levelID < numberOfNodes ) { while ( numberOfContractedNodes < numberOfNodes ) {
const int last = ( int ) remainingNodes.size(); const int last = ( int ) remainingNodes.size();
#pragma omp parallel #pragma omp parallel
{ {
@ -266,7 +264,7 @@ public:
const _ImportEdge& edge = data.insertedEdges[i]; const _ImportEdge& edge = data.insertedEdges[i];
_graph->InsertEdge( edge.source, edge.target, edge.data ); _graph->InsertEdge( edge.source, edge.target, edge.data );
} }
std::vector< _ImportEdge >().swap( data.insertedEdges ); data.insertedEdges.clear();
} }
//update priorities //update priorities
#pragma omp parallel #pragma omp parallel
@ -275,14 +273,14 @@ public:
#pragma omp for schedule ( guided ) nowait #pragma omp for schedule ( guided ) nowait
for ( int position = firstIndependent ; position < last; ++position ) { for ( int position = firstIndependent ; position < last; ++position ) {
NodeID x = remainingNodes[position].first; NodeID x = remainingNodes[position].first;
_UpdateNeighbours( &nodePriority, &nodeData, data, x ); _UpdateNeighbours( nodePriority, nodeData, data, x );
} }
} }
//remove contracted nodes from the pool //remove contracted nodes from the pool
levelID += last - firstIndependent; numberOfContractedNodes += last - firstIndependent;
remainingNodes.resize( firstIndependent ); remainingNodes.resize( firstIndependent );
std::vector< std::pair< NodeID, bool > >( remainingNodes ).swap( remainingNodes ); std::vector< std::pair< NodeID, bool > >( remainingNodes ).swap( remainingNodes );
p.printStatus(levelID); p.printStatus(numberOfContractedNodes);
} }
for ( unsigned threadNum = 0; threadNum < maxThreads; threadNum++ ) { for ( unsigned threadNum = 0; threadNum < maxThreads; threadNum++ ) {
@ -313,7 +311,7 @@ public:
} }
private: private:
void _Dijkstra( const int maxDistance, const unsigned numTargets, const int maxNodes, _ThreadData* data ){ inline void _Dijkstra( const int maxDistance, const unsigned numTargets, const int maxNodes, _ThreadData* const data ){
_Heap& heap = data->heap; _Heap& heap = data->heap;
@ -367,7 +365,8 @@ private:
return edgeQuotionFactor * ((( double ) stats.edgesAdded ) / stats.edgesDeleted ) + originalQuotientFactor * ((( double ) stats.originalEdgesAdded ) / stats.originalEdgesDeleted ) + depthFactor * nodeData->depth; return edgeQuotionFactor * ((( double ) stats.edgesAdded ) / stats.edgesDeleted ) + originalQuotientFactor * ((( double ) stats.originalEdgesAdded ) / stats.originalEdgesDeleted ) + depthFactor * nodeData->depth;
} }
template< bool Simulate > bool _Contract( _ThreadData* data, NodeID node, _ContractionInformation* stats = NULL ) { template< bool Simulate >
bool _Contract( _ThreadData* data, NodeID node, _ContractionInformation* stats = NULL ) {
_Heap& heap = data->heap; _Heap& heap = data->heap;
int insertedEdgesSize = data->insertedEdges.size(); int insertedEdgesSize = data->insertedEdges.size();
std::vector< _ImportEdge >& insertedEdges = data->insertedEdges; std::vector< _ImportEdge >& insertedEdges = data->insertedEdges;
@ -491,10 +490,9 @@ private:
return true; return true;
} }
bool _UpdateNeighbours( std::vector< double >* priorities, std::vector< _PriorityData >* const nodeData, _ThreadData* const data, NodeID node ) { bool _UpdateNeighbours( std::vector< double > & priorities, std::vector< _PriorityData > & nodeData, _ThreadData* const data, NodeID node ) {
std::vector< NodeID >& neighbours = data->neighbours; std::vector< NodeID >& neighbours = data->neighbours;
neighbours.clear(); neighbours.clear();
std::vector< NodeID>().swap(neighbours);
//find all neighbours //find all neighbours
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) { for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
@ -502,7 +500,7 @@ private:
if ( u == node ) if ( u == node )
continue; continue;
neighbours.push_back( u ); neighbours.push_back( u );
( *nodeData )[u].depth = (std::max)(( *nodeData )[node].depth + 1, ( *nodeData )[u].depth ); nodeData[u].depth = (std::max)(nodeData[node].depth + 1, nodeData[u].depth );
} }
//eliminate duplicate entries ( forward + backward edges ) //eliminate duplicate entries ( forward + backward edges )
std::sort( neighbours.begin(), neighbours.end() ); std::sort( neighbours.begin(), neighbours.end() );
@ -510,7 +508,7 @@ private:
for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) { for ( int i = 0, e = ( int ) neighbours.size(); i < e; ++i ) {
const NodeID u = neighbours[i]; const NodeID u = neighbours[i];
( *priorities )[u] = _Evaluate( data, &( *nodeData )[u], u ); priorities[u] = _Evaluate( data, &( nodeData )[u], u );
} }
return true; return true;
@ -521,7 +519,6 @@ private:
std::vector< NodeID >& neighbours = data->neighbours; std::vector< NodeID >& neighbours = data->neighbours;
neighbours.clear(); neighbours.clear();
std::vector< NodeID>().swap(neighbours);
for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) { for ( _DynamicGraph::EdgeIterator e = _graph->BeginEdges( node ) ; e < _graph->EndEdges( node ) ; ++e ) {
const NodeID target = _graph->GetTarget( e ); const NodeID target = _graph->GetTarget( e );

View File

@ -104,7 +104,7 @@ void EdgeBasedGraphFactory::Run() {
std::vector<_Restriction>::iterator restrictionIterator = inputRestrictions.begin(); std::vector<_Restriction>::iterator restrictionIterator = inputRestrictions.begin();
Percent p(_nodeBasedGraph->GetNumberOfNodes()); Percent p(_nodeBasedGraph->GetNumberOfNodes());
int numberOfResolvedRestrictions(0); int numberOfSkippedTurns(0);
int nodeBasedEdgeCounter(0); int nodeBasedEdgeCounter(0);
NodeID onlyToNode(0); NodeID onlyToNode(0);
@ -122,6 +122,7 @@ void EdgeBasedGraphFactory::Run() {
//Check every turn restriction originating from this edge if it is an 'only_*'-turn. //Check every turn restriction originating from this edge if it is an 'only_*'-turn.
if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) { if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) {
//copying iterator, so we can loop over restrictions without forgetting currect position.
std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator; std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator;
do { do {
if(v == secondRestrictionIterator->viaNode) { if(v == secondRestrictionIterator->viaNode) {
@ -161,12 +162,13 @@ void EdgeBasedGraphFactory::Run() {
for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) { for(_NodeBasedDynamicGraph::EdgeIterator e2 = _nodeBasedGraph->BeginEdges(v); e2 < _nodeBasedGraph->EndEdges(v); ++e2) {
_NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2); _NodeBasedDynamicGraph::NodeIterator w = _nodeBasedGraph->GetTarget(e2);
//if (u,v,w) is a forbidden turn, continue //if (u,v,w) is a forbidden turn, continue
bool isTurnRestricted(false);
if(isOnlyAllowed && w != onlyToNode) { if(isOnlyAllowed && w != onlyToNode) {
// INFO("skipped turn <" << u << "," << v << "," << w << ">, only allowing <" << u << "," << v << "," << onlyToNode << ">"); //We are at an only_-restriction but not at the right turn.
++numberOfSkippedTurns;
continue; continue;
} }
bool isTurnRestricted(false);
if( u != w ) { //only add an edge if turn is not a U-turn if( u != w ) { //only add an edge if turn is not a U-turn
if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) { if(restrictionIterator != inputRestrictions.end() && u == restrictionIterator->fromNode) {
std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator; std::vector<_Restriction>::iterator secondRestrictionIterator = restrictionIterator;
@ -227,7 +229,7 @@ void EdgeBasedGraphFactory::Run() {
edgeBasedNodes.push_back(currentNode); edgeBasedNodes.push_back(currentNode);
} }
} else { } else {
++numberOfResolvedRestrictions; ++numberOfSkippedTurns;
} }
} }
} }
@ -238,7 +240,7 @@ void EdgeBasedGraphFactory::Run() {
edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() ); edgeBasedNodes.erase( std::unique(edgeBasedNodes.begin(), edgeBasedNodes.end()), edgeBasedNodes.end() );
INFO("Node-based graph contains " << nodeBasedEdgeCounter << " edges"); INFO("Node-based graph contains " << nodeBasedEdgeCounter << " edges");
INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << (double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter); INFO("Edge-based graph contains " << edgeBasedEdges.size() << " edges, blowup is " << (double)edgeBasedEdges.size()/(double)nodeBasedEdgeCounter);
INFO("Edge-based graph obeys " << numberOfResolvedRestrictions << " turn restrictions, " << (inputRestrictions.size() - numberOfResolvedRestrictions )<< " skipped."); INFO("Edge-based graph skipped " << numberOfSkippedTurns << " turns, defined by " << inputRestrictions.size() << " restrictions.");
INFO("Generated " << edgeBasedNodes.size() << " edge based nodes"); INFO("Generated " << edgeBasedNodes.size() << " edge based nodes");
} }

View File

@ -59,7 +59,7 @@ public:
void printIncrement() void printIncrement()
{ {
#pragma omp atomic #pragma omp atomic
_current_value++; ++_current_value;
printStatus(_current_value); printStatus(_current_value);
} }
private: private:

View File

@ -33,8 +33,8 @@ public:
BasePlugin() { } BasePlugin() { }
//Maybe someone can explain the pure virtual destructor thing to me (dennis) //Maybe someone can explain the pure virtual destructor thing to me (dennis)
virtual ~BasePlugin() { } virtual ~BasePlugin() { }
virtual std::string GetDescriptor() = 0; virtual std::string GetDescriptor() const = 0;
virtual std::string GetVersionString() = 0; virtual std::string GetVersionString() const = 0 ;
virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0; virtual void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) = 0;
}; };

View File

@ -17,7 +17,9 @@ class HelloWorldPlugin : public BasePlugin {
public: public:
HelloWorldPlugin() {} HelloWorldPlugin() {}
virtual ~HelloWorldPlugin() { /*std::cout << GetDescriptor() << " destructor" << std::endl;*/ } virtual ~HelloWorldPlugin() { /*std::cout << GetDescriptor() << " destructor" << std::endl;*/ }
std::string GetDescriptor() { return std::string("hello"); } std::string GetDescriptor() const { return std::string("hello"); }
std::string GetVersionString() const { return std::string("0.1a"); }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
std::cout << "[hello world]: runnning handler" << std::endl; std::cout << "[hello world]: runnning handler" << std::endl;
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
@ -36,7 +38,6 @@ public:
reply.content.append(content.str()); reply.content.append(content.str());
reply.content.append("</body></html>"); reply.content.append("</body></html>");
} }
std::string GetVersionString() { return std::string("0.1a"); }
}; };
#endif /* HELLOWORLDPLUGIN_H_ */ #endif /* HELLOWORLDPLUGIN_H_ */

View File

@ -37,8 +37,8 @@ public:
LocatePlugin(ObjectsForQueryStruct * objects) { LocatePlugin(ObjectsForQueryStruct * objects) {
nodeHelpDesk = objects->nodeHelpDesk; nodeHelpDesk = objects->nodeHelpDesk;
} }
std::string GetDescriptor() { return std::string("locate"); } std::string GetDescriptor() const { return std::string("locate"); }
std::string GetVersionString() { return std::string("0.3 (DL)"); } std::string GetVersionString() const { return std::string("0.3 (DL)"); }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
//check number of parameters //check number of parameters
if(routeParameters.parameters.size() != 2) { if(routeParameters.parameters.size() != 2) {

View File

@ -43,8 +43,8 @@ public:
descriptorTable.Set("kml", 0); descriptorTable.Set("kml", 0);
descriptorTable.Set("json", 1); descriptorTable.Set("json", 1);
} }
std::string GetDescriptor() { return std::string("nearest"); } std::string GetDescriptor() const { return std::string("nearest"); }
std::string GetVersionString() { return std::string("0.3 (DL)"); } std::string GetVersionString() const { return std::string("0.3 (DL)"); }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
//check number of parameters //check number of parameters
if(routeParameters.parameters.size() != 2) { if(routeParameters.parameters.size() != 2) {

View File

@ -22,10 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
#define RAWROUTEDATA_H_ #define RAWROUTEDATA_H_
struct RawRouteData { struct RawRouteData {
void Resize() {
unsigned size = rawViaNodeCoordinates.size()-1;
segmentEndCoordinates.resize(size);
}
std::vector< _PathData > computedRouted; std::vector< _PathData > computedRouted;
std::vector< PhantomNodes > segmentEndCoordinates; std::vector< PhantomNodes > segmentEndCoordinates;
std::vector< _Coordinate > rawViaNodeCoordinates; std::vector< _Coordinate > rawViaNodeCoordinates;

View File

@ -68,8 +68,8 @@ public:
DELETE( searchEngine ); DELETE( searchEngine );
} }
std::string GetDescriptor() { return pluginDescriptorString; } std::string GetDescriptor() const { return pluginDescriptorString; }
std::string GetVersionString() { return std::string("0.3 (DL)"); } std::string GetVersionString() const { return std::string("0.3 (DL)"); }
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) { void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
//check number of parameters //check number of parameters
if(0 == routeParameters.options["start"].size() || 0 == routeParameters.options["dest"].size() ) { if(0 == routeParameters.options["start"].size() || 0 == routeParameters.options["dest"].size() ) {
@ -109,7 +109,7 @@ public:
} }
int vialat = static_cast<int>(100000.*atof(textCoord[0].c_str())); int vialat = static_cast<int>(100000.*atof(textCoord[0].c_str()));
int vialon = static_cast<int>(100000.*atof(textCoord[1].c_str())); int vialon = static_cast<int>(100000.*atof(textCoord[1].c_str()));
INFO("[debug] via" << i << ": " << vialat << "," << vialon); // INFO("[debug] via" << i << ": " << vialat << "," << vialon);
_Coordinate viaCoord(vialat, vialon); _Coordinate viaCoord(vialat, vialon);
if(false == checkCoord(viaCoord)) { if(false == checkCoord(viaCoord)) {
reply = http::Reply::stockReply(http::Reply::badRequest); reply = http::Reply::stockReply(http::Reply::badRequest);
@ -124,8 +124,6 @@ public:
searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]); searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
} }
rawRoute.Resize();
unsigned distance = 0; unsigned distance = 0;
//single route or via point routing //single route or via point routing
if(0 == routeParameters.viaPoints.size()) { if(0 == routeParameters.viaPoints.size()) {
@ -133,23 +131,16 @@ public:
segmentPhantomNodes.startPhantom = phantomNodeVector[0]; segmentPhantomNodes.startPhantom = phantomNodeVector[0];
segmentPhantomNodes.targetPhantom = phantomNodeVector[1]; segmentPhantomNodes.targetPhantom = phantomNodeVector[1];
distance = searchEngine->ComputeRoute(segmentPhantomNodes, rawRoute.computedRouted); distance = searchEngine->ComputeRoute(segmentPhantomNodes, rawRoute.computedRouted);
rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes);
//put segments at correct position of routes raw data
rawRoute.segmentEndCoordinates[0] = (segmentPhantomNodes);
} else { } else {
//Getting the shortest via path is a dynamic programming problem and is solved as such. //Getting the shortest via path is a dynamic programming problem and is solved as such.
std::vector<PhantomNodes> phantomNodes;
for(unsigned i = 0; i < phantomNodeVector.size()-1; ++i) { for(unsigned i = 0; i < phantomNodeVector.size()-1; ++i) {
PhantomNodes segmentPhantomNodes; PhantomNodes segmentPhantomNodes;
segmentPhantomNodes.startPhantom = phantomNodeVector[i]; segmentPhantomNodes.startPhantom = phantomNodeVector[i];
segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1]; segmentPhantomNodes.targetPhantom = phantomNodeVector[i+1];
phantomNodes.push_back(segmentPhantomNodes); rawRoute.segmentEndCoordinates.push_back(segmentPhantomNodes);
} }
distance = searchEngine->ComputeViaRoute(phantomNodes, rawRoute.computedRouted); distance = searchEngine->ComputeViaRoute(rawRoute.segmentEndCoordinates, rawRoute.computedRouted);
//put segments at correct position of routes raw data
// rawRoute.segmentEndCoordinates[i] = (segmentPhantomNodes);
// rawRoute.routeSegments[i] = path;
} }
if(INT_MAX == distance ) { if(INT_MAX == distance ) {
DEBUG( "Error occurred, single path not found" ); DEBUG( "Error occurred, single path not found" );
@ -199,7 +190,10 @@ public:
PhantomNodes phantomNodes; PhantomNodes phantomNodes;
phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom; phantomNodes.startPhantom = rawRoute.segmentEndCoordinates[0].startPhantom;
// INFO("Start location: " << phantomNodes.startPhantom.location)
phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom; phantomNodes.targetPhantom = rawRoute.segmentEndCoordinates[rawRoute.segmentEndCoordinates.size()-1].targetPhantom;
// INFO("TargetLocation: " << phantomNodes.targetPhantom.location);
// INFO("Number of segments: " << rawRoute.segmentEndCoordinates.size());
desc->SetConfig(descriptorConfig); desc->SetConfig(descriptorConfig);
desc->Run(reply, rawRoute, phantomNodes, *searchEngine, distance); desc->Run(reply, rawRoute, phantomNodes, *searchEngine, distance);