Perfomance fixes
This commit is contained in:
parent
cc44fef25d
commit
e79e36bea9
@ -78,7 +78,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
|
|||||||
|
|
||||||
// translate the external NodeIDs to internal IDs
|
// translate the external NodeIDs to internal IDs
|
||||||
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
ExternalNodeMap::iterator intNodeID = ext2IntNodeMap.find(source);
|
||||||
if( intNodeID == ext2IntNodeMap.end())
|
if( ext2IntNodeMap.find(source) == ext2IntNodeMap.end())
|
||||||
{
|
{
|
||||||
cerr << "after " << edgeList.size() << " edges" << endl;
|
cerr << "after " << edgeList.size() << " edges" << endl;
|
||||||
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
|
cerr << "->" << source << "," << target << "," << length << "," << dir << "," << weight << endl;
|
||||||
@ -86,7 +86,7 @@ inline NodeID readOSMRGraphFromStream(istream &in, vector<EdgeT>& edgeList, vect
|
|||||||
}
|
}
|
||||||
source = intNodeID->second;
|
source = intNodeID->second;
|
||||||
intNodeID = ext2IntNodeMap.find(target);
|
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;
|
target = intNodeID->second;
|
||||||
|
|
||||||
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); }
|
if(source == UINT_MAX || target == UINT_MAX) { cerr << "nonexisting source or target" << endl; exit(0); }
|
||||||
|
@ -44,7 +44,7 @@ public:
|
|||||||
SearchEngine(GraphT * g, NodeHelperT * nh) : _graph(g), nodeHelpDesk(nh) {}
|
SearchEngine(GraphT * g, NodeHelperT * nh) : _graph(g), nodeHelpDesk(nh) {}
|
||||||
~SearchEngine() {}
|
~SearchEngine() {}
|
||||||
|
|
||||||
const void getNodeInfo(NodeID id, _Coordinate& result) const
|
inline const void getNodeInfo(NodeID id, _Coordinate& result) const
|
||||||
{
|
{
|
||||||
result.lat = nodeHelpDesk->getLatitudeOfNode(id);
|
result.lat = nodeHelpDesk->getLatitudeOfNode(id);
|
||||||
result.lon = nodeHelpDesk->getLongitudeOfNode(id);
|
result.lon = nodeHelpDesk->getLongitudeOfNode(id);
|
||||||
|
@ -247,7 +247,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FindRoutingStarts(const _Coordinate startCoord, const _Coordinate targetCoord, PhantomNodes * routingStarts) {
|
bool FindRoutingStarts(const _Coordinate startCoord, const _Coordinate targetCoord, PhantomNodes * routingStarts) {
|
||||||
|
|
||||||
unsigned fileIndex = getFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
unsigned fileIndex = getFileIndexForLatLon(startCoord.lat, startCoord.lon);
|
||||||
std::vector<_Edge> candidates;
|
std::vector<_Edge> candidates;
|
||||||
double timestamp = get_timestamp();
|
double timestamp = get_timestamp();
|
||||||
|
@ -48,9 +48,9 @@ public:
|
|||||||
g->OpenIndexFiles();
|
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; }
|
NodeID getNumberOfNodes() const { return numberOfNodes; }
|
||||||
|
|
||||||
|
@ -71,8 +71,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
/// Handle completion of a read operation.
|
/// Handle completion of a read operation.
|
||||||
void handle_read(const boost::system::error_code& e,
|
void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred)
|
||||||
std::size_t bytes_transferred)
|
|
||||||
{
|
{
|
||||||
if (!e)
|
if (!e)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@ namespace http {
|
|||||||
/// A reply to be sent to a client.
|
/// A reply to be sent to a client.
|
||||||
struct reply
|
struct reply
|
||||||
{
|
{
|
||||||
|
reply() { content.reserve(1000000); }
|
||||||
/// The status of the reply.
|
/// The status of the reply.
|
||||||
enum status_type
|
enum status_type
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
|
//#include <valgrind/callgrind.h>
|
||||||
|
|
||||||
namespace http {
|
namespace http {
|
||||||
|
|
||||||
struct reply;
|
struct reply;
|
||||||
@ -43,7 +45,6 @@ template<typename GraphT>
|
|||||||
class request_handler : private boost::noncopyable
|
class request_handler : private boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Construct with a directory containing files to be served.
|
|
||||||
explicit request_handler(SearchEngine<EdgeData, GraphT> * s) : sEngine(s){}
|
explicit request_handler(SearchEngine<EdgeData, GraphT> * s) : sEngine(s){}
|
||||||
|
|
||||||
/// Handle a request and produce a reply.
|
/// Handle a request and produce a reply.
|
||||||
@ -91,6 +92,8 @@ public:
|
|||||||
}
|
}
|
||||||
if(command == "route")
|
if(command == "route")
|
||||||
{
|
{
|
||||||
|
// CALLGRIND_START_INSTRUMENTATION;
|
||||||
|
double timestamp = get_timestamp();
|
||||||
//http://localhost:5000/route&45.1427&12.14144&54.8733&8.59438
|
//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 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);
|
std::size_t third_amp_pos = request.find_first_of("&", second_amp_pos+1);
|
||||||
@ -103,58 +106,88 @@ public:
|
|||||||
|
|
||||||
_Coordinate startCoord(lat1, lon1);
|
_Coordinate startCoord(lat1, lon1);
|
||||||
_Coordinate targetCoord(lat2, lon2);
|
_Coordinate targetCoord(lat2, lon2);
|
||||||
|
double timestamp2 = get_timestamp();
|
||||||
|
// cout << "coordinates in " << timestamp2 - timestamp << "s" << endl;
|
||||||
|
|
||||||
|
|
||||||
vector<NodeID> * path = new vector<NodeID>();
|
vector<NodeID> * path = new vector<NodeID>();
|
||||||
PhantomNodes * phantomNodes = new PhantomNodes();
|
PhantomNodes * phantomNodes = new PhantomNodes();
|
||||||
|
timestamp = get_timestamp();
|
||||||
sEngine->FindRoutingStarts(startCoord, targetCoord, phantomNodes);
|
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);
|
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.status = reply::ok;
|
||||||
rep.content.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
|
||||||
rep.content.append("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
|
string tmp;
|
||||||
rep.content.append("<Document>");
|
|
||||||
rep.content.append("<Placemark>");
|
rep.content += ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
rep.content.append("<name>OSM Routing Engine (c) Dennis Luxen and others </name>");
|
rep.content += ("<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
|
||||||
std::stringstream out1;
|
rep.content += ("<Document>");
|
||||||
out1 << std::setprecision(10);
|
rep.content += ("<Placemark>");
|
||||||
out1 << "<description>Route from " << lat1/100000. << "," << lon1/100000. << " to " << lat2/100000. << "," << lon2/100000. << "</description>" << " ";
|
rep.content += ("<name>OSM Routing Engine (c) Dennis Luxen and others </name>");
|
||||||
rep.content.append(out1.str());
|
|
||||||
rep.content.append("<LineString>");
|
rep.content += "<description>Route from ";
|
||||||
rep.content.append("<extrude>1</extrude>");
|
doubleToString( lat1/100000., tmp);
|
||||||
rep.content.append("<tessellate>1</tessellate>");
|
rep.content += tmp;
|
||||||
rep.content.append("<altitudeMode>absolute</altitudeMode>");
|
rep.content += ",";
|
||||||
rep.content.append("<coordinates>\n");
|
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 += "</description> ";
|
||||||
|
rep.content += ("<LineString>");
|
||||||
|
rep.content += ("<extrude>1</extrude>");
|
||||||
|
rep.content += ("<tessellate>1</tessellate>");
|
||||||
|
rep.content += ("<altitudeMode>absolute</altitudeMode>");
|
||||||
|
rep.content += ("<coordinates>\n");
|
||||||
|
|
||||||
|
|
||||||
if(distance != std::numeric_limits<unsigned int>::max())
|
if(distance != std::numeric_limits<unsigned int>::max())
|
||||||
{ //A route has been found
|
{ //A route has been found
|
||||||
stringstream startOut;
|
doubleToString(phantomNodes->startCoord.lon/100000., tmp);
|
||||||
startOut << std::setprecision(10);
|
rep.content += tmp;
|
||||||
startOut << phantomNodes->startCoord.lon/100000. << "," << phantomNodes->startCoord.lat/100000. << " \n";
|
rep.content += (",");
|
||||||
rep.content.append(startOut.str());
|
doubleToString(phantomNodes->startCoord.lat/100000., tmp);
|
||||||
|
rep.content += tmp;
|
||||||
|
rep.content += (" ");
|
||||||
|
|
||||||
_Coordinate result;
|
_Coordinate result;
|
||||||
for(vector<NodeID>::iterator it = path->begin(); it != path->end(); it++)
|
for(vector<NodeID>::iterator it = path->begin(); it != path->end(); it++)
|
||||||
{
|
{
|
||||||
sEngine-> getNodeInfo(*it, result);
|
sEngine->getNodeInfo(*it, result);
|
||||||
stringstream nodeout;
|
doubleToString(result.lon/100000., tmp);
|
||||||
nodeout << std::setprecision(10);
|
rep.content += tmp;
|
||||||
nodeout << result.lon/100000. << "," << result.lat/100000. << " " << "\n";
|
rep.content += (",");
|
||||||
rep.content.append(nodeout.str());
|
doubleToString(result.lat/100000., tmp);
|
||||||
|
rep.content += tmp;
|
||||||
|
rep.content += (" ");
|
||||||
}
|
}
|
||||||
stringstream targetOut;
|
doubleToString(phantomNodes->targetCoord.lon/100000., tmp);
|
||||||
targetOut << std::setprecision(10);
|
rep.content += tmp;
|
||||||
targetOut << phantomNodes->targetCoord.lon/100000. << "," << phantomNodes->targetCoord.lat/100000. << " \n";
|
rep.content += (",");
|
||||||
rep.content.append(targetOut.str());
|
doubleToString(phantomNodes->targetCoord.lat/100000., tmp);
|
||||||
|
rep.content += tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
rep.content.append("</coordinates>");
|
rep.content += ("</coordinates>");
|
||||||
rep.content.append("</LineString>");
|
rep.content += ("</LineString>");
|
||||||
rep.content.append("</Placemark>");
|
rep.content += ("</Placemark>");
|
||||||
rep.content.append("</Document>");
|
rep.content += ("</Document>");
|
||||||
rep.content.append("</kml>");
|
rep.content += ("</kml>");
|
||||||
|
|
||||||
rep.headers.resize(3);
|
rep.headers.resize(3);
|
||||||
rep.headers[0].name = "Content-Length";
|
rep.headers[0].name = "Content-Length";
|
||||||
rep.headers[0].value = boost::lexical_cast<std::string>(rep.content.size());
|
intToString(rep.content.size(), tmp);
|
||||||
|
rep.headers[0].value = tmp;
|
||||||
rep.headers[1].name = "Content-Type";
|
rep.headers[1].name = "Content-Type";
|
||||||
rep.headers[1].value = "application/vnd.google-earth.kml+xml";
|
rep.headers[1].value = "application/vnd.google-earth.kml+xml";
|
||||||
rep.headers[2].name = "Content-Disposition";
|
rep.headers[2].name = "Content-Disposition";
|
||||||
@ -162,6 +195,9 @@ public:
|
|||||||
|
|
||||||
delete path;
|
delete path;
|
||||||
delete phantomNodes;
|
delete phantomNodes;
|
||||||
|
timestamp2 = get_timestamp();
|
||||||
|
// cout << "description in " << timestamp2 - timestamp << "s" << endl;
|
||||||
|
// CALLGRIND_STOP_INSTRUMENTATION;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rep = reply::stock_reply(reply::bad_request);
|
rep = reply::stock_reply(reply::bad_request);
|
||||||
@ -177,6 +213,25 @@ public:
|
|||||||
private:
|
private:
|
||||||
//SearchEngine object that is queried
|
//SearchEngine object that is queried
|
||||||
SearchEngine<EdgeData, GraphT> * sEngine;
|
SearchEngine<EdgeData, GraphT> * 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 ;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,21 +244,22 @@ int main (int argc, char *argv[])
|
|||||||
if(eit->speed == -1)
|
if(eit->speed == -1)
|
||||||
eit->speed = settings.speedProfile.speed[eit->type];
|
eit->speed = settings.speedProfile.speed[eit->type];
|
||||||
double weight = ( distance * 10. ) / (eit->speed / 3.6);
|
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)
|
switch(eit->direction)
|
||||||
{
|
{
|
||||||
case _Way::notSure:
|
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;
|
break;
|
||||||
case _Way::oneway:
|
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;
|
break;
|
||||||
case _Way::bidirectional:
|
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;
|
break;
|
||||||
case _Way::opposite:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
@ -26,6 +26,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user