Skip to content

Commit

Permalink
some more work, check that serviceBased still works
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Oct 11, 2024
1 parent c79b3f4 commit 1ea559b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public static void main(String[] args) {

log.info("Add LSP(s) to the scenario");
Collection<LSP> 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));

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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 =
Expand Down Expand Up @@ -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 =
Expand All @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 1ea559b

Please sign in to comment.