Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust rate #4711

Closed
buxinator opened this issue Nov 29, 2017 · 8 comments
Closed

adjust rate #4711

buxinator opened this issue Nov 29, 2017 · 8 comments

Comments

@buxinator
Copy link

Hi,
I try to adjust rates for some ways in foot.lua, to use them preferred without setting speed higher.
But actually I don't know where to do it. Please help

@oxidase
Copy link
Contributor

oxidase commented Nov 30, 2017

@buxinator rates for routability weights are specified in WayHandlers.penalties, for distance in WayHandlers.weights, and for duration there is a fallback to speed values in c++ if rates are not set in a Lua profile.

You can add a custom weight name and a way handler in handlers that will set higher rates for preferred ways without modifying speed values.

@buxinator
Copy link
Author

buxinator commented Nov 30, 2017

@oxidase can you help me with a bit of example code since i am not used to Lua scripting?
I want to use duration. How could I set a higher rate for a specific road in the Lua profile?

@oxidase
Copy link
Contributor

oxidase commented Nov 30, 2017

@buxinator let specific road has id 524005927. You can add to WayHandlers.weights

   if profile.properties.weight_name == 'custom' then
      if (way:id() == 524005927) then
         if (result.forward_mode ~= mode.inaccessible and result.forward_speed > 0) then
            print ('Changing forward rate of way ' .. tostring(way:id()) .. ' from ' ..
                      tostring(result.forward_rate) .. ' to ' .. tostring(result.forward_speed * 5))
            result.forward_rate = result.forward_speed * 5
         end
         if (result.backward_mode ~= mode.inaccessible and result.backward_speed > 0) then
            print ('Changing backward rate of way ' .. tostring(way:id()) .. ' from ' ..
                      tostring(result.backward_rate) .. ' to ' .. tostring(result.backward_speed * 5))
            result.backward_rate = result.backward_speed * 5
         end
      end
   end

and change weight_name = 'duration' to weight_name = 'custom'
and you will see in osrm-extract output

Changing forward rate of way 524005927 from -1 to 25
Changing backward rate of way 524005927 from -1 to 25

Other ways will have "durations" weights.

@buxinator
Copy link
Author

Thanks @oxidase !

Short Explanation what my goal is:
I want to use railway ways preffered and it should route as fast as possible from starting point by foot to railway lines.

if profile.properties.weight_name == 'custom' then
if (way:get_value_by_key('railway')) then.......

When I change weight_name='custom', routing only selects railway lines and nothing else.
When I use 'duration' instead of 'custom' in WayHandlers.weights the routing does not change at all. Do you have any Idea why?

@oxidase
Copy link
Contributor

oxidase commented Nov 30, 2017

@buxinator sorry, just forgot that rates must be specified for all ways if the weight name is not duration
Here is the correct handler with the else branch:

   if profile.properties.weight_name == 'custom' then
      if (way:id() == 524005927) then
         -- preferred ways
         if (result.forward_mode ~= mode.inaccessible and result.forward_speed > 0) then
            print ('Changing forward rate of way ' .. tostring(way:id()) .. ' from ' ..
                      tostring(result.forward_rate) .. ' to ' .. tostring(result.forward_speed * 5))
            result.forward_rate = result.forward_speed * 5
         end
         if (result.backward_mode ~= mode.inaccessible and result.backward_speed > 0) then
            print ('Changing backward rate of way ' .. tostring(way:id()) .. ' from ' ..
                      tostring(result.backward_rate) .. ' to ' .. tostring(result.backward_speed * 5))
            result.backward_rate = result.backward_speed * 5
         end
      else
         -- other ways
         result.forward_rate = result.forward_speed
         result.backward_rate = result.backward_speed
      end
   end

@daniel-j-h
Copy link
Member

Stale.

@mqln
Copy link

mqln commented Aug 4, 2018

Do we have a more up to date example of adjusting rate/weight?

@AveryPenningtonGSI
Copy link

It would be great to have a new example explaining the details of setting custom weights for each of the different modes of transport, explaining how to tune the route recalculation. It's quite easy to set weights high to eliminate a particular segment, but harder to understand how to tune the weight calculation to balance different priorities (especially with additional raster data used as input to weights.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants