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; unsigned nameID;
bool forward; bool forward;
bool backward; bool backward;
short turnInstruction; TurnInstruction turnInstruction;
}; };
typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph; typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,28 +23,30 @@
#include <string> #include <string>
typedef unsigned char TurnInstruction;
//This is a hack until c++0x is available enough to use scoped enums //This is a hack until c++0x is available enough to use scoped enums
struct TurnInstructionsClass { struct TurnInstructionsClass {
const static short NoTurn = 0; //Give no instruction at all const static TurnInstruction NoTurn = 0; //Give no instruction at all
const static short GoStraight = 1; //Tell user to go straight! const static TurnInstruction GoStraight = 1; //Tell user to go straight!
const static short TurnSlightRight = 2; const static TurnInstruction TurnSlightRight = 2;
const static short TurnRight = 3; const static TurnInstruction TurnRight = 3;
const static short TurnSharpRight = 4; const static TurnInstruction TurnSharpRight = 4;
const static short UTurn = 5; const static TurnInstruction UTurn = 5;
const static short TurnSharpLeft = 6; const static TurnInstruction TurnSharpLeft = 6;
const static short TurnLeft = 7; const static TurnInstruction TurnLeft = 7;
const static short TurnSlightLeft = 8; const static TurnInstruction TurnSlightLeft = 8;
const static short ReachViaPoint = 9; const static TurnInstruction ReachViaPoint = 9;
const static short HeadOn = 10; const static TurnInstruction HeadOn = 10;
const static short EnterRoundAbout = 11; const static TurnInstruction EnterRoundAbout = 11;
const static short LeaveRoundAbout = 12; const static TurnInstruction LeaveRoundAbout = 12;
const static short StayOnRoundAbout = 13; const static TurnInstruction StayOnRoundAbout = 13;
const static short StartAtEndOfStreet = 14; const static TurnInstruction StartAtEndOfStreet = 14;
const static short ReachedYourDestination = 15; const static TurnInstruction ReachedYourDestination = 15;
const static short AccessRestrictionFlag = (1<<14); const static TurnInstruction AccessRestrictionFlag = 128;
const static short InverseAccessRestrictionFlag = ~(1<<14); 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
@ -84,7 +86,7 @@ struct TurnInstructionsClass {
// Ordinals[11] = "one of the too many"; // 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) { if(angle >= 23 && angle < 67) {
return TurnSharpRight; return TurnSharpRight;
} }

View File

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

View File

@ -1,8 +1,7 @@
@routing @planetary @routing @planetary
Feature: Distance calculation 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 Given the node locations
| node | lat | lon | | node | lat | lon |
| a | 0 | 80 | | a | 0 | 80 |
@ -16,7 +15,7 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
| from | to | route | distance | | from | to | route | distance |
| a | b | ab | 8905559m ~0.1% | | a | b | ab | 8905559m ~0.1% |
Scenario: Longitudinal distances at latitude 45 Scenario: Approximated Longitudinal distances at latitude 45
Given the node locations Given the node locations
| node | lat | lon | | node | lat | lon |
| c | 45 | 80 | | 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 When I route I should get
| from | to | route | distance | | 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 Given the node locations
| node | lat | lon | | node | lat | lon |
| c | 80 | 80 | | 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 When I route I should get
| from | to | route | distance | | 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 Given the node locations
| node | lat | lon | | node | lat | lon |
| a | 80 | 0 | | a | 80 | 0 |
@ -58,7 +57,7 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
| from | to | route | distance | | from | to | route | distance |
| a | b | ab | 8905559m ~0.1% | | a | b | ab | 8905559m ~0.1% |
Scenario: Latitudinal distances at longitude 45 Scenario: Approximated Latitudinal distances at longitude 45
Given the node locations Given the node locations
| node | lat | lon | | node | lat | lon |
| a | 80 | 45 | | a | 80 | 45 |
@ -72,7 +71,7 @@ Reference distances have been calculated usign http://seismo.cqu.edu.au/CQSRG/VD
| from | to | route | distance | | from | to | route | distance |
| a | b | ab | 8905559m ~0.1% | | a | b | ab | 8905559m ~0.1% |
Scenario: Latitudinal distances at longitude 80 Scenario: Approximated Latitudinal distances at longitude 80
Given the node locations Given the node locations
| node | lat | lon | | node | lat | lon |
| a | 80 | 80 | | a | 80 | 80 |