diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java index bad24f1a..73e32368 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java @@ -7,6 +7,8 @@ import com.graphhopper.jsprit.core.util.Solutions; import java.util.Collection; import java.util.List; + +import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Network; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierPlan; @@ -21,12 +23,30 @@ * @author Kai Martins-Turner (kturner) */ public class CarrierSchedulerUtils { - public static Carrier routeCarrier(Carrier carrier, Network network) { + + /** + * Creates a VehicleRoutingProblem from a carrier and a network and solves it with Jsprit. + *

+ * This looks for me (KMT) similar to what is done in {@link org.matsim.freight.carriers.CarriersUtils#runJsprit(Scenario)}. + * So, maybe this can be more simplify. + *

+ * @Todo: include toll in the NetbasedCosts (if set), so it is also pat of the VRP + * @Todo: Find a way to reuse the netbasedCosts over the iterations(?) to avoid re-setting this up??? + *

  • Pro: saves computation times, + *
  • Con: There is now update of the costs if the network (load) changes. + *
  • --> do it at least per Carrier or generally or stay as it is? --> Discuss with KN + * @Todo: Make the number of jsprit-Iterations configurable + * + * @param carrier Carrier for which the problem should be solved + * @param network the underlying network to create the network based transport costs + * @return Carrier with the solution of the VehicleRoutingProblem and the routed plan. + */ + public static Carrier solveVrpWithJsprit(Carrier carrier, Network network) { VehicleRoutingProblem.Builder vrpBuilder = - MatsimJspritFactory.createRoutingProblemBuilder(carrier, network); + MatsimJspritFactory.createRoutingProblemBuilder(carrier, network); NetworkBasedTransportCosts.Builder tpcostsBuilder = - NetworkBasedTransportCosts.Builder.newInstance( - network, ResourceImplementationUtils.getVehicleTypeCollection(carrier)); + NetworkBasedTransportCosts.Builder.newInstance( + network, ResourceImplementationUtils.getVehicleTypeCollection(carrier)); NetworkBasedTransportCosts netbasedTransportCosts = tpcostsBuilder.build(); vrpBuilder.setRoutingCost(netbasedTransportCosts); VehicleRoutingProblem vrp = vrpBuilder.build(); diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index 2d880d20..b0103bf2 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -69,7 +69,7 @@ public void scheduleResource() { CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); carrier.getServices().put(carrierService.getId(), carrierService); } - carrier = CarrierSchedulerUtils.routeCarrier(carrier, resource.getNetwork()); + carrier = CarrierSchedulerUtils.solveVrpWithJsprit(carrier, resource.getNetwork()); } private CarrierService convertToCarrierService(LspShipmentWithTime tuple) { diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java index 51f13267..031495e7 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -88,7 +88,7 @@ protected void scheduleResource() { > vehicleType.getCapacity().getOther().intValue()) { load = 0; Carrier auxiliaryCarrier = - CarrierSchedulerUtils.routeCarrier( + CarrierSchedulerUtils.solveVrpWithJsprit( createAuxiliaryCarrier( shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), resource.getNetwork()); @@ -105,7 +105,7 @@ protected void scheduleResource() { if (!shipmentsInCurrentTour.isEmpty()) { Carrier auxiliaryCarrier = - CarrierSchedulerUtils.routeCarrier( + CarrierSchedulerUtils.solveVrpWithJsprit( createAuxiliaryCarrier( shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), resource.getNetwork());