# Poutnik's Trekking profile template for Trekking profile variants
# Version 2.7.*  -  Univ factor adjust system, Changed back to quadratic function
#                -  Merged tandem by Leopold Keller 
#                -  Not Too Steep mode  hills=6
#                -  ported ETA parameters from Trekking.brf
#                -  ported %parameters% shared with Trekking.brf to be able to use them in BRouter-web dialog.
#                -  tweaked UnivFactorCoefficient.   
#                -  Travel_Mode
#
# *)  = See also https://github.com/poutnikl/Brouter-profiles/wiki 
# **) = See also https://github.com/poutnikl/Trekking-Poutnik/wiki
# ***) = See also https://github.com/poutnikl/Brouter-profiles/wiki/Glossary
#
# LEGEND
#
# Legend above is the placeholder for generated comments of final profiles
# See the HistoryLog.txt file for file history, the wikis above for verbose comments.

# bstart /global
---context:global

# Bike profile
assign validForBikes = true

assign   is_wet                  0 # %is_wet% Wet_conditions
assign   avoid_unpaved           0 # %avoid_unpaved%
assign   cycleroutes_pref       0.2 # also CRP *)  costfactor penalty for not being cycleroute
assign   MTB_factor             0.0 # default 0.0, *)
assign   smallpaved_factor      0.0 # default 0.0, *)
assign   hills                  1 # 1=default / 0=BRouter default/ 1=+ penalty for uphills >3.0%/ 2=velomobile-like avoiding slopes, 3= simulates ascend/length time equiv.
                                  # 4=valley mode, 5=No-Flats mode, 6=Not steep mode
assign   isbike_for_mainroads   false # default=true / if false then bike friendly tag hints for mainroads are ignored, keeping their high penalties. v2.5.20
assign   path_preference        0.0 # 0.0 as default, try 0-20, see ***)
assign   UnifactorAdjust        0.0 # 0.0 as default, Use value let says -0.75..+0.75. 
assign   tandem_mode            0 # 0 as default, changing it increases pushpenalty, haulpenalty, dismountpenalty below
assign   Travel_Mode            add 0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 add 0 0
                                  # 0 as default, optins are additive as 2^N numbers
                                  # options marked by the same +)-like mark are mutually exclusive
                                  # options marked by the same x)-like mark are additive
                                  # 1 as hills 2 ( 1/80 uphill 0.5/80 downhill ) +)
                                  # 2 as +20 kg and -15 Watts as heavy load expedition mode
                                  # 4 as hills 6 (NotTooSteepMode) +) ( default 8-13% transition slope)
                                  # 8 as avoid_unsafe
                                                                    
assign   consider_smoothness    1 # 1 as default
assign   allow_traffic_penalty  1 # 1 as default

# Use the following switches to change behaviour
assign allow_steps              = true   # %allow_steps% | Set to false to disallow steps | boolean
assign   allow_fords            1 # 1 as default
assign   allow_ford_stepping    1 # 1 as default
assign allow_ferries            = true   # %allow_ferries% | set to false to disallow ferries | boolean
assign avoid_unsafe             = true  # %avoid_unsafe% | Set to true to avoid standard highways | boolean
assign considerTurnRestrictions = false  # %considerTurnRestrictions% | Set to true to take turn restrictions into account | boolean
assign processUnusedTags        = false  # %processUnusedTags% | Set to true to output unused tags in data tab | boolean

# Change elevation parameters
assign consider_elevation = true  # %consider_elevation% | Set to false to ignore elevation in routing | boolean

# Kinematic model parameters (travel time computation)
assign totalMass  = 110     # %totalMass% | Mass (in kg) of the bike + biker, for travel time computation | number
assign maxSpeed   = 35     # %maxSpeed% | Absolute maximum speed (in km/h), for travel time computation | number
assign S_C_x      = 0.225  # %S_C_x% | Drag coefficient times the reference area (in m^2), for travel time computation | number
assign C_r        = 0.01   # %C_r% | Rolling resistance coefficient (dimensionless), for travel time computation | number
assign bikerPower = 100    # %bikerPower% | Average power (in W) provided by the biker, for travel time computation | number

# ----- profile kinematic model modifications

assign bikermass 87
assign bikemass  14
assign luggagemass 20
assign bikerPowerDrop 15

# Turn instructions settings
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=orux-style]
assign turnInstructionCatchingRange = 20    # %turnInstructionCatchingRange% | Within this distance (in m) several turning instructions are combined into one and the turning angles are better approximated to the general direction | number
assign turnInstructionRoundabouts   = true  # %turnInstructionRoundabouts% | Set to "false" to avoid generating special turning instructions for roundabouts | boolean

                                                              
assign   StrictNOBicycleaccess          0 # 0 allows but penalizes foot only access / 1 forbides foot only access.
assign   valley_nonflat_multiplier = 2.0

assign   allow_default_barrier_restriction  false # If true, default access for barrier=gate is false. see node context
assign   ignore_cycle_barrier 1 # a cycle barrier has no effect with the default value 1 (usually ok for normal bikes)

# ----------------------------------------------------------------------------------------------------
# Internal parameters - not intended to be tweaked by end users, unless they know what they are doing.
#
# new in 2.7
assign    debug      false 
assign    debugcost  5.0

# # new in 2.7
# BEGIN  - Internal parareters for hills = 6 - experimental avoiding of too steep hills 
# via strongly penalizing uphillcostfactor
# ***) = See also https://github.com/poutnikl/Brouter-profiles/wiki/Glossary

assign   TooSteepUphill         5.0  # slope below this uphill limit ( % ) has no penalization
assign   TooSteepbufferreduce   7.0  # The width of the uphill scope transient zone                                        
assign   TooSteepUphillCost     80.0  # can be used optionally, but is rather overrun by the uphillcostfactor. 
assign   TooSteepCostFactor     20 # for uphill scope > TooSteepUphill + TooSteepbufferreduce                                     
                                    # with the transient zone TooSteepUphill .. TooSteepUphill + TooSteepbufferreduce
