GraphHopper.com | Forum | GitHub | Maps | Blog

Zero speed error when calculating shortest distance


#1

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


#2

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


#3

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


#4

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)?


#5

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


#6

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;