@Override public ImmutableList<ImmutableList<Parcel>> solve(GlobalStateObject state) throws InterruptedException { return validateOutputs(delegateSolver.solve(validateInputs(state)), state); } }
gso.getAvailableParcels()); SolverValidator.checkRoute(gso.getVehicles().get(0), 0); } catch (final IllegalArgumentException e) { args.noCurrentRoutes();
@Override public Solver get(long seed) { return SolverValidator.wrap(supplier.get(seed)); } }
@Test public void validateInvalidNumberOfRoutes() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.<Parcel>of(), 0, null, null); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList.of(); final GlobalStateObject state = GlobalStateObject.create( ImmutableSet.<Parcel>of(), ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateOutputs(routes, state); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).contains("found 0 routes with 1 vehicles"); fail = true; } assertThat(fail).isTrue(); }
public GlobalStateObject build() { return SolverValidator.validateInputs(buildUnsafe()); }
SolverValidator.validateOutputs(schedule, state);
@Test public void validateNegativeTime() { final GlobalStateObject state = GlobalStateObject.create( ImmutableSet.<Parcel>of(), ImmutableList.<VehicleStateObject>of(), -1, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateInputs(state); } catch (final IllegalArgumentException e) { fail = true; assertThat(e.getMessage()).contains("Time must be >= 0"); } assertThat(fail).isTrue(); }
@Test public void validateParcelTooManyTimes1() { final ImmutableSet<Parcel> empty = ImmutableSet.of(); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), new Point(0, 0), absent, empty, 0, null, null); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .of(ImmutableList.of(p1, p1, p1)); final ImmutableSet<Parcel> availableParcels = ImmutableSet.of(p1); final ImmutableList<VehicleStateObject> vehicles = ImmutableList.of(vs1); final GlobalStateObject state = GlobalStateObject.create(availableParcels, vehicles, 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateOutputs(routes, state); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).contains("found 3 occurence(s) of parcel p1"); fail = true; } assertThat(fail).isTrue(); }
@Test(expected = IllegalArgumentException.class) public void validateParcelInTwoInventories() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p2, ImmutableList.<Parcel>of()); final VehicleStateObject vs2 = VehicleStateObject.create(vdto(), POINT, absent, ImmutableSet.of(p1), 0, p2, ImmutableList.<Parcel>of()); final ImmutableSet<Parcel> empty = ImmutableSet.of(); final GlobalStateObject state = GlobalStateObject.create(empty, ImmutableList.of(vs1, vs2), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
public static Solver asSolver( Iterable<ImmutableList<ImmutableList<Parcel>>> schedules) { final Iterator<ImmutableList<ImmutableList<Parcel>>> it = schedules .iterator(); return SolverValidator.wrap( new Solver() { @Override public ImmutableList<ImmutableList<Parcel>> solve( GlobalStateObject state) { return it.next(); } }); }
try { final GlobalStateObject gso = solverHandle.get().convert(args); SolverValidator.checkRoute(gso.getVehicles().get(0), 0); } catch (final IllegalArgumentException e) { args.noCurrentRoutes();
@Test public void validateParcelTooManyTimes2() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), new Point(0, 0), absent, ImmutableSet.of(p1), 0, null, null); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .of(ImmutableList.of(p1, p1)); final ImmutableSet<Parcel> availableParcels = ImmutableSet.of(); final ImmutableList<VehicleStateObject> vehicles = ImmutableList.of(vs1); final GlobalStateObject state = GlobalStateObject.create(availableParcels, vehicles, 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateOutputs(routes, state); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()).contains("found 2 occurences of parcel p1"); fail = true; } assertThat(fail).isTrue(); }
/** * Vehicle doesn't have its cargo in its route. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute3() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p3)); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
/** * Create a new instance using the specified time unit and seed. * @param arrSolver The {@link MultiVehicleArraysSolver} that is used for * solving. * @param timeUnit The time unit to use for the underlying * {@link RandomMVArraysSolver}. */ public DebugSolverCreator(MultiVehicleArraysSolver arrSolver, Unit<Duration> timeUnit) { arraysSolver = ArraysSolverDebugger.wrap( ArraysSolverValidator.wrap(arrSolver), false); solver = SolverDebugger.wrap(SolverValidator .wrap(new MultiVehicleSolverAdapter(arraysSolver, timeUnit)), false); }
checkRoute(vs, i);
@Test public void validateIncompleteRouteForVehicle() { final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), new Point(0, 0), absent, ImmutableSet.of(p1), 0, null, null); final ImmutableList<Parcel> empty = ImmutableList.of(); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .of(empty); final ImmutableSet<Parcel> availableParcels = ImmutableSet.of(); final ImmutableList<VehicleStateObject> vehicles = ImmutableList.of(vs1); final GlobalStateObject state = GlobalStateObject.create(availableParcels, vehicles, 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateOutputs(routes, state); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()) .contains("doesn't visit all parcels in its cargo"); fail = true; } assertThat(fail).isTrue(); }
/** * Duplicate in route. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute5() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1, p1, p3)); final ImmutableSet<Parcel> available = ImmutableSet.of(p3); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }
vehicles, 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); final Solver solver = SolverValidator.wrap(new FakeSolver(routes)); solver.solve(state);
@Test public void validateOutputDestinationNotFirstInRoute() { final ImmutableSet<Parcel> empty = ImmutableSet.of(); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), new Point(0, 0), absent, empty, 0, p1, null); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .of(ImmutableList.of(p2, p1, p1, p2)); final ImmutableSet<Parcel> availableParcels = ImmutableSet.of(p1, p2); final ImmutableList<VehicleStateObject> vehicles = ImmutableList.of(vs1); final GlobalStateObject state = GlobalStateObject.create(availableParcels, vehicles, 0, SI.SECOND, SI.METERS_PER_SECOND, SI.CENTIMETER, mock(RoadModelSnapshot.class)); boolean fail = false; try { SolverValidator.validateOutputs(routes, state); } catch (final IllegalArgumentException e) { assertThat(e.getMessage()) .contains("should start with its current destination"); fail = true; } assertThat(fail).isTrue(); }
/** * Only once occurence of available parcel, should occur twice. */ @Test(expected = IllegalArgumentException.class) public void validateInvalidCurrentRoute6a() { final Point p = new Point(0, 0); final VehicleStateObject vs1 = VehicleStateObject.create(vdto(), p, absent, ImmutableSet.of(p1), 0, p1, ImmutableList.of(p1, p2)); final ImmutableSet<Parcel> available = ImmutableSet.of(p2); final GlobalStateObject state = GlobalStateObject.create(available, ImmutableList.of(vs1), 0, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, mock(RoadModelSnapshot.class)); SolverValidator.validateInputs(state); }