Issues with encoded values not matching

Whilst my graph built fine previously, when I changed the config.yml file to support turn restrictions I now have " encoded values not matching", is this a version issue or something else and how do I determine where the issue is ?

Here’s what I’ve done ( all I want is my app to recognise turn restrictions)
In my config.yml file I have
graph.flag_encoders: car
graph.flag_encoders: car|turn_costs=true
graph.encoded_values: road_class,road_class_link,road_environment,max_speed,road_access
graph.bytes_for_flags: 4
prepare.ch.weightings: fastest
prepare.ch.edge_based: edge_or_node
prepare.min_network_size: 200
prepare.min_one_way_network_size: 200
routing.non_ch.max_waypoint_distance: 1000000
graph.dataaccess: RAM_STORE

in my my mainActivity Java Ive changed the following code
in function - " LOADGRAPHSTORAGE
GraphHopper tmpHopp = new GraphHopper().forMobile();
//**************************************************************SET-UP
tmpHopp.setCHEnabled(true);
tmpHopp.setEncodingManager(EncodingManager.create(“car|turn_costs=true”));
protected PathWrapper doInBackground(Void… v) {
StopWatch sw = new StopWatch().start();

           //*******************************************************************REQUEST

GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon).
setWeighting(“fastest”).
setVehicle(“car”).
setAlgorithm(Algorithms.DIJKSTRA_BI);
req.getHints().
put(Routing.INSTRUCTIONS, “true”);
GHResponse resp = hopper.route(req);

Prior to building a graph I’ve deleted the jar files in AndroidStudioProjects\ghtrial\graphhopper\web\target

deleted the old -gh folder containing old graphs in AndroidStudioProjects\ghtrial\graphhopper

deleted files on phone under /storage/emulated/0/Download/graphhopper/maps/new-zealand-latest-gh/

I then built the graph with
$ ./graphhopper.sh -a import -i new-zealand-latest.osm.pbf

The map shows fine but I seem to have an error with
An error happened while creating graph:Encoded values do not match:
Graphhopper config: road_access|version=1732466967|bits=4|index=0|shift=0|store_both_directions=false,max_speed|version=925318033|bits=5|index=0|shift=4|store_both_directions=true,road_environment|version=-330907635|bits=3|index=0|shift=14|store_both_directions=false,road_class_link|version=150464194|bits=1|index=0|shift=17|store_both_directions=false,road_class|version=123992615|bits=5|index=0|shift=18|store_both_directions=false,roundabout|version=544120317|bits=1|index=0|shift=23|store_both_directions=false
Graph: road_class|version=887801716|bits=5|index=0|shift=0|store_both_directions=false,road_class_link|version=146044462|bits=1|index=0|shift=5|store_both_directions=false,road_environment|version=-448080443|bits=3|index=0|shift=6|store_both_directions=false,max_speed|version=2003990561|bits=5|index=0|shift=9|store_both_directions=true,road_access|version=717676379|bits=4|index=0|shift=19|store_both_directions=false,roundabout|version=544120317|bits=1|index=0|shift=23|store_both_directions=false
Change configuration to match the graph or delete /storage/emulated/0/Download/graphhopper/maps/new-zealand-latest-gh/

You need to recreate the graph files. I.e. remove graph-cache should help.

1 Like

Yes, I thought I had, I deleted the old newzealandlatest-gh folder containing the old graphs,
When you say graph-cache are you referring to the files inside new-zealand-gh folder made by running graphhopper.sh.?

Yes

Hmmm, that’s what I’m doing, I’ll try to use a different dev environment, I still get same error.

I’ve now tried this on 2 completely fresh dev environments and Im getting the same error.
Works ok when graph is created without turn_costs=true but as soon as the graph is recreated the app errors with encoded values not matching
I have tried
multiple combinations in the config.yml file
deleting all jar files in projects
deleting app off phone
clearing the phones graph folder
different dev environment

Are you configuring the GraphHopper instance to use turn_costs on the mobile app too?

E.g. create the CarFlagEncoder via new CarFlagEncoder(5,5,1) instead of (5,5,0)

Not quite, I’m doing this

in function - " LOADGRAPHSTORAGE
GraphHopper tmpHopp = new GraphHopper().forMobile();