assign   TooSteepPenaltybuffer  12.0 # higher than default 5 to filter SRTM artefacts
assign   TooSteepMaxbuffer      20.0 # higher than default 10 to filter SRTM artefacts

# END  - Internal parareters for hills = 6 - experimental avoiding of too steep hills via strongly penalizing uphillcostfactor

# == Travel_mode - parameter overriding begin (v2.7)
assign c_tm_h2 1
assign c_tm_mass 2
assign c_tm_h6 4
assign c_tm_aa 8

assign tm_aa  not lesser Travel_Mode c_tm_aa
assign Travel_Mode sub Travel_Mode ( switch tm_aa c_tm_aa 0 )
assign tm_h6  not lesser Travel_Mode c_tm_h6
assign Travel_Mode sub Travel_Mode ( switch tm_h6 c_tm_h6 0 )
assign tm_mass  not lesser Travel_Mode c_tm_mass
assign Travel_Mode sub Travel_Mode ( switch tm_mass c_tm_mass 0 )
assign tm_h2  not lesser Travel_Mode c_tm_h2
assign Travel_Mode sub Travel_Mode ( switch tm_h2 c_tm_h2 0 )

assign hills      if tm_h6   then 6 else if tm_h2 then 2 else hills
assign totalMass  add bikemass add bikermass ( switch tm_mass luggagemass 0 )
assign bikerPower sub bikerPower ( switch tm_mass bikerPowerDrop 0 )
	
assign avoid_unsafe         if tm_aa then true else	avoid_unsafe
assign TooSteepUphill	    if tm_h6 then 8 else TooSteepUphill         #Not too steep
assign TooSteepbufferreduce	if tm_h6 then 5 else TooSteepbufferreduce   #Not too steep

# == Travel_mode - parameter overriding end

#new in 2.5.12

assign   NoFlatMode             equal hills 5
assign   ValleyMode             equal hills 4
assign   TooSteepMode           equal hills 6 #v2.8
assign   originalisbike         false

# Do not confuse these profile internals
# with BRouter parameters without the "value".

assign   uphillcostvalue        switch equal hills 1 70   switch equal hills 2 80
                                switch equal hills 3 60   switch ValleyMode 150 
                                switch NoFlatMode 0       switch TooSteepMode TooSteepUphillCost
                                0 
assign   uphillcutoffvalue      switch equal hills 1 3.0  switch equal hills 2 1.0
                                switch equal hills 3 0.5  switch ValleyMode 1.5
                                switch NoFlatMode 1.5     switch TooSteepMode TooSteepUphill
                                1.5 
assign   downhillcutoffvalue    switch equal hills 1 1.5  switch equal hills 2 0.5
                                switch equal hills 3 1.5  switch ValleyMode 1.5
                                switch NoFlatMode 1.5     switch TooSteepMode 0.5
                                1.5 
assign   downhillcostvalue      switch equal hills 1 60   switch equal hills 2 80
                                switch equal hills 3 0    switch ValleyMode 150
                                switch NoFlatMode 0       switch TooSteepMode 80
                                0  

assign   Flat_Penalty         if NoFlatMode then 1.5 else 0.0


# ==============================================
# =====    Road preference processing      =====
# ==============================================

# positive smallpaved factor effect subtracts itself from MTB factor effect
# on MTB-like OSM way preference and elevation effect attenuation

#v2.5.14 assign   MTBminusSP_factor           sub MTB_factor ( max 0 smallpaved_factor )  - pre v2.5.14
#v2.5.14
assign   Hill_factor            min 3 max -3 sub MTB_factor smallpaved_factor              
assign   Road_factor            min 3 max -3 ( sub ( sub 0.0 MTB_factor ) smallpaved_factor )

assign   positive_smallpaved_factor  not lesser smallpaved_factor 0.0
assign   abs_smallpaved_factor       multiply ( switch positive_smallpaved_factor 1.0 -1.0 ) smallpaved_factor 

assign   MTB_hillcostfactor   multiply 0.3333 Hill_factor 
                  # It changes hillcosts to be 0.0 at Hill_factor = 3.0 and twice at -3.0
                  # Hill_factor 1..-1 leads hillcost to decrease e.g. from 60 to 40 / increase from 60 to 80

# ==============================================
# =====     Elevation   processing         =====
# ==============================================
               
assign   downhillcost if ( consider_elevation  )  then  ( multiply ( sub 1.0 MTB_hillcostfactor  ) downhillcostvalue ) else 0
assign   uphillcost   if ( consider_elevation  )  then ( 
             if  TooSteepMode then uphillcostvalue  else ( multiply ( sub 1.0 MTB_hillcostfactor  ) uphillcostvalue ) )
         else 0
assign   uphillcutoff    if ( consider_elevation ) then (
             if  TooSteepMode then uphillcutoffvalue 
                              else (  multiply ( max 0.0 min 1.0 add 1.0 MTB_hillcostfactor  ) uphillcutoffvalue )   )
         else 1.5
assign   downhillcutoff  if ( consider_elevation ) then (  multiply ( max 0.0 min 1.0 add 1.0 MTB_hillcostfactor  ) downhillcutoffvalue ) else 1.5 

assign   elevationpenaltybuffer if ValleyMode then 10 
                                else if TooSteepMode then TooSteepPenaltybuffer else 5   # 5 is trekking default
assign   elevationmaxbuffer     if ValleyMode then 20
                                else if TooSteepMode then TooSteepMaxbuffer
                                else 10  # 10 is trekking default
assign   elevationbufferreduce  if ValleyMode then 0.0 
                                else if TooSteepMode then TooSteepbufferreduce
                                else ( multiply 0.333 max uphillcutoff downhillcutoff ) # 0.0 is trekking default

