/** * Wraps the specified {@link SingleVehicleArraysSolver} to allow easy * debugging. Stores all invocation arguments and outputs and optionally * prints them to <code>System.out</code>. * @param s The {@link SingleVehicleArraysSolver} to wrap. * @param print If <code>true</code> all information will be printed as well. * @return The wrapped solver. */ public static SVASDebugger wrap(SingleVehicleArraysSolver s, boolean print) { return new SVASDebugger(s, print); }
/** * Decorates the original {@link MultiVehicleArraysSolver} such that both the * inputs to the solver and the outputs from the solver are validated. When an * invalid input or output is detected an {@link IllegalArgumentException} is * thrown. * @param delegate The {@link MultiVehicleArraysSolver} that will be used for * the actual solving. * @return The wrapped solver. */ public static MultiVehicleArraysSolver wrap( MultiVehicleArraysSolver delegate) { return new MultiValidator(delegate); }
/** * Wraps the specified {@link MultiVehicleArraysSolver} to allow easy * debugging. Stores all invocation arguments and outputs and optionally * prints them to <code>System.out</code>. * @param s The {@link MultiVehicleArraysSolver} to wrap. * @param print If <code>true</code> all information will be printed as well. * @return The wrapped solver. */ public static MVASDebugger wrap(MultiVehicleArraysSolver s, boolean print) { return new MVASDebugger(s, print); }
@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 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); }
@Test public void testWrapMulti() { TestUtil.testPrivateConstructor(ArraysSolverValidator.class); final MultiVehicleArraysSolver s = wrap(new FakeMultiSolver( new SolutionObject[] {new SolutionObject(new int[] {0, 1, 2, 3}, new int[] {0, 10, 100, 108}, 228)})); s.solve(travelTimes, new int[4], new int[4], new int[][] {}, new int[4], new int[2][4], new int[][] {{0, 1}, {0, 2}}, new int[2], new int[2], null); }
@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(); }
static int computeTardiness(SolutionObject[] sols, MVArraysObject arr) { int total = 0; for (int i = 0; i < sols.length; i++) { final SolutionObject sol = sols[i]; total += ArraysSolvers.computeRouteTardiness(sol.route, sol.arrivalTimes, arr.serviceTimes, arr.dueDates, arr.remainingServiceTimes[i]); } return total; }
static int computeTravelTime(SolutionObject[] sols, MVArraysObject arr) { int total = 0; for (int i = 0; i < sols.length; i++) { final SolutionObject sol = sols[i]; total += ArraysSolvers.computeTotalTravelTime(sol.route, arr.travelTime, arr.vehicleTravelTimes[i]); } return total; }
/** * A vehicle can have a dest and have remaining service time. */ public void validateInputsValidDestinations1() { validateInputs(new int[6][6], new int[6], new int[6], new int[][] {new int[] {4, 2}}, // servicePairs new int[6], // serviceTimes new int[][] {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}, // vehicleTravelTimes new int[][] {{1, 3}, {1, 1}}, // inventories new int[] {300, 0}, // remainingServiceTimes new int[] {4, 0}// current destinations , 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); }
/** * Wraps the specified {@link SingleVehicleArraysSolver} to allow easy * debugging. Every invocation of * {@link SingleVehicleArraysSolver#solve(int[][], int[], int[], int[][], int[], SolutionObject)} * all inputs and outputs are printed to <code>System.out</code>, also all * inputs and outputs are stored (accessible via * {@link SVASDebugger#getInputs()} and {@link SVASDebugger#getOutputs()}. * @param s The {@link SingleVehicleArraysSolver} to wrap. * @return The wrapped solver. */ public static SVASDebugger wrap(SingleVehicleArraysSolver s) { return new SVASDebugger(s, true); }
@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 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); }
/** * 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); }