private double calcDist(Shipment i, Shipment j) { double c_i1j1 = calcDist(i.getPickupLocation(), j.getPickupLocation()); double c_i1j2 = calcDist(i.getPickupLocation(), j.getDeliveryLocation()); double c_i2j1 = calcDist(i.getDeliveryLocation(), j.getPickupLocation()); double c_i2j2 = calcDist(i.getDeliveryLocation(), j.getDeliveryLocation()); return (c_i1j1 + c_i1j2 + c_i2j1 + c_i2j2) / 4.0; }
private void renderShipment(Graph g, Shipment shipment, Label label, boolean renderShipments) { Node n1 = g.addNode(makeId(shipment.getId(), shipment.getPickupLocation().getId())); if (label.equals(Label.ID)) n1.addAttribute("ui.label", shipment.getId()); n1.addAttribute("x", shipment.getPickupLocation().getCoordinate().getX()); n1.addAttribute("y", shipment.getPickupLocation().getCoordinate().getY()); n1.setAttribute("ui.class", "pickup"); Node n2 = g.addNode(makeId(shipment.getId(), shipment.getDeliveryLocation().getId())); if (label.equals(Label.ID)) n2.addAttribute("ui.label", shipment.getId()); n2.addAttribute("x", shipment.getDeliveryLocation().getCoordinate().getX()); n2.addAttribute("y", shipment.getDeliveryLocation().getCoordinate().getY()); n2.setAttribute("ui.class", "delivery"); if (renderShipments) { Edge s = g.addEdge(shipment.getId(), makeId(shipment.getId(), shipment.getPickupLocation().getId()), makeId(shipment.getId(), shipment.getDeliveryLocation().getId()), true); s.addAttribute("ui.class", "shipment"); } }
@Override public boolean fulfilled(JobInsertionContext insertionContext) { Shipment shipment2insert = ((Shipment) insertionContext.getJob()); if (insertionContext.getNewVehicle().getId().equals("wheelchair_bus")) { if (shipment2insert.getSize().get(PASSENGERSEATS_INDEX) > 0) { if (shipment2insert.getPickupLocation().getCoordinate().getX() > 15. || shipment2insert.getDeliveryLocation().getCoordinate().getX() > 15.) { return false; } } } return true; } };
private double scoreShipment(InsertionData best, Job job) { Shipment shipment = (Shipment) job; double maxDepotDistance_1 = Math.max( getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getPickupLocation()), getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getDeliveryLocation()) ); double maxDepotDistance_2 = Math.max( getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getPickupLocation()), getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getDeliveryLocation()) ); double maxDepotDistance = Math.max(maxDepotDistance_1, maxDepotDistance_2); double minTimeToOperate = Math.min(shipment.getPickupTimeWindow().getEnd() - shipment.getPickupTimeWindow().getStart(), shipment.getDeliveryTimeWindow().getEnd() - shipment.getDeliveryTimeWindow().getStart()); return Math.max(timeWindowParam * minTimeToOperate, minTimeWindowScore) + depotDistanceParam * maxDepotDistance; }
if (!(j instanceof Shipment)) continue; Shipment shipment = (Shipment) j; xmlConfig.setProperty(shipmentPathString + "(" + counter + ")[@id]", shipment.getId()); if (shipment.getPickupLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.id", shipment.getPickupLocation().getId()); if (shipment.getPickupLocation().getCoordinate() != null) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.coord[@x]", shipment.getPickupLocation().getCoordinate().getX()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.coord[@y]", shipment.getPickupLocation().getCoordinate().getY()); if (shipment.getPickupLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.index", shipment.getPickupLocation().getIndex()); Collection<TimeWindow> pu_tws = shipment.getPickupTimeWindows(); int index = 0; xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.duration", shipment.getPickupServiceTime()); for(TimeWindow tw : pu_tws) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(" + index + ").start", tw.getStart()); if (shipment.getDeliveryLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.id", shipment.getDeliveryLocation().getId()); if (shipment.getDeliveryLocation().getCoordinate() != null) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@x]", shipment.getDeliveryLocation().getCoordinate().getX()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@y]", shipment.getDeliveryLocation().getCoordinate().getY()); if (shipment.getDeliveryLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.index", shipment.getDeliveryLocation().getIndex()); Collection<TimeWindow> del_tws = shipment.getDeliveryTimeWindows();
/** * Creates (MATSim) {@link CarrierShipment} from a (jsprit) {@link Shipment} * * @param shipment to be transformed to MATSim * @return CarrierShipment * @see CarrierShipment, Shipment */ static CarrierShipment createCarrierShipment(Shipment shipment) { return CarrierShipment.Builder.newInstance(Id.create(shipment.getId(), CarrierShipment.class), Id.createLinkId(shipment.getPickupLocation().getId()), Id.createLinkId(shipment.getDeliveryLocation().getId()), shipment.getSize().get(0)) .setDeliveryServiceTime(shipment.getDeliveryServiceTime()) .setDeliveryTimeWindow(TimeWindow.newInstance(shipment.getDeliveryTimeWindow().getStart(), shipment.getDeliveryTimeWindow().getEnd())) .setPickupServiceTime(shipment.getPickupServiceTime()) .setPickupTimeWindow(TimeWindow.newInstance(shipment.getPickupTimeWindow().getStart(), shipment.getPickupTimeWindow().getEnd())) .build(); }
private String getFromNodeId(Shipment shipment) { return shipment.getId() + "_pickup"; }
@Override public Location getLocation() { return shipment.getDeliveryLocation(); }
comparisonShipment = shipment; }else{ double milliseconds=problem.getTransportCosts().getTransportTime(comparisonShipment.getPickupLocation(), shipment.getPickupLocation(), 0, null, null); if(milliseconds>1){ orderIndependentShipmentPickups = false; boolean cNull = comparisonShipment.getPickupTimeWindow()==null; boolean sNUll = shipment.getPickupTimeWindow()==null; if(cNull !=sNUll){ orderIndependentShipmentPickups = false; TimeWindow c = comparisonShipment.getPickupTimeWindow(); TimeWindow s =shipment.getPickupTimeWindow(); if(Math.abs(c.getStart() - s.getStart())>1 || Math.abs(c.getEnd() - s.getEnd())>1
@Override public Location getLocation() { return shipment.getPickupLocation(); }
@Override public Capacity getSize() { return shipment.getSize(); }
@Override public double getOperationTime() { return shipment.getDeliveryServiceTime(); }
/** * Adds a the pickup of the specified shipment. * * @param shipment to be picked up and added to this route * @return the builder * @throws IllegalArgumentException if method has already been called with the specified shipment. */ public Builder addPickup(Shipment shipment) { return addPickup(shipment, shipment.getPickupTimeWindow()); }
@Override public double getOperationTime() { return shipment.getPickupServiceTime(); }
/** * Builds the shipment. * * @return shipment * @throws IllegalArgumentException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord * is set */ public Shipment build() { if (pickupLocation_ == null) throw new IllegalArgumentException("The pickup location is missing."); if (deliveryLocation_ == null) throw new IllegalArgumentException("The delivery location is missing."); capacity = capacityBuilder.build(); skills = skillBuilder.build(); return new Shipment(this); }
/** * Adds a the delivery of the specified shipment. * * @param shipment to be delivered and add to this vehicleRoute * @return builder * @throws IllegalArgumentException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). */ public Builder addDelivery(Shipment shipment) { return addDelivery(shipment,shipment.getDeliveryTimeWindow()); }
if (!(j instanceof Shipment)) continue; Shipment shipment = (Shipment) j; xmlConfig.setProperty(shipmentPathString + "(" + counter + ")[@id]", shipment.getId()); if (shipment.getPickupLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.id", shipment.getPickupLocation().getId()); if (shipment.getPickupLocation().getCoordinate() != null) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.coord[@x]", shipment.getPickupLocation().getCoordinate().getX()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.coord[@y]", shipment.getPickupLocation().getCoordinate().getY()); if (shipment.getPickupLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.index", shipment.getPickupLocation().getIndex()); Collection<TimeWindow> pu_tws = shipment.getPickupTimeWindows(); int index = 0; xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.duration", shipment.getPickupServiceTime()); for(TimeWindow tw : pu_tws) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(" + index + ").start", tw.getStart()); if (shipment.getDeliveryLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.id", shipment.getDeliveryLocation().getId()); if (shipment.getDeliveryLocation().getCoordinate() != null) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@x]", shipment.getDeliveryLocation().getCoordinate().getX()); xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@y]", shipment.getDeliveryLocation().getCoordinate().getY()); if (shipment.getDeliveryLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.index", shipment.getDeliveryLocation().getIndex()); Collection<TimeWindow> del_tws = shipment.getDeliveryTimeWindows();
private double scoreShipment(InsertionData best, Job job) { Shipment shipment = (Shipment) job; double maxDepotDistance_1 = Math.max( getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getPickupLocation()), getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getDeliveryLocation()) ); double maxDepotDistance_2 = Math.max( getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getPickupLocation()), getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getDeliveryLocation()) ); double maxDepotDistance = Math.max(maxDepotDistance_1, maxDepotDistance_2); double minTimeToOperate = Math.min(shipment.getPickupTimeWindow().getEnd() - shipment.getPickupTimeWindow().getStart(), shipment.getDeliveryTimeWindow().getEnd() - shipment.getDeliveryTimeWindow().getStart()); return Math.max(timeWindowParam * minTimeToOperate, minTimeWindowScore) + depotDistanceParam * maxDepotDistance; }
private String getToNodeId(Shipment shipment) { return shipment.getId() + "_delivery"; }
private void setEndLocation(VehicleRoute route, Shipment shipment) { route.getEnd().setLocation(shipment.getDeliveryLocation()); }