Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package rinde.sim.pdptw.central.arrays;
 import static;
Adapter for SingleVehicleArraysSolver to conform to the rinde.sim.pdptw.central.Solver interface.

Rinde van Lon <>
public class SingleVehicleSolverAdapter implements Solver {
  private final SingleVehicleArraysSolver solver;
  private final Unit<DurationoutputTimeUnit;


solver The solver to use.
outputTimeUnit The time unit which is expected by the specified solver.
      Unit<DurationoutputTimeUnit) {
    this. = solver;
    this. = outputTimeUnit;
        state.vehicles.size() == 1,
        "This solver can only deal with the single vehicle problem, found %s vehicles.",
    final VehicleStateObject v = state.vehicles.iterator().next();
        v.remainingServiceTime == 0,
        "This solver can not deal with remaining service time, it should be 0, it was %s.",
    final Collection<ParcelDTOinCargo = v.contents;
    // there are always two locations: the current vehicle location and
    // the depot
    final int numLocations = 2 + (state.availableParcels.size() * 2)
        + inCargo.size();
    if (numLocations == 2) {
      // there are no orders
      final ImmutableList<ParcelDTOempty = ImmutableList.of();
      return ImmutableList.of(empty);
    } else if (state.availableParcels.size() + inCargo.size() == 1) {
      // if there is only one order, the solution is trivial
      if (!state.availableParcels.isEmpty()) {
        // parcels on the map require two visits (one for pickup, one
        // for delivery)
        final ParcelDTO dto = state.availableParcels.iterator().next();
        return ImmutableList.of(ImmutableList.of(dtodto));
      } // else
      return ImmutableList.of(ImmutableList.copyOf(inCargo));
    // else, we are going to look for the optimal solution
    final ArraysObject ao = ArraysSolvers.toSingleVehicleArrays(state,
    final SolutionObject[] curSols = ao.currentSolutions;
    final SolutionObject sol = .solve(ao.travelTimeao.releaseDates,
        ao.dueDatesao.servicePairsao.serviceTimescurSols == null ? null
            : curSols[0]);
    return ImmutableList.of(ArraysSolvers.convertSolutionObject(sol,
New to GrepCode? Check out our FAQ X