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

Commit

Permalink
towards using instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
kainagel committed Oct 10, 2024
1 parent 89283a3 commit c79b3f4
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -230,7 +229,7 @@ protected void updateShipments() {
switch (CarrierSchedulerUtils.getVrpLogic(carrier)) {
case serviceBased -> {
for (TourElement element : tour.getTourElements()) {
if (element instanceof ServiceActivity serviceActivity) {
if (element instanceof Tour.ServiceActivity serviceActivity) {
if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) {
addShipmentLoadElement(lspShipment, tour);
addShipmentTransportElement(lspShipment, tour, serviceActivity);
Expand Down Expand Up @@ -296,7 +295,8 @@ 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.ServiceActivity tourActivity) {
LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) {

LspShipmentUtils.ScheduledShipmentTransportBuilder builder =
LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance();
Expand Down Expand Up @@ -327,7 +327,15 @@ private void addShipmentTransportElement(
builder.setCarrierId(carrier.getId());
builder.setFromLinkId(tour.getStartLinkId());
builder.setToLinkId(tourActivity.getLocation());
builder.setCarrierService(tourActivity.getService());
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,
// 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
}
LspShipmentPlanElement transport = builder.build();
String idString =
transport.getResourceId()
Expand Down

0 comments on commit c79b3f4

Please sign in to comment.