Skip to content

Commit

Permalink
Adding a U-turn penalty for very sharp turns. Fixes Project-OSRM#188
Browse files Browse the repository at this point in the history
…and Project-OSRM#153 and

also partially fixes Project-OSRM#65 and Project-OSRM#167
  • Loading branch information
DennisOSRM committed Mar 20, 2012
1 parent 30d7254 commit 556e487
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
20 changes: 17 additions & 3 deletions Contractor/EdgeBasedGraphFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,21 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory(int nodes, std::vector<NodeBasedEdg
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)
_barrierNodes[id] = true;
Expand Down Expand Up @@ -221,12 +233,14 @@ void EdgeBasedGraphFactory::Run() {
assert(edgeData2.edgeBasedNodeID < _nodeBasedGraph->GetNumberOfEdges());

unsigned distance = edgeData1.distance;
//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
if(_trafficLights.find(v) != _trafficLights.end()) {
distance += trafficSignalPenalty;
}
short turnInstruction = AnalyzeTurn(u, v, w);
if(turnInstruction == TurnInstructions.UTurn)
distance += uturnPenalty;
//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
assert(edgeData1.edgeBasedNodeID != edgeData2.edgeBasedNodeID);
EdgeBasedEdge newEdge(edgeData1.edgeBasedNodeID, edgeData2.edgeBasedNodeID, v, edgeData2.nameID, distance, true, false, turnInstruction);
edgeBasedEdges.push_back(newEdge);
Expand Down
2 changes: 2 additions & 0 deletions Contractor/EdgeBasedGraphFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class EdgeBasedGraphFactory {
// SRTMLookup srtmLookup;
unsigned numberOfTurnRestrictions;
unsigned trafficSignalPenalty;
unsigned uturnPenalty;
bool takeMinimumOfSpeeds;

public:
template< class InputEdgeT >
Expand Down
28 changes: 18 additions & 10 deletions DataStructures/ExtractorCallBacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,22 @@ class ExtractorCallbacks{

//Is the highway tag listed as usable way?
if(("track" == highway && ("yes" == access || "yes" == accessTag)) || ("track" != highway && (0 < settings[highway] || "yes" == accessTag || "designated" == accessTag) )) {
if(!w.isDurationSet) {
if(!w.isDurationSet) {
if(0 < settings[highway]) {
if(0 < maxspeed)
w.speed = maxspeed;
if(settings.takeMinimumOfSpeeds)
w.speed = std::min(settings[highway], maxspeed);
else
w.speed = maxspeed;
else
w.speed = settings[highway];
} else {
w.speed = settings.defaultSpeed;
if(0 < maxspeed)
if(settings.takeMinimumOfSpeeds)
w.speed = std::min(settings.defaultSpeed, maxspeed);
else w.speed = maxspeed;
else
w.speed = settings.defaultSpeed;
highway = "default";
}
}
Expand All @@ -202,15 +210,15 @@ class ExtractorCallbacks{
}

if( settings.obeyOneways ) {
if( onewayClass == "yes" || onewayClass == "1" || onewayClass == "true" ) {
if( onewayClass == "yes" || onewayClass == "1" || onewayClass == "true" ) {
w.direction = _Way::oneway;
} else if( onewayClass == "no" || onewayClass == "0" || onewayClass == "false" ) {
w.direction = _Way::bidirectional;
} else if( onewayClass == "-1" ) {
w.direction = _Way::opposite;
} else if( oneway == "no" || oneway == "0" || oneway == "false" ) {
} else if( onewayClass == "no" || onewayClass == "0" || onewayClass == "false" ) {
w.direction = _Way::bidirectional;
} else if( onewayClass == "-1" ) {
w.direction = _Way::opposite;
} else if( oneway == "no" || oneway == "0" || oneway == "false" ) {
w.direction = _Way::bidirectional;
} else if( settings.accessTag == "bicycle" && (cycleway == "opposite" || cycleway == "opposite_track" || cycleway == "opposite_lane") ) {
} else if( settings.accessTag == "bicycle" && (cycleway == "opposite" || cycleway == "opposite_track" || cycleway == "opposite_lane") ) {
w.direction = _Way::bidirectional;
} else if( oneway == "-1") {
w.direction = _Way::opposite;
Expand Down
4 changes: 2 additions & 2 deletions DataStructures/ExtractorStructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ struct CmpWayByID : public std::binary_function<_WayIDStartAndEndEdge, _WayIDSta
};

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;
int operator[](const std::string & param) const {
if(speedProfile.find(param) == speedProfile.end())
Expand All @@ -290,7 +290,7 @@ struct Settings {
bool useRestrictions;
std::string accessTag;
int defaultSpeed;
int trafficLightPenalty;
bool takeMinimumOfSpeeds;
std::string excludeFromGrid;
};

Expand Down
2 changes: 1 addition & 1 deletion DataStructures/TurnInstructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct TurnInstructionsClass {
if (angle >= 292 && angle < 336) {
return TurnSharpLeft;
}
return 5;
return UTurn;
}

static inline bool TurnIsNecessary ( const short turnInstruction ) {
Expand Down

0 comments on commit 556e487

Please sign in to comment.