API Breaking change. Location of nodes can be specified by a hint.
This commit is contained in:
parent
91c9cb2114
commit
e83891b4fc
@ -46,13 +46,22 @@ static void EncodeObjectToBase64(const ToEncodeT & object, std::string& encoded)
|
|||||||
assert(0 == encoded.length());
|
assert(0 == encoded.length());
|
||||||
char * pointerToOriginalObject = (char *)&object;
|
char * pointerToOriginalObject = (char *)&object;
|
||||||
encoded = std::string(base64_t(pointerToOriginalObject), base64_t(pointerToOriginalObject+sizeof(ToEncodeT)));
|
encoded = std::string(base64_t(pointerToOriginalObject), base64_t(pointerToOriginalObject+sizeof(ToEncodeT)));
|
||||||
|
//replace "+" with "-" and "/" with "_"
|
||||||
|
replaceAll(encoded, "+", "-");
|
||||||
|
replaceAll(encoded, "/", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ToEncodeT>
|
template<class ToEncodeT>
|
||||||
static void DecodeObjectFraBase64(ToEncodeT & object, const std::string& encoded) {
|
static void DecodeObjectFromBase64(ToEncodeT & object, const std::string& _encoded) {
|
||||||
|
try {
|
||||||
|
string encoded(_encoded);
|
||||||
|
//replace "-" with "+" and "_" with "/"
|
||||||
|
replaceAll(encoded, "-", "+");
|
||||||
|
replaceAll(encoded, "_", "/");
|
||||||
char * pointerToDecodedObject = (char *)&object;
|
char * pointerToDecodedObject = (char *)&object;
|
||||||
std::string dec(binary_t(encoded.begin()), binary_t(encoded.begin() + encoded.length() - 1));
|
std::string dec(binary_t(encoded.begin()), binary_t(encoded.begin() + encoded.length() - 1));
|
||||||
std::copy ( dec.begin(), dec.end(), pointerToDecodedObject );
|
std::copy ( dec.begin(), dec.end(), pointerToDecodedObject );
|
||||||
|
} catch(...) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* OBJECTTOBASE64_H_ */
|
#endif /* OBJECTTOBASE64_H_ */
|
||||||
|
@ -42,6 +42,9 @@ struct PhantomNode {
|
|||||||
bool isBidirected() const {
|
bool isBidirected() const {
|
||||||
return weight2 != INT_MAX;
|
return weight2 != INT_MAX;
|
||||||
}
|
}
|
||||||
|
bool isValid(const unsigned numberOfNodes) const {
|
||||||
|
return location.isValid() && (edgeBasedNode < numberOfNodes) && (weight1 != INT_MAX) && (ratio >= 0.) && (ratio <= 1.) && (nodeBasedEdgeNameID != UINT_MAX);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PhantomNodes {
|
struct PhantomNodes {
|
||||||
|
@ -91,6 +91,23 @@ public:
|
|||||||
|
|
||||||
_nodes.swap(nodes);
|
_nodes.swap(nodes);
|
||||||
_edges.swap(edges);
|
_edges.swap(edges);
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
Percent p(GetNumberOfNodes());
|
||||||
|
for(unsigned u = 0; u < GetNumberOfNodes(); ++u) {
|
||||||
|
for(unsigned eid = BeginEdges(u); eid < EndEdges(u); ++eid) {
|
||||||
|
unsigned v = GetTarget(eid);
|
||||||
|
EdgeData & data = GetEdgeData(eid);
|
||||||
|
if(data.shortcut) {
|
||||||
|
unsigned eid2 = FindEdgeInEitherDirection(u, data.via);
|
||||||
|
assert(eid2 != UINT_MAX);
|
||||||
|
eid2 = FindEdgeInEitherDirection(data.via, v);
|
||||||
|
assert(eid2 != UINT_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.printIncrement();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetNumberOfNodes() const {
|
unsigned GetNumberOfNodes() const {
|
||||||
|
@ -167,11 +167,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply.content += "],";
|
reply.content += "],";
|
||||||
reply.content += "\"route_data\": {";
|
reply.content += "\"hint_data\": {";
|
||||||
reply.content += "\"checksum\":";
|
reply.content += "\"checksum\":";
|
||||||
intToString(rawRoute.checkSum, tmp);
|
intToString(rawRoute.checkSum, tmp);
|
||||||
reply.content += tmp;
|
reply.content += tmp;
|
||||||
reply.content += ", \"hint_array\": [";
|
reply.content += ", \"locations\": [";
|
||||||
|
|
||||||
for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) {
|
for(unsigned i = 0; i < rawRoute.segmentEndCoordinates.size(); ++i) {
|
||||||
std::string hint;
|
std::string hint;
|
||||||
|
@ -25,7 +25,7 @@ struct RawRouteData {
|
|||||||
std::vector< _PathData > computedRouted;
|
std::vector< _PathData > computedRouted;
|
||||||
std::vector< PhantomNodes > segmentEndCoordinates;
|
std::vector< PhantomNodes > segmentEndCoordinates;
|
||||||
std::vector< _Coordinate > rawViaNodeCoordinates;
|
std::vector< _Coordinate > rawViaNodeCoordinates;
|
||||||
unsigned checkSum;
|
int checkSum;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RAWROUTEDATA_H_ */
|
#endif /* RAWROUTEDATA_H_ */
|
||||||
|
@ -31,6 +31,9 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
|||||||
|
|
||||||
#include "BasePlugin.h"
|
#include "BasePlugin.h"
|
||||||
#include "RouteParameters.h"
|
#include "RouteParameters.h"
|
||||||
|
|
||||||
|
#include "../Algorithms/ObjectToBase64.h"
|
||||||
|
|
||||||
#include "../Descriptors/BaseDescriptor.h"
|
#include "../Descriptors/BaseDescriptor.h"
|
||||||
#include "../Descriptors/GPXDescriptor.h"
|
#include "../Descriptors/GPXDescriptor.h"
|
||||||
#include "../Descriptors/JSONDescriptor.h"
|
#include "../Descriptors/JSONDescriptor.h"
|
||||||
@ -48,7 +51,7 @@ private:
|
|||||||
StaticGraph<EdgeData> * graph;
|
StaticGraph<EdgeData> * graph;
|
||||||
HashTable<std::string, unsigned> descriptorTable;
|
HashTable<std::string, unsigned> descriptorTable;
|
||||||
std::string pluginDescriptorString;
|
std::string pluginDescriptorString;
|
||||||
|
bool checksumOK;
|
||||||
SearchEngine<EdgeData, StaticGraph<EdgeData> > * searchEngine;
|
SearchEngine<EdgeData, StaticGraph<EdgeData> > * searchEngine;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -62,6 +65,7 @@ public:
|
|||||||
descriptorTable.Set("", 0); //default descriptor
|
descriptorTable.Set("", 0); //default descriptor
|
||||||
descriptorTable.Set("json", 0);
|
descriptorTable.Set("json", 0);
|
||||||
descriptorTable.Set("gpx", 1);
|
descriptorTable.Set("gpx", 1);
|
||||||
|
checksumOK = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~ViaRoutePlugin() {
|
virtual ~ViaRoutePlugin() {
|
||||||
@ -72,35 +76,19 @@ public:
|
|||||||
std::string GetVersionString() const { 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( 2 > routeParameters.viaPoints.size() ) {
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
reply = http::Reply::stockReply(http::Reply::badRequest);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get start and end Coordinate
|
|
||||||
std::string start = routeParameters.options["start"];
|
|
||||||
std::string dest = routeParameters.options["dest"];
|
|
||||||
|
|
||||||
std::vector<std::string> textCoord = split (start, ',');
|
|
||||||
|
|
||||||
int lat1 = static_cast<int>(100000.*atof(textCoord[0].c_str()));
|
|
||||||
int lon1 = static_cast<int>(100000.*atof(textCoord[1].c_str()));
|
|
||||||
|
|
||||||
textCoord = split (dest, ',');
|
|
||||||
|
|
||||||
int lat2 = static_cast<int>(100000.*atof(textCoord[0].c_str()));
|
|
||||||
int lon2 = static_cast<int>(100000.*atof(textCoord[1].c_str()));
|
|
||||||
|
|
||||||
_Coordinate startCoord(lat1, lon1);
|
|
||||||
_Coordinate targetCoord(lat2, lon2);
|
|
||||||
RawRouteData rawRoute;
|
RawRouteData rawRoute;
|
||||||
rawRoute.checkSum = nodeHelpDesk->GetCheckSum();
|
rawRoute.checkSum = nodeHelpDesk->GetCheckSum();
|
||||||
if(false == checkCoord(startCoord) || false == checkCoord(targetCoord)) {
|
checksumOK = (atoi(routeParameters.options.Find("checksum").c_str()) == rawRoute.checkSum);
|
||||||
reply = http::Reply::stockReply(http::Reply::badRequest);
|
if(!checksumOK) {
|
||||||
return;
|
INFO(atoi(routeParameters.options.Find("checksum").c_str()) << "!=" << rawRoute.checkSum);
|
||||||
|
INFO("mismatching checksum");
|
||||||
}
|
}
|
||||||
rawRoute.rawViaNodeCoordinates.push_back(startCoord);
|
std::vector<std::string> textCoord;
|
||||||
|
|
||||||
for(unsigned i = 0; i < routeParameters.viaPoints.size(); ++i) {
|
for(unsigned i = 0; i < routeParameters.viaPoints.size(); ++i) {
|
||||||
textCoord = split (routeParameters.viaPoints[i], ',');
|
textCoord = split (routeParameters.viaPoints[i], ',');
|
||||||
if(textCoord.size() != 2) {
|
if(textCoord.size() != 2) {
|
||||||
@ -109,7 +97,6 @@ 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);
|
|
||||||
_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);
|
||||||
@ -117,11 +104,18 @@ public:
|
|||||||
}
|
}
|
||||||
rawRoute.rawViaNodeCoordinates.push_back(viaCoord);
|
rawRoute.rawViaNodeCoordinates.push_back(viaCoord);
|
||||||
}
|
}
|
||||||
rawRoute.rawViaNodeCoordinates.push_back(targetCoord);
|
std::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) {
|
||||||
|
if(checksumOK && i < routeParameters.hints.size() && "" != routeParameters.hints[i]) {
|
||||||
|
INFO("Decoding hint: " << routeParameters.hints[i] << " for location index " << i);
|
||||||
|
DecodeObjectFromBase64(phantomNodeVector[i], routeParameters.hints[i]);
|
||||||
|
if(phantomNodeVector[i].isValid(nodeHelpDesk->getNumberOfNodes())) {
|
||||||
|
INFO("Decoded hint " << i << " successfully");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
INFO("Brute force lookup of coordinate " << i);
|
||||||
searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
|
searchEngine->FindPhantomNodeForCoordinate( rawRoute.rawViaNodeCoordinates[i], phantomNodeVector[i]);
|
||||||
// INFO("found coord [" << i << "|" << rawRoute.rawViaNodeCoordinates.size());
|
|
||||||
}
|
}
|
||||||
unsigned distance = 0;
|
unsigned distance = 0;
|
||||||
//single route or via point routing
|
//single route or via point routing
|
||||||
|
@ -51,14 +51,14 @@ 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);
|
||||||
// time_t ltime;
|
time_t ltime;
|
||||||
// struct tm *Tm;
|
struct tm *Tm;
|
||||||
//
|
|
||||||
// ltime=time(NULL);
|
ltime=time(NULL);
|
||||||
// Tm=localtime(<ime);
|
Tm=localtime(<ime);
|
||||||
//
|
|
||||||
// INFO( Tm->tm_mday << "-" << (Tm->tm_mon < 10 ? "0" : "" ) << Tm->tm_mon << "-" << 1900+Tm->tm_year << " " << Tm->tm_hour << ":" << Tm->tm_min << ":" << Tm->tm_sec << " " <<
|
INFO((Tm->tm_mday < 10 ? "0" : "" ) << Tm->tm_mday << "-" << (Tm->tm_mon < 10 ? "0" : "" ) << Tm->tm_mon << "-" << 1900+Tm->tm_year << " " << (Tm->tm_hour < 10 ? "0" : "" ) << Tm->tm_hour << ":" << (Tm->tm_min < 10 ? "0" : "" ) << Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << Tm->tm_sec << " " <<
|
||||||
// req.endpoint.to_string() << " " << request );
|
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);
|
||||||
@ -77,21 +77,21 @@ public:
|
|||||||
std::string p = item.substr(0, found);
|
std::string p = item.substr(0, found);
|
||||||
std::transform(p.begin(), p.end(), p.begin(), (int(*)(int)) std::tolower);
|
std::transform(p.begin(), p.end(), p.begin(), (int(*)(int)) std::tolower);
|
||||||
std::string o = item.substr(found+1);
|
std::string o = item.substr(found+1);
|
||||||
if("jsonp" != p)
|
if("jsonp" != p && "hint" != p)
|
||||||
std::transform(o.begin(), o.end(), o.begin(), (int(*)(int)) std::tolower);
|
std::transform(o.begin(), o.end(), o.begin(), (int(*)(int)) std::tolower);
|
||||||
if("via" == p ) {
|
if("loc" == p) {
|
||||||
if(25 >= routeParameters.viaPoints.size()) {
|
if(25 >= routeParameters.viaPoints.size()) {
|
||||||
routeParameters.viaPoints.push_back(o);
|
routeParameters.viaPoints.push_back(o);
|
||||||
}
|
}
|
||||||
} else if("hint" == p) {
|
} else if("hint" == p) {
|
||||||
routeParameters.hints.resize(routeParameters.viaPoints.size(), 0);
|
routeParameters.hints.resize(routeParameters.viaPoints.size());
|
||||||
|
if(routeParameters.viaPoints.size())
|
||||||
routeParameters.hints.back() = o;
|
routeParameters.hints.back() = o;
|
||||||
} else {
|
} else {
|
||||||
routeParameters.options.Set(p, o);
|
routeParameters.options.Set(p, o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
// std::cout << "[debug] found handler for '" << command << "' at version: " << pluginMap.Find(command)->GetVersionString() << std::endl;
|
||||||
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
// std::cout << "[debug] remaining parameters: " << parameters.size() << std::endl;
|
||||||
rep.status = Reply::ok;
|
rep.status = Reply::ok;
|
||||||
|
Loading…
Reference in New Issue
Block a user