Zero speed error when calculating shortest distance

Hi.

Following an example, I wrote a simple Java code that makes graphhopper calculate fastest route distances for many routes offline on OSM maps of the Czech Republic. However, the code fails when I switch from fastest to shortest distance, and I get the following run-time error:

Exception in thread "main" java.lang.IllegalStateException: Speed cannot be 0 for unblocked edge, use access properties to mark edge blocked! Should only occur for shortest path calculation. See #242.

I set the graphhopper engline like this (where NAVIGATION_TYPE is either “fastest” or “shortest”):

hopper.init(new CmdArgs().
        put("prepare.min_network_size", "200").
        put("prepare.min_one_way_network_size", "200").
        put("prepare.ch.weightings", NAVIGATION_TYPE));

Could you possibly hint me what’s the problem and how to solve it?

Many thanks. Michal

1 Like

For which start+end points did you get this exception?

e.g.:
from_lon,from_lat,to_lon,to_lat
50.04961,15.198803,50.047056,15.219416

My code, the used map, the list of all routes calculated, and the list of failed routes (log.log) is available at https://drive.google.com/drive/folders/1ssxV1W24FUMEpDFNUCJnbABGkJy6l-V5?usp=sharing

Best wishes,
Michal

When you switch the NAVIGATION_TYPE - did you remove the graph folder before the restart?

E.g. on GH Maps your request seems to work ok.

If you think it is a bug can you create a code snippet that reproduces the issue using a current OSM file (or a file you uploaded)?

Hi.

  1. I do use a different map folder for each NAVIGATION_TYPE.

  2. Doesn’t the web use the fastest route? My code works ok for fastest routes too. It is shortest routes where I get the run-time error. And even this way the code fails for about 40 routes out of about 170,000.

  3. I do not claim this is a GraphHopper bug—more likely, my code misses some setting that the web version has.

Minimal example is:

package com.prgosek.minitest;

import com.graphhopper.*;
import com.graphhopper.reader.osm.*;
import com.graphhopper.routing.util.*;
import com.graphhopper.util.*;

public class MiniTest {

    private static final String NAVIGATION_TYPE = "shortest";
    private static final String MAP_FILE = "maps/czech-republic-latest.osm.pbf";
    private static final String GRAPH_FOLDER = "graphFolder_" + NAVIGATION_TYPE;

    public static void main(String[] args) {
        GraphHopper hopper = new GraphHopperOSM();
        hopper.setDataReaderFile(MAP_FILE);
        hopper.init(new CmdArgs().
                put("prepare.min_network_size", "200").
                put("prepare.min_one_way_network_size", "200").
                put("prepare.ch.weightings", NAVIGATION_TYPE));
        hopper.setGraphHopperLocation(GRAPH_FOLDER);
        hopper.setEncodingManager(new EncodingManager("car"));
        hopper.importOrLoad();

        // 50.04961,15.198803,50.047056,15.219416
        // 50.047056,15.219416,50.04961,15.198803
        GHRequest req = new GHRequest(50.04961,15.198803,50.047056,15.219416).
                setWeighting(NAVIGATION_TYPE).
                setVehicle("car");
        GHResponse rsp = hopper.route(req);
        if (rsp.hasErrors()) {
            System.out.println("ERROR" + rsp.getErrors());
        } else {
            PathWrapper path = rsp.getBest();
            System.out.println("Estimated distance is " + path.getDistance());
        }
    }
}

Could you possibly help me?

Many thanks,
Michal

Probably this is a bug in the ShortestWeighting. Can you modify it and before returning edge.getDistance() using these lines:

double speed = reverse ? flagEncoder.getReverseSpeed(edge.getFlags()) : flagEncoder.getSpeed(edge.getFlags());
if (speed == 0)
  return Double.POSITIVE_INFINITY;

Hi.

Last summer I postponed the project and hence I didn’t notice you answered my question. (My apology.) Now I had to resurrect the project. (I have to find the shortest and fastest distances between several thousand points in the Czech Republic.) My code (based on your tutorial) can calculate the fastest routes, but GraphHopper fails for some routes when I try to calculate SHORTEST routes with this exception:

java.lang.IllegalStateException: Speed cannot be 0 for unblocked edge, use access properties to mark edge blocked! Should only occur for shortest path calculation. See #242.

I upgraded to GraphHopper 0.11 but I still get the exception.

Now to my questions:

  1. Can I still apply the solution you proposed above?
  2. Where can I path it? I was not able to find the file and line of code where to put it. Could help me, please?
  3. If it’s a bug, would you correct it in GraphHopper 0.12?

And BTW, how is it possible that incorrect speed matters when the shortest route is calculated, not the fastest one?

Many thanks for your answers and help.

Best wishes,
Michal

1 Like