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]
[#jobs=1795][#vehicles=30][#vehicleTypes=1][transportCost=logio.utils.DistanceMatrix@77afea7d][activityCosts=com.graphhopper.jsprit.core.problem.cost.WaitingTimeCosts@161cd475]

Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
	at java.util.TimSort.mergeHi(TimSort.java:899)
	at java.util.TimSort.mergeAt(TimSort.java:516)
	at java.util.TimSort.mergeForceCollapse(TimSort.java:457)
	at java.util.TimSort.sort(TimSort.java:254)
	at java.util.Arrays.sort(Arrays.java:1512)
	at java.util.ArrayList.sort(ArrayList.java:1454)
	at java.util.Collections.sort(Collections.java:175)
	at com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoodsOptimized.calculateDistancesFromJob2Job(JobNeighborhoodsOptimized.java:128)
	at com.graphhopper.jsprit.core.algorithm.ruin.JobNeighborhoodsOptimized.initialise(JobNeighborhoodsOptimized.java:106)
	at com.graphhopper.jsprit.core.algorithm.box.Jsprit.create(Jsprit.java:436)
	at com.graphhopper.jsprit.core.algorithm.box.Jsprit.access$100(Jsprit.java:54)
	at com.graphhopper.jsprit.core.algorithm.box.Jsprit$Builder.buildAlgorithm(Jsprit.java:308)
	at logio.app.VehicleRoutingApp.<init>(VehicleRoutingApp.java:56)
	at logio.app.VehicleRoutingApp.main(VehicleRoutingApp.java:85)

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

1 Like