easy way to set both directions from lua, maxspeed helper

This commit is contained in:
Emil Tin 2013-05-05 09:11:11 +02:00
parent 00c0b9ce4d
commit ebd8c84940
5 changed files with 120 additions and 80 deletions

View File

@ -81,7 +81,26 @@ struct ExtractionWay {
}
return ExtractionWay::bidirectional;
}
inline void set_mode(const TravelMode m) { forward.mode = m; backward.mode = m; }
inline const TravelMode get_mode() {
if( forward.mode == backward.mode ) {
return forward.mode;
} else {
return -1;
}
}
inline void set_speed(const double s) { forward.speed = s; backward.speed = s; }
inline const double get_speed() {
if( forward.speed == backward.speed ) {
return forward.speed;
} else {
return -1;
}
}
unsigned id;
unsigned nameID;
std::string name;

View File

@ -76,6 +76,8 @@ ScriptingEnvironment::ScriptingEnvironment(const char * fileName) {
.def_readwrite("tags", &ExtractionWay::keyVals)
.def_readwrite("forward", &ExtractionWay::forward)
.def_readwrite("backward", &ExtractionWay::backward)
.property("mode", &ExtractionWay::get_mode, &ExtractionWay::set_mode)
.property("speed", &ExtractionWay::get_speed, &ExtractionWay::set_speed)
];
luabind::module(myLuaState) [

View File

@ -3,8 +3,9 @@ Feature: Bike - Mode flag
# bicycle modes:
# 1 bike
# 2 ferry
# 3 push
# 2 pushing
# 3 ferry
# 4 train
Background:
Given the profile "bicycle"
@ -22,12 +23,32 @@ Feature: Bike - Mode flag
When I route I should get
| from | to | route | turns | modes |
| a | d | ab,bc,cd | head,right,left,destination | 1,2,1 |
| d | a | cd,bc,ab | head,right,left,destination | 1,2,1 |
| c | a | bc,ab | head,left,destination | 2,1 |
| d | b | cd,bc | head,right,destination | 1,2 |
| a | c | ab,bc | head,right,destination | 1,2 |
| b | d | bc,cd | head,left,destination | 2,1 |
| a | d | ab,bc,cd | head,right,left,destination | 1,3,1 |
| d | a | cd,bc,ab | head,right,left,destination | 1,3,1 |
| c | a | bc,ab | head,left,destination | 3,1 |
| d | b | cd,bc | head,right,destination | 1,3 |
| a | c | ab,bc | head,right,destination | 1,3 |
| b | d | bc,cd | head,left,destination | 3,1 |
Scenario: Bike - Mode when using a train
Given the node map
| a | b | |
| | c | d |
And the ways
| nodes | highway | railway | bicycle |
| ab | primary | | |
| bc | | train | yes |
| cd | primary | | |
When I route I should get
| from | to | route | turns | modes |
| a | d | ab,bc,cd | head,right,left,destination | 1,4,1 |
| d | a | cd,bc,ab | head,right,left,destination | 1,4,1 |
| c | a | bc,ab | head,left,destination | 4,1 |
| d | b | cd,bc | head,right,destination | 1,4 |
| a | c | ab,bc | head,right,destination | 1,4 |
| b | d | bc,cd | head,left,destination | 4,1 |
Scenario: Bike - Mode when pushing bike against oneways
Given the node map
@ -43,9 +64,9 @@ Feature: Bike - Mode flag
When I route I should get
| from | to | route | turns | modes |
| a | d | ab,bc,cd | head,right,left,destination | 1,1,1 |
| d | a | cd,bc,ab | head,right,left,destination | 1,3,1 |
| c | a | bc,ab | head,left,destination | 3,1 |
| d | b | cd,bc | head,right,destination | 1,3 |
| d | a | cd,bc,ab | head,right,left,destination | 1,2,1 |
| c | a | bc,ab | head,left,destination | 2,1 |
| d | b | cd,bc | head,right,destination | 1,2 |
| a | c | ab,bc | head,right,destination | 1,1 |
| b | d | bc,cd | head,left,destination | 1,1 |
@ -62,12 +83,12 @@ Feature: Bike - Mode flag
When I route I should get
| from | to | route | turns | modes |
| a | d | ab,bc,cd | head,right,left,destination | 1,3,1 |
| d | a | cd,bc,ab | head,right,left,destination | 1,3,1 |
| c | a | bc,ab | head,left,destination | 3,1 |
| d | b | cd,bc | head,right,destination | 1,3 |
| a | c | ab,bc | head,right,destination | 1,3 |
| b | d | bc,cd | head,left,destination | 3,1 |
| a | d | ab,bc,cd | head,right,left,destination | 1,2,1 |
| d | a | cd,bc,ab | head,right,left,destination | 1,2,1 |
| c | a | bc,ab | head,left,destination | 2,1 |
| d | b | cd,bc | head,right,destination | 1,2 |
| a | c | ab,bc | head,right,destination | 1,2 |
| b | d | bc,cd | head,left,destination | 2,1 |
Scenario: Bike - Mode when pushing on pedestrain areas
Given the node map
@ -82,9 +103,9 @@ Feature: Bike - Mode flag
When I route I should get
| from | to | route | modes |
| a | f | ab,bcd,df | 1,3,1 |
| f | a | df,bcd,ab | 1,3,1 |
| d | a | bcd,ab | 3,1 |
| f | b | df,bcd | 1,3 |
| a | d | ab,bcd | 1,3 |
| b | f | bcd,df | 3,1 |
| a | f | ab,bcd,df | 1,2,1 |
| f | a | df,bcd,ab | 1,2,1 |
| d | a | bcd,ab | 2,1 |
| f | b | df,bcd | 1,2 |
| a | d | ab,bcd | 1,2 |
| b | f | bcd,df | 2,1 |

View File

@ -1,4 +1,5 @@
require("lib/access")
require("lib/maxspeed")
-- Begin of globals
barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true}
@ -95,6 +96,13 @@ turn_penalty = 60
turn_bias = 1.4
-- End of globals
--modes
mode_normal = 1
mode_pushing = 2
mode_ferry = 3
mode_train = 4
function get_exceptions(vector)
for i,v in ipairs(restriction_exception_tags) do
vector:Add(v)
@ -191,76 +199,62 @@ function way_function (way)
way.name = "{highway:"..highway.."}" -- if no name exists, use way type
-- this encoding scheme is excepted to be a temporary solution
end
way.forward.mode = 1
way.backward.mode = 1
way.mode = mode_normal
-- speed
if route_speeds[route] then
-- ferries (doesn't cover routes tagged using relations)
way.mode = mode_ferry
way.ignore_in_grid = true
if durationIsValid(duration) then
way.duration = math.max( 1, parseDuration(duration) )
else
way.forward.speed = route_speeds[route]
way.backward.speed = route_speeds[route]
way.speed = route_speeds[route]
end
way.forward.mode = 2
way.backward.mode = 2
elseif platform_speeds[railway] then
-- railway platforms (old tagging scheme)
way.forward.speed = platform_speeds[railway]
way.backward.speed = platform_speeds[railway]
way.speed = platform_speeds[railway]
elseif platform_speeds[public_transport] then
-- public_transport platforms (new tagging platform)
way.forward.speed = platform_speeds[public_transport]
way.backward.speed = platform_speeds[public_transport]
way.speed = platform_speeds[public_transport]
elseif railway_speeds[railway] then
-- railways
if access and access_tag_whitelist[access] then
way.forward.speed = railway_speeds[railway]
way.backward.speed = railway_speeds[railway]
way.mode = mode_train
way.speed = railway_speeds[railway]
end
elseif amenity_speeds[amenity] then
-- parking areas
way.forward.speed = amenity_speeds[amenity]
way.backward.speed = amenity_speeds[amenity]
way.speed = amenity_speeds[amenity]
elseif bicycle_speeds[highway] then
-- regular ways
way.forward.speed = bicycle_speeds[highway]
way.backward.speed = bicycle_speeds[highway]
way.speed = bicycle_speeds[highway]
elseif access_tag_whitelist[access] then
-- unknown way, but valid access tag
way.forward.speed = default_speed
way.backward.speed = default_speed
way.speed = default_speed
else
-- biking not allowed, maybe we can push our bike?
-- essentially requires pedestrian profiling, for example foot=no mean we can't push a bike
if foot ~= 'no' then
if pedestrian_speeds[highway] then
-- pedestrian-only ways and areas
way.forward.speed = pedestrian_speeds[highway]
way.backward.speed = pedestrian_speeds[highway]
way.forward.mode = 3
way.backward.mode = 3
way.speed = pedestrian_speeds[highway]
way.mode = mode_pushing
elseif man_made and man_made_speeds[man_made] then
-- man made structures
way.forward.speed = man_made_speeds[man_made]
way.backward.speed = man_made_speeds[man_made]
way.forward.mode = 3
way.backward.mode = 3
way.speed = man_made_speeds[man_made]
way.mode = mode_pushing
elseif foot == 'yes' then
way.forward.speed = walking_speed
way.backward.speed = walking_speed
way.forward.mode = 3
way.backward.mode = 3
way.speed = walking_speed
way.mode = mode_pushing
elseif foot_forward == 'yes' then
way.forward.speed = walking_speed
way.forward.mode = 3
way.forward.mode = mode_pushing
way.backward.mode = 0
elseif foot_backward == 'yes' then
way.backward.speed = walking_speed
way.backward.mode = 3
way.backward.mode = mode_pushing
way.forward.mode = 0
end
end
@ -283,18 +277,18 @@ function way_function (way)
elseif string.find(cycleway, "opposite") == 1 then
if impliedOneway then
way.forward.mode = 0
way.backward.mode = 1
way.backward.mode = mode_normal
end
elseif cycleway_tags[cycleway_left] and cycleway_tags[cycleway_right] then
-- prevent implied
elseif cycleway_tags[cycleway_left] then
if impliedOneway then
way.forward.mode = 0
way.backward.mode = 1
way.backward.mode = mode_normal
end
elseif cycleway_tags[cycleway_right] then
if impliedOneway then
way.forward.mode = 1
way.forward.mode = mode_normal
way.backward.mode = 0
end
elseif oneway == "-1" then
@ -310,10 +304,10 @@ function way_function (way)
if junction ~= "roundabout" then
if way.backward.mode == 0 then
way.backward.speed = walking_speed
way.backward.mode = 3
way.backward.mode = mode_pushing
elseif way.forward.mode == 0 then
way.forward.speed = walking_speed
way.forward.mode = 3
way.forward.mode = mode_pushing
end
end
end
@ -332,27 +326,14 @@ function way_function (way)
end
-- surfaces
if surface then
surface_speed = surface_speeds[surface]
if surface_speed then
way.forward.speed = math.min(way.forward.speed, surface_speed)
way.backward.speed = math.min(way.backward.speed, surface_speed)
end
if surface_speeds[surface] then
way.forward.speed = math.min(way.forward.speed, surface_speeds[surface])
way.backward.speed = math.min(way.backward.speed, surface_speeds[surface])
end
-- maxspeed
if maxspeed_forward and maxspeed_forward>0 then
way.forward.speed = math.min(way.forward.speed, maxspeed_forward)
elseif maxspeed and maxspeed>0 then
way.forward.speed = math.min(way.forward.speed, maxspeed)
end
if maxspeed_backward and maxspeed_backward>0 then
way.backward.speed = math.min(way.backward.speed, maxspeed_backward)
elseif maxspeed and maxspeed>0 then
way.backward.speed = math.min(way.backward.speed, maxspeed)
end
MaxSpeed.limit( way, maxspeed, maxspeed_forward, maxspeed_backward )
return true
end

17
profiles/lib/maxspeed.lua Normal file
View File

@ -0,0 +1,17 @@
local math = math
module "MaxSpeed"
function limit(way,max,maxf,maxb)
if maxf and maxf>0 then
way.forward.speed = math.min(way.forward.speed, maxf)
elseif max and max>0 then
way.forward.speed = math.min(way.forward.speed, max)
end
if maxb and maxb>0 then
way.backward.speed = math.min(way.backward.speed, maxb)
elseif max and max>0 then
way.backward.speed = math.min(way.backward.speed, max)
end
end