# ======================================================
# ===== pushing and tandem mode related penalties  =====
# ======================================================

assign   pushpenaltydefault     6
assign   pushpenaltytandemdefault     6
assign   pushpenaltySensitivity 1.0
assign   pushpenaltyRoadHill    max 1 add pushpenaltydefault multiply pushpenaltySensitivity multiply 0.5 ( sub Road_factor Hill_factor  )
                        
assign   pushpenalty            switch tandem_mode max pushpenaltyRoadHill pushpenaltytandemdefault 
                                                   pushpenaltyRoadHill   # added to the costfactor where cycling is not allowed
assign   dismountpenalty        switch tandem_mode 250 100 # added to initialcost of a way or node when forced to get off bike
assign   haulpenalty            switch tandem_mode 500 40  # added to costfactor where the bike needs to be lifted and carried


assign   uphillCFshift     0.0 # experimental shifting of up/downhillcostfactors as alternative way of 
assign   downhillCFshift   0.0 # prioritizing/penalizing of up/downhills, based on length, not elevation

assign    pass1coefficient 1.8
assign    pass2coefficient 0

assign   use_proposed_cn        1 # 0 as default, considers proposed cycle networks as unmarked but valid cycleroutes.

assign   unsafe_penalty_value 1.0 # 1 - was 2 in Trekking, but this may cause U-like safe routes
assign   cost_of_unknown      2.0 # 2 as default, cost of highway=

# ==============================================
# =====   Ford crossing global data        =====
# ==============================================

assign   c_ford_initialcost_node = 500
assign   c_ford_initialcost_way  = 1000
assign   c_ford_costfactor =  50
assign   million = 1000000

assign   ford_handling_coef 
    switch ( lesser Hill_factor -1.49 ) million switch ( lesser Hill_factor -0.99 ) 20
    switch ( lesser Hill_factor -0.49 )  5.0 switch ( lesser Hill_factor  0.01 ) 1.0
    switch ( lesser Hill_factor  0.51 )  0.4 switch ( lesser Hill_factor  1.01 ) 0.1
    switch ( lesser Hill_factor  1.51 ) 0.05 0.0

assign   ford_initialcost_way =  if ( equal ford_handling_coef million ) then million else 
                                 if ( equal ford_handling_coef 0.0 ) then 0.0 else
                                 multiply c_ford_initialcost_way ford_handling_coef

assign   ford_initialcost_node = if ( equal ford_handling_coef million ) then million else 
                                 if ( equal ford_handling_coef 0.0 ) then 0.0 else
                                 multiply c_ford_initialcost_node ford_handling_coef

assign   ford_costfactor =       if ( equal ford_handling_coef million ) then 9999 else 
                                 if ( equal ford_handling_coef 0.0 ) then 1.0 else
                                 add 1.0 multiply ( sub c_ford_costfactor 1 ) ford_handling_coef 

assign   UDcostON               true

assign   ncncoef  max 0 min 1 multiply cycleroutes_pref 0.2
assign   lcncoef  max 0 min 1 multiply cycleroutes_pref 1.0

# bend /global

# bstart /way
---context:way   # following code refers to way-tags
# bstart /wayvariables

assign isicn route_bicycle_icn=yes
assign isncn or route_bicycle_ncn=yes ncn=yes 
assign isrcn or route_bicycle_rcn=yes rcn=yes
assign islcn or route_bicycle_lcn=yes lcn=yes 

assign any_cycleroute or route_bicycle_icn=yes or route_bicycle_ncn=yes or route_bicycle_rcn=yes route_bicycle_lcn=yes

assign any_cn_yes or lcn=yes or rcn=yes ncn=yes
assign any_cn_proposed or lcn=proposed or rcn=proposed ncn=proposed
assign any_cn or any_cn_yes switch use_proposed_cn any_cn_proposed 0

assign nodeaccessgranted or any_cycleroute any_cn
                   
assign is_ldcr if (  equal cycleroutes_pref 0.0 )   then false else nodeaccessgranted

assign istrack  highway=track|road|path|footway
assign ismainroad highway=motorway|motorway_link|trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified
assign isotherroad = not or istrack ismainroad

assign hascycleway = not
  and ( or cycleway= cycleway=no|none ) and ( or cycleway:left= cycleway:left=no ) ( or cycleway:right= cycleway:right=no )
  
#2.6.* inserted originalisbike option                                      
assign isbike_candidate or bicycle_road=yes or bicycle=yes|permissive|designated or hascycleway
        if originalisbike then lcn=yes else nodeaccessgranted 

assign isbike and ( or ( not ismainroad ) isbike_for_mainroads )  isbike_candidate


assign ispaved surface=paved|asphalt|concrete|paving_stones|metal|grass_paver|wood|clay #metal, wood added in v2.7
assign isunpaved not or surface= or ispaved or surface=fine_gravel surface=cobblestone

assign probablyGood = or ispaved and ( or isbike highway=footway ) not isunpaved  #probably good surface - weather independent

assign turncost  if  ismainroad  then 90    else if ispaved then 60   else 30 
# Turn cost is based solely on estimation of road speediness and eventual time cost of turning, partially promoting tracks )

assign ismuddy and is_wet
               and ( not surface=gravel|pebblestone )  # ***)
                   ( or isunpaved ( and surface= and highway=track|path not tracktype=grade1 )  )

assign nosurface or surface= surface=unknown
assign nosurfacenortracktype and nosurface tracktype=
assign ishard or ispaved or tracktype=grade1 surface=cobblestone|sett|compacted|fine_gravel|gravel|pebblestone  
assign issoft not or nosurface ishard

assign isresidentialorliving = or highway=residential|living_street living_street=yes

assign noCrossingPenalty = and not hascycleway ( or ismainroad highway=residential|living_street|service )

# bend /wayvariables

# bstart /wayaccess

