ArraysSolverValidator { public static SolutionObject validateOutputs(SolutionObject sol, int[][] travelTime, int[] releaseDates, int[] dueDates, int[][] servicePairs, int[] serviceTimes, @Nullable SolutionObject currentSolution) { final int n = travelTime.length; final int[][] vehicleTravelTimes = new int[1][n]; for (int i = 0; i < n; i++) { vehicleTravelTimes[0][i] = travelTime[0][i]; } final Set<Integer> locationSet = newHashSet(ContiguousSet.create( Range.closedOpen(1, n - 1), DiscreteDomain.integers())); for (int i = 0; i < servicePairs.length; i++) { locationSet.remove(servicePairs[i][0]); locationSet.remove(servicePairs[i][1]); } final int[][] inventories = new int[locationSet.size()][2]; final Iterator<Integer> locationSetIterator = locationSet.iterator(); for (int i = 0; i < locationSet.size(); i++) { inventories[i][0] = 0; inventories[i][1] = locationSetIterator.next(); } final int[] remainingServiceTimes = new int[] {0}; final int[] currentDestinations = new int[] {0}; @Nullable final SolutionObject[] currentSolutions = currentSolution == null ? null : new SolutionObject[] {currentSolution}; validateInputs(travelTime, releaseDates, dueDates, servicePairs, serviceTimes, vehicleTravelTimes, inventories, remainingServiceTimes, currentDestinations, currentSolutions); final SolutionObject[] sols = new SolutionObject[] {sol}; validateOutputs(sols, travelTime, releaseDates, dueDates, servicePairs, serviceTimes, vehicleTravelTimes, inventories, remainingServiceTimes, currentDestinations); return sol; } private  ArraysSolverValidator(); static SingleVehicleArraysSolver wrap(
      SingleVehicleArraysSolver delegate); static MultiVehicleArraysSolver wrap(
      MultiVehicleArraysSolver delegate); static void validateInputs(int[][] travelTime, int[] releaseDates,
      int[] dueDates, int[][] servicePairs, int[] serviceTimes); static void validateInputs(int[][] travelTime, int[] releaseDates,
      int[] dueDates, int[][] servicePairs, int[] serviceTimes,
      int[][] vehicleTravelTimes, int[][] inventories,
      int[] remainingServiceTimes, int[] currentDestinations,
      @Nullable SolutionObject[] currentSolutions); static SolutionObject validateOutputs(SolutionObject sol,
      int[][] travelTime, int[] releaseDates, int[] dueDates,
      int[][] servicePairs, int[] serviceTimes,
      @Nullable SolutionObject currentSolution); static SolutionObject[] validateOutputs(SolutionObject[] sols,
      int[][] travelTime, int[] releaseDates, int[] dueDates,
      int[][] servicePairs, int[] serviceTimes, int[][] vehicleTravelTimes,
      int[][] inventories, int[] remainingServiceTimes,
      int[] currentDestinations);  }
