Moving TurnInstruction to unsigned char

This commit is contained in:
DennisOSRM 2012-12-17 13:14:43 +01:00
parent b247c20dbf
commit 00ed039621
10 changed files with 53 additions and 49 deletions

View File

@ -66,7 +66,7 @@ private:
unsigned nameID;
bool forward;
bool backward;
short turnInstruction;
TurnInstruction turnInstruction;
};
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;

View File

@ -60,7 +60,7 @@ public:
NodeID via;
unsigned nameID;
int distance;
short turnInstruction;
TurnInstruction turnInstruction;
bool shortcut:1;
bool forward:1;
bool backward:1;

View File

@ -280,7 +280,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
if(_trafficLights.find(v) != _trafficLights.end()) {
distance += speedProfile.trafficSignalPenalty;
}
short turnInstruction = AnalyzeTurn(u, v, w);
TurnInstruction turnInstruction = AnalyzeTurn(u, v, w);
if(turnInstruction == TurnInstructions.UTurn)
distance += speedProfile.uTurnPenalty;
// if(!edgeData1.isAccessRestricted && edgeData2.isAccessRestricted) {
@ -334,7 +334,7 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
INFO("Generated " << edgeBasedNodes.size() << " edge based nodes");
}
short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const {
TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const {
if(u == w) {
return TurnInstructions.UTurn;
}

View File

@ -69,7 +69,7 @@ private:
unsigned nameID;
bool forward;
bool backward;
short turnInstruction;
TurnInstruction turnInstruction;
};
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;
@ -138,7 +138,7 @@ public:
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
void GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode> & nodes);
void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData);
short AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
unsigned GetNumberOfNodes() const;
};

View File

@ -85,7 +85,7 @@ public:
return origEdgeData.at(id).nameID;
}
inline short getTurnInstructionFromEdgeID(const unsigned id) const {
inline TurnInstruction getTurnInstructionFromEdgeID(const unsigned id) const {
return origEdgeData.at(id).turnInstruction;
}

View File

@ -23,16 +23,17 @@ or see http://www.gnu.org/licenses/agpl.txt.
#ifndef QUERYEDGE_H_
#define QUERYEDGE_H_
#include <climits>
#include "TurnInstructions.h"
#include "../typedefs.h"
#include <climits>
struct OriginalEdgeData{
explicit OriginalEdgeData(NodeID v, unsigned n, short t) : viaNode(v), nameID(n), turnInstruction(t) {}
OriginalEdgeData() : viaNode(UINT_MAX), nameID(UINT_MAX), turnInstruction(SHRT_MAX) {}
explicit OriginalEdgeData(NodeID v, unsigned n, TurnInstruction t) : viaNode(v), nameID(n), turnInstruction(t) {}
OriginalEdgeData() : viaNode(UINT_MAX), nameID(UINT_MAX), turnInstruction(UCHAR_MAX) {}
NodeID viaNode;
unsigned nameID;
short turnInstruction;
TurnInstruction turnInstruction;
};
struct QueryEdge {

View File

@ -23,17 +23,19 @@ or see http://www.gnu.org/licenses/agpl.txt.
#include <climits>
#include "TurnInstructions.h"
struct SegmentInformation {
_Coordinate location;
NodeID nameID;
double length;
unsigned duration;
double bearing;
short turnInstruction;
TurnInstruction turnInstruction;
bool necessary;
SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const short tInstr, const bool nec) :
SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr, const bool nec) :
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(nec) {}
SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const short tInstr) :
SegmentInformation(const _Coordinate & loc, const NodeID nam, const double len, const unsigned dur, const TurnInstruction tInstr) :
location(loc), nameID(nam), length(len), duration(dur), bearing(0.), turnInstruction(tInstr), necessary(tInstr != 0) {}
};

View File

