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); }
/** * Sums the objective values of all provided {@link SolutionObject}s. The * input values are treated as instances of the <code>inputUnit</code> and are * converted to the <code>outputUnit</code>. * @param sols The {@link SolutionObject}s. * @param inputUnit The time unit of the input values. * @param outputUnit The time unit to convert the values to. * @return The sum objective value in the <code>outputUnit</code>. */ public static int computeTotalObjectiveValue(SolutionObject[] sols, Unit<Duration> inputUnit, Unit<Duration> outputUnit) { return Measure.valueOf(computeTotalObjectiveValue(sols), inputUnit) .intValue(outputUnit); }
final ArraysObject singleVehicleArrays = toSingleVehicleArrays(state, outputTimeUnit); checkArgument(!state.getVehicles().isEmpty(), "We need at least one vehicle"); final int[][] vehicleTravelTimes = toVehicleTravelTimes(state, singleVehicleArrays, outputTimeUnit); final int[][] inventories = toInventoriesArray(state, singleVehicleArrays); final int[] remainingServiceTimes = toRemainingServiceTimes(state, outputTimeUnit); final int[] currentDestinations = toVehicleDestinations(state, singleVehicleArrays); sols = toCurrentSolutions(state, singleVehicleArrays.parcel2index, singleVehicleArrays.travelTime, singleVehicleArrays.releaseDates, singleVehicleArrays.dueDates, singleVehicleArrays.serviceTimes,
index2parcelBuilder.put(deliveryIndex, pio); final int[] tw = convertTW(p.getPickupTimeWindow(), state.getTime(), timeConverter); releaseDates[index] = tw[0]; final int[] tw = convertTW(p.getDeliveryTimeWindow(), state.getTime(), timeConverter); releaseDates[index] = tw[0]; dueDates[index] = fixTWend(v.getDto().getAvailabilityTimeWindow().end(), state.getTime(), timeConverter); .build(); final int[][] travelTime = ArraysSolvers.toTravelTimeMatrix(pointList, state.getDistUnit(), speed, outputTimeUnit, RoundingMode.CEILING); sol = toCurrentSolutions(state, parcel2indexMap, travelTime, releaseDates, dueDates, serviceTimes, new int[][] {travelTime[0]}, new int[] {0});
.toSingleVehicleArrays(state, SI.MILLI(SI.SECOND)); final int[][] inventories = ArraysSolvers.toInventoriesArray(state, singleVehicleArrays);
final ArraysObject ao = ArraysSolvers.toSingleVehicleArrays(state, outputTimeUnit); : curSols[0]); return ImmutableList.of(ArraysSolvers.convertSolutionObject(sol, ao.index2parcel));
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; }
/** * Converts the list of points on a plane into a travel time matrix. For * distance between two points the Euclidean distance is used, i.e. no * obstacles or graph structure are considered. See * {@link #toTravelTimeMatrix(List, Unit, Measure, Unit, RoundingMode)} for * more options. * @param points The set of points which will be converted to a travel time * matrix. * @param speed the speed in m/s. * @param rm The rounding mode, see {@link RoundingMode}. * @return A <code>n x n</code> travel time matrix, where <code>n</code> is * the size of the <code>points</code> list. */ public static int[][] toTravelTimeMatrix(List<Point> points, double speed, RoundingMode rm) { return toTravelTimeMatrix(points, SI.METER, Measure.valueOf(speed, SI.METERS_PER_SECOND), SI.SECOND, rm); }
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; }
@Test public void convertTWtest() { final UnitConverter timeConverter = MILLI(SECOND).getConverterTo(SECOND); final int[] tw1 = convertTW(TimeWindow.create(300, 800), 5, timeConverter); assertEquals(0, tw1[0]); assertEquals(1, tw1[1]); final int[] tw2 = convertTW(TimeWindow.create(7300, 8800), 0, timeConverter); assertEquals(8, tw2[0]); assertEquals(8, tw2[1]); final int[] tw3 = convertTW(TimeWindow.create(7300, 8800), 7300, timeConverter); assertEquals(0, tw3[0]); assertEquals(1, tw3[1]); }
@Nullable static SolutionObject[] toCurrentSolutions(GlobalStateObject state, Map<Parcel, ParcelIndexObj> mapping, int[][] travelTime, int[] releaseDates, int[] dueDates, int[] serviceTimes, int[][] vehicleTravelTimes, int[] remainingServiceTimes) { final SolutionObject[] sols = new SolutionObject[state.getVehicles() .size()]; for (int i = 0; i < state.getVehicles().size(); i++) { sols[i] = convertRouteToSolutionObject(state, state.getVehicles().get(i), mapping, travelTime, releaseDates, dueDates, serviceTimes, vehicleTravelTimes[i], remainingServiceTimes[i]); } return sols; }
vehicleTravelTimes[i][index] = computeRoundedTravelTime(speed, Measure.valueOf( Point.distance(cur.getLocation(), vehicleTravelTimes[i][j] = computeRoundedTravelTime(speed, Measure.valueOf( Point.distance(cur.getLocation(), sva.location2index.get(j)),
/** * Checks correctness of tardiness computation. Also checks whether the * arrival time at the current position is correctly ignored when calculating * tardiness. */ @Test public void computeSumTardinessTest() { final int[] route = new int[] {0, 1, 2, 3}; final int[] arrivalTimes = new int[] {50, 70, 90, 100}; final int[] serviceTimes = new int[] {0, 5, 5, 0}; final int[] dueDates = new int[] {40, 70, 80, 110}; final int tardiness = ArraysSolvers.computeRouteTardiness(route, arrivalTimes, serviceTimes, dueDates, 0); assertEquals(20, tardiness); }
@Test public void travelTimeMatrix() { final Point p0 = new Point(0, 0); final Point p1 = new Point(10, 0); final Point p2 = new Point(10, 10); final Point p3 = new Point(0, 10); // input in kilometers, output in minutes (rounded up), speed 40 km/h final Measure<Double, Velocity> speed1 = Measure.valueOf(40d, KILOMETERS_PER_HOUR); final int[][] matrix1 = ArraysSolvers .toTravelTimeMatrix(asList(p0, p1, p2, p3), KILOMETER, speed1, MINUTE, RoundingMode.CEILING); assertArrayEquals(new int[] {0, 15, 22, 15}, matrix1[0]); assertArrayEquals(new int[] {15, 0, 15, 22}, matrix1[1]); assertArrayEquals(new int[] {22, 15, 0, 15}, matrix1[2]); assertArrayEquals(new int[] {15, 22, 15, 0}, matrix1[3]); final Point p4 = new Point(11, 3); // input in meters, output in milliseconds (round down), speed .0699 // m/ms final Measure<Double, Velocity> speed2 = Measure.valueOf(.0699, new ProductUnit<Velocity>(METER.divide(MILLI(SECOND)))); final int[][] matrix2 = ArraysSolvers.toTravelTimeMatrix( asList(p0, p1, p2, p3, p4), METER, speed2, MILLI(SECOND), RoundingMode.FLOOR); assertArrayEquals(new int[] {0, 143, 202, 143, 163}, matrix2[0]); assertArrayEquals(new int[] {143, 0, 143, 202, 45}, matrix2[1]); assertArrayEquals(new int[] {202, 143, 0, 143, 101}, matrix2[2]); assertArrayEquals(new int[] {143, 202, 143, 0, 186}, matrix2[3]); assertArrayEquals(new int[] {163, 45, 101, 186, 0}, matrix2[4]); }
final int[] minArrivalTimes = ArraysSolvers.computeArrivalTimes( sol.route, travelTime, remainingServiceTimes[v], vehicleTravelTimes[v], serviceTimes, releaseDates); final int totalTravelTime = ArraysSolvers.computeTotalTravelTime( sol.route, travelTime, vehicleTravelTimes[v]); final int tardiness = ArraysSolvers.computeRouteTardiness(sol.route, sol.arrivalTimes, serviceTimes, dueDates, remainingServiceTimes[v]);
assertEquals(solverOutput.size(), sols.length); final double arrObjVal = ArraysSolvers.computeTotalObjectiveValue(sols) / MS_TO_MIN; final double arrOverTime = overTime(sols, arrInput) / MS_TO_MIN;
routes.get(i).add(routes.get(i).size(), n - 1); final int[] route = Ints.toArray(routes.get(i)); final int[] arrivalTimes = ArraysSolvers.computeArrivalTimes(route, travelTime, remainingServiceTimes[i], vehicleTravelTimes[i], serviceTimes, releaseDates); final int totalTravelTime = ArraysSolvers.computeTotalTravelTime(route, travelTime, vehicleTravelTimes[i]); final int tardiness = ArraysSolvers.computeRouteTardiness(route, arrivalTimes, serviceTimes, dueDates, remainingServiceTimes[i]); sols[i] = new SolutionObject(route, arrivalTimes, totalTravelTime