forked from zossebart/brouter-mtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtb-zossebart.brf
627 lines (566 loc) · 25 KB
/
mtb-zossebart.brf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#
# mountainbike profile by zossebart
# v1.1.4
# see https://github.com/zossebart/brouter-mtb for information and releases
#
# CAUTION! always ride carefully, routing data and/or route calculation might not be accurate and safe at all times!
#
---context:global # following code refers to global config
assign turnInstructionMode = 1 # %turnInstructionMode% | Mode for the generated turn instructions | [0=none, 1=auto-choose, 2=locus-style, 3=osmand-style, 4=comment-style, 5=gpsies-style, 6=oruxmaps-style]
assign turnInstructionRoundabouts = true # %turnInstructionRoundabouts% | Set to "false" to avoid generating special turning instructions for roundabouts | boolean
assign turnInstructionCatchingRange = 4
# generate a bike route
assign validForBikes = true
assign validForCars = false
assign validForFoot = false
# Locus nav interface flags
assign is_wet = 0 # %is_wet% | Choose a safer route in wet conditions | boolean
assign mtb_hard_factor = 0 # %mtb_hard_factor% | Difficulty of the route (0:xc/am...2:allmountain...4:enduro) | number
# the global elevation parameters
assign downhillcost = max 0 ( sub 30 ( multiply mtb_hard_factor 10 ) )
assign downhillcutoff = 4
assign uphillcost = max 0 ( sub 40 ( multiply mtb_hard_factor 15 ) )
assign uphillcutoff = 1.5
# elevation filtering parameters (tbd: optimized settings)
assign elevationpenaltybuffer = 10
assign elevationmaxbuffer = 10
assign elevationbufferreduce = 0
# ++++++++++++++++++++++++++++++++++++++ some global defines for finetuning
assign voiceprio = 2 # 1: all ways have the same prio (max instructions)
# 2: mtb prio, more instructions on different small way types
assign mj_rd_penalty = 0.5 # additional penalty for major roads for finetuning
assign construction_penalty = 3 # penalty for roads in construction (oftentimes rideable by mtb)
assign steps_penalty = max 0 ( sub 15 ( multiply mtb_hard_factor 5 ) )
# penalty for steps
assign steps_ramp_uh_penalty = 5 # penalty for uphill steps with a ramp (might be smaller than default steps penalty)
assign steps_ramp_dh_penalty = 2 # penalty for downhill steps with a ramp (even smaller than uphill ramp)
assign ferry_penalty = 5000 # penalty for ferries
assign private_penalty = 6 # penalty for private ways and nodes
assign bicycle_no_penalty = 5 # penalty for ways and nodes with bicycle=no
assign slippery_muddy_penalty = if is_wet # penalty for unpaved roads and tracks, which are tricky to ride when wet
then 2
else 0
assign ford_penalty = max 0 ( sub 15 ( multiply mtb_hard_factor 8 ) )
# penalty for fords (you might not want to get your feet wet ;-) )
assign isbike_reduce = 0.7 # penalty reduction for major roads with a cycleway
assign isfoot_reduce = 0.9 # penalty reduction for major roads with a footway or sidewalk
# +++ special downhill parameters
assign considerdownhill = true # use special penalties for downhills? (enables/disables below parameters)
assign dh_penalty = max 0 ( add 2.0 ( multiply mtb_hard_factor 0.5 ) )
# additional penalty for undesired downhills (e.g. major roads)
assign dh_difficult_penalty = max 0 ( sub 10 ( multiply mtb_hard_factor 1 ) )
# additional downhill penalty for ways with high difficulty (mtb/sac_scale)
assign dh_use_tracks = lesser mtb_hard_factor 0
# use less penalty for downhill tracks than for other waytypes? (0/1)
# enables/disables dh_track_penalty
assign dh_track_penalty = multiply 0.75 dh_penalty
# percentage of reduced downhill penalty for tracks
# +++ special uphill parameters
assign consideruphill = true # use special penalties for uphills? (enables/disables below parameters)
assign uh_penalty = max 0 ( sub 2.5 ( multiply mtb_hard_factor 0.25 ) )
# additional penalty for undesired uphills (e.g. paths)
assign uh_difficult_penalty = max 0 ( sub 10 ( multiply mtb_hard_factor 1 ) )
# additional uphill penalty for ways with high difficulty (mtb/sac_scale or mtb_scale_uphill)
# ------------------------------------------- global defines end
---context:way # following code refers to way-tags
# classifier constants
assign classifier_none = 1
assign classifier_ferry = 2
#
# pre-calculate some logical expressions
#
#
# does the road have a footway or sidewalk?
#
assign has_sidewalk = not ( or sidewalk= sidewalk=no|none )
assign has_footway = not ( or footway= footway=no|none )
assign has_foot = or has_sidewalk has_footway
#
# does the road have a cycleway?
#
assign cycle = not ( or cycleway= cycleway=no|none|proposed )
assign l_cycle = not ( or cycleway:left= cycleway:left=no )
assign r_cycle = not ( or cycleway:right= cycleway:right=no )
assign has_cycleway = or cycle ( or l_cycle r_cycle )
#
# is it a low-speed highway?
#
assign islowspeed = if maxspeed=10|20|30
then true
else false
#
# is it a high-speed highway?
#
assign ishighspeed = if maxspeed=60|70|80|90|100|110|120|130|rural
then true
else false
#
# are there multiple lanes on the highway?
#
assign ismultilane = if lanes=
then false
else if lanes=1|1.5|2
then false
else true
#
# assign the penalty reduction for roads with sidewalks or cycleways
#
assign penalty_reduce = if has_cycleway
then isbike_reduce
else if has_foot
then isfoot_reduce
else 1
#
# is the road paved or unpaved?
#
assign ispaved = surface=paved|asphalt|concrete|paving_stones|grass_paver|metal|wood|compacted
assign isunpaved = not ( or surface= ispaved )
#
# is the surface potentially slippery or muddy when it's wet?
#
assign surfacebadwhenwet = and isunpaved ( not surface=compacted|fine_gravel )
assign highwaybadwhenwet = or highway=path ( or tracktype=grade5|grade4 highway=bridleway )
assign isbadwhenwet = or surfacebadwhenwet highwaybadwhenwet
assign any_cycleroute = or route_bicycle_icn=yes ( or route_bicycle_ncn=yes ( or route_bicycle_rcn=yes route_bicycle_lcn=yes ) )
#
# get the inclination (up=1, down=-1, unknown=0)
#
assign inclination =
if incline=
then 0
else if incline=yes|up|5%|8%|10%|15%|20%|25%|30%
then if reversedirection=yes
then -1
else 1
else if incline=down|-5%|-8%|-10%|-15%|-20%|-25%|-30%
then if reversedirection=yes
then 1
else -1
else 0
#
# precalculate steps penaltys
#
assign steps_uh_penalty =
if or ramp:stroller=yes ramp:bicycle=yes
then steps_ramp_uh_penalty
else multiply 1.2 ( add uh_penalty steps_penalty ) # boost steps uphill penalty even more
assign steps_dh_penalty =
if or ramp:stroller=yes ramp:bicycle=yes
then steps_ramp_dh_penalty
else add dh_penalty steps_penalty
#
# base penalties for roadtypes
#
assign hw_penalty =
if highway=motorway|motorway_link then 9999
else if highway=proposed then 9999
else if highway=construction then construction_penalty
else 0
assign hw_major_penalty =
multiply if islowspeed # reduce the penalty if the speedlimit is low
then 0.75
else 1
multiply max 1 ( multiply ishighspeed 1.2 ) # rise the penalty if the speedlimit is high
multiply max 1 ( multiply ismultilane 1.2 ) # rise the penalty if there are more than 2 lanes
if highway=trunk|trunk_link then add mj_rd_penalty 10
else if highway=primary|primary_link then add mj_rd_penalty 6.0
else if highway=secondary|secondary_link then add mj_rd_penalty 2.6
else if highway=tertiary|tertiary_link then add mj_rd_penalty 2.3
else if highway=unclassified then add mj_rd_penalty 2.2
else 0
assign hw_minor_penalty =
multiply max 1 ( multiply ishighspeed 1.2 ) # rise the penalty if the speedlimit is high
multiply max 1 ( multiply ismultilane 1.2 ) # rise the penalty if there are more than 2 lanes
if highway=residential then 1.2
else if highway=service then 1.1
else if highway=living_street then 1.1
else if highway=pedestrian then 1.1
else if highway=footway then 1.1
else 0
#
# additional penalties for other road attributes
#
assign mtb_sac_penalty =
max 0
multiply
( sub 1 ( multiply mtb_hard_factor 0.25 ) )
(
if ( or mtb:scale=3|2+ sac_scale=demanding_mountain_hiking ) then 2
else if ( or mtb:scale=4 sac_scale=alpine_hiking ) then 4
else if ( or mtb:scale=5 sac_scale=demanding_alpine_hiking ) then 50
else if ( or mtb:scale=6 sac_scale=difficult_alpine_hiking ) then 100
else 0
)
assign mtb_uh_penalty = #(supported since 1.4.4)
max 0
multiply
( sub 1 ( multiply mtb_hard_factor 0.25 ) )
(
if mtb:scale:uphill=3 then 2
else if mtb:scale:uphill=4 then 4
else if mtb:scale:uphill=5 then 50
else if mtb:scale=6 then 100
else 0
)
assign tracktype_penalty =
max 0
multiply
( sub 1 ( multiply mtb_hard_factor 0.5 ) )
(
if tracktype=grade5 then 0.2
else 0
)
assign traffic_penalty =
multiply
0.3
(
if estimated_traffic_class=2 then 1
else if estimated_traffic_class=3 then 2
else if estimated_traffic_class=4 then 3
else if estimated_traffic_class=5 then 4
else if estimated_traffic_class=6 then 5
else if estimated_traffic_class=7 then 6
else 0
)
#
# implicit access here just from the motorroad tag
# (implicit access rules from highway tag handled elsewhere)
#
assign defaultaccess =
if access=
then ( not motorroad=yes )
else
(
if access=no
then false
else
(
if access=private
then false
else true
)
)
#
# calculate logical bike access
#
assign bikeaccess =
or
any_cycleroute
(
if bicycle=
then
(
if vehicle=
then defaultaccess
else
(
if vehicle=private|no
then false
else true
)
)
else
(
if not bicycle=private
then true
else false
)
)
#
# calculate logical foot access
#
assign footaccess =
or bikeaccess
or bicycle=dismount
if foot=
then defaultaccess
else not foot=private|no
#
# combine to penalty for access
#
assign access_penalty =
if bikeaccess
then
(
if bicycle=no # bike access granted from above, but check for bicycle=no
then bicycle_no_penalty # access with penalty for bicycle=no
else
(
if bicycle=dismount # bike access granted from above, but check for bicycle=dismount
then ( multiply 0.2 bicycle_no_penalty ) # access with penalty for bicycle=dismount
else 0
)
) # full bike access
else
(
if ( or access=private or bicycle=private or vehicle=private foot=private )
then private_penalty # access with penalty for private
else 100000 # absolutely no access
)
#
# combine additional penaltys which are common for flat, up and down ways
#
assign misc_penalty =
add access_penalty
add traffic_penalty
add if ( not ford= ) then ford_penalty
else 0
add if trail_visibility=bad then 2
else
(
if trail_visibility=horrible then 5
else
(
if trail_visibility=no then 15
else 0
)
)
add if smoothness=impassable then 10
else 0
max 0 multiply ( sub 1 ( multiply mtb_hard_factor 0.3333 ) )
add if surfacebadwhenwet then slippery_muddy_penalty
else 0
add if highwaybadwhenwet then slippery_muddy_penalty
else 0
if surface=sand|mud then 3
else 0
#
# now assign the parameters for the routing engine (initialcost, turncost and flat/up/down costfactors)
#
assign turncost =
if highway=path|footway
then
(
if equal inclination -1 then 0
else 10
)
else
(
if highway=track then 50
else 150
)
#
# assign parameters for turn instruction generation
#
assign priorityclassifier =
if equal voiceprio 1 then 1
else if equal voiceprio 2
then if ( highway=motorway ) then 101
else if ( highway=motorway_link ) then 100
else if ( highway=trunk ) then 91
else if ( highway=trunk_link ) then 90
else if ( highway=primary ) then 88
else if ( highway=primary_link ) then 87
else if ( highway=secondary ) then 86
else if ( highway=secondary_link ) then 85
else if ( highway=tertiary ) then 84
else if ( highway=tertiary_link ) then 83
else if ( highway=unclassified ) then 82
else if ( highway=residential|living_street ) then 50
else if ( highway=service ) then 40
else if ( highway=road ) then 35
else if ( highway=cycleway ) then 30
else if ( highway=bridleway|track ) then 20
else if ( highway=footway|pedestrian ) then 17
else if ( highway=steps ) then 15
else if ( highway=path ) then 10
else 0
else 0
assign isroundabout = junction=roundabout
assign islinktype = highway=motorway_link|trunk_link|primary_link|secondary_link|tertiary_link
assign isgoodforcars =
if ( greater priorityclassifier 30 )
then true
else
(
if highway=residential|living_street|service
then true
else
(
if ( and highway=track tracktype=grade1 )
then true
else false
)
)
# ... encoded into a bitmask
assign classifiermask = add multiply isroundabout 4
add multiply islinktype 8
multiply isgoodforcars 16
#
# for any change in initialclassifier, initialcost is added once
#
assign initialclassifier =
if route=ferry then classifier_ferry
else classifier_none
assign initialcost =
if ( equal initialclassifier classifier_ferry ) then ferry_penalty
else 0
#
# costfactor for flat terrain
#
assign costfactor =
if and highway= not route=ferry then 100000
else
min 9999
add misc_penalty
add if ( and ( equal inclination 1 ) mtb_uh_penalty )
then
(
add
mtb_uh_penalty
(
if consideruphill then uh_difficult_penalty
else 0
)
)
else mtb_sac_penalty
add tracktype_penalty
max 1
if hw_penalty then hw_penalty
else if hw_major_penalty then hw_major_penalty
else if hw_minor_penalty then hw_minor_penalty
else if highway=path then 1
else if highway=steps
then
(
if equal inclination 1 then steps_uh_penalty
else
(
if equal inclination -1 then steps_dh_penalty
else
(
if reversedirection=yes then steps_dh_penalty
else steps_uh_penalty
)
)
)
else if highway=track|bridleway then 1
else if highway=cycleway then max 1 ( add 1.1 ( multiply mtb_hard_factor 0.1 ) )
else 40 # default for any other highway type not handled above
#
# costfactor for uphills
#
assign uphillcostfactor =
if consideruphill
then
(
if and highway= not route=ferry then 100000
else
min 9999
add misc_penalty
add if ( and ( equal inclination 1 ) mtb_uh_penalty )
then add uh_difficult_penalty mtb_uh_penalty
else
(
if mtb_sac_penalty then add uh_difficult_penalty mtb_sac_penalty
else 0
)
add if tracktype_penalty then add uh_difficult_penalty tracktype_penalty
else 0
max 1
if hw_penalty then hw_penalty
else if hw_major_penalty then multiply penalty_reduce hw_major_penalty
else if hw_minor_penalty then hw_minor_penalty
else if highway=path then uh_penalty
else if highway=steps # first try to use incline
then if equal inclination 1 then steps_uh_penalty
else if equal inclination -1 then steps_dh_penalty
else steps_uh_penalty # no incline tag, assume step is really uphill
else if highway=track then 1
else if highway=bridleway then 1.2
else if highway=cycleway then 1
else 40 # default for any other highway type not handled above
)
else 0 # no special handling for uphill selected, flat costfactor will be used instead
#
# costfactor for downhills
#
assign downhillcostfactor =
if considerdownhill
then
(
if and highway= not route=ferry then 100000
else
min 9999
add misc_penalty
add if ( and ( equal inclination 1 ) mtb_uh_penalty )
then
(
add if consideruphill then uh_difficult_penalty
else 0
mtb_uh_penalty
)
else
(
if mtb_sac_penalty then add dh_difficult_penalty mtb_sac_penalty
else 0
)
add if tracktype_penalty then add dh_difficult_penalty tracktype_penalty
else 0
max 1
if hw_penalty then add dh_penalty hw_penalty
else if hw_major_penalty then add dh_penalty hw_major_penalty
else if hw_minor_penalty then add dh_penalty hw_minor_penalty
else if highway=path then 1
else if highway=steps # first try to use incline
then if equal inclination 1 then steps_uh_penalty
else if equal inclination -1 then steps_dh_penalty
else steps_dh_penalty # no incline tag, assume step is really downhill
else if highway=track|bridleway
then if dh_use_tracks then dh_track_penalty
else dh_penalty
else if highway=cycleway then add dh_penalty 0.5
else 40 # default for any other highway type not handled above
)
else 0 # no special handling for downhill selected, flat costfactor will be used instead
---context:node # following code refers to node tags
assign defaultaccess =
if access=
then
(
if barrier=gate|fence|door|wall then false
else true
)
else
(
if access=private|no
then false
else true
)
assign bikeaccess =
or nodeaccessgranted=yes
if bicycle=
then
(
if vehicle= then defaultaccess
else
(
if vehicle=private|no then false
else true
)
)
else
(
if bicycle=private|no|dismount then false
else true
)
assign footaccess =
or bicycle=dismount
if foot= then defaultaccess
else if foot=private|no then false
else true
assign initialcost =
add if highway=traffic_signals then 100
else 0
if ( and ( or bikeaccess footaccess ) ( not highway=elevator ) )
then
(
if ( or ( not ford= ) highway=ford ) then ( multiply 100 ford_penalty )
else 0
)
# switch or access=private
# or bicycle=private
# or vehicle=private
# foot=private
# multiply 100 private_penalty # access with penalty
else 1000000