assign defaultaccess =
       if ( ford=yes ) then false
       else if ( ford=stepping_stones ) then false
       else if access= then not motorroad=yes
       else if access=private then false
	   else if access=no then false
	   else if access=agricultural then false
	   else if access=customers then false
	   else if access=delivery then false
	   else if access=permissive then true
	   else if access=destination then true
	   else if access=designated then true
       ##else if access=forestry then false
       else true    
   
assign bikeaccess =
       if nodeaccessgranted then true
       else if hascycleway then true
       else if bicycle= then   (  if bicycle_road=yes then true else
                                  if vehicle= then ( if highway=footway then false else defaultaccess ) 
                                  else not vehicle=private|no   )
                        else  not bicycle=private|no|dismount  

assign footaccess =
       if bikeaccess then true
       else if bicycle=dismount then true
       else if foot= then defaultaccess
       else not foot=private|no

assign accesspenalty =
       if bikeaccess then 0
       else if footaccess then 
        ( if StrictNOBicycleaccess then 10000 else pushpenalty )
       else 10000

# handle one-ways. On primary roads, wrong-oneways should be close to forbidden
# while on other ways we just add pushpenalty (default was 4) to the costfactor
# as you are allowed to push your bike.

assign badoneway =
       if reversedirection=yes then
         if oneway:bicycle=yes then true  
         else if oneway= then junction=roundabout 
         else oneway=yes|true|1
       else oneway=-1

assign onewaypenalty = 
       if ( badoneway ) then 
         if cycleway=opposite|opposite_lane|opposite_track  then 0
         else if oneway:bicycle=no                          then 0
         else if highway=primary|primary_link               then 50
         else if highway=secondary|secondary_link           then 30
         else if highway=tertiary|tertiary_link             then 20
         else pushpenalty
         
       else 0.0   

# bend /wayaccess


# bstart /initialcost                      
assign initialclassifier
if route=ferry then 1
else if not bikeaccess                           then 16
else if ( ford=yes )                             then 15
else if ( highway=motorway|motorway_link )       then 2
else if ( highway=trunk|trunk_link )             then 3
else if ( highway=primary|primary_link )         then 4
else if ( highway=secondary|secondary_link )     then 5
else if ( highway=tertiary|tertiary_link )       then 6
else if ( highway=unclassified )                 then 7
else if ( highway=residential )                then 8
else if ( highway=living_street )               then 9
else if ( highway=service )                    then 10
else if ( service=parking_aisle )             then 11
else if ( service=driveway )             then 12
else if ( service=alley )                   then 13
else if ( service=drive-through )    then 14
else if ( service=emergency_access )     then 15
else if ( highway=footway )          then 16
else if ( istrack )                              then 17
else if ( highway=cycleway )        then 18
                                                 else 14

assign initialcost
if route=ferry then 10000
else if ( ford=yes )                                        then ford_initialcost_way  
else add ( switch bikeaccess 0 dismountpenalty )
     if ( highway=motorway|motorway_link|trunk|trunk_link ) then 999999
else if ( highway=primary|primary_link )                    then 999999
else if ( highway=secondary|secondary_link )                then 999999
else if ( highway=tertiary|tertiary_link )     then 90000
else if ( highway=path )                                        then 5000
else if ( highway=track )                                        then 100
else if ( highway=unclassified )                            then 50
else if ( highway=road )                        then 50
else if ( highway=residential )               then 30
else if ( highway=living_street )             then 25
else if ( service=parking_aisle )         then 20
else if ( service=driveway )     then 20
else if ( service=alley )             then 20
else if ( service=drive-through )   then 15
else if ( service=emergency_access )   then 10
else if ( highway=service   )     then 5
else 30

# bend /initialcost                      


# bstart /roadmaxpenalties

# bstart /roughness_penalty
assign smoothness_penalty  
# http://wiki.openstreetmap.org/wiki/Key:smoothness

if not consider_smoothness                                then 0.0 else
if smoothness=                                            then 0.0 else #PL tłum* jeśli występuje samo: smoothness
if smoothness=excellent|very_good                         then 0.0 else
if smoothness=good                                        then 0.1 else
if smoothness=intermediate                                then 5.0 else
if smoothness=medium                                      then 5.0 else ##average
if smoothness=bad|robust_wheels|poor                      then 10.0 else
if smoothness=rough                                       then 15.0 else
if smoothness=very_bad|high_clearance                     then 20.0 else
if smoothness=horrible|off_road_wheels                    then 500.0 else ##terrible
if smoothness=very_horrible                               then 700.0 else
if smoothness=impassable                                  then 1000.0 else
0.0

assign mtb_scale_penalty  if not consider_smoothness then 0.0 else

if not consider_smoothness then 0.0 else
if trail_visibility=excellent then 0.0 else 
if trail_visibility=good then 0.1 else
if trail_visibility=intermediate then 0.3 else 
if trail_visibility=bad then 5 else 
if trail_visibility=horrible then 9 else
if trail_visibility=no then 15 else 

# Remember this is for trekking bikes, not MTB. There are MTB dedicated profiles.
# http://wiki.openstreetmap.org/wiki/Key:mtb:scale

if mtb:scale=        then 0.0 else    if mtb:scale=0-     then 0.0 else
if mtb:scale=0       then 0.0 else    if mtb:scale=0+     then 0.3 else
if mtb:scale=1-      then 0.7 else    if mtb:scale=1      then 1.2 else
if mtb:scale=1+      then 10.0 else   if mtb:scale=2-     then 20.0 else
if mtb:scale=2       then 40.0 else   if mtb:scale=2+     then 100.0 else
if mtb:scale=3       then 200.0 else  if mtb:scale=4      then 500.0 else
if mtb:scale=5       then 1000.0 else if mtb:scale=6      then 5000.0 
else 0.0

assign roughness_penalty max smoothness_penalty max mtb_scale_penalty  ( if ford=yes then ( sub ford_costfactor 1 ) else 0 ) 
    
