From 00ed039621ccdc465d9d9b411662113ab6ca2b29 Mon Sep 17 00:00:00 2001 From: DennisOSRM Date: Mon, 17 Dec 2012 13:14:43 +0100 Subject: [PATCH] Moving TurnInstruction to unsigned char --- Algorithms/StronglyConnectedComponents.h | 2 +- Contractor/ContractionCleanup.h | 2 +- Contractor/EdgeBasedGraphFactory.cpp | 4 +-- Contractor/EdgeBasedGraphFactory.h | 4 +-- DataStructures/NodeInformationHelpDesk.h | 2 +- DataStructures/QueryEdge.h | 11 ++++--- DataStructures/SegmentInformation.h | 8 +++-- DataStructures/TurnInstructions.h | 42 +++++++++++++----------- Descriptors/JSONDescriptor.h | 10 +++--- features/testbot/planetary.feature | 17 +++++----- 10 files changed, 53 insertions(+), 49 deletions(-) diff --git a/Algorithms/StronglyConnectedComponents.h b/Algorithms/StronglyConnectedComponents.h index f9790568b..6365b6684 100644 --- a/Algorithms/StronglyConnectedComponents.h +++ b/Algorithms/StronglyConnectedComponents.h @@ -66,7 +66,7 @@ private: unsigned nameID; bool forward; bool backward; - short turnInstruction; + TurnInstruction turnInstruction; }; typedef DynamicGraph< _NodeBasedEdgeData > _NodeBasedDynamicGraph; diff --git a/Contractor/ContractionCleanup.h b/Contractor/ContractionCleanup.h index c1f08b081..e42dad3a7 100644 --- a/Contractor/ContractionCleanup.h +++ b/Contractor/ContractionCleanup.h @@ -60,7 +60,7 @@ public: NodeID via; unsigned nameID; int distance; - short turnInstruction; + TurnInstruction turnInstruction; bool shortcut:1; bool forward:1; bool backward:1; diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 82ab09f11..b9586b765 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -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; } diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index 0fa0bb252..62a119e81 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -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; }; diff --git a/DataStructures/NodeInformationHelpDesk.h b/DataStructures/NodeInformationHelpDesk.h index cddfede98..abf05b71a 100644 --- a/DataStructures/NodeInformationHelpDesk.h +++ b/DataStructures/NodeInformationHelpDesk.h @@ -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; } diff --git a/DataStructures/QueryEdge.h b/DataStructures/QueryEdge.h index aab61f9c7..72cbf0f07 100644 --- a/DataStructures/QueryEdge.h +++ b/DataStructures/QueryEdge.h @@ -23,16 +23,17 @@ or see http://www.gnu.org/licenses/agpl.txt. #ifndef QUERYEDGE_H_ #define QUERYEDGE_H_ -#include - +#include "TurnInstructions.h" #include "../typedefs.h" +#include + 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 { diff --git a/DataStructures/SegmentInformation.h b/DataStructures/SegmentInformation.h index 943fd831a..cbe4b81cc 100644 --- a/DataStructures/SegmentInformation.h +++ b/DataStructures/SegmentInformation.h @@ -23,17 +23,19 @@ or see http://www.gnu.org/licenses/agpl.txt. #include +#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) {} }; diff --git a/DataStructures/TurnInstructions.h b/DataStructures/TurnInstructions.h index 624a8db4c..2e709831d 100644 --- a/DataStructures/TurnInstructions.h +++ b/DataStructures/TurnInstructions.h @@ -23,30 +23,32 @@ #include +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; } diff --git a/Descriptors/JSONDescriptor.h b/Descriptors/JSONDescriptor.h index 967c72640..140cde9fe 100644 --- a/Descriptors/JSONDescriptor.h +++ b/Descriptors/JSONDescriptor.h @@ -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 & shortestSegments, std::vector & 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 += "]"; } - } }; diff --git a/features/testbot/planetary.feature b/features/testbot/planetary.feature index e8f832321..8d09c26b9 100644 --- a/features/testbot/planetary.feature +++ b/features/testbot/planetary.feature @@ -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 |