.add(new SolutionObject(copyOf(sol.route, sol.route.length), copyOf( sol.arrivalTimes, sol.arrivalTimes.length), sol.objectiveValue));
@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(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]); }
static SolutionObject convertRouteToSolutionObject(GlobalStateObject state, VehicleStateObject vso, Map<Parcel, ParcelIndexObj> mapping, int[][] travelTime, int[] releaseDates, int[] dueDates, int[] serviceTimes, int[] vehicleTravelTimes, int remainingServiceTime) { final int[] route = new int[vso.getRoute().get().size() + 2]; final Set<Parcel> seen = newHashSet(); for (int i = 0; i < vso.getRoute().get().size(); i++) { final Parcel dto = vso.getRoute().get().get(i); if (vso.getContents().contains(dto) || seen.contains(dto)) { // it is in cargo route[i + 1] = mapping.get(dto).deliveryIndex; } else { checkArgument(state.getAvailableParcels().contains(dto), "This parcel should be available but is not: %s.", dto); // it is available route[i + 1] = mapping.get(dto).pickupIndex; } // TODO add error msg checkArgument(route[i + 1] > 0); seen.add(dto); } route[route.length - 1] = travelTime.length - 1; final int[] arrivalTimes = computeArrivalTimes(route, travelTime, remainingServiceTime, vehicleTravelTimes, serviceTimes, releaseDates); final int tardiness = computeRouteTardiness(route, arrivalTimes, serviceTimes, dueDates, remainingServiceTime); final int tt = computeTotalTravelTime(route, travelTime, vehicleTravelTimes); return new SolutionObject(route, arrivalTimes, tt + tardiness); }
/** * The first arrival time should reflect the remainingServiceTime for each * vehicle. */ @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]); }
/** * The first point to visit in a route must be the destination (if there is a * destination). */ @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}); }
/** * In this test the vehicles attempt to deliver parcels which are not in their * own inventory. */ @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); // vehicle 0 has location 2 // vehicle 1 has location 1 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 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}}; // travel time for this route: 9 + 3 // tardiness: 1 + 60 final SolutionObject sol1 = new SolutionObject(new int[] {0, 1, 3}, new int[] {0, 10, 100}, 73); // travel time for this route: 2 + 7 // tardiness: 0 + 50 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 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}}; // travel time = 0 + 3 + 7 = 10 // tardiness = 10 + 100 + 108 = 218 // objval = 228 final SolutionObject sol1 = new SolutionObject(// new int[] {0, 1, 2, 3}, // route new int[] {0, 10, 100, 108}, // arrival times 228);// objective value // travel time = 0 // tardiness = 999 // objval = 999 final SolutionObject sol2 = new SolutionObject(// new int[] {0, 3}, // route new int[] {0, 999}, // arrival times 999);// objective value 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]); }
/** * The first location visited must always be the vehicle start location (0). */ @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 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 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 validateInvalidArrivalOrder() { validateOutputs( new SolutionObject(// new int[] {0, 2, 1, 3}, // route new int[] {0, 1998, 999, 2997}, // arrival times 238), // obj. value travelTimes, new int[4], new int[4], new int[][] {{1, 2}}, new int[4], null); }
/** * All locations must be visited, can not visit non-existing locations. */ @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 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); }
/** * The last location visited must always be the depot (n-1). */ @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 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 public void testWrapSingle() { final SingleVehicleArraysSolver s = wrap(new FakeSingleSolver( new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, 10, 100, 108}, 238))); s.solve(travelTimes, new int[4], new int[4], new int[][] {}, new int[4], null); }
/** * Route length must be equal to number of locations (4). */ @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); }