Implement bicycle safety penalty
This commit is contained in:
		
							parent
							
								
									34f62b4894
								
							
						
					
					
						commit
						a3e0eb03db
					
				| @ -25,7 +25,7 @@ Feature: Bicycle - Adds penalties to unsafe roads | |||||||
|     Scenario: Bike - Apply no penalties to ways with cycleways |     Scenario: Bike - Apply no penalties to ways with cycleways | ||||||
|         Then routability should be |         Then routability should be | ||||||
|             | highway        | cycleway    | forw    | backw   | forw_rate | backw_rate | |             | highway        | cycleway    | forw    | backw   | forw_rate | backw_rate | | ||||||
|             | motorway      | lane     | 15 km/h | 15 km/h | 4.2       | 4.2        | |             | motorway       | lane        | 15 km/h |         |       4.2 |            | | ||||||
|             | primary        | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | |             | primary        | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
|             | secondary      | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | |             | secondary      | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
|             | tertiary       | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | |             | tertiary       | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
| @ -35,6 +35,8 @@ Feature: Bicycle - Adds penalties to unsafe roads | |||||||
|             | residential    | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | |             | residential    | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
|             | cycleway       | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | |             | cycleway       | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
|             | footway        | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | |             | footway        | lane        | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
|  |             | motorway       | shared_lane | 15 km/h |         |       4.2 |            | | ||||||
|  |             | primary        | shared_lane | 15 km/h | 15 km/h |       4.2 |        4.2 | | ||||||
| 
 | 
 | ||||||
|     Scenario: Bike - Apply no penalties to ways in direction of cycleways |     Scenario: Bike - Apply no penalties to ways in direction of cycleways | ||||||
|         Then routability should be |         Then routability should be | ||||||
| @ -59,6 +61,10 @@ Feature: Bicycle - Adds penalties to unsafe roads | |||||||
|             | residential   |                | lane          | 15 km/h    | 15 km/h    | 4.2       | 4.2        | |             | residential   |                | lane          | 15 km/h    | 15 km/h    | 4.2       | 4.2        | | ||||||
|             | cycleway      |                | lane          | 15 km/h    | 15 km/h    | 4.2       | 4.2        | |             | cycleway      |                | lane          | 15 km/h    | 15 km/h    | 4.2       | 4.2        | | ||||||
|             | footway       |                | lane          | 6 km/h +-1 | 15 km/h    | 1.7       | 4.2        | |             | footway       |                | lane          | 6 km/h +-1 | 15 km/h    | 1.7       | 4.2        | | ||||||
|  |             | motorway      | shared_lane    |               | 15 km/h    |            | 4.2       |            | | ||||||
|  |             | primary       | shared_lane    |               | 15 km/h    | 15 km/h    | 4.2       | 2.9        | | ||||||
|  |             | motorway      |                | shared_lane   |            | 15 km/h    |           | 4.2        | | ||||||
|  |             | primary       |                | shared_lane   | 15 km/h    | 15 km/h    | 2.9       | 4.2        | | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     Scenario: Bike - Don't apply penalties for all kind of cycleways |     Scenario: Bike - Don't apply penalties for all kind of cycleways | ||||||
|  | |||||||
| @ -94,7 +94,8 @@ local profile = { | |||||||
|   	'opposite_track', |   	'opposite_track', | ||||||
|   	'share_busway', |   	'share_busway', | ||||||
|   	'sharrow', |   	'sharrow', | ||||||
|   	'shared' |   	'shared', | ||||||
|  |     'shared_lane' | ||||||
|   }, |   }, | ||||||
| 
 | 
 | ||||||
|   unsafe_highway_list = Set { |   unsafe_highway_list = Set { | ||||||
| @ -377,10 +378,7 @@ function way_function (way, result) | |||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   -- oneway |   -- oneway | ||||||
|   local implied_oneway = false |   local implied_oneway = junction == "roundabout" or junction == "circular" or data.highway == "motorway" | ||||||
|   if junction == "roundabout" or junction == "circular" or data.highway == "motorway" then |  | ||||||
|     implied_oneway = true |  | ||||||
|   end |  | ||||||
|   local reverse = false |   local reverse = false | ||||||
| 
 | 
 | ||||||
|   if oneway_bicycle == "yes" or oneway_bicycle == "1" or oneway_bicycle == "true" then |   if oneway_bicycle == "yes" or oneway_bicycle == "1" or oneway_bicycle == "true" then | ||||||
| @ -507,25 +505,33 @@ function way_function (way, result) | |||||||
|   -- convert duration into cyclability |   -- convert duration into cyclability | ||||||
|   if properties.weight_name == 'cyclability' then |   if properties.weight_name == 'cyclability' then | ||||||
|       local is_unsafe = profile.safety_penalty < 1 and profile.unsafe_highway_list[data.highway] |       local is_unsafe = profile.safety_penalty < 1 and profile.unsafe_highway_list[data.highway] | ||||||
|  |       local forward_is_unsafe = is_unsafe and not has_cycleway_right | ||||||
|  |       local backward_is_unsafe = is_unsafe and not has_cycleway_left | ||||||
|       local is_undesireable = data.highway == "service" and profile.service_penalties[service] |       local is_undesireable = data.highway == "service" and profile.service_penalties[service] | ||||||
|       local penalty = 1.0 |       local forward_penalty = 1. | ||||||
|       if is_unsafe then |       local backward_penalty = 1. | ||||||
|         penalty = math.min(penalty, profile.safety_penalty) |       if forward_is_unsafe then | ||||||
|  |         forward_penalty = math.min(forward_penalty, profile.safety_penalty) | ||||||
|       end |       end | ||||||
|  |       if backward_is_unsafe then | ||||||
|  |          backward_penalty = math.min(backward_penalty, profile.safety_penalty) | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|       if is_undesireable then |       if is_undesireable then | ||||||
|         penalty = math.min(penalty, profile.service_penalties[service]) |          forward_penalty = math.min(forward_penalty, profile.service_penalties[service]) | ||||||
|  |          backward_penalty = math.min(backward_penalty, profile.service_penalties[service]) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       if result.forward_speed > 0 then |       if result.forward_speed > 0 then | ||||||
|         -- convert from km/h to m/s |         -- convert from km/h to m/s | ||||||
|         result.forward_rate = result.forward_speed / 3.6 * penalty |         result.forward_rate = result.forward_speed / 3.6 * forward_penalty | ||||||
|       end |       end | ||||||
|       if result.backward_speed > 0 then |       if result.backward_speed > 0 then | ||||||
|         -- convert from km/h to m/s |         -- convert from km/h to m/s | ||||||
|         result.backward_rate = result.backward_speed / 3.6 * penalty |         result.backward_rate = result.backward_speed / 3.6 * backward_penalty | ||||||
|       end |       end | ||||||
|       if result.duration > 0 then |       if result.duration > 0 then | ||||||
|         result.weight = result.duration / penalty |         result.weight = result.duration / forward_penalty | ||||||
|       end |       end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user