Understanding Average Speed

I was looking at the average speed encoding class in the graphopper engine, graphhopper/core/src/main/java/com/graphhopper/routing/util/parsers/CarAverageSpeedParser.java at 102a58dc1ecbbfb2e351075018be8fd1d7459330 · graphhopper/graphhopper · GitHub

I see that the average speeds are essentially hard coded based on road types, is this then what is used in calculation of ETAs and working out the best route?

If I have data on the true average driving speed or want to use some function of the road speed limit is there any way to force it to do this?

Thank you for any assistance.

These are only the fallback values. If a maxspeed tag is present, the average speed is assumed to be 90% of that limit:

Thankyou @otbutz I missed that!

Hi @otbutz

A final question if you know, if I do have the correct average driving speeds would there be a way to force the engine to use these speeds when calculating the best route?

My current thought process is the following, do you think I am on the right track?

  • Create a custom TagParser for my new tag say true_driving_speed
  • Override DefaultImportRegistry and add an entry in the createImportUnit function for my new tag.
  • Where I am unsure is how to force the routing engine to use my speed as the road speed, Is the default speed value used by the routing engine max_speed, because if it is I can assume (I think) true_driving_speed will be lower than max_speed so I can create a custom model with
"speed": [
      {
        "if": "true",
        "limit_to": "true_driving_speed"
      }
    ]

Thank you for the help, it is much appreciated

That should work :+1:

If you are using a recent GraphHopper version you will see that the car_average_speed is used explicitly in the custom model (see config-example.yml, which points to car.json which uses car_average_speed). You could simply use 'true_driving_speed` there instead (without relying on true_driving_speed being lower than max_speed or something). You could also modify CarAverageSpeedParser to plug in your own speeds there.

Hi @easbar

Thank you for the response, when I look in the car.json though it uses the limit_to function for the car_average_speed, my understanding of the limit_to is it would take the minimum of the road speed and the car_average_speed thus if the road speed was lower than the car_average_speed for whatever reason this would resolve to the road speed.

i.e. its also relies on the fact that the car_average_speed is lower than the road speed.

My thoughts are is there a way to explicitly set the speed value on the road, i.e. override the road speed wth the true_driving_speed rather than just limiting it.

Yes, limit_to only limits the speed, but the default speed is unlimited. The default speed used to be car_average_speed implicitly, but in recent GraphHopper versions it is unlimited, which is why there is now this explicit rule limiting to car_average_speed. If you remove the limit_to: car_average_speed rule you should get an error saying that you have to limit the speed. So basically the first limit_to rule sets the speed.

Yes. if: true, limit_to: true_driving_speed (as first statement in the custom model) will set the speed to this exact value, just like if: true, limit_to: car_average_speed sets it to car_average_speed.

Thank you @easbar, I understand now

Appreciate the assistance