diff --git a/pom.xml b/pom.xml
index ffa13b01..3e938dc1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,12 +37,6 @@
${project.parent.version}
-
- org.matsim.contrib
- vsp
- ${project.parent.version}
-
-
org.matsim
diff --git a/src/main/java/doxyfilter.sh b/src/main/java/doxyfilter.sh
old mode 100755
new mode 100644
diff --git a/src/main/java/org/matsim/freight/logistics/LSPUtils.java b/src/main/java/org/matsim/freight/logistics/LSPUtils.java
index 2821a8a0..e40c44e9 100644
--- a/src/main/java/org/matsim/freight/logistics/LSPUtils.java
+++ b/src/main/java/org/matsim/freight/logistics/LSPUtils.java
@@ -237,6 +237,8 @@ public LogisticChainBuilder addTracker(LSPSimulationTracker track
}
public LogisticChain build() {
+ //TODO: Prüfe of das alle Elemente Verbunden sind (in irgendeiner Art). Plus Hinweis auf die Änderung.
+
return new LogisticChainImpl(this);
}
}
diff --git a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java
index d76277d6..b9ef4efa 100644
--- a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java
+++ b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java
@@ -103,6 +103,9 @@ public static void main(String[] args) {
.controller()
.setOverwriteFileSetting(
OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
+ // The VSP default settings are designed for person transport simulation. After talking to Kai,
+ // they will be set to WARN here. Kai MT may'23
+ config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn);
var freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore);
@@ -170,12 +173,7 @@ public void install() {
});
log.info("Run MATSim");
- // The VSP default settings are designed for person transport simulation. After talking to Kai,
- // they will be set to WARN here. Kai MT may'23
- controler
- .getConfig()
- .vspExperimental()
- .setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn);
+
controler.run();
// print the schedules for the assigned LSPShipments
diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java
index 80462bde..57231be2 100644
--- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java
+++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java
@@ -47,7 +47,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.jetbrains.annotations.NotNull;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
@@ -71,6 +70,7 @@
import org.matsim.freight.carriers.controler.CarrierStrategyManager;
import org.matsim.freight.logistics.*;
import org.matsim.freight.logistics.examples.ExampleConstants;
+import org.matsim.freight.logistics.resourceImplementations.CarrierSchedulerUtils;
import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils;
import org.matsim.freight.logistics.shipment.LspShipment;
import org.matsim.vehicles.VehicleType;
@@ -132,17 +132,10 @@ public static void main(String[] args) {
lsps.add(createLspWithDirectChain(scenario, "Kaufland_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), vehicleTypes));
LSPUtils.addLSPs(scenario, new LSPs(lsps));
-
Controler controler = prepareControler(scenario);
log.info("Run MATSim");
- // The VSP default settings are designed for person transport simulation. After talking to Kai,
- // they will be set to WARN here. Kai MT may'23
- controler
- .getConfig()
- .vspExperimental()
- .setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn);
controler.run();
runCarrierAnalysis(controler.getControlerIO().getOutputPath(), config);
@@ -167,13 +160,17 @@ private static Config prepareConfig(String[] args) {
config.global().setRandomSeed(4177);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
+ // The VSP default settings are designed for person transport simulation. After talking to Kai,
+ // they will be set to WARN here. Kai MT may'23
+ config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn);
+
FreightCarriersConfigGroup freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore);
return config;
}
- private static @NotNull Controler prepareControler(Scenario scenario) {
+ private static Controler prepareControler(Scenario scenario) {
log.info("Prepare controler");
Controler controler = new Controler(scenario);
controler.addOverridingModule(
@@ -347,6 +344,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp
.getCarrierCapabilities()
//.setNumberOfJspritIterations // TODO Das mal hier einbauen. --> Ist aktuell in CarrierUtils.
.setFleetSize(CarrierCapabilities.FleetSize.INFINITE);
+ CarrierSchedulerUtils.setVrpLogic(distributionCarrier, LSPUtils.LogicOfVrp.serviceBased);
CarriersUtils.addCarrierVehicle(
distributionCarrier,
@@ -371,6 +369,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp
mainCarrierElement.connectWithNextElement(hubElement);
hubElement.connectWithNextElement(distributionCarrierElement);
+ //TODO: Hier das Verbinden einfügen und in der Reihenfolge ist es. KMT Nov'24
hubChain =
LSPUtils.LogisticChainBuilder.newInstance(Id.create("hubChain", LogisticChain.class))
.addLogisticChainElement(mainCarrierElement)
@@ -421,6 +420,7 @@ private static LogisticChain createDirectChain(Scenario scenario, String lspName
LogisticChain directChain;
Carrier directCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_directCarrier", Carrier.class));
directCarrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE);
+ CarrierSchedulerUtils.setVrpLogic(directCarrier, LSPUtils.LogicOfVrp.serviceBased);
CarriersUtils.addCarrierVehicle(directCarrier,
CarrierVehicle.newInstance(
diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java
index c1d277be..e27b2e27 100644
--- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java
+++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java
@@ -26,7 +26,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.jetbrains.annotations.NotNull;
import org.matsim.analysis.personMoney.PersonMoneyEventsAnalysisModule;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
@@ -159,7 +158,7 @@ private static Config prepareConfig(String[] args) {
return config;
}
- private static @NotNull Controler prepareControler(Scenario scenario, RoadPricingScheme rpScheme) {
+ private static Controler prepareControler(Scenario scenario, RoadPricingScheme rpScheme) {
log.info("Prepare controler");
Controler controler = new Controler(scenario);
controler.addOverridingModule(
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 3f8126d8..bbd9235c 100644
--- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java
+++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java
@@ -43,6 +43,10 @@ public class CarrierSchedulerUtils {
* @return Carrier with the solution of the VehicleRoutingProblem and the routed plan.
*/
public static Carrier solveVrpWithJsprit(Carrier carrier, Scenario scenario) {
+ // Maybe it make sense to store this object instead of rebuilding it for each carrier (in each iteration) ???
+ // pro: save computation time
+ // con: interdependencies, if something changes in the network (load), the object is not up-to-date & it is not clear, if the object is thread safe
+ // Decision for the time being: rebuild it for each carrier to have a clear state KMT/KN Aug'24
NetworkBasedTransportCosts netbasedTransportCosts;
Network network = scenario.getNetwork();
RoadPricingScheme roadPricingScheme = null;
@@ -127,10 +131,16 @@ public static void setVrpLogic(Carrier carrier, LSPUtils.LogicOfVrp logicOfVrp){
* This decides later, whether the VRP is build base on {@link org.matsim.freight.carriers.CarrierService}s or {@link org.matsim.freight.carriers.CarrierShipment}s.
*
* @param carrier The carrier for which the setting should be got.
- * @return the logic of the VRP
+ * @return the logic of the VRP, returns {@link LSPUtils.LogicOfVrp#serviceBased} if not set.
*/
public static LSPUtils.LogicOfVrp getVrpLogic(Carrier carrier){
- return (LSPUtils.LogicOfVrp) carrier.getAttributes().getAttribute(LOGIC_OF_VRP);
+ LSPUtils.LogicOfVrp result = (LSPUtils.LogicOfVrp) carrier.getAttributes().getAttribute(LOGIC_OF_VRP);
+ if (result == null){
+ log.error("VRPLogic not found for carrier {}. Will return {}", carrier.getId(), LSPUtils.LogicOfVrp.serviceBased);
+ return LSPUtils.LogicOfVrp.serviceBased;
+ } else {
+ return result ;
+ }
}
}
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 785a49d3..249b5a76 100644
--- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java
+++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java
@@ -31,7 +31,6 @@
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.freight.carriers.Tour.Leg;
-import org.matsim.freight.carriers.Tour.ServiceActivity;
import org.matsim.freight.carriers.Tour.TourElement;
import org.matsim.freight.logistics.*;
import org.matsim.freight.logistics.shipment.LspShipment;
@@ -92,17 +91,21 @@ protected void scheduleResource() {
// TODO KMT: Verstehe es nur mäßig, was er hier mit den Fahrzeugtypen macht. Er nimmt einfach
// das erste/nächste(?) und schaut ob es da rein passt... Aber was ist, wenn es mehrere
// gibt???
- VehicleType vehicleType =
- ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next();
- if ((load + lspShipment.getSize())
- > vehicleType.getCapacity().getOther().intValue()) {
+ VehicleType vehicleType = ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next();
+ if ((load + lspShipment.getSize()) > vehicleType.getCapacity().getOther().intValue()) {
load = 0;
Carrier auxiliaryCarrier =
CarrierSchedulerUtils.solveVrpWithJsprit(
createAuxiliaryCarrier(shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime),
scenario);
scheduledPlans.add(auxiliaryCarrier.getSelectedPlan());
- carrier.getServices().putAll(auxiliaryCarrier.getServices());
+ var vrpLogic = CarrierSchedulerUtils.getVrpLogic(carrier);
+ switch (vrpLogic) {
+ case serviceBased -> { carrier.getServices().putAll(auxiliaryCarrier.getServices()); }
+ case shipmentBased -> { carrier.getShipments().putAll(auxiliaryCarrier.getShipments()); }
+ default -> throw new IllegalStateException("Unexpected value: " + vrpLogic);
+ }
+
cumulatedLoadingTime = 0;
shipmentsInCurrentTour.clear();
}
@@ -115,11 +118,19 @@ protected void scheduleResource() {
if (!shipmentsInCurrentTour.isEmpty()) {
Carrier auxiliaryCarrier =
CarrierSchedulerUtils.solveVrpWithJsprit(
- createAuxiliaryCarrier(
- shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime),
+ createAuxiliaryCarrier(shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime),
scenario);
scheduledPlans.add(auxiliaryCarrier.getSelectedPlan());
- carrier.getServices().putAll(auxiliaryCarrier.getServices());
+
+ switch (CarrierSchedulerUtils.getVrpLogic(carrier)) {
+ case serviceBased -> { carrier.getServices().putAll(auxiliaryCarrier.getServices()); }
+ case shipmentBased -> { carrier.getShipments().putAll(auxiliaryCarrier.getShipments());
+ //TODO: When using shipmentbased, only ONE Vrp should be created and solved. -> No need for the auxiliary carrier(s). KMT'Aug 24
+ //Then we can also just pass all the vehicles over :)
+ //And need the TimeWindows for the Shipments...
+ }
+ default -> throw new IllegalStateException("Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier));
+ }
shipmentsInCurrentTour.clear();
}
@@ -173,6 +184,8 @@ private Collection unifyTourIds(Collection carrierPl
private CarrierService convertToCarrierService(LspShipment lspShipment) {
Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class);
CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getTo())
+ //TODO TimeWindows are not set. This seems to be a problem. KMT'Aug'24
+ //If added here, we also need to decide what happens, if the vehicles StartTime (plus TT) is > TimeWindowEnd ....
.setCapacityDemand(lspShipment.getSize())
.setServiceDuration(lspShipment.getDeliveryServiceTime())
.build();
@@ -184,21 +197,66 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) {
return carrierService;
}
+ /**
+ * This method converts a LspShipment to a CarrierShipment.
+ * Please note: This method may get removed in the future, in case that the LSPShipment and the CarrierShipment are merged. KMT'Aug'24
+
+ * @param lspShipment the LspShipment to convert
+ * @return a CarrierShipment
+ */
+ private CarrierShipment convertToCarrierShipment(LspShipment lspShipment) {
+ Id serviceId = Id.create(lspShipment.getId().toString(), CarrierShipment.class);
+ CarrierShipment carrierShipment = CarrierShipment.Builder.newInstance(serviceId, lspShipment.getFrom(), lspShipment.getTo(), lspShipment.getSize())
+ //TODO TimeWindows are not set. This seems to be a problem. KMT'Aug'24
+ //If added here, we also need to decide what happens, if the vehicles StartTime (plus TT) is > TimeWindowEnd ....
+ .setDeliveryServiceTime(lspShipment.getDeliveryServiceTime())
+ .build();
+ //ensure that the ids of the lspShipment and the carrierShipment are the same. This is needed for updating the LSPShipmentPlan
+ if (! Objects.equals(lspShipment.getId().toString(), carrierShipment.getId().toString())) {
+ log.error("Id of LspShipment: {} and CarrierService: {} do not match", lspShipment.getId().toString(), carrierShipment.getId().toString(),
+ new IllegalStateException("Id of LspShipment and CarrierService do not match"));
+ }
+ return carrierShipment;
+ }
+
+
@Override
protected void updateShipments() {
for (LspShipment lspShipment : lspShipmentsToSchedule) {
for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) {
Tour tour = scheduledTour.getTour();
- for (TourElement element : tour.getTourElements()) {
- if (element instanceof ServiceActivity serviceActivity) {
- if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) {
- addShipmentLoadElement(lspShipment, tour);
- addShipmentTransportElement(lspShipment, tour, serviceActivity);
- addShipmentUnloadElement(lspShipment, tour, serviceActivity);
- addDistributionTourStartEventHandler(serviceActivity.getService(), lspShipment, resource, tour);
- addDistributionServiceEventHandler(serviceActivity.getService(), lspShipment, resource);
+
+ switch (CarrierSchedulerUtils.getVrpLogic(carrier)) {
+ case serviceBased -> {
+ for (TourElement element : tour.getTourElements()) {
+ if (element instanceof Tour.ServiceActivity serviceActivity) {
+ if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) {
+ addShipmentLoadElement(lspShipment, tour);
+ addShipmentTransportElement(lspShipment, tour, serviceActivity);
+ addShipmentUnloadElement(lspShipment, serviceActivity);
+ addDistributionTourStartEventHandler(serviceActivity, lspShipment, resource, tour);
+ addDistributionServiceEventHandler(serviceActivity, lspShipment, resource);
+ }
+ }
+ }
+ }
+ case shipmentBased -> {
+ //TODO needs to get fixed. KMT'Aug'24
+ for (TourElement element : tour.getTourElements()) {
+ if (element instanceof Tour.Delivery deliveryActivity) {
+ if (Objects.equals(lspShipment.getId().toString(), deliveryActivity.getShipment().getId().toString())) {
+ addShipmentLoadElement(lspShipment, tour);
+ addShipmentTransportElement(lspShipment, tour, deliveryActivity);
+ addShipmentUnloadElement(lspShipment, deliveryActivity);
+ addDistributionTourStartEventHandler(deliveryActivity, lspShipment, resource, tour);
+ addDistributionServiceEventHandler(deliveryActivity, lspShipment, resource);
+ }
+ }
}
}
+ default ->
+ throw new IllegalStateException(
+ "Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier));
}
}
}
@@ -220,7 +278,7 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) {
double startTimeOfTransport = legAfterStart.getExpectedDepartureTime();
double cumulatedLoadingTime = 0;
for (TourElement element : tour.getTourElements()) {
- if (element instanceof ServiceActivity activity) {
+ if (element instanceof Tour.ServiceActivity activity) {
cumulatedLoadingTime = cumulatedLoadingTime + activity.getDuration();
}
}
@@ -236,7 +294,7 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) {
}
private void addShipmentTransportElement(
- LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) {
+ LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) {
LspShipmentUtils.ScheduledShipmentTransportBuilder builder =
LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance();
@@ -250,7 +308,7 @@ private void addShipmentTransportElement(
int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart()));
final Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1);
- final int serviceIndex = tour.getTourElements().indexOf(serviceActivity);
+ final int serviceIndex = tour.getTourElements().indexOf(tourActivity);
final Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1);
final double startTimeOfTransport = legAfterStart.getExpectedDepartureTime();
final double endTimeOfTransport =
@@ -266,8 +324,15 @@ private void addShipmentTransportElement(
builder.setEndTime(endTimeOfTransport);
builder.setCarrierId(carrier.getId());
builder.setFromLinkId(tour.getStartLinkId());
- builder.setToLinkId(serviceActivity.getLocation());
- builder.setCarrierService(serviceActivity.getService());
+ builder.setToLinkId(tourActivity.getLocation());
+ switch( tourActivity ){
+ case Tour.ServiceActivity serviceActivity -> builder.setCarrierService( serviceActivity.getService() );
+ case Tour.ShipmentBasedActivity shipment -> builder.setCarrierShipment( shipment.getShipment() );
+ default -> throw new IllegalStateException("Unexpected value: " + tourActivity);
+ // yyyy: At the jsprit level, it makes sense to have these different since services run about 10x faster than shipments. However,
+ // at the matsim level we could consider to either only have shipments (from depot to xx for what used to be services), or only have
+ // services. See also MATSim issue #3510 kai/kai, oct'24
+ }
LspShipmentPlanElement transport = builder.build();
String idString =
transport.getResourceId()
@@ -279,8 +344,7 @@ private void addShipmentTransportElement(
.addPlanElement(id, transport);
}
- private void addShipmentUnloadElement(
- LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) {
+ private void addShipmentUnloadElement(LspShipment tuple, Tour.TourActivity tourActivity) {
LspShipmentUtils.ScheduledShipmentUnloadBuilder builder =
LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance();
@@ -292,11 +356,27 @@ private void addShipmentUnloadElement(
}
}
- int serviceIndex = tour.getTourElements().indexOf(serviceActivity);
- ServiceActivity serviceAct = (ServiceActivity) tour.getTourElements().get(serviceIndex);
+ final double startTime = tourActivity.getExpectedArrival();
+ final double endTime = startTime + tourActivity.getDuration();
+ //Todo: Check if it also works with shipmentBased activity, or if we in that case need the way with the switch-case and the data from the shipmentBasedActivity. KMT Oct'24
+
+// switch( tourActivity ){
+// case Tour.ServiceActivity serviceActivity -> {
+// startTime = tourActivity.getExpectedArrival();
+// endTime = startTime + tourActivity.getDuration();
+//
+//// startTime = serviceActivity.getExpectedArrival(); //Why is there also a arrivalTime in the Tour.ServiceActivity? Why do not take the date in TourActivity.getExpectedArrivalTime()? KMT Oct'24
+//// endTime = startTime + serviceActivity.getDuration();
+// }
+// case Tour.ShipmentBasedActivity shipmentBasedActivity -> {
+// //Todo: Not tested ; maybe we need to take the data from the shipment itself (as is was originally done with the service: serviceActivity.getService() ,..... KMT Oct'24
+// startTime = shipmentBasedActivity.getExpectedArrival(); //Why is there also a arrivalTime in the Tour.ServiceActivity? Why do not take the date in TourActivity.getExpectedArrivalTime()? KMT Oct'24
+// endTime = startTime + shipmentBasedActivity.getDuration();
+//
+// }
+// default -> {}
+// }
- final double startTime = serviceAct.getExpectedArrival();
- final double endTime = startTime + serviceAct.getDuration();
Assert.isTrue(
endTime >= startTime,
"latest End must be later than earliest start. start: " + startTime + " ; end: " + endTime);
@@ -317,36 +397,55 @@ private void addShipmentUnloadElement(
private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrentTour, double startTime) {
final Id carrierId = Id.create(carrier.getId().toString() + carrierCnt, Carrier.class);
carrierCnt++;
+
+ CarrierVehicle carrierVehicle = carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next();
+ CarrierVehicle cv = CarrierVehicle.Builder.newInstance(
+ carrierVehicle.getId(), carrierVehicle.getLinkId(), carrierVehicle.getType())
+ .setEarliestStart(startTime)
+ .setLatestEnd(24 * 60 * 60)
+ .build();
Carrier auxiliaryCarrier = CarriersUtils.createCarrier(carrierId);
- CarrierVehicle carrierVehicle =
- carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next();
- final VehicleType vehicleType = carrierVehicle.getType();
-
- CarrierVehicle.Builder vBuilder =
- CarrierVehicle.Builder.newInstance(
- carrierVehicle.getId(), carrierVehicle.getLinkId(), vehicleType);
- vBuilder.setEarliestStart(startTime);
- vBuilder.setLatestEnd(24 * 60 * 60);
- CarrierVehicle cv = vBuilder.build();
auxiliaryCarrier.getCarrierCapabilities().getCarrierVehicles().put(cv.getId(), cv);
auxiliaryCarrier.getCarrierCapabilities().setFleetSize(FleetSize.FINITE);
- for (LspShipment lspShipment : shipmentsInCurrentTour) {
- CarrierService carrierService = convertToCarrierService(lspShipment);
- auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService);
+ switch (CarrierSchedulerUtils.getVrpLogic(carrier)) {
+ case serviceBased -> {
+ for (LspShipment lspShipment : shipmentsInCurrentTour) {
+ CarrierService carrierService = convertToCarrierService(lspShipment);
+ auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService);
+ }
+ }
+ case shipmentBased -> {
+ for (LspShipment lspShipment : shipmentsInCurrentTour) {
+ CarrierShipment carrierShipment = convertToCarrierShipment(lspShipment);
+ auxiliaryCarrier.getShipments().put(carrierShipment.getId(), carrierShipment);
+ }
+ }
+ default -> throw new IllegalStateException("Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier));
}
+
+
return auxiliaryCarrier;
}
private void addDistributionServiceEventHandler(
- CarrierService carrierService,
+ Tour.TourActivity tourActivity,
LspShipment lspShipment,
LSPCarrierResource resource) {
for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
- DistributionServiceStartEventHandler handler =
- new DistributionServiceStartEventHandler(carrierService, lspShipment, element, resource);
+ DistributionServiceStartEventHandler handler;
+ switch (tourActivity) {
+ case Tour.ServiceActivity serviceActivity-> {
+ handler = new DistributionServiceStartEventHandler(serviceActivity.getService(), lspShipment, element, resource, null);
+ }
+ case Tour.ShipmentBasedActivity shipmentBasedActivity-> {
+ handler = new DistributionServiceStartEventHandler(null, lspShipment, element, resource, shipmentBasedActivity.getShipment());
+ }
+ default -> throw new IllegalStateException("Unexpected value: " + tourActivity);
+ }
+
lspShipment.addSimulationTracker(handler);
break;
}
@@ -354,19 +453,29 @@ private void addDistributionServiceEventHandler(
}
private void addDistributionTourStartEventHandler(
- CarrierService carrierService,
+ Tour.TourActivity tourActivity,
LspShipment lspShipment,
LSPCarrierResource resource,
Tour tour) {
for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
- LSPTourStartEventHandler handler =
- new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour);
+ LSPTourStartEventHandler handler;
+ switch (tourActivity) {
+ case Tour.ServiceActivity serviceActivity-> {
+ handler = new LSPTourStartEventHandler(lspShipment, serviceActivity.getService(), element, resource, tour, null);
+ }
+ case Tour.ShipmentBasedActivity shipmentBasedActivity-> {
+ handler = new LSPTourStartEventHandler(lspShipment, null , element, resource, tour, shipmentBasedActivity.getShipment());
+ }
+ default -> throw new IllegalStateException("Unexpected value: " + tourActivity);
+ }
+
lspShipment.addSimulationTracker(handler);
break;
}
}
}
+
}
diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java
index 80e04fc5..047ade24 100644
--- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java
+++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java
@@ -1,22 +1,22 @@
/*
- *********************************************************************** *
- * project: org.matsim.*
- * *
- * *********************************************************************** *
- * *
- * copyright : (C) 2022 by the members listed in the COPYING, *
- * LICENSE and WARRANTY file. *
- * email : info at matsim dot org *
- * *
- * *********************************************************************** *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * See also COPYING, LICENSE and WARRANTY file *
- * *
- * ***********************************************************************
+ *********************************************************************** *
+ * project: org.matsim.*
+ * *
+ * *********************************************************************** *
+ * *
+ * copyright : (C) 2022 by the members listed in the COPYING, *
+ * LICENSE and WARRANTY file. *
+ * email : info at matsim dot org *
+ * *
+ * *********************************************************************** *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * See also COPYING, LICENSE and WARRANTY file *
+ * *
+ * ***********************************************************************
*/
package org.matsim.freight.logistics.resourceImplementations;
@@ -25,8 +25,11 @@
import org.matsim.core.controler.events.AfterMobsimEvent;
import org.matsim.core.controler.listener.AfterMobsimListener;
import org.matsim.freight.carriers.CarrierService;
+import org.matsim.freight.carriers.CarrierShipment;
import org.matsim.freight.carriers.events.CarrierServiceStartEvent;
+import org.matsim.freight.carriers.events.CarrierShipmentDeliveryStartEvent;
import org.matsim.freight.carriers.events.eventhandler.CarrierServiceStartEventHandler;
+import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentDeliveryStartEventHandler;
import org.matsim.freight.logistics.LSPCarrierResource;
import org.matsim.freight.logistics.LSPSimulationTracker;
import org.matsim.freight.logistics.LogisticChainElement;
@@ -36,20 +39,24 @@
import org.matsim.freight.logistics.shipment.LspShipmentUtils;
/*package-private*/ class DistributionServiceStartEventHandler
- implements AfterMobsimListener,
+ implements AfterMobsimListener,
CarrierServiceStartEventHandler,
+ CarrierShipmentDeliveryStartEventHandler,
LSPSimulationTracker {
private final CarrierService carrierService;
+ private final CarrierShipment carrierShipment;
private final LogisticChainElement logisticChainElement;
private final LSPCarrierResource resource;
private LspShipment lspShipment;
DistributionServiceStartEventHandler(
- CarrierService carrierService,
- LspShipment lspShipment,
- LogisticChainElement element,
- LSPCarrierResource resource) {
+ CarrierService carrierService,
+ LspShipment lspShipment,
+ LogisticChainElement element,
+ LSPCarrierResource resource,
+ CarrierShipment carrierShipment) {
+ this.carrierShipment = carrierShipment;
this.carrierService = carrierService;
this.lspShipment = lspShipment;
this.logisticChainElement = element;
@@ -65,7 +72,16 @@ public void reset(int iteration) {
@Override
public void handleEvent(CarrierServiceStartEvent event) {
if (event.getServiceId() == carrierService.getId()
- && event.getCarrierId() == resource.getCarrier().getId()) {
+ && event.getCarrierId() == resource.getCarrier().getId()) {
+ logTransport(event);
+ logUnload(event);
+ }
+ }
+
+ @Override
+ public void handleEvent(CarrierShipmentDeliveryStartEvent event) {
+ if (event.getShipmentId() == this.carrierShipment.getId()
+ && event.getCarrierId() == resource.getCarrier().getId()) {
logTransport(event);
logUnload(event);
}
@@ -75,7 +91,18 @@ private void logTransport(CarrierServiceStartEvent event) {
String idString = resource.getId() + "" + logisticChainElement.getId() + "TRANSPORT";
Id id = Id.create(idString, LspShipmentPlanElement.class);
LspShipmentPlanElement abstractPlanElement =
- lspShipment.getShipmentLog().getPlanElements().get(id);
+ lspShipment.getShipmentLog().getPlanElements().get(id);
+ if (abstractPlanElement instanceof LspShipmentLeg transport) {
+ transport.setEndTime(event.getTime());
+ }
+ }
+
+ //TODO: Inhaltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante
+ private void logTransport(CarrierShipmentDeliveryStartEvent event) {
+ String idString = resource.getId() + "" + logisticChainElement.getId() + "TRANSPORT";
+ Id id = Id.create(idString, LspShipmentPlanElement.class);
+ LspShipmentPlanElement abstractPlanElement =
+ lspShipment.getShipmentLog().getPlanElements().get(id);
if (abstractPlanElement instanceof LspShipmentLeg transport) {
transport.setEndTime(event.getTime());
}
@@ -83,7 +110,7 @@ private void logTransport(CarrierServiceStartEvent event) {
private void logUnload(CarrierServiceStartEvent event) {
LspShipmentUtils.LoggedShipmentUnloadBuilder builder =
- LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance();
+ LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance();
builder.setCarrierId(event.getCarrierId());
builder.setLinkId(event.getLinkId());
builder.setLogisticChainElement(logisticChainElement);
@@ -92,14 +119,36 @@ private void logUnload(CarrierServiceStartEvent event) {
builder.setEndTime(event.getTime() + event.getServiceDuration());
LspShipmentPlanElement unload = builder.build();
String idString =
- unload.getResourceId()
- + ""
- + unload.getLogisticChainElement().getId()
- + unload.getElementType();
+ unload.getResourceId()
+ + ""
+ + unload.getLogisticChainElement().getId()
+ + unload.getElementType();
+ Id unloadId = Id.create(idString, LspShipmentPlanElement.class);
+ lspShipment.getShipmentLog().addPlanElement(unloadId, unload);
+ }
+
+ //TODO: Inhaltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante
+ private void logUnload(CarrierShipmentDeliveryStartEvent event) {
+ LspShipmentUtils.LoggedShipmentUnloadBuilder builder =
+ LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance();
+ builder.setCarrierId(event.getCarrierId());
+ builder.setLinkId(event.getLinkId());
+ builder.setLogisticChainElement(logisticChainElement);
+ builder.setResourceId(resource.getId());
+ builder.setStartTime(event.getTime());
+ builder.setEndTime(event.getTime() + event.getDeliveryDuration());
+ LspShipmentPlanElement unload = builder.build();
+ String idString =
+ unload.getResourceId()
+ + ""
+ + unload.getLogisticChainElement().getId()
+ + unload.getElementType();
Id unloadId = Id.create(idString, LspShipmentPlanElement.class);
lspShipment.getShipmentLog().addPlanElement(unloadId, unload);
}
+ //Todo: Wird das auch inhaltlich irgendwo genutzt,oder ist das nur für die Tests da?
+ //todo ctd. Brauchen wir den CarrierService hier eigentlich wirklich oder kann das zurück gebaut werden? KMT Okt'24
public CarrierService getCarrierService() {
return carrierService;
}
diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java
index cd6d94ed..4b3ff6a8 100644
--- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java
+++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java
@@ -1,22 +1,22 @@
/*
- *********************************************************************** *
- * project: org.matsim.*
- * *
- * *********************************************************************** *
- * *
- * copyright : (C) 2022 by the members listed in the COPYING, *
- * LICENSE and WARRANTY file. *
- * email : info at matsim dot org *
- * *
- * *********************************************************************** *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * See also COPYING, LICENSE and WARRANTY file *
- * *
- * ***********************************************************************
+ *********************************************************************** *
+ * project: org.matsim.*
+ * *
+ * *********************************************************************** *
+ * *
+ * copyright : (C) 2022 by the members listed in the COPYING, *
+ * LICENSE and WARRANTY file. *
+ * email : info at matsim dot org *
+ * *
+ * *********************************************************************** *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * See also COPYING, LICENSE and WARRANTY file *
+ * *
+ * ***********************************************************************
*/
package org.matsim.freight.logistics.resourceImplementations;
@@ -25,6 +25,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.CarrierService;
+import org.matsim.freight.carriers.CarrierShipment;
import org.matsim.freight.carriers.Tour;
import org.matsim.freight.carriers.Tour.ServiceActivity;
import org.matsim.freight.carriers.Tour.TourElement;
@@ -39,23 +40,29 @@
import org.matsim.freight.logistics.shipment.LspShipmentPlanElement;
import org.matsim.freight.logistics.shipment.LspShipmentUtils;
+import java.util.Objects;
+
/*package-private*/ class LSPTourStartEventHandler
- implements CarrierTourStartEventHandler, LSPSimulationTracker {
+ implements CarrierTourStartEventHandler, LSPSimulationTracker {
private final Tour tour;
private final CarrierService carrierService;
+ private final CarrierShipment carrierShipment;
private final LogisticChainElement logisticChainElement;
private final LSPCarrierResource resource;
private LspShipment lspShipment;
public LSPTourStartEventHandler(
- LspShipment lspShipment,
- CarrierService carrierService,
- LogisticChainElement logisticChainElement,
- LSPCarrierResource resource,
- Tour tour) {
+ LspShipment lspShipment,
+ CarrierService carrierService,
+ LogisticChainElement logisticChainElement,
+ LSPCarrierResource resource,
+ Tour tour,
+ CarrierShipment carrierShipment)
+ {
this.lspShipment = lspShipment;
this.carrierService = carrierService;
+ this.carrierShipment = carrierShipment;
this.logisticChainElement = logisticChainElement;
this.resource = resource;
this.tour = tour;
@@ -68,41 +75,36 @@ public void reset(int iteration) {
@Override
public void handleEvent(CarrierTourStartEvent event) {
- if (event.getTourId().equals(tour.getId())) {
+ if (event.getTourId().equals(tour.getId()) && event.getCarrierId() == resource.getCarrier().getId()) {
for (TourElement tourElement : tour.getTourElements()) {
- if (tourElement instanceof ServiceActivity serviceActivity) {
- if (serviceActivity.getService().getId() == carrierService.getId()
- && event.getCarrierId() == resource.getCarrier().getId()) {
- if (resource instanceof DistributionCarrierResource) { //DistributionTourStarts
- logLoad(
- event.getCarrierId(),
- event.getLinkId(),
- event.getTime() - getCumulatedLoadingTime(tour),
- event.getTime());
- logTransport(
- event.getCarrierId(),
- event.getLinkId(), tour.getEndLinkId(),
- event.getTime());
- } else if (resource instanceof MainRunCarrierResource) { //MainRunTourStarts
- logLoad(event.getCarrierId(),
- event.getLinkId(),
- event.getTime() - getCumulatedLoadingTime(tour),
- event.getTime());
- logTransport(event.getCarrierId(),
- event.getLinkId(),
- tour.getEndLinkId(),
- event.getTime());
+ switch (tourElement) {
+ //This could even be short, if the Id would be available already on the level of Tour.TourActivity. KMT Oct'24
+ case ServiceActivity serviceActivity -> {
+ if (serviceActivity.getService().getId() == carrierService.getId()) {
+ logLoadAndTransport(event);
+ }
+ }
+ case Tour.ShipmentBasedActivity shipmentBasedActivity -> {
+ if (Objects.equals(shipmentBasedActivity.getShipment().getId().toString(), carrierService.getId().toString())) {
+ logLoadAndTransport(event);
}
}
+ case null, default -> {}
}
}
}
}
- private void logLoad(Id carrierId, Id linkId,
- double startTime, double endTime) {
+ private void logLoadAndTransport(CarrierTourStartEvent event) {
+ if (resource instanceof DistributionCarrierResource || resource instanceof MainRunCarrierResource) {
+ logLoad(event.getCarrierId(), event.getLinkId(), event.getTime() - getCumulatedLoadingTime(tour), event.getTime());
+ logTransport(event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime());
+ }
+ }
+
+ private void logLoad(Id carrierId, Id linkId, double startTime, double endTime) {
LspShipmentUtils.LoggedShipmentLoadBuilder builder =
- LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance();
+ LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance();
builder.setCarrierId(carrierId);
builder.setLinkId(linkId);
builder.setLogisticsChainElement(logisticChainElement);
@@ -111,18 +113,18 @@ private void logLoad(Id carrierId, Id linkId,
builder.setEndTime(endTime);
LspShipmentPlanElement loggedShipmentLoad = builder.build();
String idString =
- loggedShipmentLoad.getResourceId()
- + ""
- + loggedShipmentLoad.getLogisticChainElement().getId()
- + loggedShipmentLoad.getElementType();
+ loggedShipmentLoad.getResourceId()
+ + ""
+ + loggedShipmentLoad.getLogisticChainElement().getId()
+ + loggedShipmentLoad.getElementType();
Id loadId = Id.create(idString, LspShipmentPlanElement.class);
lspShipment.getShipmentLog().addPlanElement(loadId, loggedShipmentLoad);
}
private void logTransport(Id carrierId, Id fromLinkId,
- Id toLinkId, double startTime) {
+ Id toLinkId, double startTime) {
LspShipmentUtils.LoggedShipmentTransportBuilder builder =
- LspShipmentUtils.LoggedShipmentTransportBuilder.newInstance();
+ LspShipmentUtils.LoggedShipmentTransportBuilder.newInstance();
builder.setCarrierId(carrierId);
builder.setFromLinkId(fromLinkId);
builder.setToLinkId(toLinkId);
@@ -131,10 +133,10 @@ private void logTransport(Id carrierId, Id fromLinkId,
builder.setStartTime(startTime);
LspShipmentLeg transport = builder.build();
String idString =
- transport.getResourceId()
- + ""
- + transport.getLogisticChainElement().getId()
- + transport.getElementType();
+ transport.getResourceId()
+ + ""
+ + transport.getLogisticChainElement().getId()
+ + transport.getElementType();
Id transportId = Id.create(idString, LspShipmentPlanElement.class);
lspShipment.getShipmentLog().addPlanElement(transportId, transport);
}
diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java
index 9e1f13c8..8dcde45f 100644
--- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java
+++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java
@@ -362,7 +362,7 @@ private void addMainTourRunStartEventHandler(
for (LogisticChainElement element : this.resource.getClientElements()) {
if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) {
LSPTourStartEventHandler handler =
- new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour);
+ new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour, null);
lspShipment.addSimulationTracker(handler);
break;
}
diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java
index 4250e867..bd476a54 100644
--- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java
+++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java
@@ -213,7 +213,7 @@ private void logHandlingInHub(
.setResourceId(resourceId)
.setStartTime(startTime)
.setEndTime(endTime)
- .setLogisticsChainElement(servicesWaitedFor.get(carrierService).element)
+ .setLogisticsChainElement(servicesWaitedFor.get(carrierService).logisticChainElement)
.build();
Id loadId =
Id.create(
@@ -268,11 +268,11 @@ public Id getLinkId() {
public static class TransshipmentHubEventHandlerPair {
public final LspShipment lspShipment;
- public final LogisticChainElement element;
+ public final LogisticChainElement logisticChainElement;
public TransshipmentHubEventHandlerPair(LspShipment lspShipment, LogisticChainElement element) {
this.lspShipment = lspShipment;
- this.element = element;
+ this.logisticChainElement = element;
}
}
}
diff --git a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java
index 01efd96b..3b2c46e8 100644
--- a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java
+++ b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java
@@ -27,6 +27,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.CarrierService;
+import org.matsim.freight.carriers.CarrierShipment;
import org.matsim.freight.carriers.TimeWindow;
import org.matsim.freight.logistics.LSPPlan;
import org.matsim.freight.logistics.LSPResource;
@@ -420,6 +421,7 @@ public static final class ScheduledShipmentTransportBuilder {
Id fromLinkId;
Id toLinkId;
CarrierService carrierService;
+ CarrierShipment carrierShipment; //TODO: Put CarrierShipment and CarrieTask behind one interface and use that here (CarrierTask...)
private ScheduledShipmentTransportBuilder() {}
@@ -459,6 +461,10 @@ public void setCarrierService(CarrierService carrierService) {
this.carrierService = carrierService;
}
+ public void setCarrierShipment(CarrierShipment carrierShipment) {
+ this.carrierShipment = carrierShipment;
+ }
+
public ScheduledLspShipmentTransport build() {
return new ScheduledLspShipmentTransport(this);
}
diff --git a/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java b/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java
index d4f69efa..71b084e2 100644
--- a/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java
+++ b/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java
@@ -24,6 +24,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.CarrierService;
+import org.matsim.freight.carriers.CarrierShipment;
import org.matsim.freight.logistics.LSPResource;
import org.matsim.freight.logistics.LogisticChainElement;
@@ -37,6 +38,7 @@ final class ScheduledLspShipmentTransport implements LspShipmentLeg {
private final Id fromLinkId;
private final Id toLinkId;
private final CarrierService carrierService;
+ private final CarrierShipment carrierShipment; //TODO: Put CarrierShipment and CarrieTask behind one interface and use that here (CarrierTask...)
ScheduledLspShipmentTransport(LspShipmentUtils.ScheduledShipmentTransportBuilder builder) {
this.startTime = builder.startTime;
@@ -47,6 +49,7 @@ final class ScheduledLspShipmentTransport implements LspShipmentLeg {
this.fromLinkId = builder.fromLinkId;
this.toLinkId = builder.toLinkId;
this.carrierService = builder.carrierService;
+ this.carrierShipment = builder.carrierShipment;
}
@Override
@@ -103,4 +106,8 @@ public Id getFromLinkId() {
public CarrierService getCarrierService() {
return carrierService;
}
+
+ public CarrierShipment getCarrierShipment() {
+ return carrierShipment;
+ }
}
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java
index 43b715df..c4fd34c0 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java
@@ -432,7 +432,7 @@ public void testCompletedLSPScheduling() {
Entry entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
@@ -459,7 +459,7 @@ public void testCompletedLSPScheduling() {
Entry entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), toLinkId);
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java
index 00a65c68..3cead4c8 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java
@@ -258,7 +258,7 @@ public void testFirstReloadLSPScheduling() {
for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) {
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java
index a99a92d7..4a39f6c6 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java
@@ -323,7 +323,7 @@ public void testMainRunLSPScheduling() {
for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) {
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java
index 5b9d5790..f27a1e08 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java
@@ -435,7 +435,7 @@ public void testCompletedLSPScheduling() {
Entry entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
@@ -462,7 +462,7 @@ public void testCompletedLSPScheduling() {
Entry entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), toLinkId);
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java
index dc5fc7b7..e1661887 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java
@@ -257,7 +257,7 @@ public void testFirstReloadLSPScheduling() {
for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) {
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java
index 6378e53c..c9811f9e 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java
@@ -323,7 +323,7 @@ public void testMainRunLSPScheduling() {
for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) {
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java
index d08ec364..23ee9f61 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java
@@ -367,7 +367,7 @@ public void testSecondReloadLSPScheduling() {
entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
@@ -399,7 +399,7 @@ public void testSecondReloadLSPScheduling() {
Entry entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), toLinkId);
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java
index e9f5d639..6a37cd65 100644
--- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java
+++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java
@@ -367,7 +367,7 @@ public void testSecondReloadLSPScheduling() {
entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), shipment.getFrom());
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);
@@ -405,7 +405,7 @@ public void testSecondReloadLSPScheduling() {
entry = iter.next();
CarrierService service = entry.getKey();
LspShipment shipment = entry.getValue().lspShipment;
- LogisticChainElement element = entry.getValue().element;
+ LogisticChainElement element = entry.getValue().logisticChainElement;
assertSame(service.getLocationLinkId(), toLinkId);
assertEquals(service.getCapacityDemand(), shipment.getSize());
assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);