From 1ea559bba1c0089434596179adbe8fd8831f7a41 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 09:28:20 +0200 Subject: [PATCH] some more work, check that serviceBased still works --- ...eTwoLspsGroceryDeliveryMultipleChains.java | 10 ++--- .../DistributionCarrierScheduler.java | 37 +++++++++++++------ 2 files changed, 30 insertions(+), 17 deletions(-) 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 c8f6d436..3c63b4d3 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 @@ -122,9 +122,9 @@ public static void main(String[] args) { log.info("Add LSP(s) to the scenario"); Collection lsps = new LinkedList<>(); -// lsps.add(createLspWithTwoChains(scenario, "Edeka", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); -// lsps.add(createLspWithTwoChains(scenario, "Kaufland", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); -// lsps.add(createLspWithDirectChain(scenario, "Edeka_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), vehicleTypes)); + lsps.add(createLspWithTwoChains(scenario, "Edeka", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); + lsps.add(createLspWithTwoChains(scenario, "Kaufland", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); + lsps.add(createLspWithDirectChain(scenario, "Edeka_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), vehicleTypes)); lsps.add(createLspWithDirectChain(scenario, "Kaufland_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), vehicleTypes)); LSPUtils.addLSPs(scenario, new LSPs(lsps)); @@ -343,7 +343,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.shipmentBased); + CarrierSchedulerUtils.setVrpLogic(distributionCarrier, LSPUtils.LogicOfVrp.serviceBased); CarriersUtils.addCarrierVehicle( distributionCarrier, @@ -418,7 +418,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.shipmentBased); + CarrierSchedulerUtils.setVrpLogic(directCarrier, LSPUtils.LogicOfVrp.serviceBased); CarriersUtils.addCarrierVehicle(directCarrier, CarrierVehicle.newInstance( 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 fb775818..5e474e56 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -278,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(); } } @@ -294,8 +294,6 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { } private void addShipmentTransportElement( -// LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { -// LspShipment lspShipment, Tour tour, Tour.ServiceActivity tourActivity) { LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = @@ -330,11 +328,10 @@ private void addShipmentTransportElement( switch( tourActivity ){ case Tour.ServiceActivity serviceActivity -> builder.setCarrierService( serviceActivity.getService() ); case Tour.ShipmentBasedActivity shipment -> builder.setCarrierShipment( shipment.getShipment() ); - case null, default -> { - } - // yyyy: At the jsprit level, it makes sense to have these different since services run about 10x faster than shipments. However, + 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. kai/kai, oct'24 + // services. See also MATSim issue #3510 kai/kai, oct'24 } LspShipmentPlanElement transport = builder.build(); String idString = @@ -348,7 +345,7 @@ private void addShipmentTransportElement( } private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, ServiceActivity serviceActivity) { + LspShipment tuple, Tour tour, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); @@ -360,11 +357,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);