| Forum | GitHub | Maps | Blog

Class JobNeighborhoodsOptimized bug?


I’m not pretty sure, what happened, but this class (com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoodsOptimized) throws an error on few specific data input. StackTrace:

[main] INFO com.graphhopper.jsprit.core.problem.VehicleRoutingProblem - setup problem: [fleetSize=FINITE]

Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(
	at java.util.TimSort.mergeAt(
	at java.util.TimSort.mergeForceCollapse(
	at java.util.TimSort.sort(
	at java.util.Arrays.sort(
	at java.util.ArrayList.sort(
	at java.util.Collections.sort(
	at com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoodsOptimized.calculateDistancesFromJob2Job(
	at com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoodsOptimized.initialise(

It has sth to do with custom distance matrix implementation, but I can’t figure out, where is the problem. It tries to sort, but I have no idea what can be sorted. Thanks for your help


Can you check whether every distance/costs are defined, i.e. for all locations x,y, costs(x,y) should return a number.


If for example, there is a division by 0 you usually get NaN (not a number) which in turn violates the contract of this sorting algo above.


My defined class usually returns custom saved value (real, road distance), but when it is not saved, it returns euclidean distance. I’m sure it never returns NaN value


Oh, don’t know why, but my class really returned NaN value even thought there’s no division, there must be rounding error while using sin cos functions (when calculating euclidean distance from longitude latitude) Thank you for your help