tmpHopp.setCHEnabled(true);
tmpHopp.setEncodingManager(EncodingManager.create(“car|turn_costs=true”));
protected PathWrapper doInBackground(Void… v) {
StopWatch sw = new StopWatch().start();

I Modified code to :
GraphHopper tmpHopp = new GraphHopper().forMobile();
CarFlagEncoder cfe = new CarFlagEncoder(5,5,1);
tmpHopp.setEncodingManager(EncodingManager.create(cfe));
tmpHopp.setCHEnabled(true);

I still get the exact same error and the same version values
2020-01-08 19:06:33.439 2352-2352/com.graphhopper.android I/GH: An error happened while creating graph:Encoded values do not match:
Graphhopper config: road_access|version=1732466967|bits=4|index=0|shift=0|store_both_directions=false,max_speed|version=925318033|bits=5|index=0|shift=4|store_both_directions=true,
road_environment|version=-330907635|bits=3|index=0|shift=14|store_both_directions=false,
road_class_link|version=150464194|bits=1|index=0|shift=17|store_both_directions=false,
road_class|version=123992615|bits=5|index=0|shift=18|store_both_directions=false,
roundabout|version=544120317|bits=1|index=0|shift=23|store_both_directions=false

Graph: road_class|version=887801716|bits=5|index=0|shift=0|store_both_directions=false,
road_class_link|version=146044462|bits=1|index=0|shift=5|store_both_directions=false,
road_environment|version=-448080443|bits=3|index=0|shift=6|store_both_directions=false,
max_speed|version=2003990561|bits=5|index=0|shift=9|store_both_directions=true,
road_access|version=717676379|bits=4|index=0|shift=19|store_both_directions=false,
roundabout|version=544120317|bits=1|index=0|shift=23|store_both_directions=false

Change configuration to match the graph or delete /storage/emulated/0/Download/graphhopper/maps/new-zealand-latest-gh/

You use different versions of GraphHopper for graph creation and on Android. You can see this in

Graphhopper config: road_access|...|bits=4
vs.
Graph: road_class|...|bits=5

Well, it’s a mystery, If I change the config.yml to the default settings and the java code in mainActivity.java to default it works just fine ( except that it won’t respect the turn restrictions/ turn costs I want)
It only seems to report encoded data mismatches when I implement the carflagencoder and use the encoding manager and change the config file to respect turncosts.

if I uncomment the 2 commented lines here the mismatch occurs
GraphHopper tmpHopp = new GraphHopper().forMobile();
// CarFlagEncoder cfe = new CarFlagEncoder(5,5,1);
// tmpHopp.setEncodingManager(EncodingManager.create(“cfe”));
tmpHopp.setCHEnabled(true);`

Which GraphHopper version are you using?

graph.encoded_values: road_class,road_class_link,road_environment,max_speed,road_access

All properties that you specify explicitly in the config.yml need to be specified in the Java code too (Android). Or I would do the opposite: instead of using the config.yml for the import I would also use Java code to init GraphHopper.

1.0 snapshot.

If you update to the latest pre-release 1.0-pre15 you can remove the two lines with graph.encoded_values and graph.bytes_for_flags, then do the import again and see if this works.

I think with this the configuration with the Java code should be the same like with the config.yml (and still a few default encoded values are added like road_class or max_speed etc).

But the best would be if you use Java for the import and for Android if you want to avoid this hassle.

There is always the possibility to tweak the Java code until it matches the config.yml but this is tricky.

Yay, that works! , for reference here’s what I did
using graphhopper 1.0 pre15 ( android) from https://github.com/graphhopper/graphhopper/releases/tag/1.0-pre15
In MainActivity.Java

void loadGraphStorage() {
    logUser("loading graph (" + Constants.VERSION + ") ... ");
    new GHAsyncTask<Void, Void, Path>() {
        protected Path saveDoInBackground(Void... v) throws Exception {
            GraphHopper tmpHopp = new GraphHopper().forMobile();
            tmpHopp.setEncodingManager(EncodingManager.create("car|turn_costs=true"));
            tmpHopp.getCHFactoryDecorator().setEdgeBasedCHMode(CHAlgoFactoryDecorator.EdgeBasedCHMode.EDGE_OR_NODE);

            tmpHopp.load(new File(mapsFolder, currentArea).getAbsolutePath() + "-gh");
            log("found graph " + tmpHopp.getGraphHopperStorage().toString() + ", nodes:" + tmpHopp.getGraphHopperStorage().getNodes());
            hopper = tmpHopp;
            return null;
        } 


public void calcPath(final double fromLat, final double fromLon,
                     final double toLat, final double toLon) {

    log("calculating path ...");
    new AsyncTask<Void, Void, PathWrapper>() {
        float time;

        protected PathWrapper doInBackground(Void... v) {
            StopWatch sw = new StopWatch().start();
            GHRequest req = new GHRequest(fromLat, fromLon, toLat, toLon).
                    setAlgorithm(Algorithms.DIJKSTRA_BI).
                    setWeighting("fastest").
                    setVehicle("car");
            req.getHints().
                    put(Routing.INSTRUCTIONS, "false");
            GHResponse resp = hopper.route(req);
            time = sw.stop().getSeconds();
            return resp.getBest();
        }

Config.yml
code only

    graphhopper:
datareader.file: new-zealand-latest.pbf
graph.flag_encoders: car|turn_costs=true
prepare.ch.weightings: fastest
prepare.ch.edge_based: edge_or_node
prepare.min_network_size: 200
prepare.min_one_way_network_size: 200
routing.non_ch.max_waypoint_distance: 1000000
graph.dataaccess: RAM_STORE
1 Like

I am using GraphHopper version 0.13.0 for Android. I try to get max_speed value so I have specified in config.yml properties as below

Now my problem is how to define all above properties in the Java code?