@Override public double getSpeed() { return dto.getSpeed(); }
GraphTravelTimes(GraphRoadModel rm, Unit<Duration> tu, Point centerMostPoint, Iterator<Vehicle> vehicles) { roadModel = rm; double max = 0; while (vehicles.hasNext()) { final Vehicle v = vehicles.next(); max = Math.max(max, v.getDTO().getSpeed()); } vehicleSpeed = Measure.valueOf(max, roadModel.getSpeedUnit()); depotLocations = ImmutableList.of(centerMostPoint); this.timeUnit = tu; }
/** * Checks whether the vehicles defined for the specified scenario have the * same speed. If the speed is the same it is returned, otherwise an exception * is thrown. * @param s The {@link Scenario} to get the speed from. * @return The vehicle speed if all vehicles have the same speed. * @throws IllegalArgumentException if either: not all vehicles have the same * speed, or there are no vehicles. */ public static double getVehicleSpeed(Scenario s) { double vehicleSpeed = -1d; for (final TimedEvent te : s.getEvents()) { if (te instanceof AddVehicleEvent) { if (vehicleSpeed == -1d) { vehicleSpeed = ((AddVehicleEvent) te).getVehicleDTO().getSpeed(); } else { checkArgument( vehicleSpeed == ((AddVehicleEvent) te).getVehicleDTO().getSpeed(), "All vehicles are expected to have the same speed."); } } } checkArgument(vehicleSpeed > 0, "There are no vehicles in the scenario."); return vehicleSpeed; }
DefaultTravelTimes(RoadModel rm, Unit<Duration> tu, Iterable<? extends AddDepotEvent> depots, Iterable<? extends AddVehicleEvent> vehicles) { roadModel = rm; double max = 0; for (final AddVehicleEvent ave : vehicles) { max = Math.max(max, ave.getVehicleDTO().getSpeed()); } vehicleSpeed = Measure.valueOf(max, roadModel.getSpeedUnit()); final ImmutableList.Builder<Point> depotBuilder = ImmutableList.builder(); for (final AddDepotEvent ade : depots) { depotBuilder.add(ade.getPosition()); } depotLocations = depotBuilder.build(); timeUnit = tu; }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o instanceof VehicleDTO) { VehicleDTO that = (VehicleDTO) o; return (this.startPosition.equals(that.getStartPosition())) && (Double.doubleToLongBits(this.speed) == Double.doubleToLongBits(that.getSpeed())) && (this.capacity == that.getCapacity()) && (this.availabilityTimeWindow.equals(that.getAvailabilityTimeWindow())); } return false; }
GraphTravelTimes(GraphRoadModel rm, Unit<Duration> tu, Iterable<? extends AddDepotEvent> depots, Iterable<? extends AddVehicleEvent> vehicles) { roadModel = rm; double max = 0; for (final AddVehicleEvent ave : vehicles) { max = Math.max(max, ave.getVehicleDTO().getSpeed()); } vehicleSpeed = Measure.valueOf(max, roadModel.getSpeedUnit()); final ImmutableList.Builder<Point> depotBuilder = ImmutableList.builder(); for (final AddDepotEvent ade : depots) { depotBuilder.add(ade.getPosition()); } depotLocations = depotBuilder.build(); timeUnit = tu; }
@Override public JsonElement doSerialize(VehicleDTO src, Type typeOfSrc, JsonSerializationContext context) { final JsonArray arr = new JsonArray(); arr.add( context.serialize(src.getAvailabilityTimeWindow(), TimeWindow.class)); arr.add(context.serialize(src.getCapacity())); arr.add(context.serialize(src.getSpeed())); arr.add(context.serialize(src.getStartPosition())); return arr; } }
@Override public JsonElement doSerialize(VehicleDTO src, Type typeOfSrc, JsonSerializationContext context) { final JsonArray arr = new JsonArray(); arr.add( context.serialize(src.getAvailabilityTimeWindow(), TimeWindow.class)); arr.add(context.serialize(src.getCapacity())); arr.add(context.serialize(src.getSpeed())); arr.add(context.serialize(src.getStartPosition())); return arr; } }
public long computeTravelTime(Point from, Point to) { final double speedKMH = vehicle.getDto().getSpeed(); final double distKM = Point.distance(from, to); final double travelTimeH = distKM / speedKMH; // convert to nanoseconds return DoubleMath.roundToLong(travelTimeH * H_TO_NS, RoundingMode.HALF_DOWN); }
(Gendreau06ObjectiveFunction) builder.getObjectiveFunction(); checkState(Math.abs(state.getVehicles().get(0).getDto().getSpeed() - objFunc.getVehicleSpeed()) < MAX_SPEED_DIFF, "Speed of vehicle (%s) does not correspond with speed in objective" + " function (%s).", state.getVehicles().get(0).getDto().getSpeed(), objFunc.getVehicleSpeed());
/** * Copy the value of the specified vehicle into this builder. * @param dto The dto to copy values from. * @return This, as per the builder pattern. */ public Builder use(VehicleDTO dto) { return startPosition(dto.getStartPosition()) .availabilityTimeWindow(dto.getAvailabilityTimeWindow()) .speed(dto.getSpeed()) .capacity(dto.getCapacity()); }
v.getDto().getSpeed(), state.getSpeedUnit());
final VehicleStateObject cur = iterator.next(); final Measure<Double, Velocity> speed = Measure.valueOf( cur.getDto().getSpeed(), state.getSpeedUnit());
Point vehicleLocation = vso.getLocation(); final Measure<Double, Velocity> maxSpeed = Measure.valueOf(vso.getDto().getSpeed(), state.getSpeedUnit());
void checkVehicles(List<? extends TestVehicle> expected, ImmutableList<VehicleStateObject> states) { assertEquals(expected.size(), states.size()); for (int i = 0; i < expected.size(); i++) { final TestVehicle vehicle = expected.get(i); final VehicleDTO dto = vehicle.dto; final VehicleStateObject vs = states.get(i); assertEquals(dto.getAvailabilityTimeWindow(), vs.getDto().getAvailabilityTimeWindow()); assertEquals(dto.getCapacity(), vs.getDto().getCapacity()); assertEquals(dto.getSpeed(), vs.getDto().getSpeed(), 0); assertEquals(dto.getStartPosition(), vs.getDto().getStartPosition()); assertEquals(rm.getPosition(expected.get(i)), vs.getLocation()); final Parcel dest = rm.getDestinationToParcel(vehicle); if (dest == null) { assertFalse(vs.getDestination().isPresent()); } else { assertEquals(dest, vs.getDestination().get()); } if (pm.getVehicleState(vehicle) == VehicleState.IDLE) { assertEquals(0, vs.getRemainingServiceTime()); } else { assertEquals(pm.getVehicleActionInfo(vehicle).timeNeeded(), vs.getRemainingServiceTime()); } } }