Merge branch 'master' of

https://DennisOSRM@github.com/DennisOSRM/Project-OSRM.git
This commit is contained in:
DennisOSRM 2012-02-23 16:29:55 +01:00
commit a88ad71be6
15 changed files with 570 additions and 578 deletions

View File

@ -39,7 +39,7 @@ class DouglasPeucker {
private: private:
typedef std::pair<std::size_t, std::size_t> PairOfPoints; typedef std::pair<std::size_t, std::size_t> PairOfPoints;
//Stack to simulate the recursion //Stack to simulate the recursion
SimpleStack<PairOfPoints > recursionStack; std::stack<PairOfPoints > recursionStack;
double ComputeDistanceOfPointToLine(const _Coordinate& inputPoint, const _Coordinate& source, const _Coordinate& target) { double ComputeDistanceOfPointToLine(const _Coordinate& inputPoint, const _Coordinate& source, const _Coordinate& target) {
double r; double r;
@ -81,7 +81,7 @@ public:
std::size_t leftBorderOfRange = 0; std::size_t leftBorderOfRange = 0;
std::size_t rightBorderOfRange = 1; std::size_t rightBorderOfRange = 1;
//Sweep linerarily over array and identify those ranges that need to be checked //Sweep linerarily over array and identify those ranges that need to be checked
recursionStack.hint(inputVector.size()); // recursionStack.hint(inputVector.size());
do { do {
assert(inputVector[leftBorderOfRange].necessary); assert(inputVector[leftBorderOfRange].necessary);
assert(inputVector[inputVector.size()-1].necessary); assert(inputVector[inputVector.size()-1].necessary);

View File

@ -98,7 +98,7 @@ private:
public: public:
template< class InputEdge > template< class InputEdge >
Contractor( int nodes, std::vector< InputEdge >& inputEdges, const double eqf = 8.4, const double oqf = 4.1, const double df = 3.) Contractor( int nodes, std::vector< InputEdge >& inputEdges, const double eqf = 2, const double oqf = 2, const double df = 1)
: edgeQuotionFactor(eqf), originalQuotientFactor(oqf), depthFactor(df) { : edgeQuotionFactor(eqf), originalQuotientFactor(oqf), depthFactor(df) {
std::vector< _ImportEdge > edges; std::vector< _ImportEdge > edges;
edges.reserve( 2 * inputEdges.size() ); edges.reserve( 2 * inputEdges.size() );
@ -213,12 +213,13 @@ public:
_ThreadData* data = threadData[omp_get_thread_num()]; _ThreadData* data = threadData[omp_get_thread_num()];
#pragma omp parallel for schedule ( guided ) #pragma omp parallel for schedule ( guided )
for ( int x = 0; x < ( int ) numberOfNodes; ++x ) { for ( int x = 0; x < ( int ) numberOfNodes; ++x ) {
nodePriority[x] = _Evaluate( data, &nodeData[x], x ); nodePriority[x] = _Evaluate( data, &nodeData[x], x, false );
} }
} }
std::cout << "ok" << std::endl << "preprocessing ..." << std::flush; std::cout << "ok" << std::endl << "preprocessing ..." << std::flush;
while ( numberOfContractedNodes < numberOfNodes ) { while ( numberOfContractedNodes < numberOfNodes ) {
bool topOnePercent = (numberOfNodes - numberOfContractedNodes) > 0.01*numberOfNodes;
const int last = ( int ) remainingNodes.size(); const int last = ( int ) remainingNodes.size();
#pragma omp parallel #pragma omp parallel
{ {
@ -240,7 +241,10 @@ 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;
_Contract< false > ( data, x ); if(topOnePercent)
_Contract< false, true > ( data, x );
else
_Contract< false, false > ( data, x );
nodePriority[x] = -1; nodePriority[x] = -1;
} }
std::sort( data->insertedEdges.begin(), data->insertedEdges.end() ); std::sort( data->insertedEdges.begin(), data->insertedEdges.end() );
@ -259,6 +263,19 @@ public:
_ThreadData& data = *threadData[threadNum]; _ThreadData& data = *threadData[threadNum];
for ( int i = 0; i < ( int ) data.insertedEdges.size(); ++i ) { for ( int i = 0; i < ( int ) data.insertedEdges.size(); ++i ) {
const _ImportEdge& edge = data.insertedEdges[i]; const _ImportEdge& edge = data.insertedEdges[i];
_DynamicGraph::EdgeIterator currentEdgeID = _graph->FindEdge(edge.source, edge.target);
if(currentEdgeID != _graph->EndEdges(edge.source)) {
_DynamicGraph::EdgeData & currentEdgeData = _graph->GetEdgeData(currentEdgeID);
if(edge.data.forward == currentEdgeData.forward && edge.data.backward == currentEdgeData.backward ) {
if(_graph->GetEdgeData(_graph->FindEdge(edge.source, edge.target)).distance <= edge.data.distance) {
continue;
}
if(currentEdgeData.distance > edge.data.distance) {
currentEdgeData.distance = edge.data.distance;
continue;
}
}
}
_graph->InsertEdge( edge.source, edge.target, edge.data ); _graph->InsertEdge( edge.source, edge.target, edge.data );
} }
data.insertedEdges.clear(); data.insertedEdges.clear();
@ -270,7 +287,7 @@ 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, topOnePercent );
} }
} }
//remove contracted nodes from the pool //remove contracted nodes from the pool
@ -308,7 +325,7 @@ public:
} }
private: private:
inline void _Dijkstra( const int maxDistance, const unsigned numTargets, const int maxNodes, const short hopLimit, _ThreadData* const data ){ inline void _Dijkstra( const int maxDistance, const unsigned numTargets, const int maxNodes, const int hopLimit, _ThreadData* const data ){
_Heap& heap = data->heap; _Heap& heap = data->heap;
@ -355,11 +372,14 @@ private:
} }
} }
double _Evaluate( _ThreadData* const data, _PriorityData* const nodeData, NodeID node ){ double _Evaluate( _ThreadData* const data, _PriorityData* const nodeData, NodeID node, bool topOnePercent ){
_ContractionInformation stats; _ContractionInformation stats;
//perform simulated contraction //perform simulated contraction
_Contract< true > ( data, node, &stats ); if(topOnePercent)
_Contract< true, true > ( data, node, &stats );
else
_Contract< true, false > ( data, node, &stats );
// Result will contain the priority // Result will contain the priority
if ( stats.edgesDeleted == 0 || stats.originalEdgesDeleted == 0 ) if ( stats.edgesDeleted == 0 || stats.originalEdgesDeleted == 0 )
@ -367,7 +387,7 @@ 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 > template< bool Simulate, bool topOnePercent >
bool _Contract( _ThreadData* data, NodeID node, _ContractionInformation* stats = NULL ) { 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();
@ -407,9 +427,9 @@ private:
} }
if( Simulate ) if( Simulate )
_Dijkstra( maxDistance, numTargets, 1000, 5, data ); _Dijkstra( maxDistance, numTargets, 1000, (true ? INT_MAX : 5), data );
else else
_Dijkstra( maxDistance, numTargets, 2000, 7, data ); _Dijkstra( maxDistance, numTargets, 2000, (true ? INT_MAX : 7), data );
for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) { for ( _DynamicGraph::EdgeIterator outEdge = _graph->BeginEdges( node ), endOutEdges = _graph->EndEdges( node ); outEdge != endOutEdges; ++outEdge ) {
const _EdgeBasedContractorEdgeData& outData = _graph->GetEdgeData( outEdge ); const _EdgeBasedContractorEdgeData& outData = _graph->GetEdgeData( outEdge );
@ -477,12 +497,12 @@ private:
neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() ); neighbours.resize( std::unique( neighbours.begin(), neighbours.end() ) - neighbours.begin() );
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];
_graph->DeleteEdgesTo( neighbours[i], node ); _graph->DeleteEdgesTo( neighbours[i], node );
} }
} }
bool _UpdateNeighbours( std::vector< double > & priorities, std::vector< _PriorityData > & nodeData, _ThreadData* const data, NodeID node ) { bool _UpdateNeighbours( std::vector< double > & priorities, std::vector< _PriorityData > & nodeData, _ThreadData* const data, NodeID node, bool topOnePercent ) {
std::vector< NodeID >& neighbours = data->neighbours; std::vector< NodeID >& neighbours = data->neighbours;
neighbours.clear(); neighbours.clear();
@ -501,7 +521,7 @@ private:
int neighbourSize = ( int ) neighbours.size(); int neighbourSize = ( int ) neighbours.size();
for ( int i = 0, e = neighbourSize; i < e; ++i ) { for ( int i = 0, e = neighbourSize; 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, topOnePercent );
} }
return true; return true;

View File

@ -312,7 +312,7 @@ short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const N
//If street names stay the same and if we are certain that it is not a roundabout, we skip it. //If street names stay the same and if we are certain that it is not a roundabout, we skip it.
if( (data1.nameID == data2.nameID) && (0 != data1.nameID)) if( (data1.nameID == data2.nameID) && (0 != data1.nameID))
return TurnInstructions.NoTurn; return TurnInstructions.NoTurn;
if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) == 1) ) if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) )
return TurnInstructions.NoTurn; return TurnInstructions.NoTurn;
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);

