Custom model or FlagEncoder flow

Could someone explain the flow of FlagEncoder class and custom model in JSON?
My goal is having as much settings as possible in the custom model, so:

  1. Having FalgEncoder is obligatory?
  2. For example: deleting truck parameters (weight, width, height, length, weightPerDriveAxle) from Flag Encoder an putting it in custom JSON doesn’t give me the same result. So how can I relocate my parameters from FlagEncoder to custom ? And why the result is another?
  3. I want to do it because of having information in the one file without much code and logic interference → all needed information in one, clear place. I think it could be better with any profile changes and GH updating
  4. Is this good idea or I overestimated custom model meaning ?
  5. Correct me if I’m wrong - I have some FlagEncoder classes with default settings, so when I want to change sth I do it in the custom model. In result that parameter is overwrote than it was in the FlagEncoder. So custom model is above FlagEncoder…

Currently yes, but see Remove FlagEncoder · Issue #2463 · graphhopper/graphhopper · GitHub

Soon there will be hopefully only custom models. For now you can start with e.g. RoadsFlagEncoder/RoadsTagParser which basically does nothing but adds a compatibility layer so that you influence the speed and priority only via a custom model.

For example: deleting truck parameters (weight, width, height, length, weightPerDriveAxle)

It should be possible to achieve exactly the same using a custom model.

So custom model is above FlagEncoder…

Yes. Every custom model requires a base profile and currently this requires a FlagEncoder (vehicle).

thank you, what about maps in FlagEncoder ? For example ‘defaultSpeedMap’ - is there any possibility to delete it and have it only in custom model ?

And some params as maxPossibleSpeed…

You surely can remove the defaultSpeedMap from the code and build your own GraphHopper jar.

But for the most developers this is too complicated and for them we recommend to create a custom model based on the roads encoder (called RoadsTagParser in recent versions) that allows all roads and has a very high default speed that you then reduce and restrict with a custom_model like this:

- name: my_car
      weighting: custom
      vehicle: roads
      turn_costs: true
      u_turn_costs: 120
      custom_model:  {
        "distance_influence": 150,
        "speed": [{
          "if": "true",
          "limit_to": 130
        }, {
          "if": "road_class == RESIDENTIAL",
          "limit_to": 30
        }, {
          "if": "road_class == UNCLASSIFIED",
          "limit_to": 40
        }, {
          "if": "road_class == TERTIARY",
          "limit_to": 70
        }, {
          "if": "road_class == SECONDARY",
          "limit_to": 90
        }, {
          "if": "road_class == PRIMARY",
          "limit_to": 100
        }, {
          "if": "max_speed >= 100",
          "limit_to": 100
        }, {
          "else_if": "max_speed >= 70",
          "limit_to": 70
        }, {
          "else_if": "max_speed >= 50",
          "limit_to": 50
        }],
        "priority": [{
          "if": "road_class==FOOTWAY || road_class==PATH || road_class==CYCLEWAY",
          "multiply_by": 0
        }],
}}

(untested!)

In master you’ll soon (probably already today) be able to write the limit to the max_speed much simpler. Instead of

{
          "if": "max_speed >= 100",
          "limit_to": 100
        }, {
          "else_if": "max_speed >= 70",
          "limit_to": 70
        }, {
          "else_if": "max_speed >= 50",
          "limit_to": 50
        }

you can then write:

{ "if": "true", "limit_to": "max_speed" }

or probably better:

{ "if": "true", "limit_to": "max_speed*0.9" }

Is There any possibility to make few profiles on the same FlagEncoder ?
I have three car profiles - the basic is the same, but differences are implemented in custom model. Can I use CarFlagEncoder to that three profiles or every profile has to have their own FlagEncoder?

Multiple (as many as you want) profiles can share the same flag encoder

Powered by Discourse