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

Commit

Permalink
minor internal simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Aug 14, 2024
1 parent d583037 commit b8b0c07
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.matsim.freight.carriers.ScheduledTour;
import org.matsim.freight.carriers.Tour;
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 @@ -82,14 +83,12 @@ public void scheduleResource() {
}

private CarrierService convertToCarrierService(LspShipment lspShipment) {
Id<CarrierService> serviceId =
Id.create(lspShipment.getId().toString(), CarrierService.class);
CarrierService.Builder builder =
CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom());
builder.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow());
builder.setCapacityDemand(lspShipment.getSize());
builder.setServiceDuration(lspShipment.getDeliveryServiceTime());
CarrierService carrierService = builder.build();
Id<CarrierService> serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class);
CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom())
.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow())
.setCapacityDemand(lspShipment.getSize())
.setServiceDuration(lspShipment.getDeliveryServiceTime())
.build();
pairs.add(new LSPCarrierPair(lspShipment, carrierService));
return carrierService;
}
Expand All @@ -100,11 +99,10 @@ protected void updateShipments() {
for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) {
Tour tour = scheduledTour.getTour();
for (TourElement element : tour.getTourElements()) {
if (element instanceof Tour.ServiceActivity serviceActivity) {
LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService());
if (element instanceof ServiceActivity serviceActivity) {
for (LSPCarrierPair pair : pairs) {
if (pair.lspShipment == carrierPair.lspShipment
&& pair.carrierService.getId() == carrierPair.carrierService.getId()) {
if (pair.lspShipment == lspShipment
&& pair.carrierService.getId() == serviceActivity.getService().getId()) {
addShipmentLoadElement(lspShipment, tour, serviceActivity);
addShipmentTransportElement(lspShipment, tour, serviceActivity);
addShipmentUnloadElement(lspShipment, tour);
Expand All @@ -119,7 +117,7 @@ protected void updateShipments() {
}

private void addShipmentLoadElement(
LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) {
LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) {

LspShipmentUtils.ScheduledShipmentLoadBuilder builder =
LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,11 @@ private Collection<ScheduledTour> unifyTourIds(Collection<CarrierPlan> carrierPl
}

private CarrierService convertToCarrierService(LspShipment lspShipment) {
Id<CarrierService> serviceId =
Id.create(lspShipment.getId().toString(), CarrierService.class);
CarrierService.Builder builder =
CarrierService.Builder.newInstance(serviceId, lspShipment.getTo());
builder.setCapacityDemand(lspShipment.getSize());
builder.setServiceDuration(lspShipment.getDeliveryServiceTime());
CarrierService carrierService = builder.build();
Id<CarrierService> serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class);
CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getTo())
.setCapacityDemand(lspShipment.getSize())
.setServiceDuration(lspShipment.getDeliveryServiceTime())
.build();
pairs.add(new LSPCarrierPair(lspShipment, carrierService));
return carrierService;
}
Expand All @@ -189,10 +187,9 @@ protected void updateShipments() {
Tour tour = scheduledTour.getTour();
for (TourElement element : tour.getTourElements()) {
if (element instanceof ServiceActivity serviceActivity) {
LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService());
for (LSPCarrierPair pair : pairs) {
if (pair.lspShipment == carrierPair.lspShipment
&& pair.carrierService.getId() == carrierPair.carrierService.getId()) {
if (pair.lspShipment == lspShipment
&& pair.carrierService.getId() == serviceActivity.getService().getId()) {
addShipmentLoadElement(lspShipment, tour);
addShipmentTransportElement(lspShipment, tour, serviceActivity);
addShipmentUnloadElement(lspShipment, tour, serviceActivity);
Expand Down

0 comments on commit b8b0c07

Please sign in to comment.