View File

@ -151,19 +151,19 @@ public:
//run two-Target Dijkstra routing step. //run two-Target Dijkstra routing step.
while(_forwardHeap->Size() + _backwardHeap->Size() > 0){ while(_forwardHeap->Size() + _backwardHeap->Size() > 0){
if(_forwardHeap->Size() > 0){ if(_forwardHeap->Size() > 0){
_RoutingStep(_forwardHeap, _backwardHeap, true, &middle1, &_localUpperbound1, 2*offset); _RoutingStep<true>(_forwardHeap, _backwardHeap, &middle1, &_localUpperbound1, 2*offset);
} }
if(_backwardHeap->Size() > 0){ if(_backwardHeap->Size() > 0){
_RoutingStep(_backwardHeap, _forwardHeap, false, &middle1, &_localUpperbound1, 2*offset); _RoutingStep<false>(_backwardHeap, _forwardHeap, &middle1, &_localUpperbound1, 2*offset);
} }
} }
if(_backwardHeap2->Size() > 0) { if(_backwardHeap2->Size() > 0) {
while(_forwardHeap2->Size() + _backwardHeap2->Size() > 0){ while(_forwardHeap2->Size() + _backwardHeap2->Size() > 0){
if(_forwardHeap2->Size() > 0){ if(_forwardHeap2->Size() > 0){
_RoutingStep(_forwardHeap2, _backwardHeap2, true, &middle2, &_localUpperbound2, 2*offset); _RoutingStep<true>(_forwardHeap2, _backwardHeap2, &middle2, &_localUpperbound2, 2*offset);
} }
if(_backwardHeap2->Size() > 0){ if(_backwardHeap2->Size() > 0){
_RoutingStep(_backwardHeap2, _forwardHeap2, false, &middle2, &_localUpperbound2, 2*offset); _RoutingStep<false>(_backwardHeap2, _forwardHeap2, &middle2, &_localUpperbound2, 2*offset);
} }
} }
} }
@ -324,16 +324,14 @@ public:
} }
int offset = (phantomNodes.startPhantom.isBidirected() ? std::max(phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.weight2) : phantomNodes.startPhantom.weight1) ; int offset = (phantomNodes.startPhantom.isBidirected() ? std::max(phantomNodes.startPhantom.weight1, phantomNodes.startPhantom.weight2) : phantomNodes.startPhantom.weight1) ;
offset += (phantomNodes.targetPhantom.isBidirected() ? std::max(phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.weight2) : phantomNodes.targetPhantom.weight1) ; offset += (phantomNodes.targetPhantom.isBidirected() ? std::max(phantomNodes.targetPhantom.weight1, phantomNodes.targetPhantom.weight2) : phantomNodes.targetPhantom.weight1) ;
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, 2*offset); _RoutingStep<true>(_forwardHeap, _backwardHeap, &middle, &_upperbound, 2*offset);
} }
if(_backwardHeap->Size() > 0){ if(_backwardHeap->Size() > 0){
_RoutingStep(_backwardHeap, _forwardHeap, false, &middle, &_upperbound, 2*offset); _RoutingStep<false>(_backwardHeap, _forwardHeap, &middle, &_upperbound, 2*offset);
} }
} }
// INFO("dist: " << _upperbound); // INFO("dist: " << _upperbound);
if ( _upperbound == INT_MAX ) { if ( _upperbound == INT_MAX ) {
return _upperbound; return _upperbound;
@ -341,7 +339,6 @@ public:
std::deque<NodeID> packedPath; std::deque<NodeID> packedPath;
_RetrievePackedPathFromHeap(_forwardHeap, _backwardHeap, middle, packedPath); _RetrievePackedPathFromHeap(_forwardHeap, _backwardHeap, middle, packedPath);
//Setting weights to correspond with that of the actual chosen path //Setting weights to correspond with that of the actual chosen path
if(packedPath[0] == phantomNodes.startPhantom.edgeBasedNode && phantomNodes.startPhantom.isBidirected()) { if(packedPath[0] == phantomNodes.startPhantom.edgeBasedNode && phantomNodes.startPhantom.isBidirected()) {
// INFO("Setting weight1=" << phantomNodes.startPhantom.weight1 << " to that of weight2=" << phantomNodes.startPhantom.weight2); // INFO("Setting weight1=" << phantomNodes.startPhantom.weight1 << " to that of weight2=" << phantomNodes.startPhantom.weight2);
@ -414,8 +411,8 @@ private:
// std::cout << std::endl; // std::cout << std::endl;
} }
template<bool forwardDirection>
inline void _RoutingStep(HeapPtr & _forwardHeap, HeapPtr & _backwardHeap, const bool & forwardDirection, NodeID *middle, int *_upperbound, const int edgeBasedOffset) const { inline void _RoutingStep(HeapPtr & _forwardHeap, HeapPtr & _backwardHeap, NodeID *middle, int *_upperbound, const int edgeBasedOffset) const {
const NodeID node = _forwardHeap->DeleteMin(); const NodeID node = _forwardHeap->DeleteMin();
const int distance = _forwardHeap->GetKey(node); const int distance = _forwardHeap->GetKey(node);
// INFO((forwardDirection ? "[forw]" : "[back]") << " settled node " << node << " at distance " << distance); // INFO((forwardDirection ? "[forw]" : "[back]") << " settled node " << node << " at distance " << distance);
@ -485,7 +482,7 @@ private:
inline void _UnpackPath(std::deque<NodeID> & packedPath, std::vector<_PathData> & unpackedPath) const { inline void _UnpackPath(std::deque<NodeID> & packedPath, std::vector<_PathData> & unpackedPath) const {
const unsigned sizeOfPackedPath = packedPath.size(); const unsigned sizeOfPackedPath = packedPath.size();
SimpleStack<std::pair<NodeID, NodeID> > recursionStack(sizeOfPackedPath); std::stack<std::pair<NodeID, NodeID> > recursionStack;
//We have to push the path in reverse order onto the stack because it's LIFO. //We have to push the path in reverse order onto the stack because it's LIFO.
for(unsigned i = sizeOfPackedPath-1; i > 0; --i){ for(unsigned i = sizeOfPackedPath-1; i > 0; --i){

View File

@ -67,7 +67,6 @@ public:
} }
descriptionFactory.Run(config.z, durationOfTrip); descriptionFactory.Run(config.z, durationOfTrip);
reply.content += "\"route_summary\": {" reply.content += "\"route_summary\": {"
"\"total_distance\":"; "\"total_distance\":";
reply.content += descriptionFactory.summary.lengthString; reply.content += descriptionFactory.summary.lengthString;
@ -107,9 +106,9 @@ public:
roundAbout.nameID = segment.nameID; roundAbout.nameID = segment.nameID;
roundAbout.startIndex = prefixSumOfNecessarySegments; roundAbout.startIndex = prefixSumOfNecessarySegments;
} else { } else {
if(0 != prefixSumOfNecessarySegments) if(0 != prefixSumOfNecessarySegments){
reply.content += ","; reply.content += ",";
}
reply.content += "[\""; reply.content += "[\"";
if(TurnInstructions.LeaveRoundAbout == segment.turnInstruction) { if(TurnInstructions.LeaveRoundAbout == segment.turnInstruction) {
reply.content += TurnInstructions.TurnStrings[TurnInstructions.EnterRoundAbout]; reply.content += TurnInstructions.TurnStrings[TurnInstructions.EnterRoundAbout];

View File

@ -29,7 +29,7 @@
//====================== //======================
// OBJECTS // OBJECTS
//Map //Map
var HOST_ROUTING_URL = 'http://141.3.24.68:5000/viaroute'; var HOST_ROUTING_URL = 'http://141.3.24.240:5000/viaroute';
//var HOST_ROUTING_URL = 'http://routingdemo.geofabrik.de/route-via/'; //var HOST_ROUTING_URL = 'http://routingdemo.geofabrik.de/route-via/';
var HOST_WEBSITE = 'http://map.project-osrm.org/';//location.host var HOST_WEBSITE = 'http://map.project-osrm.org/';//location.host

View File

@ -26,7 +26,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include "ObjectForPluginStruct.h" #include "ObjectForPluginStruct.h"
#include "BasePlugin.h" #include "BasePlugin.h"
#include "RouteParameters.h" #include "RouteParameters.h"
#include "../Util/StringUtil.h"
#include "../DataStructures/NodeInformationHelpDesk.h" #include "../DataStructures/NodeInformationHelpDesk.h"
/* /*
@ -57,33 +57,47 @@ public:
_Coordinate result; _Coordinate result;
nodeHelpDesk->FindNearestNodeCoordForLatLon(_Coordinate(lat, lon), result); nodeHelpDesk->FindNearestNodeCoordForLatLon(_Coordinate(lat, lon), result);
std::string tmp;
std::string JSONParameter;
//json
JSONParameter = routeParameters.options.Find("jsonp");
if("" != JSONParameter) {
reply.content += JSONParameter;
reply.content += "(";
}
//Write to stream //Write to stream
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
reply.content.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); reply.content += ("{");
reply.content.append("<kml xmlns=\"http://www.opengis.net/kml/2.2\">"); reply.content += ("\"version\":0.3,");
reply.content.append("<Placemark>"); reply.content += ("\"status\":0,");
reply.content += ("\"result\":");
std::stringstream out1; convertInternalLatLonToString(result.lat, tmp);
out1 << setprecision(10); reply.content += "[";
out1 << "<name>Nearest Place in map to " << lat/100000. << "," << lon/100000. << "</name>"; reply.content += tmp;
reply.content.append(out1.str()); convertInternalLatLonToString(result.lon, tmp);
reply.content.append("<Point>"); reply.content += ", ";
reply.content += tmp;
std::stringstream out2; reply.content += "]";
out2 << setprecision(10); reply.content += ",\"transactionId\": \"OSRM Routing Engine JSON Locate (v0.3)\"";
out2 << "<coordinates>" << result.lon / 100000. << "," << result.lat / 100000. << "</coordinates>"; reply.content += ("}");
reply.content.append(out2.str());
reply.content.append("</Point>");
reply.content.append("</Placemark>");
reply.content.append("</kml>");
reply.headers.resize(3); reply.headers.resize(3);
reply.headers[0].name = "Content-Length"; if("" != JSONParameter) {
reply.headers[0].value = boost::lexical_cast<std::string>(reply.content.size()); reply.content += ")";
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/vnd.google-earth.kml+xml"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"placemark.kml\""; reply.headers[2].value = "attachment; filename=\"location.js\"";
} else {
reply.headers[1].name = "Content-Type";
reply.headers[1].value = "application/x-javascript";
reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"location.json\"";
}
reply.headers[0].name = "Content-Length";
intToString(reply.content.size(), tmp);
reply.headers[0].value = tmp;
return; return;
} }
private: private:

View File

@ -62,40 +62,34 @@ public:
//query to helpdesk //query to helpdesk
_Coordinate result; _Coordinate result;
nodeHelpDesk->FindNearestPointOnEdge(_Coordinate(lat, lon), result); nodeHelpDesk->FindNearestPointOnEdge(_Coordinate(lat, lon), result);
unsigned descriptorType = descriptorTable[routeParameters.options.Find("output")];
std::stringstream out1;
std::stringstream out2;
std::string tmp; std::string tmp;
std::string JSONParameter; std::string JSONParameter;
switch(descriptorType){
case 1:
//json //json
JSONParameter = routeParameters.options.Find("jsonp"); JSONParameter = routeParameters.options.Find("jsonp");
if("" != JSONParameter) { if("" != JSONParameter) {
reply.content += JSONParameter; reply.content += JSONParameter;
reply.content += "(\n"; reply.content += "(";
} }
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
reply.content += ("{"); reply.content += ("{");
reply.content += ("\"version\":0.3,"); reply.content += ("\"version\":0.3,");
reply.content += ("\"status\":0,"); reply.content += ("\"status\":0,");
reply.content += ("\"status_message\":"); reply.content += ("\"result\":");
out1 << setprecision(10); convertInternalLatLonToString(result.lat, tmp);
out1 << "\"Nearest Place in map to " << lat/100000. << "," << lon/100000. << "\","; reply.content += "[";
reply.content.append(out1.str()); reply.content += tmp;
reply.content += ("\"coordinate\": "); convertInternalLatLonToString(result.lon, tmp);
out2 << setprecision(10); reply.content += ", ";
out2 << "[" << result.lat / 100000. << "," << result.lon / 100000. << "]"; reply.content += tmp;
reply.content.append(out2.str()); reply.content += "]";
reply.content += ",\"transactionId\": \"OSRM Routing Engine JSON Nearest (v0.3)\"";
reply.content += ("}"); reply.content += ("}");
reply.headers.resize(3); reply.headers.resize(3);
reply.headers[0].name = "Content-Length"; if("" != JSONParameter) {
intToString(reply.content.size(), tmp); reply.content += ")";
reply.headers[0].value = tmp;if("" != JSONParameter) {
reply.content += ")\n";
reply.headers[1].name = "Content-Type"; reply.headers[1].name = "Content-Type";
reply.headers[1].value = "text/javascript"; reply.headers[1].value = "text/javascript";
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
@ -106,38 +100,9 @@ public:
reply.headers[2].name = "Content-Disposition"; reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"location.json\""; reply.headers[2].value = "attachment; filename=\"location.json\"";
} }
break;
default:
reply.status = http::Reply::ok;
//Write to stream
reply.content.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
reply.content.append("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
reply.content.append("<Placemark>");
out1 << setprecision(10);
out1 << "<name>Nearest Place in map to " << lat/100000. << "," << lon/100000. << "</name>";
reply.content.append(out1.str());
reply.content.append("<Point>");
out2 << setprecision(10);
out2 << "<coordinates>" << result.lon / 100000. << "," << result.lat / 100000. << "</coordinates>";
reply.content.append(out2.str());
reply.content.append("</Point>");
reply.content.append("</Placemark>");
reply.content.append("</kml>");
reply.headers.resize(3);
reply.headers[0].name = "Content-Length"; reply.headers[0].name = "Content-Length";
reply.headers[0].value = boost::lexical_cast<std::string>(reply.content.size()); intToString(reply.content.size(), tmp);
reply.headers[1].name = "Content-Type"; reply.headers[0].value = tmp;
reply.headers[1].value = "application/vnd.google-earth.kml+xml";
reply.headers[2].name = "Content-Disposition";
reply.headers[2].value = "attachment; filename=\"placemark.kml\"";
break;
}
} }
private: private:
NodeInformationHelpDesk * nodeHelpDesk; NodeInformationHelpDesk * nodeHelpDesk;

View File

@ -119,14 +119,12 @@ public:
} }
rawRoute.rawViaNodeCoordinates.push_back(targetCoord); rawRoute.rawViaNodeCoordinates.push_back(targetCoord);
vector<PhantomNode> phantomNodeVector(rawRoute.rawViaNodeCoordinates.size()); vector<PhantomNode> phantomNodeVector(rawRoute.rawViaNodeCoordinates.size());
for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); ++i) { for(unsigned i = 0; i < rawRoute.rawViaNodeCoordinates.size(); ++i) {
searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]); searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
} }
unsigned distance = 0; unsigned distance = 0;
//single route or via point routing //single route or via point routing
if(0 == routeParameters.viaPoints.size()) { if(2 == rawRoute.rawViaNodeCoordinates.size()) {
PhantomNodes segmentPhantomNodes; PhantomNodes segmentPhantomNodes;
segmentPhantomNodes.startPhantom = phantomNodeVector[0]; segmentPhantomNodes.startPhantom = phantomNodeVector[0];
segmentPhantomNodes.targetPhantom = phantomNodeVector[1]; segmentPhantomNodes.targetPhantom = phantomNodeVector[1];
@ -145,7 +143,6 @@ public:
if(INT_MAX == distance ) { if(INT_MAX == distance ) {
DEBUG( "Error occurred, single path not found" ); DEBUG( "Error occurred, single path not found" );
} }
reply.status = http::Reply::ok; reply.status = http::Reply::ok;
BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc; BaseDescriptor<SearchEngine<EdgeData, StaticGraph<EdgeData> > > * desc;
@ -197,7 +194,6 @@ public:
desc->SetConfig(descriptorConfig); desc->SetConfig(descriptorConfig);
desc->Run(reply, rawRoute, phantomNodes, *searchEngine, distance); desc->Run(reply, rawRoute, phantomNodes, *searchEngine, distance);
if("" != JSONParameter) { if("" != JSONParameter) {
reply.content += ")\n"; reply.content += ")\n";
} }

View File

@ -201,6 +201,6 @@ env.Program(target = 'osrm-extract', source = ["extractor.cpp", Glob('DataStruct
env.Program(target = 'osrm-prepare', source = ["createHierarchy.cpp", 'Contractor/EdgeBasedGraphFactory.cpp', Glob('Util/SRTMLookup/*.cpp'), Glob('Algorithms/*.cpp')]) env.Program(target = 'osrm-prepare', source = ["createHierarchy.cpp", 'Contractor/EdgeBasedGraphFactory.cpp', Glob('Util/SRTMLookup/*.cpp'), Glob('Algorithms/*.cpp')])
env.Append(CCFLAGS = ['-lboost_regex', '-lboost_iostreams', '-lbz2', '-lz', '-lprotobuf']) env.Append(CCFLAGS = ['-lboost_regex', '-lboost_iostreams', '-lbz2', '-lz', '-lprotobuf'])
env.Append(LINKFLAGS = ['-lboost_system']) env.Append(LINKFLAGS = ['-lboost_system'])
env.Program(target = 'osrm-routed', source = ["routed.cpp", 'Descriptors/DescriptionFactory.cpp', Glob('ThirdParty/*.cc')], CCFLAGS = ['-DROUTED']) env.Program(target = 'osrm-routed', source = ["routed.cpp", 'Descriptors/DescriptionFactory.cpp', Glob('ThirdParty/*.cc')], CCFLAGS = env['CCFLAGS'] + ['-DROUTED'])
env = conf.Finish() env = conf.Finish()

View File

@ -52,10 +52,11 @@ enum CompressionType {
struct Request { struct Request {
std::string uri; std::string uri;
boost::asio::ip::address endpoint;
}; };
struct Reply { struct Reply {
Reply() : status(ok) { content.reserve(1000000); } Reply() : status(ok) { content.reserve(2 << 20); }
enum status_type { enum status_type {
ok = 200, ok = 200,
badRequest = 400, badRequest = 400,
@ -63,9 +64,9 @@ struct Reply {
} status; } status;
std::vector<Header> headers; std::vector<Header> headers;
std::string content;
std::vector<boost::asio::const_buffer> toBuffers(); std::vector<boost::asio::const_buffer> toBuffers();
std::vector<boost::asio::const_buffer> HeaderstoBuffers(); std::vector<boost::asio::const_buffer> HeaderstoBuffers();
std::string content;
static Reply stockReply(status_type status); static Reply stockReply(status_type status);
void setSize(unsigned size) { void setSize(unsigned size) {
for (std::size_t i = 0; i < headers.size(); ++i) { for (std::size_t i = 0; i < headers.size(); ++i) {

View File

@ -68,7 +68,7 @@ private:
// std::cout << "[debug] using deflate" << std::endl; // std::cout << "[debug] using deflate" << std::endl;
// if(compressionType == noCompression) // if(compressionType == noCompression)
// std::cout << "[debug] no compression" << std::endl; // std::cout << "[debug] no compression" << std::endl;
request.endpoint = TCPsocket.remote_endpoint().address();
requestHandler.handle_request(request, reply); requestHandler.handle_request(request, reply);
Header compressionHeader; Header compressionHeader;

View File

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

View File

@ -2,8 +2,8 @@ Threads = 8
IP = 0.0.0.0 IP = 0.0.0.0
Port = 5000 Port = 5000
hsgrData=/opt/osm/germany.osrm.hsgr hsgrData=/opt/osm/berlin.osrm.hsgr
nodesData=/opt/osm/germany.osrm.nodes nodesData=/opt/osm/berlin.osrm.nodes
ramIndex=/opt/osm/germany.osrm.ramIndex ramIndex=/opt/osm/berlin.osrm.ramIndex
fileIndex=/opt/osm/germany.osrm.fileIndex fileIndex=/opt/osm/berlin.osrm.fileIndex
namesData=/opt/osm/germany.osrm.names namesData=/opt/osm/berlin.osrm.names