# bend /roughness_penalty

# bstart /MTB_SP_tweaks

assign rough_coef = add 1.0 ( multiply 0.33 roughness_penalty ) 

assign univ_factor_coef_raw 
    if ismainroad then (
    add ( switch isunpaved -0.5 0 )
    switch highway=motorway|motorway_link|trunk|trunk_link 1.0
    switch highway=primary|primary_link                    0.9
    switch highway=secondary|secondary_link                0.7
    switch highway=tertiary|tertiary_link                  0.4
    switch  highway=unclassified                           0.25 
    0
    ) else if istrack then (
    add ( switch  highway=path|footway -0.25 0.0 )
    switch  or ispaved tracktype=grade1                    0.1
    multiply rough_coef    
        switch ( nosurfacenortracktype ) ( switch isbike 0.0 -0.25 )
        switch nosurface  
           ( switch or isbike tracktype=grade2|grade3 -0.25 -0.5 )
        switch surface=compacted|fine_gravel -0.25
        switch surface=cobblestone|sett      -0.4
        switch surface=ground|grass          -0.5
        switch surface=sand|dirt|mud             -0.6   
        switch surface=gravel|pebblestone|mud -0.75
        -0.6 
    ) 
    else 
    ( switch ispaved 0.25 switch isunpaved -0.25 0.0 )


# UCF = UCFR + UFA - UFA * UCFR * UCFR

assign univ_factor_coef   if equal UnifactorAdjust 0.0 then  univ_factor_coef_raw else
                          sub ( add univ_factor_coef_raw  UnifactorAdjust )
                              ( multiply UnifactorAdjust multiply univ_factor_coef_raw univ_factor_coef_raw )

assign nonpath_penalty = 
    if    equal path_preference 0.0    then 0.0 # nonpath_penalty inactive
    else  multiply ( max 0 path_preference )
        if ismainroad    then 1    
        else if not or istrack highway=cycleway  then 0.6
        else if ispaved  then 0.4  
        else if or not highway=path 
                or not isunpaved  tracktype=grade1|grade2 
                   then 0.25 
        else if or not isunpaved 
                or not highway=path
                or not tracktype=grade3|grade4|grade5  surface=gravel|cobblestone|pebblestone    
                  then 0.15
        else 0.0

assign MTB_factor_for_road  if  ( equal MTB_factor 0.0 ) then     0.0
                            else  multiply MTB_factor  univ_factor_coef

assign abs_univ_factor
    if lesser univ_factor_coef 0.0 then  multiply -1.0 univ_factor_coef
                                   else  univ_factor_coef 

assign smallpaved_factor_for_road
    if  ( equal smallpaved_factor 0.0 ) then 0.0 else 
    multiply  abs_smallpaved_factor
              if  positive_smallpaved_factor then abs_univ_factor  else ( sub 1.0 abs_univ_factor )  
           

# bend /MTB_SP_tweaks                                             
                                             
# bstart /HWclass_bfactor_components

assign highwayclass_basefactor  
    if ismainroad then 
        switch highway=trunk|trunk_link          1.8  switch highway=primary|primary_link      1.5
        switch highway=secondary|secondary_link  1.2  switch highway=tertiary|tertiary_link    1.1   1.0
      else if istrack  then 
        switch highway=track 0.0 switch highway=path 500.0 switch highway=road 0.0 switch highway=footway  1.2  1.0  # highway=road 
     else 
        switch highway=pedestrian 2.0 switch highway=bridleway 3.0
        switch highway=cycleway   1.0 switch isresidentialorliving   1.0
        switch highway=service    1.1 
        switch service=parking_aisle 1.5
        switch service=driveway 1.2 
        switch service=alley 0.5
        switch service=drive-through 1.0
        switch service=emergency_access 4.0 cost_of_unknown
  
  
assign tracktype_penalty 
    if tracktype=  then 0.0 else 
        switch tracktype=grade1 0.0 switch tracktype=grade2 0.3 switch tracktype=grade3 0.6
        switch tracktype=grade4 1.0 switch tracktype=grade5 100.0                         0.5
        
assign surface_penalty
    if nosurface then 0.0 else
        switch surface=asphalt 0.0
        switch concrete=lanes 0.5
        switch concrete=plates 6.0  
        switch surface=concrete 0.2
        switch surface=metal 0.3
        switch surface=paved 0.5
        switch surface=paving_stones 0.4
        switch surface=grass_paver 3.7
        switch surface=wood 0.3
        switch surface=clay 0.0
        switch surface=cobblestone 6.0
        switch surface=sett 4.8
        switch surface=gravel 8.0
        switch surface=pebblestone 1.2         
		switch surface=ground|earth|dirt 7.0
		switch surface=unpaved 5.0
		switch surface=compacted 4.0
        switch surface=fine_gravel 7.0
        switch surface=grass 8.0 
		switch surface=sand 7.7
		switch surface=mud 9.0
		0.6
    
assign tracktype_surface_penalty 
    if nosurfacenortracktype then  ( switch ismainroad 0.0 switch isotherroad  0.0 switch highway=path 0.8 0.4  ) 
    else if nosurface then tracktype_penalty
    else if tracktype= then  surface_penalty  else
    max tracktype_penalty surface_penalty
                                       
assign not_isbike_penalty   if isbike then 0.0 
     else if ismainroad then
        add switch bicycle=use_sidepath 2.0 0.0  
        switch highway=trunk|trunk_link          8.2  switch highway=primary|primary_link      1.5  
        switch highway=secondary|secondary_link  0.4  0.3 # tertiary|tertiary_link|unclassified
     else if istrack then  
        switch highway=footway            3.5   switch or ispaved tracktype=grade1 0.0 
        switch and tracktype= not isunpaved  ( switch highway=path 3.5 1.0 )
        switch tracktype=                 3.0   switch tracktype=grade1           0.2
        switch tracktype=grade2           0.6   switch tracktype=grade3           1.2
        switch tracktype=grade4           2.0   switch tracktype=grade5           3.0
        3.0 
     else 
        switch    highway=pedestrian 2.0   switch    highway=bridleway  2.0
        switch    highway=cycleway   0.0   switch    highway=residential|living_street 0.0
        switch    highway=service    0.0   
        switch    service=parking_aisle 0.0    
        switch    service=driveway 0.0   
        switch    service=alley 0.0   
        switch    service=drive-through 0.0  
        switch    service=emergency_access 4.0  0.0

