Increase number of vehicle in graphhopper/Encoder problems

Hi,

We are trying to extend graphhopper to use multiple vehicle types (7) and ran into a problem when testing it.
The problem is that the number of vehicles used is too large for the FlagEncoders.
We followed the suggestion inside the code to extend the flag encoders from int to long, but the problem still persists

In the EncoderManager class we modified the registerEncoder method to use longs as follows

private void registerEncoder( AbstractFlagEncoder encoder ) {
    int encoderCount = edgeEncoders.size();
    long usedBits = encoder.defineNodeBits(encoderCount, edgeEncoderNextBit);
    if (usedBits > bytesForFlags)
        throw new IllegalArgumentException(String.format(ERR, bytesForFlags, "node"));
    encoder.setNodeBitMask(usedBits - nextNodeBit, nextNodeBit);
    nextNodeBit = usedBits;

    usedBits = encoder.defineWayBits(encoderCount, nextWayBit);
    if (usedBits > bytesForFlags)
        throw new IllegalArgumentException(String.format(ERR, bytesForFlags, "way") + WAY_ERR);
    encoder.setWayBitMask(usedBits - nextWayBit, nextWayBit);
    nextWayBit = usedBits;

    usedBits = encoder.defineRelationBits(encoderCount, nextRelBit);
    if (usedBits > bytesForFlags)
        throw new IllegalArgumentException(String.format(ERR, bytesForFlags, "relation"));
    encoder.setRelBitMask(usedBits - nextRelBit, nextRelBit);
    nextRelBit = usedBits;

    edgeEncoderNextBit = usedBits;

    // turn flag bits are independent from edge encoder bits
    usedBits = encoder.defineTurnBits(encoderCount, nextTurnBit, determineRequiredBits(maxTurnCost));
    if (usedBits > maxTurnFlagsBits)
        throw new IllegalArgumentException(String.format(ERR, bytesForFlags, "turn"));
    nextTurnBit = usedBits;

    //everything okay, add encoder
    edgeEncoders.add(encoder);
}

We also changed the signature of all the methods in the AbstractEncoder class (defineNodeBits, defineWayBits, etc) to use longs instead of ints. However, whenever we try to instantiate multiple vehicle types we still get the following error

Caused by: java.lang.IllegalArgumentException: Encoders are requesting more than 32 bits of way flags. Decrease the number of vehicles or increase the flags to take long. at com.graphhopper.routing.util.EncodingManager.registerEncoder(EncodingManager.java:207) at com.graphhopper.routing.util.EncodingManager.<init>(EncodingManager.java:148) at com.graphhopper.routing.util.EncodingManager.<init>(EncodingManager.java:105) at com.graphhopper.routing.util.EncodingManager.<init>(EncodingManager.java:100) at com.graphhopper.GraphHopper.init(GraphHopper.java:576) at com.graphhopper.daemonservice.RouteHandler.<clinit>(RouteHandler.java:67)

Do you guys have any insight of what might be happening or how to go around this error? Any help would be appreciated.

The latest version says how to do it via a config parameter: graph.bytesForFlags=8

Hi @karussell,

Thanks for the quick reply, unfortunately we did quite some changes for our particular use case, and have a tight dependency with the 0.4 version and making the changes as you suggest would require to change our complete infrastructure, do you perhaps have any other idea of how to go around this problem?

0.4 should be possible too: https://github.com/graphhopper/graphhopper/issues/433

1 Like

Thanks a lot, that did it!