@ -23,30 +23,32 @@
#include <string>
typedef unsigned char TurnInstruction;
//This is a hack until c++0x is available enough to use scoped enums
struct TurnInstructionsClass {
const static short NoTurn = 0; //Give no instruction at all
const static short GoStraight = 1; //Tell user to go straight!
const static short TurnSlightRight = 2;
const static short TurnRight = 3;
const static short TurnSharpRight = 4;
const static short UTurn = 5;
const static short TurnSharpLeft = 6;
const static short TurnLeft = 7;
const static short TurnSlightLeft = 8;
const static short ReachViaPoint = 9;
const static short HeadOn = 10;
const static short EnterRoundAbout = 11;
const static short LeaveRoundAbout = 12;
const static short StayOnRoundAbout = 13;
const static short StartAtEndOfStreet = 14;
const static short ReachedYourDestination = 15;
const static TurnInstruction NoTurn = 0; //Give no instruction at all
const static TurnInstruction GoStraight = 1; //Tell user to go straight!
const static TurnInstruction TurnSlightRight = 2;
const static TurnInstruction TurnRight = 3;
const static TurnInstruction TurnSharpRight = 4;
const static TurnInstruction UTurn = 5;
const static TurnInstruction TurnSharpLeft = 6;
const static TurnInstruction TurnLeft = 7;
const static TurnInstruction TurnSlightLeft = 8;
const static TurnInstruction ReachViaPoint = 9;
const static TurnInstruction HeadOn = 10;
const static TurnInstruction EnterRoundAbout = 11;
const static TurnInstruction LeaveRoundAbout = 12;
const static TurnInstruction StayOnRoundAbout = 13;
const static TurnInstruction StartAtEndOfStreet = 14;
const static TurnInstruction ReachedYourDestination = 15;
const static short AccessRestrictionFlag = (1<<14);
const static short InverseAccessRestrictionFlag = ~(1<<14);
const static TurnInstruction AccessRestrictionFlag = 128;
const static TurnInstruction InverseAccessRestrictionFlag = 0x7f; // ~128 does not work without a warning.
const static int AccessRestrictionPenalty = 1 << 15; //unrelated to the bit set in the restriction flag
const static int AccessRestrictionPenalty = 1 << 15; //unrelated to the bit set in the restriction flag
// std::string TurnStrings[16];
// std::string Ordinals[12];
@ -84,7 +86,7 @@ struct TurnInstructionsClass {
// Ordinals[11] = "one of the too many";
// };
static inline double GetTurnDirectionOfInstruction( const double angle ) {
static inline TurnInstruction GetTurnDirectionOfInstruction( const double angle ) {
if(angle >= 23 && angle < 67) {
return TurnSharpRight;
}

View File

@ -69,7 +69,9 @@ public:
void SetConfig(const _DescriptorConfig & c) { config = c; }
void Run(http::Reply & reply, const RawRouteData &rawRoute, PhantomNodes &phantomNodes, SearchEngineT &sEngine) {
WriteHeaderToOutput(reply.content);
if(rawRoute.lengthOfShortestPath != INT_MAX) {
descriptionFactory.SetStartSegment(phantomNodes.startPhantom);
reply.content += "0,"
@ -102,7 +104,7 @@ public:
BuildTextualDescription(descriptionFactory, reply, rawRoute.lengthOfShortestPath, sEngine, shortestSegments);
} else {
BOOST_FOREACH(const SegmentInformation & segment, descriptionFactory.pathDescription) {
short currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag;
TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag;
numberOfEnteredRestrictedAreas += (currentInstruction != segment.turnInstruction);
}
}
@ -155,7 +157,7 @@ public:
BuildTextualDescription(alternateDescriptionFactory, reply, rawRoute.lengthOfAlternativePath, sEngine, alternativeSegments);
} else {
BOOST_FOREACH(const SegmentInformation & segment, alternateDescriptionFactory.pathDescription) {
short currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag;
TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag;
numberOfEnteredRestrictedAreas += (currentInstruction != segment.turnInstruction);
}
}
@ -242,7 +244,6 @@ public:
reply.content += "},";
reply.content += "\"transactionId\": \"OSRM Routing Engine JSON Descriptor (v0.3)\"";
reply.content += "}";
}
void GetRouteNames(std::vector<Segment> & shortestSegments, std::vector<Segment> & alternativeSegments, SearchEngineT &sEngine, RouteNames & routeNames) {
@ -312,7 +313,7 @@ public:
std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction;
//Fetch data from Factory and generate a string from it.
BOOST_FOREACH(const SegmentInformation & segment, descriptionFactory.pathDescription) {
short currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag;
TurnInstruction currentInstruction = segment.turnInstruction & TurnInstructions.InverseAccessRestrictionFlag;
numberOfEnteredRestrictedAreas += (currentInstruction != segment.turnInstruction);
if(TurnInstructions.TurnIsNecessary( currentInstruction) ) {
if(TurnInstructions.EnterRoundAbout == currentInstruction) {
@ -384,7 +385,6 @@ public:
reply.content += "0.0";
reply.content += "]";
}
}
};

View File

@ -1,8 +1,7 @@
@routing @planetary
Feature: Distance calculation
Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VDistance/
Scenario: Longitudinal distances at equator
Scenario: Approximated Longitudinal distances at equator
Given the node locations
| node | lat | lon |
| a | 0 | 80 |
@ -16,7 +15,7 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
| from | to | route | distance |
| a | b | ab | 8905559m ~0.1% |
Scenario: Longitudinal distances at latitude 45
Scenario: Approximated Longitudinal distances at latitude 45
Given the node locations
| node | lat | lon |
| c | 45 | 80 |
@ -28,9 +27,9 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
When I route I should get
| from | to | route | distance |
| c | d | cd | 6028844m ~0.5% |
| c | d | cd | 6291910m ~0.5% |
Scenario: Longitudinal distances at latitude 80
Scenario: Approximated Longitudinal distances at latitude 80
Given the node locations
| node | lat | lon |
| c | 80 | 80 |
@ -42,9 +41,9 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
When I route I should get
| from | to | route | distance |
| c | d | cd | 1431469m ~0.5% |
| c | d | cd | 1545140m ~0.5% |
Scenario: Latitudinal distances at longitude 0
Scenario: Approximated Latitudinal distances at longitude 0
Given the node locations
| node | lat | lon |
| a | 80 | 0 |
@ -58,7 +57,7 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
| from | to | route | distance |
| a | b | ab | 8905559m ~0.1% |
Scenario: Latitudinal distances at longitude 45
Scenario: Approximated Latitudinal distances at longitude 45
Given the node locations
| node | lat | lon |
| a | 80 | 45 |
@ -72,7 +71,7 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
| from | to | route | distance |
| a | b | ab | 8905559m ~0.1% |
Scenario: Latitudinal distances at longitude 80
Scenario: Approximated Latitudinal distances at longitude 80
Given the node locations
| node | lat | lon |
| a | 80 | 80 |