assign wet_penalty    if   not is_wet    then 0.0 else
    switch surface=cobblestone|sett     1.0     switch ispaved                      0.0
    switch surface=compacted            0.6     switch surface=fine_gravel          0.8
    switch surface=                     switch not istrack 0.5 switch highway=path  2.0 1.0 
    switch surface=grass                switch highway=path  2.5 1.5
    switch surface=ground|earth|unpaved|sand|dirt|mud   switch highway=path 3.5 2.0
    2.0
    
# bend /HWclass_bfactor_components
    
# bend /roadmaxpenalties

# bstart /trafficpenalties
# Penalty for unsafe roads. As wet fallback, it does not so strictly avoid unsafe
assign unsafe_penalty  
    if and avoid_unsafe and ismainroad not isbike 
       then multiply unsafe_penalty_value  ( if is_wet then  0.5 else 1.0 )  
       else 0.0  



assign trafficpenalty0 = (
    if not allow_traffic_penalty then 0.0 else
    if highway=primary|primary_link then
    (
      if      estimated_traffic_class=4 then 0.2
      else if estimated_traffic_class=5 then 0.4
      else if estimated_traffic_class=6|7 then 0.6 
      else 0
    )
    else if highway=secondary|secondary_link then
    (
      if      estimated_traffic_class=3 then 0.2
      else if estimated_traffic_class=4 then 0.4
      else if estimated_traffic_class=5 then 0.6
      else if estimated_traffic_class=6|7 then 1
      else 0
    )
    else if highway=tertiary|tertiary_link then
    (
      if      estimated_traffic_class=2 then 0.1
      else if estimated_traffic_class=3 then 0.3
      else if estimated_traffic_class=4 then 0.5
      else if estimated_traffic_class=5|6|7 then 1
      else 0
    )
    else 0
    )
    
assign trafficpenalty =
  if hascycleway then min 0.3 trafficpenalty0
  else trafficpenalty0
  
# bend /trafficpenalties
   
# bstart /costfactors

assign penaltymax = max roughness_penalty max tracktype_surface_penalty max wet_penalty trafficpenalty

assign rawcostfactor ( # can be <1, adjusted to >=1 in final step of calculation of costfactor, uphillcostfactor,downhillcostfactor
  switch and highway= not route=ferry  10000 #only highways unless ferry
  switch highway=motorway|motorway_link|proposed|abandoned  10000
  
  # all other exclusions below (access, steps, ferries,..) should not be deleted by the decoder, to be available in voice-hint-processing
  min 9999 
  
  switch    highway=steps  switch allow_steps haulpenalty 10000
  switch    route=ferry    switch allow_ferries 4000 10000
  switch    ford=yes  switch allow_fords   10000 10000
  switch    ford=stepping_stones switch allow_ford_stepping 6000.0 10000.0
  switch    highway=construction                     10000
  
  if and avoid_unpaved isunpaved then 50
  else add highwayclass_basefactor
       add not_isbike_penalty
       add unsafe_penalty
           max penaltymax
               nonpath_penalty
 )  

assign isCFgt9997       greater rawcostfactor 9997
  
assign LDCRboost  multiply sub 1.0 rawcostfactor    cycleroutes_pref

assign cycleroute_tweak 
  #2.6 reworked : non cyclenetwork penalty = + cycleroutes_pref  ( 0..1 , default 0.2)
  #               ICN boost                = - ( CF - 1 ) * cycleroutes_pref, leading to CF=1.0 for cycleroutes_pref = 1.0
  #               other CN: weitgted average of above, with weights ncncoef, lcncoef shifting with cycleroutes_pref

         if not greater cycleroutes_pref 0.0 then
            0.0
         else if not is_ldcr then
           cycleroutes_pref
         else if isicn then 
            LDCRboost
         else if isncn then
            add multiply ncncoef cycleroutes_pref
                multiply ( sub  1.0 ncncoef ) LDCRboost 
         else
            add multiply lcncoef cycleroutes_pref
                multiply ( sub  1.0 lcncoef ) LDCRboost 
                                                 
  # can be <1, adjusted to >=1 in final step of calculation 
  # of costfactor, uphillcostfactor,downhillcostfactor                              

assign rawcostfactor2
  if isCFgt9997 then
    rawcostfactor
  else 
    if debug then
       add debugcost
       add MTB_factor_for_road
           smallpaved_factor_for_road 
    else
      add rawcostfactor 
      add cycleroute_tweak 
      add MTB_factor_for_road
      smallpaved_factor_for_road   
    
assign access-penalty max onewaypenalty accesspenalty

assign costfactor    
  if isCFgt9997 then
    rawcostfactor2
  else
    add access-penalty 
    add Flat_Penalty 
        max 1.0 rawcostfactor2
      
assign uphillcostfactor
  if debug then costfactor else
  if or not UDcostON isCFgt9997 then 
     costfactor
  else
     add access-penalty
         add switch TooSteepMode  ( sub TooSteepCostFactor 1.0 ) 0.0 
             if ValleyMode  then
               ( multiply rawcostfactor2 valley_nonflat_multiplier )
             else
               add uphillCFshift
               add rawcostfactor2
                   switch ismainroad
                      ( multiply 0.4 sub univ_factor_coef 0.5 ) 
                      ( multiply -0.5 univ_factor_coef )
                              
 assign downhillcostfactor
   if debug then costfactor else
   if or not UDcostON isCFgt9997 then 
     costfactor
   else
     add access-penalty
         max 1.0 
             if ValleyMode  then
                ( multiply rawcostfactor2 valley_nonflat_multiplier )
             else
                add downhillCFshift
                add rawcostfactor2
                    multiply -0.2 univ_factor_coef
                         
