diff --git a/Contractor/GraphLoader.h b/Contractor/GraphLoader.h index 5e9ab28b2..1b0073021 100644 --- a/Contractor/GraphLoader.h +++ b/Contractor/GraphLoader.h @@ -78,7 +78,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector& edgeList, vect // translate the external NodeIDs to internal IDs ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source); - if( intNodeID == ext2IntNodeMap.end()) + if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end()) { cerr << "after " << edgeList.size() << " edges" << endl; cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl; @@ -86,7 +86,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector& edgeList, vect } source = intNodeID->second; intNodeID = ext2IntNodeMap.find(target); - if(intNodeID == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); } + if(ext2IntNodeMap.find(target) == ext2IntNodeMap.end()) { cerr << "unresolved target NodeID : " << target << endl; exit(0); } target = intNodeID->second; if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); } diff --git a/Contractor/SearchEngine.h b/Contractor/SearchEngine.h index 9a56d0c2a..a4da2610f 100644 --- a/Contractor/SearchEngine.h +++ b/Contractor/SearchEngine.h @@ -44,7 +44,7 @@ public: SearchEngine(GraphT * g, NodeHelperT * nh) : _graph(g), nodeHelpDesk(nh) {} ~SearchEngine() {} - const void getNodeInfo(NodeID id, _Coordinate& result) const + inline const void getNodeInfo(NodeID id, _Coordinate& result) const { result.lat = nodeHelpDesk->getLatitudeOfNode(id); result.lon = nodeHelpDesk->getLongitudeOfNode(id); diff --git a/DataStructures/NNGrid.h b/DataStructures/NNGrid.h index e37493cc3..05e6e7e19 100644 --- a/DataStructures/NNGrid.h +++ b/DataStructures/NNGrid.h @@ -247,7 +247,6 @@ public: } bool FindRoutingStarts(const _Coordinate startCoord, const _Coordinate targetCoord, PhantomNodes * routingStarts) { - unsigned fileIndex = getFileIndexForLatLon(startCoord.lat, startCoord.lon); std::vector<_Edge> candidates; double timestamp = get_timestamp(); diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index b709a1e5a..9c413d1e6 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -48,9 +48,9 @@ public: g->OpenIndexFiles(); } - int getLatitudeOfNode(const NodeID node) const { return int2ExtNodeMap->at(node).lat; } + inline int getLatitudeOfNode(const NodeID node) const { return int2ExtNodeMap->at(node).lat; } - int getLongitudeOfNode(const NodeID node) const { return int2ExtNodeMap->at(node).lon; } + inline int getLongitudeOfNode(const NodeID node) const { return int2ExtNodeMap->at(node).lon; } NodeID getNumberOfNodes() const { return numberOfNodes; } diff --git a/HttpServer/connection.h b/HttpServer/connection.h index 3f5cf3d50..e5c5c294c 100644 --- a/HttpServer/connection.h +++ b/HttpServer/connection.h @@ -71,8 +71,7 @@ public: private: /// Handle completion of a read operation. - void handle_read(const boost::system::error_code& e, - std::size_t bytes_transferred) + void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred) { if (!e) { diff --git a/HttpServer/reply.h b/HttpServer/reply.h index 748032a0f..13c3f9469 100644 --- a/HttpServer/reply.h +++ b/HttpServer/reply.h @@ -34,6 +34,7 @@ namespace http { /// A reply to be sent to a client. struct reply { + reply() { content.reserve(1000000); } /// The status of the reply. enum status_type { diff --git a/HttpServer/request_handler.h b/HttpServer/request_handler.h index 8902b0c8c..92fd63c11 100644 --- a/HttpServer/request_handler.h +++ b/HttpServer/request_handler.h @@ -33,6 +33,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #include "../typedefs.h" +//#include + namespace http { struct reply; @@ -43,7 +45,6 @@ template class request_handler : private boost::noncopyable { public: - /// Construct with a directory containing files to be served. explicit request_handler(SearchEngine * s) : sEngine(s){} /// Handle a request and produce a reply. @@ -91,6 +92,8 @@ public: } if(command == "route") { +// CALLGRIND_START_INSTRUMENTATION; + double timestamp = get_timestamp(); //http://localhost:5000/route&45.1427&12.14144&54.8733&8.59438 std::size_t second_amp_pos = request.find_first_of("&", first_amp_pos+1); std::size_t third_amp_pos = request.find_first_of("&", second_amp_pos+1); @@ -103,58 +106,88 @@ public: _Coordinate startCoord(lat1, lon1); _Coordinate targetCoord(lat2, lon2); + double timestamp2 = get_timestamp(); +// cout << "coordinates in " << timestamp2 - timestamp << "s" << endl; + + vector * path = new vector(); PhantomNodes * phantomNodes = new PhantomNodes(); + timestamp = get_timestamp(); sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes); + timestamp2 = get_timestamp(); +// cout << "routing starts in " << timestamp2 - timestamp << "s" << endl; + timestamp = get_timestamp(); unsigned int distance = sEngine->ComputeRoute(phantomNodes, path, startCoord, targetCoord); - + timestamp2 = get_timestamp(); +// cout << "shortest path in " << timestamp2 - timestamp << "s" << endl; + timestamp = get_timestamp(); rep.status = reply::ok; - rep.content.append(""); - rep.content.append(""); - rep.content.append(""); - rep.content.append(""); - rep.content.append("OSM Routing Engine (c) Dennis Luxen and others "); - std::stringstream out1; - out1 << std::setprecision(10); - out1 << "Route from " << lat1/100000. << "," << lon1/100000. << " to " << lat2/100000. << "," << lon2/100000. << "" << " "; - rep.content.append(out1.str()); - rep.content.append(""); - rep.content.append("1"); - rep.content.append("1"); - rep.content.append("absolute"); - rep.content.append("\n"); + + string tmp; + + rep.content += (""); + rep.content += (""); + rep.content += (""); + rep.content += (""); + rep.content += ("OSM Routing Engine (c) Dennis Luxen and others "); + + rep.content += "Route from "; + doubleToString( lat1/100000., tmp); + rep.content += tmp; + rep.content += ","; + doubleToString( lon1/100000., tmp); + rep.content += tmp; + rep.content += " to "; + doubleToString( lat2/100000., tmp); + rep.content += tmp; + rep.content += ","; + doubleToString( lon2/100000., tmp); + rep.content += tmp; + rep.content += " "; + rep.content += (""); + rep.content += ("1"); + rep.content += ("1"); + rep.content += ("absolute"); + rep.content += ("\n"); + if(distance != std::numeric_limits::max()) { //A route has been found - stringstream startOut; - startOut << std::setprecision(10); - startOut << phantomNodes->startCoord.lon/100000. << "," << phantomNodes->startCoord.lat/100000. << " \n"; - rep.content.append(startOut.str()); + doubleToString(phantomNodes->startCoord.lon/100000., tmp); + rep.content += tmp; + rep.content += (","); + doubleToString(phantomNodes->startCoord.lat/100000., tmp); + rep.content += tmp; + rep.content += (" "); _Coordinate result; for(vector::iterator it = path->begin(); it != path->end(); it++) { - sEngine-> getNodeInfo(*it, result); - stringstream nodeout; - nodeout << std::setprecision(10); - nodeout << result.lon/100000. << "," << result.lat/100000. << " " << "\n"; - rep.content.append(nodeout.str()); + sEngine->getNodeInfo(*it, result); + doubleToString(result.lon/100000., tmp); + rep.content += tmp; + rep.content += (","); + doubleToString(result.lat/100000., tmp); + rep.content += tmp; + rep.content += (" "); } - stringstream targetOut; - targetOut << std::setprecision(10); - targetOut << phantomNodes->targetCoord.lon/100000. << "," << phantomNodes->targetCoord.lat/100000. << " \n"; - rep.content.append(targetOut.str()); + doubleToString(phantomNodes->targetCoord.lon/100000., tmp); + rep.content += tmp; + rep.content += (","); + doubleToString(phantomNodes->targetCoord.lat/100000., tmp); + rep.content += tmp; } - rep.content.append(""); - rep.content.append(""); - rep.content.append(""); - rep.content.append(""); - rep.content.append(""); + rep.content += (""); + rep.content += (""); + rep.content += (""); + rep.content += (""); + rep.content += (""); rep.headers.resize(3); rep.headers[0].name = "Content-Length"; - rep.headers[0].value = boost::lexical_cast(rep.content.size()); + intToString(rep.content.size(), tmp); + rep.headers[0].value = tmp; rep.headers[1].name = "Content-Type"; rep.headers[1].value = "application/vnd.google-earth.kml+xml"; rep.headers[2].name = "Content-Disposition"; @@ -162,6 +195,9 @@ public: delete path; delete phantomNodes; + timestamp2 = get_timestamp(); +// cout << "description in " << timestamp2 - timestamp << "s" << endl; +// CALLGRIND_STOP_INSTRUMENTATION; return; } rep = reply::stock_reply(reply::bad_request); @@ -177,6 +213,25 @@ public: private: //SearchEngine object that is queried SearchEngine * sEngine; + + /* used to be boosts lexical cast, but this was too slow */ + inline void doubleToString(const double value, std::string & output) + { + // The largest 32-bit integer is 4294967295, that is 10 chars + // On the safe side, add 1 for sign, and 1 for trailing zero + char buffer[12] ; + sprintf(buffer, "%f", value) ; + output = buffer ; + } + + inline void intToString(const int value, std::string & output) + { + // The largest 32-bit integer is 4294967295, that is 10 chars + // On the safe side, add 1 for sign, and 1 for trailing zero + char buffer[12] ; + sprintf(buffer, "%i", value) ; + output = buffer ; + } }; } diff --git a/extractLargeNetwork.cpp b/extractLargeNetwork.cpp index 463fb3b99..15e34aca5 100644 --- a/extractLargeNetwork.cpp +++ b/extractLargeNetwork.cpp @@ -244,21 +244,22 @@ int main (int argc, char *argv[]) if(eit->speed == -1) eit->speed = settings.speedProfile.speed[eit->type]; double weight = ( distance * 10. ) / (eit->speed / 3.6); - double intWeight = max(1, (int) weight); + int intWeight = max(1, (int) weight); + int intDist = max(1, (int)distance); switch(eit->direction) { case _Way::notSure: - fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 0 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << "\n"; break; case _Way::oneway: - fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 1 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << "\n"; break; case _Way::bidirectional: - fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 0 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 0 << " " << intWeight << "\n"; break; case _Way::opposite: - fout << startit->first << " " << targetit->first << " " << max(1, (int)distance) << " " << 1 << " " << intWeight << "\n"; + fout << startit->first << " " << targetit->first << " " << intDist << " " << 1 << " " << intWeight << "\n"; break; default: assert(false); diff --git a/typedefs.h b/typedefs.h index 09e8dd37c..5f9772884 100644 --- a/typedefs.h +++ b/typedefs.h @@ -26,6 +26,8 @@ or see http://www.gnu.org/licenses/agpl.txt. #endif #include +#include +#include using namespace std;