Custom weighting -stable version- (Resolved)

I attempted to shift to the stable maven version of graphhopper core.
Now when running custom weighting I receive;

Weighting should never return NaN values

Is there a new method? I’m currently using for v2.1

CustomModel model = new CustomModel();
            HashMap map = new HashMap();
            map.put("footway", 0);
            map.put("pedestrian", 0);
            map.put("steps", 0);
            map.put("service", 1.0);
            map.put("path", 0);
            map.put("track", 0);
            model.getPriority().put("road_class", map);

new CustomProfile("paxster").setCustomModel(model).setVehicle("foot").setWeighting("custom")

I cannot reproduce this. Can you share a unit test or some more information about the config and map you are using?

Hi Easbar. Sorry, I don’t have access to unit test. If you have a place I can upload files for you please let me know.

EncodingManager encodingManager = EncodingManager.create(FlagEncoderFactory.FOOT + "|block_private=false," + FlagEncoderFactory.CAR + "," + FlagEncoderFactory.MOTORCYCLE + "|turn_costs=true");
            
            String locationGrapphopperFiles = "Processed files location";
            String locationRoutingFile = "Location of your pbf";
            // Exclude footways, pedestrian areas, stairs  from paxster profile
            CustomModel model = new CustomModel();
            HashMap map = new HashMap();
            map.put("footway", 0);
            map.put("pedestrian", 0);
            map.put("steps", 0);
            map.put("service", 1.0);
            map.put("path", 0);
            map.put("track", 0);
            model.getPriority().put("road_class", map);
            
                                                graphHopper = new GraphHopperOSM()
                                                    .setGraphHopperLocation(locationGrapphopperFiles)
                                                    .setEncodingManager(encodingManager) 
                                                    .setDataReaderFile(locationRoutingFile)
                                                    .setElevation(true)
                                                    .setAllowWrites(true)
                                                    .setMemoryMapped()
                                                    .setElevationProvider(new CGIARProvider(System.getProperty("user.home")+File.separator+"srtm"+File.separator))

                                                    .setProfiles(Arrays.asList(
                                                        new Profile("foot").setVehicle("foot").setWeighting("fastest"),
                                                        new Profile("car").setVehicle("car").setWeighting("fastest"),
                                                        new Profile("rural").setVehicle("motorcycle").setWeighting("fastest").setTurnCosts(true).putHint("u_turn_costs", 3),
                                                        new CustomProfile("paxster").setCustomModel(model).setVehicle("foot").setWeighting("custom")
                                                        ))  

                                                    .forDesktop();
            
            // This is for CH profiles only
            ArrayList<CHProfile> chProfiles = new ArrayList();
            chProfiles.add(new CHProfile("car"));
            chProfiles.add(new CHProfile("foot"));
            chProfiles.add(new CHProfile("rural"));
            chProfiles.add(new CHProfile("paxster"));
            
            graphHopper.getCHPreparationHandler().setCHProfiles(chProfiles);
            
            graphHopper.setMemoryMapped();
            graphHopper.importOrLoad();

Maven

<dependency>
            <groupId>com.graphhopper</groupId>
            <artifactId>graphhopper-core</artifactId>
            <version>stable</version>
            <!--<version>2.1</version>-->
            <!--<version>1.0</version>-->
        </dependency>
        <dependency>
            <groupId>com.graphhopper</groupId>
            <artifactId>graphhopper-reader-osm</artifactId>
            <version>stable</version>
            <!--<version>2.1</version>-->
            <!--<version>1.0</version>-->
        </dependency>
        <dependency>
            <groupId>com.graphhopper</groupId>
            <artifactId>jsprit-core</artifactId>
            <version>1.9.0-beta.4</version>
            <!--<version>1.9.0-beta</version>-->
        </dependency>

PBF file
http://download.geofabrik.de/australia-oceania/new-zealand-latest.osm.pbf

SRTM elevation data - Areas in yellow (I don’t have a reliable place to share the files)


Ah I think I misread your first comment. So you mean it was working with 2.1, but it does not work with newer versions?

I can reproduce this using the stable tag (commit dd2c20c763e4c19b701e92386432b37713cd8dc5). The error I get is:

 java.lang.IllegalStateException: Weighting should never return NaN values, in:249239->575071 (578313); -39.80610347850852,176.193057399833 -> -39.80610347850852,176.193057399833, out:249239->575072 (578314); -39.80610347850852,176.193057399833 -> -39.81206189420958,176.19393451945336

Judging from the error message there is a zero distance edge (different node IDs, but same coordinates).

Can you please try version 2.3? And by the way the stable tag is currently an older version than 2.1. 2.1 also works.

The error occurs because there is a zero distance edge (time is therefore also zero) and we divide by zero priority (0/0=NaN). This was fixed here: https://github.com/graphhopper/graphhopper/blob/0522c495ccad5f22fe19c6e858a40a7bd6f74eae/core/src/main/java/com/graphhopper/routing/ch/CHPreparationGraph.java#L172-L177 in https://github.com/graphhopper/graphhopper/pull/2132 The weight can still be NaN, but all edges that do not have finite weights are rejected by CHPreparationGraph.

1 Like

Hi Easbar,

Thanks for taking the time to investigate. I didn’t notice “stable” was older and I just presumed as it was at the top of maven repository, that it was the latest. I think I need more sleep :slight_smile:
V2.3 is working fine. Looking forward to the release of 3.0!

I notice that the stable version is down the bottom now.