Adding a U-turn penalty for very sharp turns. Fixes #188 and #153 and

also partially fixes #65 and #167
This commit is contained in:
DennisOSRM 2012-03-20 12:35:52 +01:00
parent 30d72543b9
commit 556e487a15
5 changed files with 40 additions and 16 deletions

View File

@ -61,9 +61,21 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
trafficSignalPenalty = 0; trafficSignalPenalty = 0;
} }
} }
if("uturnPenalty" == v.first) {
std::string value = v.second.get<std::string>("");
try {
uturnPenalty = 10*boost::lexical_cast<int>(v.second.get<std::string>(""));
} catch(boost::bad_lexical_cast &) {
uturnPenalty = 0;
}
}
if("takeMinimumOfSpeeds" == v.first) {
std::string value = v.second.get<std::string>("");
takeMinimumOfSpeeds = (v.second.get<std::string>("") == "yes");
}
} }
INFO("traffic signal penalty: " << trafficSignalPenalty); // INFO("traffic signal penalty: " << trafficSignalPenalty << ", U-Turn penalty: " << uturnPenalty << ", takeMinimumOfSpeeds=" << (takeMinimumOfSpeeds ? "yes" : "no"));
BOOST_FOREACH(NodeID id, bn) BOOST_FOREACH(NodeID id, bn)
_barrierNodes[id] = true; _barrierNodes[id] = true;
@ -221,12 +233,14 @@ void EdgeBasedGraphFactory::Run() {
assert(edgeData2.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges()); assert(edgeData2.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges());
unsigned distance = edgeData1.distance; unsigned distance = edgeData1.distance;
//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
if(_trafficLights.find(v) != _trafficLights.end()) { if(_trafficLights.find(v) != _trafficLights.end()) {
distance += trafficSignalPenalty; distance += trafficSignalPenalty;
} }
short turnInstruction = AnalyzeTurn(u, v, w); short turnInstruction = AnalyzeTurn(u, v, w);
if(turnInstruction == TurnInstructions.UTurn)
distance += uturnPenalty;
//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID); assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID);
EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, v, edgeData2.nameID, distance, true, false, turnInstruction); EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, v, edgeData2.nameID, distance, true, false, turnInstruction);
edgeBasedEdges.push_back(newEdge); edgeBasedEdges.push_back(newEdge);

View File

@ -116,6 +116,8 @@ private:
// SRTMLookup srtmLookup; // SRTMLookup srtmLookup;
unsigned numberOfTurnRestrictions; unsigned numberOfTurnRestrictions;
unsigned trafficSignalPenalty; unsigned trafficSignalPenalty;
unsigned uturnPenalty;
bool takeMinimumOfSpeeds;
public: public:
template< class InputEdgeT > template< class InputEdgeT >

View File

@ -179,10 +179,18 @@ public:
if(!w.isDurationSet) { if(!w.isDurationSet) {
if(0 < settings[highway]) { if(0 < settings[highway]) {
if(0 < maxspeed) if(0 < maxspeed)
if(settings.takeMinimumOfSpeeds)
w.speed = std::min(settings[highway], maxspeed);
else
w.speed = maxspeed; w.speed = maxspeed;
else else
w.speed = settings[highway]; w.speed = settings[highway];
} else { } else {
if(0 < maxspeed)
if(settings.takeMinimumOfSpeeds)
w.speed = std::min(settings.defaultSpeed, maxspeed);
else w.speed = maxspeed;
else
w.speed = settings.defaultSpeed; w.speed = settings.defaultSpeed;
highway = "default"; highway = "default";
} }

View File

@ -265,7 +265,7 @@ struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDSta
}; };
struct Settings { struct Settings {
Settings() : obeyBollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar"), defaultSpeed(30), trafficLightPenalty(0), excludeFromGrid("ferry") {} Settings() : obeyBollards(true), obeyOneways(true), useRestrictions(true), accessTag("motorcar"), defaultSpeed(30), takeMinimumOfSpeeds(false), excludeFromGrid("ferry") {}
StringToIntPairMap speedProfile; StringToIntPairMap speedProfile;
int operator[](const std::string & param) const { int operator[](const std::string & param) const {
if(speedProfile.find(param) == speedProfile.end()) if(speedProfile.find(param) == speedProfile.end())
@ -290,7 +290,7 @@ struct Settings {
bool useRestrictions; bool useRestrictions;
std::string accessTag; std::string accessTag;
int defaultSpeed; int defaultSpeed;
int trafficLightPenalty; bool takeMinimumOfSpeeds;
std::string excludeFromGrid; std::string excludeFromGrid;
}; };

View File

@ -101,7 +101,7 @@ struct TurnInstructionsClass {
if (angle >= 292 && angle < 336) { if (angle >= 292 && angle < 336) {
return TurnSharpLeft; return TurnSharpLeft;
} }
return 5; return UTurn;
} }
static inline bool TurnIsNecessary ( const short turnInstruction ) { static inline bool TurnIsNecessary ( const short turnInstruction ) {