compute turn penalties in lua profiles

This commit is contained in:
Emil Tin
2013-02-23 08:33:33 +01:00
committed by DennisOSRM
parent 53af4ee39f
commit f9abfbf68a
7 changed files with 95 additions and 15 deletions
+21 -7
View File
@@ -150,7 +150,7 @@ void EdgeBasedGraphFactory::InsertEdgeBasedNode(
edgeBasedNodes.push_back(currentNode);
}
void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename, lua_State *myLuaState) {
Percent p(_nodeBasedGraph->GetNumberOfNodes());
int numberOfSkippedTurns(0);
int nodeBasedEdgeCounter(0);
@@ -273,15 +273,16 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
if(_trafficLights.find(v) != _trafficLights.end()) {
distance += speedProfile.trafficSignalPenalty;
}
TurnInstruction turnInstruction = AnalyzeTurn(u, v, w);
if(TurnInstructions.UTurn == turnInstruction) {
unsigned penalty = 0;
TurnInstruction turnInstruction = AnalyzeTurn(u, v, w, penalty, myLuaState);
if(turnInstruction == TurnInstructions.UTurn)
distance += speedProfile.uTurnPenalty;
}
// if(!edgeData1.isAccessRestricted && edgeData2.isAccessRestricted) {
// distance += TurnInstructions.AccessRestrictionPenalty;
// turnInstruction |= TurnInstructions.AccessRestrictionFlag;
// }
distance += penalty;
//distance += heightPenalty;
//distance += ComputeTurnPenalty(u, v, w);
@@ -325,7 +326,21 @@ void EdgeBasedGraphFactory::Run(const char * originalEdgeDataFilename) {
INFO("Generated " << edgeBasedNodes.size() << " edge based nodes");
}
TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const {
TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const {
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
if( speedProfile.has_turn_function ) {
try {
//call lua profile to compute turn penalty
penalty = luabind::call_function<int>( myLuaState, "turn_function", 180-angle );
} catch (const luabind::error &er) {
std::cerr << er.what() << std::endl;
//TODO handle lua errors
}
} else {
penalty = 0;
}
if(u == w) {
return TurnInstructions.UTurn;
}
@@ -371,7 +386,6 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(const NodeID u, const NodeID
return TurnInstructions.NoTurn;
}
double angle = GetAngleBetweenTwoEdges(inputNodeInfoList[u], inputNodeInfoList[v], inputNodeInfoList[w]);
return TurnInstructions.GetTurnDirectionOfInstruction(angle);
}
+13 -3
View File
@@ -50,6 +50,14 @@
#include "../DataStructures/TurnInstructions.h"
#include "../Util/BaseConfiguration.h"
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <luabind/luabind.hpp>
class EdgeBasedGraphFactory : boost::noncopyable {
public:
struct EdgeBasedNode {
@@ -71,9 +79,10 @@ public:
};
struct SpeedProfileProperties{
SpeedProfileProperties() : trafficSignalPenalty(0), uTurnPenalty(0) {}
SpeedProfileProperties() : trafficSignalPenalty(0), uTurnPenalty(0), has_turn_function(false) {}
int trafficSignalPenalty;
int uTurnPenalty;
bool has_turn_function;
} speedProfile;
private:
@@ -133,10 +142,11 @@ public:
template< class InputEdgeT >
explicit EdgeBasedGraphFactory(int nodes, std::vector<InputEdgeT> & inputEdges, std::vector<NodeID> & _bollardNodes, std::vector<NodeID> & trafficLights, std::vector<_Restriction> & inputRestrictions, std::vector<NodeInfo> & nI, SpeedProfileProperties speedProfile);
void Run(const char * originalEdgeDataFilename);
void Run(const char * originalEdgeDataFilename, lua_State *myLuaState);
void GetEdgeBasedEdges( DeallocatingVector< EdgeBasedEdge >& edges );
void GetEdgeBasedNodes( DeallocatingVector< EdgeBasedNode> & nodes);
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w) const;
void GetOriginalEdgeData( std::vector< OriginalEdgeData> & originalEdgeData);
TurnInstruction AnalyzeTurn(const NodeID u, const NodeID v, const NodeID w, unsigned& penalty, lua_State *myLuaState) const;
unsigned GetNumberOfNodes() const;
};