Custom model and FlagEncoder differences

Hello, I’m quite new in GH. Could someone explain me sth? Now I’m using GH3 and I have my profile settings in CarFlagEncoder class.

    public CarFlagEncoder(PMap properties) {
        super(properties.getInt("speed_bits", 5),
                properties.getDouble("speed_factor", 5),
                properties.getInt("max_turn_costs", properties.getBool("turn_costs", false) ? 1 : 0));

        restrictedValues.add("agricultural");
        restrictedValues.add("forestry");
        restrictedValues.add("no");
        restrictedValues.add("restricted");
        restrictedValues.add("delivery");
        restrictedValues.add("military");
        restrictedValues.add("emergency");
        restrictedValues.add("private");

        blockPrivate(properties.getBool("block_private", true));
        blockFords(properties.getBool("block_fords", false));
        blockBarriersByDefault(properties.getBool("block_barriers", true));
        setSpeedTwoDirections(properties.getBool("speed_two_directions", false));

        intendedValues.add("yes");
        intendedValues.add("designated");
        intendedValues.add("permissive");

        potentialBarriers.add("gate");
        potentialBarriers.add("lift_gate");
        potentialBarriers.add("kissing_gate");
        potentialBarriers.add("swing_gate");
        potentialBarriers.add("cattle_grid");
        potentialBarriers.add("chain");

        absoluteBarriers.add("fence");
        absoluteBarriers.add("bollard");
        absoluteBarriers.add("stile");
        absoluteBarriers.add("turnstile");
        absoluteBarriers.add("cycle_barrier");
        absoluteBarriers.add("motorcycle_barrier");
        absoluteBarriers.add("block");
        absoluteBarriers.add("bus_trap");
        absoluteBarriers.add("sump_buster");

        badSurfaceSpeedMap.add("cobblestone");
        badSurfaceSpeedMap.add("grass_paver");
        badSurfaceSpeedMap.add("gravel");
        badSurfaceSpeedMap.add("sand");
        badSurfaceSpeedMap.add("paving_stones");
        badSurfaceSpeedMap.add("dirt");
        badSurfaceSpeedMap.add("ground");
        badSurfaceSpeedMap.add("grass");
        badSurfaceSpeedMap.add("unpaved");
        badSurfaceSpeedMap.add("compacted");

        // autobahn
        defaultSpeedMap.put("motorway", 100);
        defaultSpeedMap.put("motorway_link", 70);
        defaultSpeedMap.put("motorroad", 90);
        // bundesstraße
        defaultSpeedMap.put("trunk", 70);
        defaultSpeedMap.put("trunk_link", 65);
        // linking bigger town
        defaultSpeedMap.put("primary", 65);
        defaultSpeedMap.put("primary_link", 60);
        // linking towns + villages
        defaultSpeedMap.put("secondary", 60);
        defaultSpeedMap.put("secondary_link", 50);
        // streets without middle line separation
        defaultSpeedMap.put("tertiary", 50);
        defaultSpeedMap.put("tertiary_link", 40);
        defaultSpeedMap.put("unclassified", 30);
        defaultSpeedMap.put("residential", 30);
        // spielstraße
        defaultSpeedMap.put("living_street", 5);
        defaultSpeedMap.put("service", 20);
        // unknown road
        defaultSpeedMap.put("road", 20);
        // forestry stuff
        defaultSpeedMap.put("track", 15);

        trackTypeSpeedMap.put("grade1", 20); // paved
        trackTypeSpeedMap.put("grade2", 15); // now unpaved - gravel mixed with ...
        trackTypeSpeedMap.put("grade3", 10); // ... hard and soft materials
        trackTypeSpeedMap.put(null, defaultSpeedMap.get("track"));

        // limit speed on bad surfaces to 30 km/h
        badSurfaceSpeed = 30;
        maxPossibleSpeed = 140;
    }

But now I wanna to change it into a modern type - custom model (weightning into ‘custom’ from ‘fastest’)
My code now:

 profiles:
    - name: car
      vehicle: car
      weighting: custom
      custom_model: {
        "speed": [
          {
            "if": "true",
            "limit_to": 140
          },
          {
            "if": "road_class == MOTORWAY",
            "multiply_by": 0.9
          },
          {
            "if": "road_class == TRUNK || road_class == PRIMARY",
            "multiply_by": 0.8
          }
        ],
        "priority": [
          {
            "if": "road_environment == TUNNEL",
            "multiply_by": 0.95
          }
        ],
        "distance_influence": 70
      }

And my questions :

  1. Using my custom_model (weightning ‘custom’ instead of ‘fastest’) it takes only my settings from that model and it doesn’t see my CarFlagEncoder ? Or it takes both?
  2. Which speed “multiply_by” takes? My max - 140km/? Or some max speed for the kind of route?
  3. I have a few maps in my CarFlagEncoder f.ex with barriers - Must I have it all in my custom_model or there are some defaults and in my custom_model I have to have only params which I want to change ?
  4. What are differences between weightning “custom” and “fastest” ? And it is good idea to change it?
  5. Are there any possibilities to change distance_influence without custom_model?

The CarFlagEncoder determines the car$average_speed value which in turn is used by FastestWeighting, i.e. this is the value of edge.get(encoder.getAverageSpeedEnc()). The custom model also works with this value. So for example if its value was 120 for some motorway your second rule would result in 120*0.9=108km/h.

The other thing the CarFlagEncoder determines is the car$access value, which is the one returned from edge.get(encoder.getAccessEnc()). This will include information about the barriers. It will be still included when you use a custom model, so to answer question you only can/need to adjust things you’d like to change in the custom model.

The difference between custom and fastest weighting is that the first can be modified using custom model, while the second can only be slightly modified (like destination/private penalty). Also in the long run the fastest weighting will be removed (maybe for GH 6.0 or 7.0). Otherwise there is no reason to change it. You only need to switch to the custom weighting if you want to adjust the routing using a custom model.

Yes, you can change the distance influence, or at least achieve the same effect, using the short_fastest weighting. It has a very similar parameter called short_fastest.distance_factor.

2 Likes

Thank you so much.
One more question, where can I check deffault speed for routs ? As you told: 120*0.9=108km/h . So when can I check that it is 120 km/h ? It is default from OSM?

No OSM does not provide any speeds for the different road types. It only contains speed limits as they are written on traffic signs along the streets. It does not provide country specific defaults either.
You can find the speeds GraphHopper uses in the different flag encoders (for example CarFlagEncoder.java here: graphhopper/CarFlagEncoder.java at af5ac0b0ae024da4b23966b1eef480508b5eedbb · graphhopper/graphhopper · GitHub).

For country specific speeds we also have so called CountryRules that might change the default speeds depending on the countries, but currently this is only implemented for Germany and Austria, so this is still work in progress.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.