# bend /costfactors

# bstart /priorityclassifiers

# way priorities used for voice hint generation

assign priorityclassifier =
  
  if      ( highway=motorway                  ) then  30
  else if ( highway=motorway_link             ) then  29
  else if ( highway=trunk                     ) then  28
  else if ( highway=trunk_link                ) then  27
  else if ( highway=primary                   ) then  26
  else if ( highway=primary_link              ) then  25
  else if ( highway=secondary                 ) then  24
  else if ( highway=secondary_link            ) then  23
  else if ( highway=tertiary                  ) then  22
  else if ( highway=tertiary_link             ) then  21
  else if ( highway=unclassified              ) then  20
  else if ( isresidentialorliving             ) then  6
  else if ( highway=service                   ) then  5
  else if ( service=parking_aisle       ) then 4
  else if ( service=driveway              ) then 4
  else if ( service=alley                   ) then 4 
  else if ( service=drive-through     )     then 4
  else if ( service=emergency_access         ) then 3
  else if ( highway=cycleway                  ) then  2
  else if ( or bicycle=designated bicycle_road=yes  ) then  1
  else if ( highway=track                     ) then if tracktype=grade1 then 6 else 4
  else if ( highway=bridleway|road|path|footway ) then  1
  else if ( highway=steps                     ) then  1
  else if ( highway=pedestrian                ) then  1
  else 0
                                                      
# some more classifying bits used for voice hint generation...

assign isbadoneway = not equal onewaypenalty 0
assign isgoodoneway = if reversedirection=yes then oneway=-1
                      else if oneway= then junction=roundabout else oneway=yes|true|1
assign isroundabout = junction=roundabout
assign islinktype = highway=motorway_link|trunk_link|primary_link|secondary_link|tertiary_link
assign isgoodforcars = if greater priorityclassifier 6 then true
                  else if ( or isresidentialorliving  highway=service ) then true
                  else if service=parking_aisle then true
                  else if service=driveway then true
                  else if service=alley then true
                  else if service=drive-through then true
                  else if service=emergency_access then false
                  else if ( and highway=track tracktype=grade1 ) then true
                  else false

# ... encoded into a bitmask

assign classifiermask add          isbadoneway
                      add multiply isgoodoneway   2
                      add multiply isroundabout   4
                      add multiply islinktype     8
                          multiply isgoodforcars 16
                          
# bend /priorityclassifiers                          

# bend /way                          

# bstart /node
---context:node  # following code refers to node tags

assign   initial_cost_node    0     # 0 as default

assign defaultaccess =                                                                                                                              
         if ( highway=traffic_signals ) then true
	   else if ( highway=stop ) then true
	   else if ( highway=give_way ) then true
	   else if ( highway=mini_roundabout ) then true
	   else if ( highway=bus_stop ) then true
	   else if ( highway=speed_camera ) then true
	   else if ( highway=passing_place ) then true  

       else if ( railway=crossing ) then true	   
	   else if ( railway=level_crossing ) then true	  	   
	   
	   else if ( barrier=border_control ) then true	  
	   else if ( barrier=lift_gate ) then true
	   else if ( barrier=cycle_barrier ) then true
	   else if ( barrier=sally_port ) then true
	   else if ( barrier=chain ) then true
	   else if ( barrier=bump_gate ) then true
	   else if ( barrier=hampshire_gate ) then true
	   else if ( barrier=block ) then true
	   else if ( barrier=log ) then true
	   else if ( barrier=sump_buster ) then true
	   else if ( barrier=spikes ) then true
	   else if ( barrier=tree ) then true
	   else if ( barrier=fallen_tree ) then true
	   else if ( barrier=jersey_barrier ) then true
	   else if ( barrier=stone ) then true
	   else if ( barrier=rope ) then true
	   else if ( barrier=bus_trap ) then true
	   else if ( barrier=cattle_grid ) then true
	   else if ( barrier=debris ) then true
	   else if ( barrier=motorcycle_barrier ) then true
	   else if ( barrier=bar ) then true
	   else if ( barrier=checkpoint ) then true
	   else if ( barrier=horse_stile ) then true
	   else if ( barrier=kerb ) then true
	   else if ( barrier=ditch ) then true
	   else if ( barrier=wall ) then false
	   else if ( barrier=turnstile ) then true
	   else if ( barrier=kissing_gate ) then true
	   else if ( barrier=stile ) then true
	   else if ( barrier=bollard ) then true
	##   else if ( barrier=toll_booth) then true
	   ##else if ( barrier=kent_carriage_gap ) then true
	   ##else if ( barrier=tank_trap ) then true
	   
	   else if ( traffic_calming=yes ) then true
	   else if ( traffic_calming=speed_bump ) then true
	   else if ( traffic_calming=hump ) then true
	   else if ( traffic_calming=bump ) then true
	   else if ( traffic_calming=table ) then true
	   else if ( traffic_calming=cushion ) then true
	   else if ( traffic_calming=rumble_strip ) then true
	   else if ( traffic_calming=dip ) then true
	   else if ( traffic_calming=chicane ) then true
	   else if ( traffic_calming=choker ) then true
	   else if ( traffic_calming=dip ) then true
	   else if ( traffic_calming=island ) then true
	  	    
	   else if ( highway=crossing ) then true
	   else if ( crossing=traffic_signals ) then true
	   else if ( crossing=yes ) then true
	   	   	   
	   else if ( ford=yes ) then true
	   else if ( ford=stepping_stones ) then true
	   
	   
       else if ( access= ) then  if allow_default_barrier_restriction then not barrier=gate # add default barrier restrictions here! - modified v2.5.15, conditioned in 2.6
                                                                 else true 
       else if ( access=private ) then false
	   else if ( access=no ) then false
	  ## else if ( access=customers ) then true
	   else if ( access=agricultural ) then true
	   ##else if ( access=delivery ) then false
	   else if ( access=permissive ) then true
	   else if ( access=destination ) then true
	   else if ( access=designated ) then true
      ## else if ( access=forestry ) then false
       else true