@Test(expected = IllegalArgumentException.class) public void validateInvalidRouteLength() { validateOutputs(new SolutionObject(new int[3], new int[1], 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateDuplicatesInRouteStart() { validateOutputs( new SolutionObject(new int[] {1, 1, 1, 1}, new int[1], 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidRouteDuplicates() { validateOutputs( new SolutionObject(new int[] {1, 2, 0, 3}, new int[1], 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidRouteDepot() { validateOutputs( new SolutionObject(new int[] {0, 1, 3, 2}, new int[1], 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidRouteNonExisting() { validateOutputs( new SolutionObject(new int[] {0, 1, 9, 3}, new int[1], 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidArrivalTimesLength() { validateOutputs( new SolutionObject(new int[] {0, 1, 2, 3}, new int[1], 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidArrivalTimesFirst() { validateOutputs(new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {1, -1, 0, 1}, 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidArrivalTimes1() { validateOutputs(new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, -1, 0, 1}, 0), new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidArrivalTimes2() { validateOutputs(new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 1}, 0), travelTimes, new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidArrivalTimes3() { validateOutputs(new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, 10, 0, 1}, 0), travelTimes, new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidObjective() { validateOutputs(new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, 10, 100, 108}, 0), travelTimes, new int[4], new int[4], new int[][] {}, new int[4], null); }
@Test(expected = IllegalArgumentException.class) public void validateMissingLocation2Vehicles() { final SolutionObject sol1 = new SolutionObject(new int[] {0, 2, 3}, new int[] {0, 10, 100, 108}, 238); final SolutionObject sol2 = new SolutionObject(new int[] {0, 2, 3}, new int[] {0, 10, 100, 108}, 238); validateOutputs(new SolutionObject[] {sol1, sol2}, travelTimes, new int[4], new int[4], new int[][] {}, new int[4], new int[2][4], new int[2][2], new int[2], new int[2]); }
@Test public void validateMultiVehicleCorrect() { final int[][] travelTime = new int[][] { new int[] {999, 999, 999, 999}, new int[] {999, 0, 999, 3}, new int[] {999, 999, 0, 7}, new int[] {999, 999, 999, 0}}; final int[] releaseDates = {0, 7, 8, 0}; final int[] dueDates = {0, 9, 100, 40}; final int[][] vehicleTravelTime = new int[][] { new int[] {999, 9, 999, 999}, new int[] {999, 999, 2, 999}}; final SolutionObject sol1 = new SolutionObject(new int[] {0, 1, 3}, new int[] {0, 10, 100}, 73); final SolutionObject sol2 = new SolutionObject(new int[] {0, 2, 3}, new int[] {0, 15, 90}, 59); validateOutputs(new SolutionObject[] {sol1, sol2}, travelTime, releaseDates, dueDates, new int[][] {}, new int[4], vehicleTravelTime, new int[2][2], new int[2], new int[2]); }
@Test(expected = IllegalArgumentException.class) public void validateRouteWithoutInventoryLocations() { final SolutionObject sol1 = new SolutionObject(new int[] {0, 1, 3}, new int[] {0, 10, 100}, 73); final SolutionObject sol2 = new SolutionObject(new int[] {0, 2, 3}, new int[] {0, 15, 90}, 59); final int[][] inventories = new int[][] {{0, 2}, {1, 1}}; validateOutputs(new SolutionObject[] {sol1, sol2}, new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], new int[2][4], inventories, new int[2], new int[2]); }
@Test(expected = IllegalArgumentException.class) public void validateRemainingServiceTime() { final SolutionObject sol1 = new SolutionObject(new int[] {0, 1, 3}, new int[] {0, 10, 100}, 73); final SolutionObject sol2 = new SolutionObject(new int[] {0, 2, 3}, new int[] {0, 15, 90}, 59); final int[] remainingServiceTimes = new int[] {3, 700}; validateOutputs(new SolutionObject[] {sol1, sol2}, new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], new int[2][4], new int[0][0], remainingServiceTimes, new int[2]); }
@Test(expected = IllegalArgumentException.class) public void validateCurrentDestination() { final SolutionObject sol1 = new SolutionObject(new int[] {0, 2, 3}, new int[] {0, 10, 100}, 73); final SolutionObject sol2 = new SolutionObject(new int[] {0, 1, 3}, new int[] {0, 15, 90}, 59); final int[] remainingServiceTimes = new int[] {0, 0}; validateOutputs(new SolutionObject[] {sol1, sol2}, new int[4][4], new int[4], new int[4], new int[][] {}, new int[4], new int[2][4], new int[0][0], remainingServiceTimes, new int[] {1, 2}); }
@Test public void validateCorrect() { validateOutputs( new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, 10, 100, 108}, 238), travelTimes, new int[4], new int[4], new int[][] {}, new int[4], null).toString(); }
@Test public void validateCorrect2() { final int[][] tt = new int[][] { new int[] {999, 999, 999, 999}, new int[] {999, 0, 3, 999}, new int[] {999, 999, 0, 7}, new int[] {999, 999, 999, 0}}; final SolutionObject sol1 = new SolutionObject( new int[] {0, 1, 2, 3}, new int[] {0, 10, 100, 108}, 228); final SolutionObject sol2 = new SolutionObject( new int[] {0, 3}, new int[] {0, 999}, 999); validateOutputs(new SolutionObject[] {sol1, sol2}, tt, new int[4], new int[4], new int[][] {}, new int[4], new int[2][4], new int[2][2], new int[2], new int[2]); }
@Test(expected = IllegalArgumentException.class) public void validateBig() { final int[][] travelTime = new int[][] { {0, 132, 233, 491, 644, 513, 284, 447, 435, 255, 140, 246}, {132, 0, 168, 380, 548, 508, 228, 399, 394, 301, 161, 163}, {233, 168, 0, 276, 414, 351, 61, 232, 227, 216, 127, 35}, {491, 380, 276, 0, 185, 439, 256, 263, 282, 463, 402, 250}, {644, 548, 414, 185, 0, 427, 373, 283, 307, 555, 534, 399}, {513, 508, 351, 439, 427, 0, 297, 177, 160, 280, 376, 373}, {284, 228, 61, 256, 373, 297, 0, 172, 167, 210, 162, 77}, {447, 399, 232, 263, 283, 177, 172, 0, 25, 286, 312, 242}, {435, 394, 227, 282, 307, 160, 167, 25, 0, 265, 298, 240}, {255, 301, 216, 463, 555, 280, 210, 286, 265, 0, 141, 250}, {140, 161, 127, 402, 534, 376, 162, 312, 298, 141, 0, 155}, {246, 163, 35, 250, 399, 373, 77, 242, 240, 250, 155, 0}}; final int[] releaseDates = {0, 1245143, 1755843, 63643, 1330543, 711843, 1811843, 212643, 1453443, 0, 188143, 0}; final int[] dueDates = {0, 2139143, 2606143, 1758143, 2242143, 1968143, 2564143, 1395843, 2401143, 1843643, 2030043, 2940143}; final int[][] servicePairs = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; final int[] serviceTimes = createServiceTimes(300, releaseDates.length); final SolutionObject sol = new SolutionObject( new int[] {0, 1, 10, 9, 5, 8, 7, 4, 3, 6, 2, 11}, new int[] {0, 132, 4384, 3467, 2982, 1614, 4023, 2399, 2074, 1034, 593, 4719}, 1719); validateOutputs(sol, travelTime, releaseDates, dueDates, servicePairs, serviceTimes, null); }
@Test(expected = IllegalArgumentException.class) public void validateInvalidArrivalOrder() { validateOutputs( new SolutionObject( new int[] {0, 2, 1, 3}, new int[] {0, 1998, 999, 2997}, 238), travelTimes, new int[4], new int[4], new int[][] {{1, 2}}, new int[4], null); }