diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 950b4bbff..7dcd75b57 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -28,7 +28,7 @@ #include "EdgeBasedGraphFactory.h" template<> -EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, boost::property_tree::ptree speedProfile, std::string & srtm) : inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()), trafficSignalPenalty(0) { +EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector & inputEdges, std::vector & bn, std::vector & tl, std::vector<_Restriction> & irs, std::vector & nI, boost::property_tree::ptree speedProfile, std::string & srtm) : inputNodeInfoList(nI), numberOfTurnRestrictions(irs.size()), trafficSignalPenalty(0), turnPenalty(0), turnBias(1.0) { BOOST_FOREACH(_Restriction & restriction, irs) { std::pair restrictionSource = std::make_pair(restriction.fromNode, restriction.viaNode); unsigned index; @@ -73,6 +73,21 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector(""); takeMinimumOfSpeeds = (v.second.get("") == "yes"); } + if("turnPenalty" == v.first) { + try { + turnPenalty = boost::lexical_cast(v.second.get("")); + } catch(boost::bad_lexical_cast &) { + turnPenalty = 0; + } + } + if("turnBias" == v.first) { + std::string value = v.second.get(""); + try { + turnBias = boost::lexical_cast(v.second.get("")); + } catch(boost::bad_lexical_cast &) { + turnBias = 1; + } + } } // INFO("traffic signal penalty: " << trafficSignalPenalty << ", U-Turn penalty: " << uturnPenalty << ", takeMinimumOfSpeeds=" << (takeMinimumOfSpeeds ? "yes" : "no")); @@ -236,11 +251,12 @@ void EdgeBasedGraphFactory::Run() { if(_trafficLights.find(v) != _trafficLights.end()) { distance += trafficSignalPenalty; } - short turnInstruction = AnalyzeTurn(u, v, w); + unsigned penalty = 0; + short turnInstruction = AnalyzeTurn(u, v, w, penalty); + //distance += heightPenalty; if(turnInstruction == TurnInstructions.UTurn) distance += uturnPenalty; - //distance += heightPenalty; - //distance += ComputeTurnPenalty(u, v, w); + distance += penalty; assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID); EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, v, edgeData2.nameID, distance, true, false, turnInstruction); edgeBasedEdges.push_back(newEdge); @@ -260,8 +276,11 @@ void EdgeBasedGraphFactory::Run() { INFO("Generated " << edgeBasedNodes.size() << " edge based nodes"); } -short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const { - if(u == w) { +short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty) const { + double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); + penalty = ComputeTurnPenalty( angle ); + + if(u == w) { return TurnInstructions.UTurn; } @@ -297,10 +316,22 @@ short EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const N if( (data1.nameID == data2.nameID) && (0 == data1.nameID) && (_nodeBasedGraph->GetOutDegree(v) <= 2) ) return TurnInstructions.NoTurn; - double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]); return TurnInstructions.GetTurnDirectionOfInstruction(angle); } +unsigned EdgeBasedGraphFactory::ComputeTurnPenalty(const float angle) const { + unsigned out; + float a = angle-180; + float k = turnPenalty/(90.0*90.0); + if( a>=0 ) { + out = k*a*a*turnBias; //right turn + } else { + out = k*a*a/turnBias; //left turn + } + //INFO("angle " << a << ", out "<< out); + return out; +} + unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const { return _nodeBasedGraph->GetNumberOfEdges(); } diff --git a/Contractor/EdgeBasedGraphFactory.h b/Contractor/EdgeBasedGraphFactory.h index d53bb1cb1..d1e22b6fb 100644 --- a/Contractor/EdgeBasedGraphFactory.h +++ b/Contractor/EdgeBasedGraphFactory.h @@ -117,6 +117,8 @@ private: unsigned numberOfTurnRestrictions; unsigned trafficSignalPenalty; unsigned uturnPenalty; + unsigned turnPenalty; + double turnBias; bool takeMinimumOfSpeeds; public: @@ -127,8 +129,9 @@ public: template< class ImportEdgeT > void GetEdgeBasedEdges( std::vector< ImportEdgeT >& edges ); void GetEdgeBasedNodes( std::vector< EdgeBasedNode> & nodes); - short AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const; - unsigned GetNumberOfNodes() const; + short AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty) const; + unsigned ComputeTurnPenalty(const float angle) const; + unsigned GetNumberOfNodes() const; }; #endif /* EDGEBASEDGRAPHFACTORY_H_ */ diff --git a/DataStructures/TurnInstructions.h b/DataStructures/TurnInstructions.h index bb45db5c1..46446243f 100644 --- a/DataStructures/TurnInstructions.h +++ b/DataStructures/TurnInstructions.h @@ -80,7 +80,7 @@ struct TurnInstructionsClass { }; static inline double GetTurnDirectionOfInstruction( const double angle ) { - if(angle >= 23 && angle < 67) { + if(angle >= 23 && angle < 67) { return TurnSharpRight; } if (angle >= 67 && angle < 113) { diff --git a/speedprofiles/bicycle.ini b/speedprofiles/bicycle.ini index 1664beb88..ed75b5817 100644 --- a/speedprofiles/bicycle.ini +++ b/speedprofiles/bicycle.ini @@ -1,28 +1,34 @@ [bicycle] - accessTag = bicycle - defaultSpeed = 17 - obeyOneways = yes - useRestrictions = yes - obeyBollards = no + accessTag = bicycle + obeyOneways = yes + useRestrictions = yes + obeyBollards = no + takeMinimumOfSpeeds = yes + excludeFromGrid = ferry + + defaultSpeed = 17 + trafficSignalPenalty = 10 + turnPenalty = 50 + turnBias = 1.4 + + cycleway = 19 + primary = 19 + primary_link = 19 + secondary = 18 + secondary_link = 18 + tertiary = 17 + residential = 16 + unclassified = 16 + road = 16 + living_street = 15 + service = 15 + track = 13 + path = 13 + footway = 5 + pedestrian = 5 + pier = 5 + platform = 5 + steps = 3 + + ferry = 5 - cycleway = 19 - primary = 19 - primary_link = 19 - secondary = 17 - secondary_link = 17 - tertiary = 15 - residential = 15 - unclassified = 15 - living_street = 13 - road = 13 - service = 12 - track = 12 - path = 12 - footway = 10 - pedestrian = 5 - pier = 5 - steps = 3 - ferry = 5 - - excludeFromGrid = ferry - trafficSignalPenalty = 10 \ No newline at end of file