assign bikeaccess =
       if highway=crossing then (  or not bicycle=no|dismount way:noCrossingPenalty  )
       else if nodeaccessgranted=yes then true
       else if bicycle= then
       (
         if vehicle= then defaultaccess
         else not vehicle=private|no
       )
       else not bicycle=private|no|dismount

assign footaccess =
       if bicycle=dismount then true
       else if foot= then defaultaccess
       else not foot=private|no


assign initialcost =
        add ( if ( and barrier=cycle_barrier|chicane not ignore_cycle_barrier ) then
                  ( add ( switch bikeaccess dismountpenalty 0 ) haulpenalty )
              else if highway=traffic_signals           then 400.0
              else if highway=stop                 then 60.0
			  else if highway=give_way             then 60.0 	
              else if highway=mini_roundabout      then 0.4 
			  else if highway=bus_stop             then 100.0 #domyślnie 10.0
			  else if highway=speed_camera         then 0.0  #domyślnie 0.0  #PL Fotoradar; fotoradary. Im wyższa wartość tym bardziej rosną szanse na omijanie dróg z fotoradarami
			  else if highway=passing_place        then 0.0  #domyślnie 5.0  #PL Punkt mijania; wąska droga. Np. drogi w Norwegii. Im wyższa wartość tym bardziej rosną szanse na omijanie takich dróg; https://wiki.openstreetmap.org/wiki/Tag:highway%3Dpassing_place							
              else if railway=level_crossing       then 20.0 #domyślnie 20.0 #PL Przejazdy kolejowe (drogowe). Im wyższa wartość tym większe omijanie dróg z przejazdami kolejowymi.
              else if railway=crossing             then 20.0
			  
              else if traffic_calming=yes          then 2.0
			  else if traffic_calming=speed_bump   then 2.0
			  else if traffic_calming=hump         then 2.0
			  else if traffic_calming=bump         then 2.0
			  else if traffic_calming=table        then 1.0
			  else if traffic_calming=cushion      then 1.0
			  else if traffic_calming=rumble_strip then 0.5
			  else if traffic_calming=dip          then 1.8
			  else if traffic_calming=chicane      then 1.0
			  else if traffic_calming=choker       then 1.0
			  else if traffic_calming=island       then 0.1	

              else if barrier=cattle_grid          then 2.0	       
	          else if barrier=lift_gate            then 500.0
	          else if barrier=cycle_barrier        then 10.0
	          else if barrier=sally_port           then 4000.0
	          else if barrier=chain                then 500.0
	          else if barrier=bump_gate            then 3000.0
	          else if barrier=hampshire_gate       then 3000.0
	          else if barrier=block                then 5000.0
	          else if barrier=log                  then 1500.0
	          else if barrier=sump_buster          then 0.5
	          else if barrier=spikes               then 1300.0
	          else if barrier=tree                 then 4000.0
	          else if barrier=fallen_tree          then 4000.0
	          else if barrier=jersey_barrier       then 4000.0   
	          else if barrier=stone                then 4000.0
	          else if barrier=rope                 then 500.0
	          else if barrier=bus_trap             then 2.0
	          else if barrier=gate                 then 50.0
			  else if barrier=motorcycle_barrier   then 400.0
			  else if barrier=bar                  then 300.0
			  else if barrier=checkpoint           then 500.0
			  else if barrier=horse_stile          then 500.0
			  else if barrier=kerb                 then 100.0
			  else if barrier=debris               then 4000.0
			  else if barrier=ditch                then 4000.0
			  else if barrier=wall                 then 4000.0
			  else if barrier=turnstile            then 600.0
			  else if barrier=kissing_gate         then 1000.0
			  else if barrier=stile                then 700.0
			  else if barrier=bollard              then 400.0
			##  else if barrier=toll_booth        then 400.0
              else if ford=yes                     then 10000.0
			  else if access=no                    then 10000.0
			  else if access=private               then 10000.0       	      
	      ## brak w lookup ## else if access=customers             then 2.0
	          else if access=agricultural          then 100.0
	        ## brak w lookup ## else if access=delivery              then 10000.0
             ## brak w lookup ## else if access=forestry              then 0.0            
			  else if ford=stepping_stones         then 6000.0
			  
	          else if barrier=border_control       then 100.0
	   
	          ##else if ( barrier=kent_carriage_gap ) then true
	          ##else if ( barrier=tank_trap ) then true
       
			  
			  
			  

             else if highway=crossing                  then 1.0
	     else if crossing=yes                      then 1.0
							else if crossing=uncontrolled     then 2.0 
              else if crossing=traffic_signals                 then 200.0
                            else if crossing=unmarked         then 10.0
                            else if crossing=island           then 1.0
                            else if crossing=zebra            then 1.0
                            else if crossing=no               then 0.0 
			

			
			## else if obstacle=yes 0
			## else if obstacle=vegetation
			## else if obstacle=yes 0
			## else if obstacle=fallen_tree 0
			## else if obstacle=unevenness 0
			## else if obstacle=precipice 0
			## else if obstacle=heap 0
			## else if obstacle=hole 0
              else initial_cost_node )
            if bikeaccess then 0  else ( if footaccess then dismountpenalty else 1000000 )

# bend /node            
- to jest profil rowerowy Brouter, Co zrobić aby ten profil prowadził chodnikiem obok drogi gdy jest droga tertiary