parent
7ce75733d0
commit
8cddaf39c4
@ -156,7 +156,6 @@ void EdgeBasedGraphFactory::Run() {
|
||||
currentNode.lon2 = inputNodeInfoList[v].lon;
|
||||
currentNode.id = _nodeBasedGraph->GetEdgeData(e1).edgeBasedNodeID;
|
||||
currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid;
|
||||
|
||||
// short startHeight = srtmLookup.height(currentNode.lon1/100000.,currentNode.lat1/100000. );
|
||||
// short targetHeight = srtmLookup.height(currentNode.lon2/100000.,currentNode.lat2/100000. );
|
||||
// short heightDiff = startHeight - targetHeight;
|
||||
@ -242,6 +241,7 @@ void EdgeBasedGraphFactory::Run() {
|
||||
currentNode.lon2 = inputNodeInfoList[w].lon;
|
||||
currentNode.id = edgeBasedTarget;
|
||||
currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e2).ignoreInGrid;
|
||||
INFO("created node #" << edgeBasedNodes.size() << " (" << v << "," << w << ")");
|
||||
edgeBasedNodes.push_back(currentNode);
|
||||
|
||||
}
|
||||
@ -254,7 +254,6 @@ void EdgeBasedGraphFactory::Run() {
|
||||
currentNode.lon2 = inputNodeInfoList[v].lon;
|
||||
currentNode.id = edgeBasedSource;
|
||||
currentNode.ignoreInGrid = _nodeBasedGraph->GetEdgeData(e1).ignoreInGrid;
|
||||
|
||||
// short startHeight = srtmLookup.height(currentNode.lon1/100000.,currentNode.lat1/100000. );
|
||||
// short targetHeight = srtmLookup.height(currentNode.lon2/100000.,currentNode.lat2/100000. );
|
||||
// short heightDiff = startHeight - targetHeight;
|
||||
|
@ -206,6 +206,7 @@ public:
|
||||
if(INT_MAX != resultNode.weight2) {
|
||||
resultNode.weight2 -= resultNode.weight1;
|
||||
}
|
||||
resultNode.ratio = ratio;
|
||||
// INFO("New weight1: " << resultNode.weight1 << ", new weight2: " << resultNode.weight2);
|
||||
// INFO("selected node: " << resultNode.edgeBasedNode << ", bidirected: " << (resultNode.isBidirected() ? "yes" : "no") << "\n--")
|
||||
return foundNode;
|
||||
|
@ -24,17 +24,19 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
#include "ExtractorStructs.h"
|
||||
|
||||
struct PhantomNode {
|
||||
PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX) {}
|
||||
PhantomNode() : edgeBasedNode(UINT_MAX), nodeBasedEdgeNameID(UINT_MAX), weight1(INT_MAX), weight2(INT_MAX), ratio(0.) {}
|
||||
NodeID edgeBasedNode;
|
||||
unsigned nodeBasedEdgeNameID;
|
||||
int weight1;
|
||||
int weight2;
|
||||
double ratio;
|
||||
_Coordinate location;
|
||||
void Reset() {
|
||||
edgeBasedNode = UINT_MAX;
|
||||
nodeBasedEdgeNameID = UINT_MAX;
|
||||
weight1 = INT_MAX;
|
||||
weight2 = INT_MAX;
|
||||
ratio = 0.;
|
||||
location.Reset();
|
||||
}
|
||||
bool isBidirected() const {
|
||||
|
@ -334,11 +334,22 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// INFO("dist: " << _upperbound);
|
||||
if ( _upperbound == INT_MAX ) {
|
||||
return _upperbound;
|
||||
}
|
||||
std::deque<NodeID> packedPath;
|
||||
_RetrievePackedPathFromHeap(_forwardHeap, _backwardHeap, middle, packedPath);
|
||||
|
||||
|
||||
//Setting weights to correspond with that of the actual chosen path
|
||||
if(packedPath[0] == phantomNodes.startPhantom.edgeBasedNode && phantomNodes.startPhantom.isBidirected()) {
|
||||
// INFO("Setting weight1=" << phantomNodes.startPhantom.weight1 << " to that of weight2=" << phantomNodes.startPhantom.weight2);
|
||||
phantomNodes.startPhantom.weight1 = phantomNodes.startPhantom.weight2;
|
||||
} else {
|
||||
// INFO("Setting weight2=" << phantomNodes.startPhantom.weight2 << " to that of weight1=" << phantomNodes.startPhantom.weight1);
|
||||
phantomNodes.startPhantom.weight2 = phantomNodes.startPhantom.weight1;
|
||||
}
|
||||
// std::cout << "0: ";
|
||||
// for(unsigned i = 0; i < packedPath.size(); ++i)
|
||||
// std::cout << packedPath[i] << " ";
|
||||
|
@ -34,24 +34,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
#include "../Plugins/RawRouteData.h"
|
||||
|
||||
struct _RouteSummary {
|
||||
std::string lengthString;
|
||||
std::string durationString;
|
||||
std::string startName;
|
||||
std::string destName;
|
||||
_RouteSummary() : lengthString("0"), durationString("0"), startName("unknown street"), destName("unknown street") {}
|
||||
void BuildDurationAndLengthStrings(unsigned distance, unsigned time) {
|
||||
//compute distance/duration for route summary
|
||||
std::ostringstream s;
|
||||
s << 10*(round(distance/10.));
|
||||
lengthString = s.str();
|
||||
int travelTime = time/10 + 1;
|
||||
s.str("");
|
||||
s << travelTime;
|
||||
durationString = s.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct _DescriptorConfig {
|
||||
_DescriptorConfig() : instructions(true), geometry(true), encodeGeometry(false), z(18) {}
|
||||
bool instructions;
|
||||
|
@ -65,9 +65,10 @@ void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) {
|
||||
pc.printUnencodedString(pathDescription, output);
|
||||
}
|
||||
|
||||
unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
||||
void DescriptionFactory::Run(const unsigned zoomLevel, const unsigned duration) {
|
||||
|
||||
if(0 == pathDescription.size())
|
||||
return 0;
|
||||
return;
|
||||
|
||||
unsigned entireLength = 0;
|
||||
/** starts at index 1 */
|
||||
@ -94,8 +95,24 @@ unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
||||
indexOfSegmentBegin = i;
|
||||
}
|
||||
}
|
||||
if(pathDescription[0].length == 0){
|
||||
pathDescription[0].turnInstruction = 14;
|
||||
|
||||
//Post-processing to remove empty or nearly empty path segments
|
||||
if(0. == startPhantom.ratio || 0 == pathDescription[0].length) {
|
||||
pathDescription.erase(pathDescription.begin());
|
||||
pathDescription[0].turnInstruction = TurnInstructions.HeadOn;
|
||||
pathDescription[0].necessary = true;
|
||||
startPhantom.nodeBasedEdgeNameID = pathDescription[0].nameID;
|
||||
} else {
|
||||
pathDescription[0].duration *= startPhantom.ratio;
|
||||
}
|
||||
if(1. == targetPhantom.ratio || 0 == pathDescription.back().length) {
|
||||
pathDescription.pop_back();
|
||||
pathDescription.back().necessary = true;
|
||||
pathDescription.back().turnInstruction = TurnInstructions.NoTurn;
|
||||
targetPhantom.nodeBasedEdgeNameID = (pathDescription.end()-2)->nameID;
|
||||
// INFO("Deleting last turn instruction");
|
||||
} else {
|
||||
pathDescription[indexOfSegmentBegin].duration *= (1.-targetPhantom.ratio);
|
||||
}
|
||||
|
||||
//Generalize poly line
|
||||
@ -109,5 +126,12 @@ unsigned DescriptionFactory::Run(const unsigned zoomLevel) {
|
||||
}
|
||||
}
|
||||
|
||||
return entireLength;
|
||||
BuildRouteSummary(entireLength, duration);
|
||||
return;
|
||||
}
|
||||
|
||||
void DescriptionFactory::BuildRouteSummary(const unsigned distance, const unsigned time) {
|
||||
summary.startName = startPhantom.nodeBasedEdgeNameID;
|
||||
summary.destName = targetPhantom.nodeBasedEdgeNameID;
|
||||
summary.BuildDurationAndLengthStrings(distance, time);
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "../Algorithms/PolylineCompressor.h"
|
||||
#include "../DataStructures/ExtractorStructs.h"
|
||||
#include "../DataStructures/SegmentInformation.h"
|
||||
#include "../DataStructures/TurnInstructions.h"
|
||||
|
||||
/* This class is fed with all way segments in consecutive order
|
||||
* and produces the description plus the encoded polyline */
|
||||
@ -36,7 +37,28 @@ class DescriptionFactory {
|
||||
DouglasPeucker<SegmentInformation> dp;
|
||||
PolylineCompressor pc;
|
||||
PhantomNode startPhantom, targetPhantom;
|
||||
|
||||
void BuildRouteSummary(const unsigned distance, const unsigned time);
|
||||
|
||||
public:
|
||||
struct _RouteSummary {
|
||||
std::string lengthString;
|
||||
std::string durationString;
|
||||
unsigned startName;
|
||||
unsigned destName;
|
||||
_RouteSummary() : lengthString("0"), durationString("0"), startName(0), destName(0) {}
|
||||
void BuildDurationAndLengthStrings(unsigned distance, unsigned time) {
|
||||
//compute distance/duration for route summary
|
||||
std::ostringstream s;
|
||||
s << 10*(round(distance/10.));
|
||||
lengthString = s.str();
|
||||
int travelTime = time/10 + 1;
|
||||
s.str("");
|
||||
s << travelTime;
|
||||
durationString = s.str();
|
||||
}
|
||||
} summary;
|
||||
|
||||
//I know, declaring this public is considered bad. I'm lazy
|
||||
std::vector <SegmentInformation> pathDescription;
|
||||
DescriptionFactory();
|
||||
@ -48,51 +70,7 @@ public:
|
||||
void SetStartSegment(const PhantomNode & startPhantom);
|
||||
void SetEndSegment(const PhantomNode & startPhantom);
|
||||
void AppendEncodedPolylineString(std::string & output, bool isEncoded);
|
||||
unsigned Run(const unsigned zoomLevel);
|
||||
|
||||
void Run(const unsigned zoomLevel, const unsigned duration);
|
||||
};
|
||||
|
||||
#endif /* DESCRIPTIONFACTORY_H_ */
|
||||
|
||||
//private:
|
||||
// void appendInstructionNameToString(const std::string & nameOfStreet, const std::string & instructionOrDirection, std::string &output, bool firstAdvice = false) {
|
||||
// output += "[";
|
||||
// if(config.instructions) {
|
||||
// output += "\"";
|
||||
// if(firstAdvice) {
|
||||
// output += "Head ";
|
||||
// }
|
||||
// output += instructionOrDirection;
|
||||
// output += "\",\"";
|
||||
// output += nameOfStreet;
|
||||
// output += "\",";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void appendInstructionLengthToString(unsigned length, std::string &output) {
|
||||
// if(config.instructions){
|
||||
// std::string tmpDistance;
|
||||
// intToString(10*(round(length/10.)), tmpDistance);
|
||||
// output += tmpDistance;
|
||||
// output += ",";
|
||||
// intToString(descriptionFactory.startIndexOfGeometry, tmp);
|
||||
// output += tmp;
|
||||
// output += ",";
|
||||
// intToString(descriptionFactory.durationOfInstruction, tmp);
|
||||
// output += tmp;
|
||||
// output += ",";
|
||||
// output += "\"";
|
||||
// output += tmpDistance;
|
||||
// output += "\",";
|
||||
// double angle = descriptionFactory.GetAngleBetweenCoordinates();
|
||||
// DirectionOfInstruction direction;
|
||||
// getDirectionOfInstruction(angle, direction);
|
||||
// output += "\"";
|
||||
// output += direction.shortDirection;
|
||||
// output += "\",";
|
||||
// std::stringstream numberString;
|
||||
// numberString << fixed << setprecision(2) << angle;
|
||||
// output += numberString.str();
|
||||
// }
|
||||
// output += "]";
|
||||
// }
|
||||
|
@ -34,7 +34,6 @@ template<class SearchEngineT>
|
||||
class JSONDescriptor : public BaseDescriptor<SearchEngineT>{
|
||||
private:
|
||||
_DescriptorConfig config;
|
||||
_RouteSummary summary;
|
||||
DescriptionFactory descriptionFactory;
|
||||
_Coordinate current;
|
||||
|
||||
@ -51,9 +50,7 @@ public:
|
||||
void Run(http::Reply & reply, RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine, const unsigned durationOfTrip) {
|
||||
WriteHeaderToOutput(reply.content);
|
||||
if(durationOfTrip != INT_MAX) {
|
||||
summary.startName = sEngine.GetEscapedNameForNameID(phantomNodes.startPhantom.nodeBasedEdgeNameID);
|
||||
descriptionFactory.SetStartSegment(phantomNodes.startPhantom);
|
||||
summary.destName = sEngine.GetEscapedNameForNameID(phantomNodes.targetPhantom.nodeBasedEdgeNameID);
|
||||
reply.content += "0,"
|
||||
"\"status_message\": \"Found route between points\",";
|
||||
|
||||
@ -69,20 +66,20 @@ public:
|
||||
"\"status_message\": \"Cannot find route between points\",";
|
||||
}
|
||||
|
||||
summary.BuildDurationAndLengthStrings(descriptionFactory.Run(config.z), durationOfTrip);
|
||||
descriptionFactory.Run(config.z, durationOfTrip);
|
||||
|
||||
reply.content += "\"route_summary\": {"
|
||||
"\"total_distance\":";
|
||||
reply.content += summary.lengthString;
|
||||
reply.content += descriptionFactory.summary.lengthString;
|
||||
reply.content += ","
|
||||
"\"total_time\":";
|
||||
reply.content += summary.durationString;
|
||||
reply.content += descriptionFactory.summary.durationString;
|
||||
reply.content += ","
|
||||
"\"start_point\":\"";
|
||||
reply.content += summary.startName;
|
||||
reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.startName);
|
||||
reply.content += "\","
|
||||
"\"end_point\":\"";
|
||||
reply.content += summary.destName;
|
||||
reply.content += sEngine.GetEscapedNameForNameID(descriptionFactory.summary.destName);
|
||||
reply.content += "\"";
|
||||
reply.content += "},";
|
||||
reply.content += "\"route_geometry\": ";
|
||||
@ -135,8 +132,9 @@ public:
|
||||
intToString(segment.duration, tmpDuration);
|
||||
reply.content += tmpDuration;
|
||||
reply.content += ",\"";
|
||||
intToString(segment.length, tmpLength);
|
||||
reply.content += tmpLength;
|
||||
reply.content += "\",\"";
|
||||
reply.content += "m\",\"";
|
||||
reply.content += Azimuth::Get(segment.bearing);
|
||||
reply.content += "\",";
|
||||
doubleToStringWithTwoDigitsBehindComma(segment.bearing, tmpBearing);
|
||||
|
@ -366,7 +366,7 @@ unsigned readHSGRFromStream(istream &in, vector<NodeT>& nodeList, vector<EdgeT>
|
||||
in.read((char*) & numberOfNodes, sizeof(unsigned));
|
||||
nodeList.resize(numberOfNodes + 1);
|
||||
NodeT currentNode;
|
||||
for(unsigned nodeCounter = 0; nodeCounter < numberOfNodes; ++nodeCounter ) {
|
||||
for(unsigned nodeCounter = 0; nodeCounter <= numberOfNodes; ++nodeCounter ) {
|
||||
in.read((char*) ¤tNode, sizeof(NodeT));
|
||||
nodeList[nodeCounter] = currentNode;
|
||||
}
|
||||
|
@ -197,8 +197,7 @@ int main (int argc, char *argv[]) {
|
||||
}
|
||||
//Serialize numberOfNodes, nodes
|
||||
edgeOutFile.write((char*) &numberOfNodes, sizeof(unsigned));
|
||||
edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph<EdgeData>::_StrNode)*(numberOfNodes));
|
||||
|
||||
edgeOutFile.write((char*) &_nodes[0], sizeof(StaticGraph<EdgeData>::_StrNode)*(numberOfNodes+1));
|
||||
|
||||
//Serialize number of Edges
|
||||
edgeOutFile.write((char*) &position, sizeof(unsigned));
|
||||
|
Loading…
Reference in New Issue
Block a user