Solvers { public static ExtendedStats computeStats(GlobalStateObject state, @Nullable ImmutableList<ImmutableList<Parcel>> routes) { return computeStats(state, routes, GeomHeuristics.euclidean()); } private  Solvers(); static AdapterBuilder<SimSolver> solverBuilder(Solver sol); static AdapterBuilder<SimulationConverter> converterBuilder(); static ExtendedStats computeStats(GlobalStateObject state,
      @Nullable ImmutableList<ImmutableList<Parcel>> routes); static ExtendedStats computeStats(GlobalStateObject state,
      @Nullable ImmutableList<ImmutableList<Parcel>> routes,
      GeomHeuristic heuristic); static Callable<ImmutableList<ImmutableList<Parcel>>> createSolverCallable(
      Solver solver, GlobalStateObject state); static MeasureableSolver timeMeasurementDecorator(Solver s);  }
@Test public void convertDecompositionTest() { final Optional<Connection<?>> absent = Optional.absent(); final VehicleDTO vd1 = VehicleDTO.builder() .startPosition(new Point(5, 5)) .speed(30d) .capacity(0) .availabilityTimeWindow(TimeWindow.create(100L, 100000L)) .build(); final Parcel a = Parcel.builder(new Point(0, 0), new Point(10, 10)) .pickupTimeWindow(TimeWindow.create(0, 30)) .deliveryTimeWindow(TimeWindow.create(70, 80)) .pickupDuration(5000L) .deliveryDuration(10000L) .build(); final Parcel b = Parcel.builder(new Point(5, 0), new Point(10, 7)) .pickupTimeWindow(TimeWindow.create(0, 30)) .deliveryTimeWindow(TimeWindow.create(70, 80)) .pickupDuration(5000L) .deliveryDuration(10000L) .build(); final Parcel c = Parcel.builder(new Point(3, 0), new Point(6, 7)) .pickupTimeWindow(TimeWindow.create(0, 30)) .deliveryTimeWindow(TimeWindow.create(70, 80)) .pickupDuration(5000L) .deliveryDuration(10000L) .build(); final Parcel d = Parcel.builder(new Point(3, 0), new Point(6, 2)) .pickupTimeWindow(TimeWindow.create(0, 30)) .deliveryTimeWindow(TimeWindow.create(70, 80)) .pickupDuration(5000L) .deliveryDuration(10000L) .build(); final ImmutableSet<Parcel> availableParcels = ImmutableSet .<Parcel>builder() .add(b).add(c) .build(); final ImmutableList<VehicleStateObject> vehicles = ImmutableList .<VehicleStateObject>builder() .add( VehicleStateObject.create( vd1, new Point(7, 9), absent, ImmutableSet.<Parcel>of(a), 0L, null, null)) .add(VehicleStateObject.create( vd1, new Point(3, 2), absent, ImmutableSet.<Parcel>of(d), 0L, null, null)) .build(); final GlobalStateObject state = GlobalStateObject.create(availableParcels, vehicles, 0L, SI.MILLI(SI.SECOND), NonSI.KILOMETERS_PER_HOUR, SI.KILOMETER, ss); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .<ImmutableList<Parcel>>builder() .add(ImmutableList.<Parcel>of(a, b, c, c, b)) .add(ImmutableList.<Parcel>of(d, d)) .build(); final StatisticsDTO stats = Solvers.computeStats(state, routes); final ObjectiveFunction objFunc = Gendreau06ObjectiveFunction.instance(); final double cost = objFunc.computeCost(stats); final double cost0 = objFunc.computeCost(Solvers.computeStats( state.withSingleVehicle(0), ImmutableList.of(routes.get(0)))); final double cost1 = objFunc.computeCost(Solvers.computeStats( state.withSingleVehicle(1), ImmutableList.of(routes.get(1)))); assertEquals(cost, cost0 + cost1, 0.001); }
@Test public void precisionTest() throws InterruptedException { final Parcel A = Parcel.builder(new Point(5, 5), new Point(2, 0)) .serviceDuration(180000L) .build(); final GlobalStateObject gso = GlobalStateObjectBuilder.globalBuilder() .addAvailableParcel(A) .addVehicle(GlobalStateObjectBuilder.vehicleBuilder() .setLocation(new Point(5, 5)) .setRoute(ImmutableList.<Parcel>of(A, A)) .setRemainingServiceTime(120000L) .setDestination(A) .build()) .setPlaneTravelTimes(new Point(0, 0), new Point(10, 10)) .build(); final ImmutableList<ImmutableList<Parcel>> schedule = ImmutableList.of(ImmutableList.of(A, A)); final double rinSimCost = Gendreau06ObjectiveFunction.instance(50d) .computeCost(Solvers.computeStats(gso, schedule)) * 60000d; assertThat(rinSimCost).isWithin(0.00001).of(563828.5364288616); final Graph<LengthData> g = new TableGraph<>(); Graphs.addBiPath(g, new Point(5, 5), new Point(2, 0), new Point(0, 0), new Point(5, 5)); final GlobalStateObject gso2 = GlobalStateObjectBuilder.globalBuilder() .addAvailableParcel(A) .addVehicle(GlobalStateObjectBuilder.vehicleBuilder() .setLocation(new Point(5, 5)) .setRoute(ImmutableList.<Parcel>of(A, A)) .setRemainingServiceTime(120000L) .setDestination(A) .build()) .setSnapshot(RoadModelSnapshotTestUtil.createGraphRoadModelSnapshot(g, SI.KILOMETER)) .build(); final double rinSimCost2 = Gendreau06ObjectiveFunction.instance(50d) .computeCost(Solvers.computeStats(gso2, schedule)) * 60000d; assertThat(rinSimCost2).isWithin(0.00001).of(563828.5364288616); }
@Test public void vehicleOnConnectionTest() { final DependencyProvider graphdp = mock(DependencyProvider.class); final Graph g = new TableGraph<>(); final Point a = new Point(0, 0); final Point b = new Point(2, 0); final Point c = new Point(2, 1); Graphs.addBiPath(g, a, b, c); final PDPRoadModel graphRm = PDPGraphRoadModel.builderForGraphRm( RoadModelBuilders.staticGraph(g) .withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND)) .withAllowVehicleDiversion(true) .build(graphdp); when(graphdp.get(RoadModel.class)).thenReturn(graphRm); final MovingTestVehicle mv1 = new MovingTestVehicle(a, b, graphRm); graphRm.register(mv1); final Parcel mp1 = createParcel(b, c); final ImmutableSet<Parcel> availableParcels = ImmutableSet .<Parcel>builder() .add(mp1) .build(); Optional<? extends Connection<?>> vehicleConnection = Optional.absent(); ImmutableList<VehicleStateObject> vehicles = ImmutableList .<VehicleStateObject>builder() .add( VehicleStateObject.create( mv1.getDTO(), graphRm.getPosition(mv1), vehicleConnection, ImmutableSet.<Parcel>of(mp1), 0L, null, null)) .build(); GlobalStateObject state = GlobalStateObject.create(availableParcels, vehicles, 0L, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, graphRm.getSnapshot()); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .<ImmutableList<Parcel>>builder() .add(ImmutableList.<Parcel>of(mp1)) .build(); ExtendedStats stats = Solvers.computeStats(state, routes); assertEquals(6d, stats.totalDistance, 0.00001); assertEquals(6d, stats.totalTravelTime, 0.00001); mv1.tickImpl(TimeLapseFactory.create(SI.SECOND, 0L, 1L)); assertEquals(new Point(1, 0), graphRm.getPosition(mv1)); vehicleConnection = ((GraphRoadModel) graphRm).getConnection(mv1); vehicles = ImmutableList .<VehicleStateObject>builder() .add( VehicleStateObject.create( mv1.getDTO(), graphRm.getPosition(mv1), vehicleConnection, ImmutableSet.<Parcel>of(mp1), 0L, null, null)) .build(); state = GlobalStateObject.create(availableParcels, vehicles, 1L, SI.SECOND, SI.METERS_PER_SECOND, SI.METER, graphRm.getSnapshot()); stats = Solvers.computeStats(state, routes); assertEquals(5d, stats.totalDistance, 0.00001); assertEquals(5d, stats.totalTravelTime, 0.00001); }
@Test public void vehicleOnStartPositionTest() { final TestVehicle vehicle = new TestVehicle(new Point(0, 0)); final Parcel parcel = createParcel(new Point(0, 0), new Point(0, 0)); final Graph g = new TableGraph<>(); g.addConnection(new Point(0, 0), new Point(1, 0)); final DependencyProvider graphdp = mock(DependencyProvider.class); final PDPRoadModel graphRm = PDPGraphRoadModel.builderForGraphRm( RoadModelBuilders.staticGraph(g).withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND)) .withAllowVehicleDiversion(true) .build(graphdp); when(graphdp.get(RoadModel.class)).thenReturn(graphRm); final ImmutableSet<Parcel> availableParcels = ImmutableSet .<Parcel>builder() .add(parcel) .build(); final VehicleStateObject vehicelState = GlobalStateObjectBuilder.vehicleBuilder().setVehicleDTO(vehicle.getDTO()) .setDestination(parcel).setRoute(availableParcels.asList()).build(); final GlobalStateObject globalState = GlobalStateObjectBuilder.globalBuilder().addAvailableParcel(parcel) .addVehicle(vehicelState).setSnapshot(graphRm.getSnapshot()) .buildUnsafe(); final ImmutableList<ImmutableList<Parcel>> routes = ImmutableList .<ImmutableList<Parcel>>builder() .add(ImmutableList.<Parcel>of(parcel)) .build(); final ExtendedStats stats = Solvers.computeStats(globalState, routes); assertEquals(0d, stats.totalDistance, 0.00001); }