Block_area is not working at all - need some help


#1

I’m trying to make a route to a particular town, but it keeps giving a wrong route (suggesting a road with bad conditions) even if I add a block_area. How do I make to block_area to work properly? Here’s a image of the problem:

Imgur

Here’s my graphhopper configuration:


protected static void start(CmdArgs cmdArgs) throws IOException {
hopper = new GraphHopperOSM().init(cmdArgs)
.setAllowWrites(true)
.setElevation(false)
.setEnableInstructions(false)
.setCHEnabled(false)
.setEncodingManager(loadEncodingManager())
.forDesktop()
.importOrLoad();
}

protected static EncodingManager loadEncodingManager() {
	java.util.List<AbstractFlagEncoder> encoders = new ArrayList<>();
	encoders.add(new CarFlagEncoder());
	
	return new EncodingManager(encoders);
};

A configuration parameter which might be relevant:

cmdArgs.put(“routing.round_trip.max_retries”, “1”);


And the request with the blocked area:


GHPlace from = new GHPlace(latitudeFrom, longitudeFrom), to = new GHPlace(latitudeTo, longitudeTo);

GHRequest request = new GHRequest(from, to)
.setWeighting(“fastest”)
.setVehicle(“car”)
.setAlgorithm(Parameters.Algorithms.DIJKSTRA_BI);

String blockArea = “-18.684626,-42.473831, -18.514772, -42.198486”;
request.getHints().put(Routing.BLOCK_AREA, blockArea);

GHResponse rsp = hopper.route(request);

rsp.getBest(); //get best calculated path

Am I missing something?


#2

To use blockl_area you need to disable CH:

request.getHints().put(Parameters.CH.DISABLE, true);


#3

Hi karussell, thanks for the reply!

The CH is disabled by default with the “.setCHEnabled(false)” in the initialization method. Still, I’ve tested with adding the line in the request but it still didn’t work :confused:


#4

I’ve done some debugging and It seems that the BlockAreaWeighting is working accordingly, since some of the coordinates inside the blocked area are indeed being caught by the blockarea.contains(edge) method, and therefore the calcWeight method from BlockAreaWeighthing is returning Double.POSITIVE_INFINITY.

So maybe the problem relies into something else? Maybe some configuration so the weighting value gets considered in the Path calculation?


#5

Ok, it seems the request works fine, but the problem probably relies on the JSprit library to find the best path? We use here a Cost Matrix which gives a weight to every possible route, but it doesn’t store the actual path. Here’s an example code:

// get all the correct paths with its corresponding weight and time from GraphHopper request
PathWrapper costs = DistanceHelpper.getCosts(from.getCoordinate(), to.getCoordinate());

//do some convertion - not really important for this case
costToGo = UnitConvertor.meterToKilometer(costs.getDistance());
timeToGo = UnitConvertor.millisecondsToMinutes(costs.getTime());

//add all the routes and its corresponding cost
costMatrixBuilder.addTransportDistance(from.getId(), to.getId(), costToGo);
costMatrixBuilder.addTransportTime(from.getId(), to.getId(), timeToGo);

//build the matrix
costMatrixBuilder.build();


In that case, I believe that the corresponding path wouldn’t be the one calculated, right? Because the Matrix doesn’t know the path the route should go, except from it’s weight. Is there a Matrix that takes the path in consideration?

Thanks