Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
renaming and JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Jul 30, 2024
1 parent 472a3f3 commit a84c4a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
* <p>
* 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.
* <p>
* @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???
* <li> Pro: saves computation times,
* <li> Con: There is now update of the costs if the network (load) changes.
* <li> --> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -105,7 +105,7 @@ protected void scheduleResource() {

if (!shipmentsInCurrentTour.isEmpty()) {
Carrier auxiliaryCarrier =
CarrierSchedulerUtils.routeCarrier(
CarrierSchedulerUtils.solveVrpWithJsprit(
createAuxiliaryCarrier(
shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime),
resource.getNetwork());
Expand Down

0 comments on commit a84c4a3

Please sign in to comment.