diff --git a/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java b/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java index dbf68e4a..c63d9258 100644 --- a/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/LSPResourceScheduler.java @@ -41,20 +41,20 @@ public abstract class LSPResourceScheduler { protected LSPResource resource; - protected ArrayList lspShipmentsWithTime; + protected ArrayList lspShipmentsToSchedule; protected LSPPlan lspPlan; public final void scheduleShipments(LSPPlan lspPlan, LSPResource resource, int bufferTime) { this.lspPlan = lspPlan; this.resource = resource; - this.lspShipmentsWithTime = new ArrayList<>(); + this.lspShipmentsToSchedule = new ArrayList<>(); initializeValues(resource); presortIncomingShipments(); scheduleResource(); updateShipments(); switchHandledShipments(bufferTime); - lspShipmentsWithTime.clear(); + lspShipmentsToSchedule.clear(); } /** @@ -79,27 +79,25 @@ public final void scheduleShipments(LSPPlan lspPlan, LSPResource resource, int b protected abstract void updateShipments(); private void presortIncomingShipments() { - this.lspShipmentsWithTime = new ArrayList<>(); + this.lspShipmentsToSchedule = new ArrayList<>(); for (LogisticChainElement element : resource.getClientElements()) { - lspShipmentsWithTime.addAll(element.getIncomingShipments().getLspShipmentsWTime()); + lspShipmentsToSchedule.addAll(element.getIncomingShipments().getLspShipmentsWTime()); } - lspShipmentsWithTime.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime)); + lspShipmentsToSchedule.sort(Comparator.comparingDouble(LspShipmentUtils::getTimeOfLspShipment)); } private void switchHandledShipments(int bufferTime) { - for (LspShipmentWithTime lspShipmentWithTime : lspShipmentsWithTime) { - var shipmentPlan = - LspShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipmentWithTime.getLspShipment().getId()); + for (LspShipment lspShipmentWithTime : lspShipmentsToSchedule) { + var shipmentPlan = LspShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipmentWithTime.getId()); double endOfTransportTime = shipmentPlan.getMostRecentEntry().getEndTime() + bufferTime; - LspShipmentWithTime outgoingTuple = - new LspShipmentWithTime(endOfTransportTime, lspShipmentWithTime.getLspShipment()); - for (LogisticChainElement element : resource.getClientElements()) { + LspShipmentUtils.setTimeOfLspShipment(lspShipmentWithTime, endOfTransportTime); + for (LogisticChainElement element : resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipmentWithTime)) { - element.getOutgoingShipments().getLspShipmentsWTime().add(outgoingTuple); element.getIncomingShipments().getLspShipmentsWTime().remove(lspShipmentWithTime); + element.getOutgoingShipments().getLspShipmentsWTime().add(lspShipmentWithTime); if (element.getNextElement() != null) { - element.getNextElement().getIncomingShipments().getLspShipmentsWTime().add(outgoingTuple); - element.getOutgoingShipments().getLspShipmentsWTime().remove(outgoingTuple); + element.getNextElement().getIncomingShipments().getLspShipmentsWTime().add(lspShipmentWithTime); + element.getOutgoingShipments().getLspShipmentsWTime().remove(lspShipmentWithTime); } } } diff --git a/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java b/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java deleted file mode 100644 index 60eacfd1..00000000 --- a/src/main/java/org/matsim/freight/logistics/LspShipmentWithTime.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * *********************************************************************** * - * * 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; - -import org.matsim.freight.logistics.shipment.LspShipment; - -public class LspShipmentWithTime { - // yyyyyy find better solution for this. It is not so good to define an interface, and then - // immediately define a class that goes beyond it. - // Maybe the time should be added to the interface? However, I don't even know what that time - // means (delivery time? current time?). kai, - // jun'22 - - private final LspShipment lspShipment; - private final double time; - - public LspShipmentWithTime(double time, LspShipment lspShipment) { - this.lspShipment = lspShipment; - this.time = time; - } - - public LspShipment getLspShipment() { - return lspShipment; - } - - public double getTime() { - return time; - } -} diff --git a/src/main/java/org/matsim/freight/logistics/WaitingShipments.java b/src/main/java/org/matsim/freight/logistics/WaitingShipments.java index e76da764..55e72fa3 100644 --- a/src/main/java/org/matsim/freight/logistics/WaitingShipments.java +++ b/src/main/java/org/matsim/freight/logistics/WaitingShipments.java @@ -43,9 +43,9 @@ public interface WaitingShipments { void addShipment(double time, LspShipment lspShipment); - Collection getSortedLspShipments(); + Collection getSortedLspShipments(); - Collection getLspShipmentsWTime(); + Collection getLspShipmentsWTime(); void clear(); } diff --git a/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java b/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java index 2c73f797..6404d32a 100644 --- a/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java +++ b/src/main/java/org/matsim/freight/logistics/WaitingShipmentsImpl.java @@ -25,10 +25,11 @@ import java.util.Comparator; import java.util.List; import org.matsim.freight.logistics.shipment.LspShipment; +import org.matsim.freight.logistics.shipment.LspShipmentUtils; /* package-private */ class WaitingShipmentsImpl implements WaitingShipments { - private final List shipments; + private final List shipments; WaitingShipmentsImpl() { this.shipments = new ArrayList<>(); @@ -36,14 +37,14 @@ @Override public void addShipment(double time, LspShipment lspShipment) { - LspShipmentWithTime tuple = new LspShipmentWithTime(time, lspShipment); - this.shipments.add(tuple); - shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime)); + LspShipmentUtils.setTimeOfLspShipment(lspShipment, time); + this.shipments.add(lspShipment); + shipments.sort(Comparator.comparingDouble(LspShipmentUtils::getTimeOfLspShipment)); } @Override - public Collection getSortedLspShipments() { - shipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime)); + public Collection getSortedLspShipments() { + shipments.sort(Comparator.comparingDouble(LspShipmentUtils::getTimeOfLspShipment)); return shipments; } @@ -52,7 +53,7 @@ public void clear() { } @Override - public Collection getLspShipmentsWTime() { + public Collection getLspShipmentsWTime() { return shipments; } @@ -62,8 +63,8 @@ public String toString() { strb.append("WaitingShipmentsImpl{").append("No of Shipments= ").append(shipments.size()); if (!shipments.isEmpty()) { strb.append("; ShipmentIds="); - for (LspShipmentWithTime shipment : getSortedLspShipments()) { - strb.append("[").append(shipment.getLspShipment().getId()).append("]"); + for (LspShipment shipment : getSortedLspShipments()) { + strb.append("[").append(shipment.getId()).append("]"); } } strb.append('}'); diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index 6588a1e2..4d8c35b3 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -74,42 +74,42 @@ public void initializeValues(LSPResource resource) { @Override public void scheduleResource() { - for (LspShipmentWithTime tupleToBeAssigned : lspShipmentsWithTime) { - CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); + for (LspShipment lspShipmentToBeAssigned : lspShipmentsToSchedule) { + CarrierService carrierService = convertToCarrierService(lspShipmentToBeAssigned); carrier.getServices().put(carrierService.getId(), carrierService); } CarrierSchedulerUtils.solveVrpWithJsprit(carrier, scenario); } - private CarrierService convertToCarrierService(LspShipmentWithTime tuple) { + private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = - Id.create(tuple.getLspShipment().getId().toString(), CarrierService.class); + Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, tuple.getLspShipment().getFrom()); - builder.setServiceStartTimeWindow(tuple.getLspShipment().getPickupTimeWindow()); - builder.setCapacityDemand(tuple.getLspShipment().getSize()); - builder.setServiceDuration(tuple.getLspShipment().getDeliveryServiceTime()); + CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()); + builder.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()); + builder.setCapacityDemand(lspShipment.getSize()); + builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); CarrierService carrierService = builder.build(); - pairs.add(new LSPCarrierPair(tuple, carrierService)); + pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @Override protected void updateShipments() { - for (LspShipmentWithTime tuple : lspShipmentsWithTime) { + for (LspShipment lspShipment : lspShipmentsToSchedule) { 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(tuple, serviceActivity.getService()); + LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); for (LSPCarrierPair pair : pairs) { - if (pair.tuple == carrierPair.tuple + if (pair.lspShipment == carrierPair.lspShipment && pair.carrierService.getId() == carrierPair.carrierService.getId()) { - addShipmentLoadElement(tuple, tour, serviceActivity); - addShipmentTransportElement(tuple, tour, serviceActivity); - addShipmentUnloadElement(tuple, tour, serviceActivity); - addCollectionTourEndEventHandler(pair.carrierService, tuple, resource, tour); - addCollectionServiceEventHandler(pair.carrierService, tuple, resource); + addShipmentLoadElement(lspShipment, tour, serviceActivity); + addShipmentTransportElement(lspShipment, tour, serviceActivity); + addShipmentUnloadElement(lspShipment, tour); + addCollectionTourEndEventHandler(pair.carrierService, lspShipment, resource, tour); + addCollectionServiceEventHandler(pair.carrierService, lspShipment, resource); } } } @@ -119,47 +119,52 @@ protected void updateShipments() { } private void addShipmentLoadElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1); double startTimeOfLoading = legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime(); builder.setStartTime(startTimeOfLoading); - builder.setEndTime(startTimeOfLoading + tuple.getLspShipment().getDeliveryServiceTime()); + builder.setEndTime(startTimeOfLoading + lspShipment.getDeliveryServiceTime()); LspShipmentPlanElement load = builder.build(); String idString = load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, load); } private void addShipmentTransportElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); Leg legAfterService = (Leg) tour.getTourElements().get(serviceIndex + 1); double startTimeOfTransport = legAfterService.getExpectedDepartureTime(); builder.setStartTime(startTimeOfTransport); Leg lastLeg = (Leg) tour.getTourElements().getLast(); - double endTimeOfTransport = - lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); + double endTimeOfTransport = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); builder.setEndTime(endTimeOfTransport); builder.setCarrierId(carrier.getId()); builder.setFromLinkId(serviceActivity.getLocation()); @@ -172,18 +177,19 @@ private void addShipmentTransportElement( + transport.getLogisticChainElement().getId() + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, transport); } private void addCollectionServiceEventHandler( - CarrierService carrierService, LspShipmentWithTime tuple, LSPCarrierResource resource) { + CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { CollectionServiceEndEventHandler endHandler = new CollectionServiceEndEventHandler( - carrierService, tuple.getLspShipment(), element, resource); - tuple.getLspShipment().addSimulationTracker(endHandler); + carrierService, lspShipment, element, resource); + lspShipment.addSimulationTracker(endHandler); break; } } @@ -191,27 +197,27 @@ private void addCollectionServiceEventHandler( private void addCollectionTourEndEventHandler( CarrierService carrierService, - LspShipmentWithTime tuple, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourEndEventHandler handler = new LSPTourEndEventHandler( - tuple.getLspShipment(), carrierService, element, resource, tour); - tuple.getLspShipment().addSimulationTracker(handler); + lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } } - private void addShipmentUnloadElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + private void addShipmentUnloadElement(LspShipment lspShipment, Tour tour) { + LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticsChainElement(element); } } @@ -227,7 +233,7 @@ private void addShipmentUnloadElement( + unload.getLogisticChainElement().getId() + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, unload); } @@ -241,5 +247,5 @@ private double getUnloadEndTime(Tour tour) { return unloadEndTime; } - private record LSPCarrierPair(LspShipmentWithTime tuple, CarrierService carrierService) {} + private record LSPCarrierPair(LspShipment lspShipment, CarrierService carrierService) {} } 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 7eaf9e73..16aae7ca 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -34,6 +34,7 @@ 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; import org.matsim.freight.logistics.shipment.LspShipmentPlanElement; import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.vehicles.VehicleType; @@ -84,17 +85,17 @@ protected void scheduleResource() { int load = 0; double cumulatedLoadingTime = 0; double availabilityTimeOfLastShipment = 0; - ArrayList copyOfAssignedShipments = new ArrayList<>(lspShipmentsWithTime); - ArrayList shipmentsInCurrentTour = new ArrayList<>(); + ArrayList copyOfAssignedShipments = new ArrayList<>(lspShipmentsToSchedule); + ArrayList shipmentsInCurrentTour = new ArrayList<>(); List scheduledPlans = new LinkedList<>(); - for (LspShipmentWithTime tuple : copyOfAssignedShipments) { + for (LspShipment lspShipment : copyOfAssignedShipments) { // 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 + tuple.getLspShipment().getSize()) + if ((load + lspShipment.getSize()) > vehicleType.getCapacity().getOther().intValue()) { load = 0; Carrier auxiliaryCarrier = @@ -106,10 +107,10 @@ protected void scheduleResource() { cumulatedLoadingTime = 0; shipmentsInCurrentTour.clear(); } - shipmentsInCurrentTour.add(tuple); - load = load + tuple.getLspShipment().getSize(); - cumulatedLoadingTime = cumulatedLoadingTime + tuple.getLspShipment().getDeliveryServiceTime(); - availabilityTimeOfLastShipment = tuple.getTime(); + shipmentsInCurrentTour.add(lspShipment); + load = load + lspShipment.getSize(); + cumulatedLoadingTime = cumulatedLoadingTime + lspShipment.getDeliveryServiceTime(); + availabilityTimeOfLastShipment = LspShipmentUtils.getTimeOfLspShipment(lspShipment); } if (!shipmentsInCurrentTour.isEmpty()) { @@ -169,34 +170,34 @@ private Collection unifyTourIds(Collection carrierPl return scheduledToursUnified; } - private CarrierService convertToCarrierService(LspShipmentWithTime tuple) { + private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = - Id.create(tuple.getLspShipment().getId().toString(), CarrierService.class); + Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, tuple.getLspShipment().getTo()); - builder.setCapacityDemand(tuple.getLspShipment().getSize()); - builder.setServiceDuration(tuple.getLspShipment().getDeliveryServiceTime()); + CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()); + builder.setCapacityDemand(lspShipment.getSize()); + builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); CarrierService carrierService = builder.build(); - pairs.add(new LSPCarrierPair(tuple, carrierService)); + pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @Override protected void updateShipments() { - for (LspShipmentWithTime tuple : lspShipmentsWithTime) { + for (LspShipment lspShipment : lspShipmentsToSchedule) { for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof ServiceActivity serviceActivity) { - LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); + LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); for (LSPCarrierPair pair : pairs) { - if (pair.tuple == carrierPair.tuple + if (pair.lspShipment == carrierPair.lspShipment && pair.carrierService.getId() == carrierPair.carrierService.getId()) { - addShipmentLoadElement(tuple, tour, serviceActivity); - addShipmentTransportElement(tuple, tour, serviceActivity); - addShipmentUnloadElement(tuple, tour, serviceActivity); - addDistributionTourStartEventHandler(pair.carrierService, tuple, resource, tour); - addDistributionServiceEventHandler(pair.carrierService, tuple, resource); + addShipmentLoadElement(lspShipment, tour); + addShipmentTransportElement(lspShipment, tour, serviceActivity); + addShipmentUnloadElement(lspShipment, tour, serviceActivity); + addDistributionTourStartEventHandler(pair.carrierService, lspShipment, resource, tour); + addDistributionServiceEventHandler(pair.carrierService, lspShipment, resource); } } } @@ -205,18 +206,18 @@ protected void updateShipments() { } } - private void addShipmentLoadElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } - int startIndex = - tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); double cumulatedLoadingTime = 0; @@ -232,22 +233,24 @@ private void addShipmentLoadElement( String idString = load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, load); } private void addShipmentTransportElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } - int startIndex = - tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + + 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 Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1); @@ -274,20 +277,23 @@ private void addShipmentTransportElement( + transport.getLogisticChainElement().getId() + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, transport); } private void addShipmentUnloadElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { builder.setLogisticsChainElement(element); } } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); ServiceActivity serviceAct = (ServiceActivity) tour.getTourElements().get(serviceIndex); @@ -306,11 +312,11 @@ private void addShipmentUnloadElement( + String.valueOf(unload.getLogisticChainElement().getId()) + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) .addPlanElement(id, unload); } - private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrentTour, double startTime) { + private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrentTour, double startTime) { final Id carrierId = Id.create(carrier.getId().toString() + carrierCnt, Carrier.class); carrierCnt++; Carrier auxiliaryCarrier = CarriersUtils.createCarrier(carrierId); @@ -327,21 +333,21 @@ private Carrier createAuxiliaryCarrier(ArrayList shipmentsI auxiliaryCarrier.getCarrierCapabilities().getCarrierVehicles().put(cv.getId(), cv); auxiliaryCarrier.getCarrierCapabilities().setFleetSize(FleetSize.FINITE); - for (LspShipmentWithTime tuple : shipmentsInCurrentTour) { - CarrierService carrierService = convertToCarrierService(tuple); + for (LspShipment lspShipment : shipmentsInCurrentTour) { + CarrierService carrierService = convertToCarrierService(lspShipment); auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService); } return auxiliaryCarrier; } private void addDistributionServiceEventHandler( - CarrierService carrierService, LspShipmentWithTime tuple, LSPCarrierResource resource) { + CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { DistributionServiceStartEventHandler handler = - new DistributionServiceStartEventHandler( - carrierService, tuple.getLspShipment(), element, resource); - tuple.getLspShipment().addSimulationTracker(handler); + new DistributionServiceStartEventHandler(carrierService, lspShipment, element, resource); + lspShipment.addSimulationTracker(handler); break; } } @@ -349,19 +355,19 @@ private void addDistributionServiceEventHandler( private void addDistributionTourStartEventHandler( CarrierService carrierService, - LspShipmentWithTime tuple, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourStartEventHandler handler = - new LSPTourStartEventHandler( - tuple.getLspShipment(), carrierService, element, resource, tour); - tuple.getLspShipment().addSimulationTracker(handler); + new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } } - private record LSPCarrierPair(LspShipmentWithTime tuple, CarrierService carrierService) {} + private record LSPCarrierPair(LspShipment lspShipment, CarrierService carrierService) {} } 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 6c61da0c..18846fc8 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java @@ -32,6 +32,7 @@ import org.matsim.freight.carriers.jsprit.NetworkBasedTransportCosts; import org.matsim.freight.carriers.jsprit.NetworkRouter; import org.matsim.freight.logistics.*; +import org.matsim.freight.logistics.shipment.LspShipment; import org.matsim.freight.logistics.shipment.LspShipmentPlanElement; import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.vehicles.VehicleType; @@ -76,28 +77,28 @@ protected void initializeValues(LSPResource resource) { @Override protected void scheduleResource() { int load = 0; - List copyOfAssignedShipments = new ArrayList<>(lspShipmentsWithTime); - copyOfAssignedShipments.sort(Comparator.comparingDouble(LspShipmentWithTime::getTime)); - ArrayList shipmentsInCurrentTour = new ArrayList<>(); + List copyOfAssignedShipments = new ArrayList<>(lspShipmentsToSchedule); + copyOfAssignedShipments.sort(Comparator.comparingDouble(LspShipmentUtils::getTimeOfLspShipment)); + ArrayList shipmentsInCurrentTour = new ArrayList<>(); // ArrayList scheduledTours = new ArrayList<>(); List scheduledPlans = new LinkedList<>(); - for (LspShipmentWithTime tuple : copyOfAssignedShipments) { + for (LspShipment lspShipment : copyOfAssignedShipments) { // Add job as "services" to the carrier. So the carrier has this available - CarrierService carrierService = convertToCarrierService(tuple); + CarrierService carrierService = convertToCarrierService(lspShipment); carrier.getServices().put(carrierService.getId(), carrierService); VehicleType vehicleType = ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next(); - if ((load + tuple.getLspShipment().getSize()) + if ((load + lspShipment.getSize()) > vehicleType.getCapacity().getOther().intValue()) { load = 0; CarrierPlan plan = createPlan(carrier, shipmentsInCurrentTour); scheduledPlans.add(plan); shipmentsInCurrentTour.clear(); } - shipmentsInCurrentTour.add(tuple); - load = load + tuple.getLspShipment().getSize(); + shipmentsInCurrentTour.add(lspShipment); + load = load + lspShipment.getSize(); } if (!shipmentsInCurrentTour.isEmpty()) { CarrierPlan plan = createPlan(carrier, shipmentsInCurrentTour); @@ -114,7 +115,7 @@ protected void scheduleResource() { carrier.setSelectedPlan(plan); } - private CarrierPlan createPlan(Carrier carrier, List tuples) { + private CarrierPlan createPlan(Carrier carrier, List lspShipments) { // TODO: Allgemein: Hier ist alles manuell zusammen gesetzt; es findet KEINE Tourenplanung // statt! @@ -130,16 +131,16 @@ private CarrierPlan createPlan(Carrier carrier, List tuples tourBuilder.scheduleStart(Id.create(resource.getStartLinkId(), Link.class)); double totalLoadingTime = 0; - double latestTupleTime = 0; + double latestLspShipmentTime = 0; - for (LspShipmentWithTime tuple : tuples) { - totalLoadingTime = totalLoadingTime + tuple.getLspShipment().getDeliveryServiceTime(); - if (tuple.getTime() > latestTupleTime) { - latestTupleTime = tuple.getTime(); + for (LspShipment lspShipment : lspShipments) { + totalLoadingTime = totalLoadingTime + lspShipment.getDeliveryServiceTime(); + if (LspShipmentUtils.getTimeOfLspShipment(lspShipment) > latestLspShipmentTime) { + latestLspShipmentTime = LspShipmentUtils.getTimeOfLspShipment(lspShipment); } tourBuilder.addLeg(new Leg()); - CarrierService carrierService = convertToCarrierService(tuple); - pairs.add(new LSPShipmentCarrierServicePair(tuple, carrierService)); + CarrierService carrierService = convertToCarrierService(lspShipment); + pairs.add(new LSPShipmentCarrierServicePair(lspShipment, carrierService)); tourBuilder.scheduleService(carrierService); } @@ -157,7 +158,7 @@ private CarrierPlan createPlan(Carrier carrier, List tuples Tour vehicleTour = tourBuilder.build(); CarrierVehicle vehicle = carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next(); - double tourStartTime = latestTupleTime + totalLoadingTime; + double tourStartTime = latestLspShipmentTime + totalLoadingTime; ScheduledTour sTour = ScheduledTour.newInstance(vehicleTour, vehicle, tourStartTime); tours.add(sTour); @@ -222,34 +223,34 @@ private double scorePlanManually(CarrierPlan plan) { return (-score); // negative, because we are looking at "costs" instead of "utility" } - private CarrierService convertToCarrierService(LspShipmentWithTime tuple) { + private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = - Id.create(tuple.getLspShipment().getId().toString(), CarrierService.class); + Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, resource.getEndLinkId()); - builder.setCapacityDemand(tuple.getLspShipment().getSize()); - builder.setServiceDuration(tuple.getLspShipment().getDeliveryServiceTime()); + builder.setCapacityDemand(lspShipment.getSize()); + builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); return builder.build(); } @Override protected void updateShipments() { - for (LspShipmentWithTime lspShipmentWithTime : lspShipmentsWithTime) { + for (LspShipment LspShipment : lspShipmentsToSchedule) { for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof Tour.ServiceActivity serviceActivity) { LSPShipmentCarrierServicePair carrierPair = new LSPShipmentCarrierServicePair( - lspShipmentWithTime, serviceActivity.getService()); + LspShipment, serviceActivity.getService()); for (LSPShipmentCarrierServicePair pair : pairs) { - if (pair.tuple == carrierPair.tuple + if (pair.lspShipment == carrierPair.lspShipment && pair.carrierService.getId() == carrierPair.carrierService.getId()) { - addShipmentLoadElement(lspShipmentWithTime, tour); - addShipmentTransportElement(lspShipmentWithTime, tour, serviceActivity); - addShipmentUnloadElement(lspShipmentWithTime, tour, serviceActivity); - addMainTourRunStartEventHandler(pair.carrierService, lspShipmentWithTime, resource, tour); - addMainRunTourEndEventHandler(pair.carrierService, lspShipmentWithTime, resource, tour); + addShipmentLoadElement(LspShipment, tour); + addShipmentTransportElement(LspShipment, tour, serviceActivity); + addShipmentUnloadElement(LspShipment, tour); + addMainTourRunStartEventHandler(pair.carrierService, LspShipment, resource, tour); + addMainRunTourEndEventHandler(pair.carrierService, LspShipment, resource, tour); } } } @@ -258,18 +259,16 @@ protected void updateShipments() { } } - private void addShipmentLoadElement( - LspShipmentWithTime tuple, Tour tour) { + private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } - int startIndex = - tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); double cumulatedLoadingTime = 0; @@ -287,22 +286,20 @@ private void addShipmentLoadElement( + String.valueOf(load.getLogisticChainElement().getId()) + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, load); } - private void addShipmentTransportElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + private void addShipmentTransportElement(LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } - int startIndex = - tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); builder.setStartTime(startTimeOfTransport); @@ -317,17 +314,16 @@ private void addShipmentTransportElement( + String.valueOf(transport.getLogisticChainElement().getId()) + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, transport); } - private void addShipmentUnloadElement( - LspShipmentWithTime tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + private void addShipmentUnloadElement(LspShipment lspShipment, Tour tour) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticsChainElement(element); } } @@ -337,8 +333,7 @@ private void addShipmentUnloadElement( cumulatedLoadingTime = cumulatedLoadingTime + activity.getDuration(); } } - int startIndex = - tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); builder.setStartTime( legAfterStart.getExpectedDepartureTime() + legAfterStart.getExpectedTransportTime()); @@ -353,21 +348,21 @@ private void addShipmentUnloadElement( + String.valueOf(unload.getLogisticChainElement().getId()) + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, unload); } private void addMainTourRunStartEventHandler( - CarrierService carrierService, - LspShipmentWithTime tuple, + CarrierService carrierService, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourStartEventHandler handler = - new LSPTourStartEventHandler( - tuple.getLspShipment(), carrierService, element, resource, tour); - tuple.getLspShipment().addSimulationTracker(handler); + new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } @@ -375,19 +370,18 @@ private void addMainTourRunStartEventHandler( private void addMainRunTourEndEventHandler( CarrierService carrierService, - LspShipmentWithTime tuple, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourEndEventHandler handler = - new LSPTourEndEventHandler( - tuple.getLspShipment(),carrierService, element, resource, tour); - tuple.getLspShipment().addSimulationTracker(handler); + new LSPTourEndEventHandler(lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } } - private record LSPShipmentCarrierServicePair(LspShipmentWithTime tuple, CarrierService carrierService) {} + private record LSPShipmentCarrierServicePair(LspShipment lspShipment, CarrierService carrierService) {} } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java index a5491b99..e4d15190 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java @@ -28,11 +28,11 @@ import org.matsim.freight.logistics.LSPResource; import org.matsim.freight.logistics.LSPResourceScheduler; import org.matsim.freight.logistics.LogisticChainElement; -import org.matsim.freight.logistics.LspShipmentWithTime; import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils.TranshipmentHubSchedulerBuilder; import org.matsim.freight.logistics.shipment.LspShipmentPlan; import org.matsim.freight.logistics.shipment.LspShipmentPlanElement; import org.matsim.freight.logistics.shipment.LspShipmentUtils; +import org.matsim.freight.logistics.shipment.LspShipment; /*package-private*/ class TransshipmentHubScheduler extends LSPResourceScheduler { @@ -43,7 +43,7 @@ private TransshipmentHubTourEndEventHandler eventHandler; TransshipmentHubScheduler(TranshipmentHubSchedulerBuilder builder) { - this.lspShipmentsWithTime = new ArrayList<>(); + this.lspShipmentsToSchedule = new ArrayList<>(); this.capacityNeedLinear = builder.getCapacityNeedLinear(); this.capacityNeedFixed = builder.getCapacityNeedFixed(); } @@ -55,8 +55,8 @@ protected void initializeValues(LSPResource resource) { @Override protected void scheduleResource() { - for (LspShipmentWithTime tupleToBeAssigned : lspShipmentsWithTime) { - updateSchedule(tupleToBeAssigned); + for (LspShipment lspShipmentToBeAssigned : lspShipmentsToSchedule) { + updateSchedule(lspShipmentToBeAssigned); } } @@ -66,39 +66,39 @@ protected void updateShipments() { log.error("This method is not implemented. Nothing will happen here. "); } - private void updateSchedule(LspShipmentWithTime tuple) { - addShipmentHandleElement(tuple); - addShipmentToEventHandler(tuple); + private void updateSchedule(LspShipment lspShipment) { + addShipmentHandleElement(lspShipment); + addShipmentToEventHandler(lspShipment); } - private void addShipmentHandleElement(LspShipmentWithTime tuple) { + private void addShipmentHandleElement(LspShipment lspShipment) { LspShipmentUtils.ScheduledShipmentHandleBuilder builder = LspShipmentUtils.ScheduledShipmentHandleBuilder.newInstance(); - builder.setStartTime(tuple.getTime()); - builder.setEndTime( - tuple.getTime() + capacityNeedFixed + capacityNeedLinear * tuple.getLspShipment().getSize()); + builder.setStartTime(LspShipmentUtils.getTimeOfLspShipment(lspShipment)); + builder.setEndTime(LspShipmentUtils.getTimeOfLspShipment(lspShipment) + capacityNeedFixed + capacityNeedLinear * lspShipment.getSize()); builder.setResourceId(transshipmentHubResource.getId()); for (LogisticChainElement element : transshipmentHubResource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticsChainElement(element); } } LspShipmentPlanElement handle = builder.build(); + String idString = handle.getResourceId() + String.valueOf(handle.getLogisticChainElement().getId()) + handle.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getLspShipment().getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, handle); } - private void addShipmentToEventHandler(LspShipmentWithTime tuple) { + private void addShipmentToEventHandler(LspShipment lspShipment) { for (LogisticChainElement element : transshipmentHubResource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LspShipmentPlan lspShipmentPlan = - LspShipmentUtils.getOrCreateShipmentPlan(lspPlan, tuple.getLspShipment().getId()); - eventHandler.addShipment(tuple.getLspShipment(), element, lspShipmentPlan); + LspShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipment.getId()); + eventHandler.addShipment(lspShipment, element, lspShipmentPlan); break; } } diff --git a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentImpl.java b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentImpl.java index 4d0f48a5..8ff44b2a 100644 --- a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentImpl.java +++ b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentImpl.java @@ -105,6 +105,8 @@ public double getPickupServiceTime() { return pickupServiceTime; } + + @Override public String toString() { return "LSPShipmentImpl{" 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 4ce345f7..01efd96b 100644 --- a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java +++ b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java @@ -60,6 +60,30 @@ public static LspShipmentPlan getOrCreateShipmentPlan(LSPPlan lspPlan, Id + * This will replace the LSPShipmentWithTime class and thus reduce the complexity of the code. + * KMT Jul'24 + * @param lspShipment the LspShipment to store the time in + * @param time the time to store + */ + public static void setTimeOfLspShipment(LspShipment lspShipment, double time){ + lspShipment.getAttributes().putAttribute("time", time); + } + + /** + * Returns the time stored in the LspShipment. + *

+ * This will replace the LSPShipmentWithTime class and thus reduce the complexity of the code. KMT Jul'24 + * @param lspShipment the LspShipment to get the time from + * @return the time as double + */ + public static double getTimeOfLspShipment(LspShipment lspShipment) { + return (double) lspShipment.getAttributes().getAttribute("time"); + } + public static final class LspShipmentBuilder { final Id id; final List lspShipmentRequirements; diff --git a/src/test/java/org/matsim/freight/logistics/adapterTests/CollectionResourceTest.java b/src/test/java/org/matsim/freight/logistics/adapterTests/CollectionResourceTest.java index 1d60b887..f044ca9d 100644 --- a/src/test/java/org/matsim/freight/logistics/adapterTests/CollectionResourceTest.java +++ b/src/test/java/org/matsim/freight/logistics/adapterTests/CollectionResourceTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -41,7 +40,7 @@ public class CollectionResourceTest { - //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. + //Die Tracker sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. private org.matsim.vehicles.VehicleType collectionType; @@ -57,9 +56,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -74,7 +73,6 @@ public void initialize() { collectionCarrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(collectionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); capabilities = capabilitiesBuilder.build(); @@ -114,7 +112,7 @@ public void testCollectionResource() { assertFalse(capabilities.getVehicleTypes().isEmpty()); ArrayList types = new ArrayList<>(capabilities.getVehicleTypes()); if (types.size() == 1) { - assertSame(types.get(0), collectionType); + assertSame(types.getFirst(), collectionType); assertEquals(10, collectionType.getCapacity().getOther().intValue()); assertEquals(0.0004, collectionType.getCostInformation().getCostsPerMeter(), 0.0); assertEquals(0.38, collectionType.getCostInformation().getCostsPerSecond(), 0.0); @@ -124,7 +122,7 @@ public void testCollectionResource() { } ArrayList vehicles = new ArrayList<>(capabilities.getCarrierVehicles().values()); if (vehicles.size() == 1) { - assertSame(vehicles.get(0), collectionCarrierVehicle); + assertSame(vehicles.getFirst(), collectionCarrierVehicle); assertSame(collectionCarrierVehicle.getType(), collectionType); assertSame(collectionCarrierVehicle.getLinkId(), collectionLinkId); } diff --git a/src/test/java/org/matsim/freight/logistics/adapterTests/DistributionResourceTest.java b/src/test/java/org/matsim/freight/logistics/adapterTests/DistributionResourceTest.java index a4db475d..4e764d60 100644 --- a/src/test/java/org/matsim/freight/logistics/adapterTests/DistributionResourceTest.java +++ b/src/test/java/org/matsim/freight/logistics/adapterTests/DistributionResourceTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -42,8 +41,8 @@ public class DistributionResourceTest { - //die Trackers sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. - //Man kann sie deshalb ja extra au�erhalb des Builders einsetzen. + //Die Tracker sind ja erst ein Bestandteil des Scheduling bzw. Replanning und kommen hier noch nicht rein. + //Man kann sie deshalb ja extra außerhalb des Builders einsetzen. private org.matsim.vehicles.VehicleType distributionType; private CarrierVehicle distributionCarrierVehicle; @@ -58,9 +57,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("DistributionCarrier", Carrier.class); + Id carrierId = Id.create("DistributionCarrier", Carrier.class); Id vehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -75,7 +74,6 @@ public void initialize() { distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); capabilities = capabilitiesBuilder.build(); @@ -95,10 +93,7 @@ public void testCollectionResource() { assertNotNull(distributionResource.getClientElements()); assertTrue(distributionResource.getClientElements().isEmpty()); assertTrue(LSPCarrierResource.class.isAssignableFrom(distributionResource.getClass())); - if (LSPCarrierResource.class.isAssignableFrom(distributionResource.getClass())) { -// assertTrue(Carrier.class.isAssignableFrom(distributionResource.getClassOfResource())); - assertSame(distributionResource.getCarrier(), distributionCarrier); - } + assertSame(distributionResource.getCarrier(), distributionCarrier); assertSame(distributionResource.getEndLinkId(), distributionLinkId); assertSame(distributionResource.getStartLinkId(), distributionLinkId); assertNotNull(distributionResource.getSimulationTrackers()); @@ -118,7 +113,7 @@ public void testCollectionResource() { assertFalse(capabilities.getVehicleTypes().isEmpty()); ArrayList types = new ArrayList<>(capabilities.getVehicleTypes()); if (types.size() == 1) { - assertSame(types.get(0), distributionType); + assertSame(types.getFirst(), distributionType); assertEquals(10, distributionType.getCapacity().getOther().intValue()); assertEquals(0.0004, distributionType.getCostInformation().getCostsPerMeter(), 0.0); assertEquals(0.38, distributionType.getCostInformation().getCostsPerSecond(), 0.0); @@ -128,7 +123,7 @@ public void testCollectionResource() { } ArrayList vehicles = new ArrayList<>(capabilities.getCarrierVehicles().values()); if (vehicles.size() == 1) { - assertSame(vehicles.get(0), distributionCarrierVehicle); + assertSame(vehicles.getFirst(), distributionCarrierVehicle); assertSame(distributionCarrierVehicle.getType(), distributionType); assertSame(distributionCarrierVehicle.getLinkId(), distributionLinkId); } diff --git a/src/test/java/org/matsim/freight/logistics/adapterTests/MainRunResourceTest.java b/src/test/java/org/matsim/freight/logistics/adapterTests/MainRunResourceTest.java index 5dfe0fce..05cf35e5 100644 --- a/src/test/java/org/matsim/freight/logistics/adapterTests/MainRunResourceTest.java +++ b/src/test/java/org/matsim/freight/logistics/adapterTests/MainRunResourceTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -55,10 +54,10 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("MainRunCarrier", Carrier.class); + Id carrierId = Id.create("MainRunCarrier", Carrier.class); Id vehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(30); @@ -75,7 +74,6 @@ public void initialize() { CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(mainRunType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); capabilities = capabilitiesBuilder.build(); @@ -94,10 +92,7 @@ public void testMainRunResource() { assertNotNull(mainRunResource.getClientElements()); assertTrue(mainRunResource.getClientElements().isEmpty()); assertTrue(LSPCarrierResource.class.isAssignableFrom(mainRunResource.getClass())); - if (LSPCarrierResource.class.isAssignableFrom(mainRunResource.getClass())) { -// assertTrue(Carrier.class.isAssignableFrom(mainRunResource.getClassOfResource())); - assertSame(mainRunResource.getCarrier(), carrier); - } + assertSame(mainRunResource.getCarrier(), carrier); assertSame(mainRunResource.getEndLinkId(), toLinkId); assertSame(mainRunResource.getStartLinkId(), fromLinkId); assertNotNull(mainRunResource.getSimulationTrackers()); @@ -116,7 +111,7 @@ public void testMainRunResource() { assertFalse(capabilities.getVehicleTypes().isEmpty()); ArrayList types = new ArrayList<>(capabilities.getVehicleTypes()); if (types.size() == 1) { - assertSame(types.get(0), mainRunType); + assertSame(types.getFirst(), mainRunType); assertEquals(30, mainRunType.getCapacity().getOther().intValue()); assertEquals(0.0008, mainRunType.getCostInformation().getCostsPerMeter(), 0.0); assertEquals(0.38, mainRunType.getCostInformation().getCostsPerSecond(), 0.0); @@ -125,7 +120,7 @@ public void testMainRunResource() { } ArrayList vehicles = new ArrayList<>(capabilities.getCarrierVehicles().values()); if (vehicles.size() == 1) { - assertSame(vehicles.get(0), carrierVehicle); + assertSame(vehicles.getFirst(), carrierVehicle); assertSame(carrierVehicle.getType(), mainRunType); assertSame(carrierVehicle.getLinkId(), fromLinkId); } diff --git a/src/test/java/org/matsim/freight/logistics/examples/lspReplanning/CollectionLSPReplanningTest.java b/src/test/java/org/matsim/freight/logistics/examples/lspReplanning/CollectionLSPReplanningTest.java index fb34b02e..fa77bb1e 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/lspReplanning/CollectionLSPReplanningTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/lspReplanning/CollectionLSPReplanningTest.java @@ -106,7 +106,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLink.getId(), collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -114,8 +113,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); LSPResource collectionResource = adapterBuilder.build(); @@ -157,7 +156,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java b/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java index a4bba784..15180dda 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java @@ -77,7 +77,10 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLink.getId(), collectionVehicleType); Carrier carrier = CarriersUtils.createCarrier(Id.create("CollectionCarrier", Carrier.class)); - carrier.setCarrierCapabilities(CarrierCapabilities.Builder.newInstance().addType(collectionVehicleType).addVehicle(carrierVehicle).setFleetSize(FleetSize.INFINITE).build()); + carrier.setCarrierCapabilities(CarrierCapabilities.Builder.newInstance() + .addVehicle(carrierVehicle) + .setFleetSize(FleetSize.INFINITE) + .build()); LSPResource collectionResource = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier) .setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)).setLocationLinkId(collectionLink.getId()).build(); @@ -116,7 +119,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 @@ -149,7 +152,7 @@ public void initialize() { controler.addOverridingModule( new LSPModule() ); controler.addOverridingModule( new AbstractModule(){ @Override public void install(){ - bind( LSPScorerFactory.class ).toInstance( () -> new ExampleLSPScoring.TipScorer() ); + bind( LSPScorerFactory.class ).toInstance(ExampleLSPScoring.TipScorer::new); } }); diff --git a/src/test/java/org/matsim/freight/logistics/examples/lspScoring/MultipleIterationsCollectionLSPScoringTest.java b/src/test/java/org/matsim/freight/logistics/examples/lspScoring/MultipleIterationsCollectionLSPScoringTest.java index e9ad8611..7c2b37ab 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/lspScoring/MultipleIterationsCollectionLSPScoringTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/lspScoring/MultipleIterationsCollectionLSPScoringTest.java @@ -93,7 +93,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLink.getId(), collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -143,7 +142,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 @@ -175,7 +174,7 @@ public void initialize() { controler.addOverridingModule( new LSPModule() ); controler.addOverridingModule( new AbstractModule(){ @Override public void install(){ - bind( LSPScorerFactory.class ).toInstance( () -> new ExampleLSPScoring.TipScorer() ); + bind( LSPScorerFactory.class ).toInstance(ExampleLSPScoring.TipScorer::new); bind( LSPStrategyManager.class ).toInstance( new LSPModule.LSPStrategyManagerEmptyImpl() ); bind( CarrierStrategyManager.class ).toProvider(() -> { CarrierStrategyManager strategyManager = CarrierControlerUtils.createDefaultCarrierStrategyManager(); diff --git a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java index fb13ae0c..9dd5cc58 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java @@ -33,7 +33,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.VspExperimentalConfigGroup; @@ -91,9 +90,9 @@ private static Scenario prepareScenario(Config config) { } private static LSP createLSP(Scenario scenario) { - Network network = scenario.getNetwork(); + scenario.getNetwork(); - // A plan with two different logistic chains on the left and right, with respective carriers is created + // A plan with two different logistic chains on the left and right, with respective carriers is created LSPPlan multipleOneEchelonChainsPlan; { LogisticChainElement leftCarrierElement; @@ -249,7 +248,7 @@ public void install() { LSP lsp = LSPUtils.getLSPs(controler.getScenario()).getLSPs().values().iterator().next(); initialPlanCount = lsp.getPlans().size(); - initialPlanShipmentPlanCount = lsp.getPlans().get(0).getShipmentPlans().size(); + initialPlanShipmentPlanCount = lsp.getPlans().getFirst().getShipmentPlans().size(); controler.run(); diff --git a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java index 1334632b..47ad17c8 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java @@ -260,7 +260,7 @@ public void install() { final EventBasedCarrierScorer4MultipleChains carrierScorer = new EventBasedCarrierScorer4MultipleChains(); bind(CarrierScoringFunctionFactory.class).toInstance(carrierScorer); - bind(LSPScorerFactory.class).toInstance( () -> new MyLSPScorer()); + bind(LSPScorerFactory.class).toInstance(MyLSPScorer::new); bind(CarrierStrategyManager.class).toProvider(() -> { CarrierStrategyManager strategyManager = CarrierControlerUtils.createDefaultCarrierStrategyManager(); strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new BestPlanSelector<>()), null, 1); diff --git a/src/test/java/org/matsim/freight/logistics/examples/requirementsChecking/AssignerRequirementsTest.java b/src/test/java/org/matsim/freight/logistics/examples/requirementsChecking/AssignerRequirementsTest.java index 4e1c2b3f..7968f1f8 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/requirementsChecking/AssignerRequirementsTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/requirementsChecking/AssignerRequirementsTest.java @@ -1,24 +1,3 @@ -/* - *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2024 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.* @@ -42,7 +21,7 @@ package org.matsim.freight.logistics.examples.requirementsChecking; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import java.util.ArrayList; import java.util.Collections; @@ -94,7 +73,6 @@ public void initialize() { CarrierVehicle redVehicle = CarrierVehicle.newInstance(redVehicleId, collectionLinkId, collectionType); CarrierCapabilities redCapabilities = CarrierCapabilities.Builder.newInstance() - .addType(collectionType) .addVehicle(redVehicle) .setFleetSize(FleetSize.INFINITE) .build(); @@ -126,7 +104,6 @@ public void initialize() { CarrierVehicle blueVehicle = CarrierVehicle.newInstance(blueVehicleId, collectionLinkId, collectionType); CarrierCapabilities blueCapabilities = CarrierCapabilities.Builder.newInstance() - .addType(collectionType) .addVehicle(blueVehicle) .setFleetSize(FleetSize.INFINITE) .build(); @@ -171,7 +148,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -203,11 +180,13 @@ public void initialize() { public void testAssignerRequirements() { for (Id shipmentId : blueChain.getLspShipmentIds()) { LspShipment shipment = LSPUtils.findLspShipment(blueChain.getLSP(), shipmentId); - assertTrue(shipment.getRequirements().iterator().next() instanceof BlueRequirement); + assert shipment != null; + assertInstanceOf(BlueRequirement.class, shipment.getRequirements().iterator().next()); } for (Id shipmentId : redChain.getLspShipmentIds()) { LspShipment shipment = LSPUtils.findLspShipment(redChain.getLSP(), shipmentId); - assertTrue(shipment.getRequirements().iterator().next() instanceof RedRequirement); + assert shipment != null; + assertInstanceOf(RedRequirement.class, shipment.getRequirements().iterator().next()); } } diff --git a/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java b/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java index a21406e5..f55f5a8d 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java @@ -21,9 +21,6 @@ package org.matsim.freight.logistics.examples.simulationTrackers; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -58,6 +55,8 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; +import static org.junit.jupiter.api.Assertions.*; + public class CollectionTrackerTest { private static final Logger log = LogManager.getLogger(CollectionTrackerTest.class); @RegisterExtension @@ -97,7 +96,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLink.getId(), collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -105,8 +103,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); LSPResource collectionResource = adapterBuilder.build(); @@ -158,7 +156,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -209,7 +207,7 @@ public void testCollectionTracker() { assertEquals(1, logisticChain.getSimulationTrackers().size()); LSPSimulationTracker tracker = logisticChain.getSimulationTrackers().iterator().next(); - assertTrue(tracker instanceof LinearCostTracker); + assertInstanceOf(LinearCostTracker.class, tracker); LinearCostTracker linearTracker = (LinearCostTracker) tracker; double totalScheduledCosts = 0; double totalTrackedCosts = 0; @@ -281,7 +279,7 @@ public void testCollectionTracker() { // (yy I do not understand why we do not need to do this for the end activity of the tour.) } } - log.warn("scheduledDistanceCosts=" + scheduledDistanceCosts); + log.warn("scheduledDistanceCosts={}", scheduledDistanceCosts); } totalScheduledCosts += scheduledDistanceCosts; assertEquals(scheduledDistanceCosts, trackedDistanceCosts, Math.max(scheduledDistanceCosts, trackedDistanceCosts) * 0.01); @@ -293,7 +291,7 @@ public void testCollectionTracker() { double fixedTrackedCostsPerShipment = (totalTrackedCosts * shareOfFixedCosts) / totalNumberOfTrackedShipments; double fixedScheduledCostsPerShipment = (totalScheduledCosts * shareOfFixedCosts) / totalNumberOfScheduledShipments; - assertEquals(totalTrackedWeight, totalTrackedWeight, 0); + assertEquals(totalTrackedWeight, totalScheduledWeight, 0); assertEquals(totalNumberOfTrackedShipments, totalNumberOfScheduledShipments, 0); assertEquals(totalTrackedCosts, totalScheduledCosts, Math.max(totalScheduledCosts, totalTrackedCosts) * 0.01); assertEquals(linearTrackedCostsPerShipment, linearScheduledCostsPerShipment, Math.max(linearTrackedCostsPerShipment, linearScheduledCostsPerShipment) * 0.01); diff --git a/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/CollectionElementTest.java b/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/CollectionElementTest.java index e8681b29..9f425365 100644 --- a/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/CollectionElementTest.java +++ b/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/CollectionElementTest.java @@ -27,7 +27,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -51,9 +50,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -67,7 +66,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/DistributionElementTest.java b/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/DistributionElementTest.java index 6dcc2a4c..a816d633 100644 --- a/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/DistributionElementTest.java +++ b/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/DistributionElementTest.java @@ -27,7 +27,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -53,9 +52,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("DistributionCarrier", Carrier.class); + Id carrierId = Id.create("DistributionCarrier", Carrier.class); Id vehicleTypeId = Id.create("DistributionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -77,8 +76,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("DistributionCarrierResource", LSPResource.class); - adapter = ResourceImplementationUtils.DistributionCarrierResourceBuilder.newInstance(carrier) + Id.create("DistributionCarrierResource", LSPResource.class); + adapter = ResourceImplementationUtils.DistributionCarrierResourceBuilder.newInstance(carrier) .setDistributionScheduler(ResourceImplementationUtils.createDefaultDistributionCarrierScheduler(scenario)) .setLocationLinkId(distributionLinkId) .build(); diff --git a/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/MainRunElementTest.java b/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/MainRunElementTest.java index 5a7fe385..1e83c360 100644 --- a/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/MainRunElementTest.java +++ b/src/test/java/org/matsim/freight/logistics/logisticChainElementTests/MainRunElementTest.java @@ -27,7 +27,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -51,10 +50,10 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("MainRunCarrier", Carrier.class); + Id carrierId = Id.create("MainRunCarrier", Carrier.class); Id vehicleTypeId = Id.create("MainRunCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(30); @@ -71,7 +70,6 @@ public void initialize() { CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(mainRunType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/logisticChainTests/CollectionChainTest.java b/src/test/java/org/matsim/freight/logistics/logisticChainTests/CollectionChainTest.java index 4c8ea5b5..df06fa8f 100644 --- a/src/test/java/org/matsim/freight/logistics/logisticChainTests/CollectionChainTest.java +++ b/src/test/java/org/matsim/freight/logistics/logisticChainTests/CollectionChainTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -51,9 +50,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -67,7 +66,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/logisticChainTests/CompleteLogisticChainTest.java b/src/test/java/org/matsim/freight/logistics/logisticChainTests/CompleteLogisticChainTest.java index 13afaa97..cea7f72d 100644 --- a/src/test/java/org/matsim/freight/logistics/logisticChainTests/CompleteLogisticChainTest.java +++ b/src/test/java/org/matsim/freight/logistics/logisticChainTests/CompleteLogisticChainTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -61,9 +60,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder .newInstance(collectionVehicleTypeId); @@ -79,7 +78,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -127,7 +125,6 @@ public void initialize() { CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("MainRunVehicle"), fromLinkId, mainRunType); CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); @@ -180,7 +177,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/lspCreationTests/CollectionLSPCreationTest.java b/src/test/java/org/matsim/freight/logistics/lspCreationTests/CollectionLSPCreationTest.java index 75401fa5..e7634cf6 100644 --- a/src/test/java/org/matsim/freight/logistics/lspCreationTests/CollectionLSPCreationTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspCreationTests/CollectionLSPCreationTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -52,9 +51,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -68,7 +67,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -76,8 +74,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); LSPResource collectionResource = adapterBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/lspCreationTests/CompleteLSPCreationTest.java b/src/test/java/org/matsim/freight/logistics/lspCreationTests/CompleteLSPCreationTest.java index 1a8600d6..32db2031 100644 --- a/src/test/java/org/matsim/freight/logistics/lspCreationTests/CompleteLSPCreationTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspCreationTests/CompleteLSPCreationTest.java @@ -28,7 +28,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -52,10 +51,10 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); collectionVehicleTypeBuilder.setCapacity(10); @@ -70,7 +69,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -119,7 +117,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); @@ -169,7 +166,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CollectionLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CollectionLSPMobsimTest.java index 4419384b..bf98cbda 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CollectionLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CollectionLSPMobsimTest.java @@ -100,7 +100,6 @@ public void initialize() { // define carrier: Id carrierId = Id.create("CollectionCarrier", Carrier.class); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -155,7 +154,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -183,12 +182,7 @@ public void initialize() { lsps = new LSPs(lspList); } Controler controler = new Controler(scenario); - controler.getEvents().addHandler(new BasicEventHandler() { - @Override - public void handleEvent(Event event) { - log.warn(event); - } - }); + controler.getEvents().addHandler((BasicEventHandler) event -> log.warn(event)); controler.addOverridingModule(new AbstractModule() { @Override diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CompleteLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CompleteLSPMobsimTest.java index 1988bcec..7e435277 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CompleteLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/CompleteLSPMobsimTest.java @@ -86,7 +86,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -135,7 +134,6 @@ public void initialize() { CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId, mainRunType); CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -185,7 +183,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -246,7 +243,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -261,7 +258,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstAndSecondReloadLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstAndSecondReloadLSPMobsimTest.java index 2b6e7a76..79e2751f 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstAndSecondReloadLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstAndSecondReloadLSPMobsimTest.java @@ -90,7 +90,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -141,7 +140,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -218,7 +216,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -233,7 +231,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstReloadLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstReloadLSPMobsimTest.java index d8fdf860..7155658e 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstReloadLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/FirstReloadLSPMobsimTest.java @@ -91,7 +91,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -162,7 +161,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -177,7 +176,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunLSPMobsimTest.java index 7d4e9723..9022a2d9 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunLSPMobsimTest.java @@ -90,7 +90,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -139,7 +138,6 @@ public void initialize() { CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId, mainRunType); CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -194,7 +192,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -209,7 +207,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunOnlyLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunOnlyLSPMobsimTest.java index ecc10a2a..961f9020 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunOnlyLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MainRunOnlyLSPMobsimTest.java @@ -89,7 +89,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -140,7 +139,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -155,7 +154,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java index 66960b3e..b76d11ca 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCollectionLSPMobsimTest.java @@ -93,7 +93,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLink.getId(), collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -101,8 +100,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); LSPResource collectionResource = adapterBuilder.build(); @@ -144,7 +143,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCompleteLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCompleteLSPMobsimTest.java index 8f8c8a04..0e25899e 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCompleteLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsCompleteLSPMobsimTest.java @@ -95,7 +95,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -146,7 +145,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -196,7 +194,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -260,7 +257,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -275,7 +272,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstAndSecondReloadLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstAndSecondReloadLSPMobsimTest.java index 391ca626..050dda7d 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstAndSecondReloadLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstAndSecondReloadLSPMobsimTest.java @@ -96,7 +96,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -147,7 +146,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -224,7 +222,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -239,7 +237,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -314,6 +312,6 @@ public void testFirstReloadLSPMobsim() { @Test public void compareEvents(){ MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "output_events.xml.gz", utils.getOutputDirectory() + "output_events.xml.gz" ); - //Please note, that this result contains also reloding / hubHandlingStarts after the main run (even if there is no further distribution carrier) + //Please note, that this result contains also reloading / hubHandlingStarts after the main run (even if there is no further distribution carrier) } } diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java index c5bb82b0..96e68e1e 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsFirstReloadLSPMobsimTest.java @@ -94,7 +94,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -166,7 +165,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -181,7 +180,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java index 1a6fa2f4..9a25f460 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleIterationsMainRunLSPMobsimTest.java @@ -60,6 +60,7 @@ import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; +@SuppressWarnings("ALL") public class MultipleIterationsMainRunLSPMobsimTest { @RegisterExtension @@ -95,7 +96,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -146,7 +146,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -202,7 +201,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -217,7 +216,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java index fb6f8f90..3a051156 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCollectionLSPMobsimTest.java @@ -88,7 +88,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLink.getId(), collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -96,8 +95,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); LSPResource collectionResource = adapterBuilder.build(); @@ -139,7 +138,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java index f6f3960a..1f6257e3 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsCompleteLSPMobsimTest.java @@ -98,7 +98,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -149,7 +148,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -199,7 +197,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -263,7 +260,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -278,7 +275,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -308,10 +305,10 @@ public void initialize() { LSPUtils.addLSPs(scenario, lsps); controler.addOverridingModule(new LSPModule()); controler.addOverridingModule( new AbstractModule(){ - @Override public void install(){ + @Override public void install(){ bind( LSPStrategyManager.class ).toProvider(() -> { LSPStrategyManager strategyManager = new LSPStrategyManagerImpl(); - strategyManager.addStrategy(new AssignmentStrategyFactory().createStrategy(), null, 1); + strategyManager.addStrategy(new AssignmentStrategyFactory().createStrategy(), null, 1); return strategyManager; }); bind( CarrierStrategyManager.class ).toProvider(() -> { @@ -338,7 +335,7 @@ public void initialize() { @Test public void testCompleteLSPMobsim() { for (LspShipment shipment : completeLSP.getLspShipments()) { - log.info("comparing shipment: " + shipment.getId()); + log.info("comparing shipment: {}", shipment.getId()); assertFalse(shipment.getShipmentLog().getPlanElements().isEmpty()); ArrayList scheduleElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(completeLSP.getSelectedPlan(), shipment.getId()).getPlanElements().values()); scheduleElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstAndSecondReloadLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstAndSecondReloadLSPMobsimTest.java index fd7a39fb..352674b7 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstAndSecondReloadLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstAndSecondReloadLSPMobsimTest.java @@ -95,7 +95,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -146,7 +145,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -223,7 +221,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -238,7 +236,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -271,7 +269,7 @@ public void initialize() { @Override public void install(){ bind( LSPStrategyManager.class ).toProvider(() -> { LSPStrategyManager strategyManager = new LSPStrategyManagerImpl(); - strategyManager.addStrategy(new AssignmentStrategyFactory().createStrategy(), null, 1); + strategyManager.addStrategy(new AssignmentStrategyFactory().createStrategy(), null, 1); return strategyManager; }); bind( CarrierStrategyManager.class ).toProvider(() -> { diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java index da82b7cf..5d949c0a 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsFirstReloadLSPMobsimTest.java @@ -90,7 +90,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -162,7 +161,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -177,7 +176,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java index e160cc96..4b9c04a2 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/MultipleShipmentsMainRunLSPMobsimTest.java @@ -90,7 +90,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -140,7 +139,6 @@ public void initialize() { CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId, mainRunType); CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -196,7 +194,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -211,7 +209,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java index adbecdef..a4521fc2 100644 --- a/src/test/java/org/matsim/freight/logistics/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspMobsimTests/RepeatedMultipleShipmentsCompleteLSPMobsimTest.java @@ -90,7 +90,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -141,7 +140,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -191,7 +189,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -254,7 +251,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -269,7 +266,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, MatsimRandom.getRandom()); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspPlanTests/CollectionLSPPlanTest.java b/src/test/java/org/matsim/freight/logistics/lspPlanTests/CollectionLSPPlanTest.java index c6797f4d..ee000e6f 100644 --- a/src/test/java/org/matsim/freight/logistics/lspPlanTests/CollectionLSPPlanTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspPlanTests/CollectionLSPPlanTest.java @@ -27,7 +27,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -51,9 +50,9 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id carrierId = Id.create("CollectionCarrier", Carrier.class); + Id carrierId = Id.create("CollectionCarrier", Carrier.class); Id vehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder vehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(vehicleTypeId); vehicleTypeBuilder.setCapacity(10); @@ -67,7 +66,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/lspPlanTests/CompleteLSPPlanTest.java b/src/test/java/org/matsim/freight/logistics/lspPlanTests/CompleteLSPPlanTest.java index 3efe8d0f..2d811c99 100644 --- a/src/test/java/org/matsim/freight/logistics/lspPlanTests/CompleteLSPPlanTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspPlanTests/CompleteLSPPlanTest.java @@ -27,7 +27,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.scenario.ScenarioUtils; @@ -52,10 +51,10 @@ public void initialize() { config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario.getNetwork()).readFile("scenarios/2regions/2regions-network.xml"); - Network network = scenario.getNetwork(); + scenario.getNetwork(); - Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); + Id collectionCarrierId = Id.create("CollectionCarrier", Carrier.class); Id collectionVehicleTypeId = Id.create("CollectionCarrierVehicleType", VehicleType.class); CarrierVehicleType.Builder collectionVehicleTypeBuilder = CarrierVehicleType.Builder.newInstance(collectionVehicleTypeId); collectionVehicleTypeBuilder.setCapacity(10); @@ -70,7 +69,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -78,8 +76,8 @@ public void initialize() { collectionCarrier.setCarrierCapabilities(collectionCapabilities); - Id collectionResourceId = Id.create("CollectionCarrierResource", LSPResource.class); - final LSPResource collectionCarrierResource = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(collectionCarrier) + Id.create("CollectionCarrierResource", LSPResource.class); + final LSPResource collectionCarrierResource = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(collectionCarrier) .setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)) .setLocationLinkId(collectionLinkId) .build(); @@ -120,7 +118,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); @@ -170,7 +167,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); diff --git a/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CollectionLspShipmentAssigmentTest.java b/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CollectionLspShipmentAssigmentTest.java index fbe1c7f3..36f8e395 100644 --- a/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CollectionLspShipmentAssigmentTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CollectionLspShipmentAssigmentTest.java @@ -71,7 +71,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -79,8 +78,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); LSPResource collectionResource = adapterBuilder.build(); @@ -120,7 +119,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CompleteLspShipmentAssignerTest.java b/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CompleteLspShipmentAssignerTest.java index 0dc32141..a3b520d4 100644 --- a/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CompleteLspShipmentAssignerTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspShipmentAssignmentTests/CompleteLspShipmentAssignerTest.java @@ -75,7 +75,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -124,7 +123,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = collectionCapabilitiesBuilder.build(); @@ -174,7 +172,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -233,7 +230,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -248,7 +245,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CollectionShipmentBuilderTest.java b/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CollectionShipmentBuilderTest.java index 7e886f5a..11957dbf 100644 --- a/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CollectionShipmentBuilderTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CollectionShipmentBuilderTest.java @@ -64,7 +64,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CompleteShipmentBuilderTest.java b/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CompleteShipmentBuilderTest.java index ad1fd3ea..cb3ea748 100644 --- a/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CompleteShipmentBuilderTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspShipmentTest/CompleteShipmentBuilderTest.java @@ -61,7 +61,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -76,7 +76,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && diff --git a/src/test/java/org/matsim/freight/logistics/lspShipmentTest/DistributionShipmentBuilderTest.java b/src/test/java/org/matsim/freight/logistics/lspShipmentTest/DistributionShipmentBuilderTest.java index aaaa3966..380a86b9 100644 --- a/src/test/java/org/matsim/freight/logistics/lspShipmentTest/DistributionShipmentBuilderTest.java +++ b/src/test/java/org/matsim/freight/logistics/lspShipmentTest/DistributionShipmentBuilderTest.java @@ -64,7 +64,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java index 76b370b3..4064ef67 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java @@ -73,7 +73,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -81,8 +80,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); collectionResource = adapterBuilder.build(); @@ -123,7 +122,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -186,15 +185,15 @@ public void testCollectionLSPScheduling() { assertEquals(planElements.get(1).getStartTime(), planElements.get(0).getEndTime(), 0.0); assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); assertEquals(2, shipment.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -205,7 +204,7 @@ public void testCollectionLSPScheduling() { assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(endHandler.getResourceId(), collectionLSP.getResources().iterator().next().getId()); - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); 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 0700e202..e4227cbd 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java @@ -86,7 +86,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -137,7 +136,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -186,7 +184,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -247,7 +244,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -262,7 +259,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -418,18 +415,18 @@ public void testCompletedLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); while (iter.hasNext()) { @@ -455,8 +452,8 @@ public void testCompletedLSPScheduling() { assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); while (iter.hasNext()) { @@ -486,8 +483,8 @@ public void testCompletedLSPScheduling() { ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -495,15 +492,15 @@ public void testCompletedLSPScheduling() { assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); - assertSame(endHandler.getLogisticChainElement(), solutionElements.get(0)); + assertSame(endHandler.getLogisticChainElement(), solutionElements.getFirst()); assertSame(endHandler.getLspShipment(), shipment); assertSame(endHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(endHandler.getResourceId(), resources.get(0).getId()); + assertSame(endHandler.getResourceId(), resources.getFirst().getId()); //CollectionServiceEnd - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); @@ -512,15 +509,15 @@ public void testCompletedLSPScheduling() { assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); - assertSame(serviceHandler.getElement(), solutionElements.get(0)); + assertSame(serviceHandler.getElement(), solutionElements.getFirst()); assertSame(serviceHandler.getLspShipment(), shipment); assertSame(serviceHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(serviceHandler.getResourceId(), resources.get(0).getId()); + assertSame(serviceHandler.getResourceId(), resources.getFirst().getId()); //MainRunStart - assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -538,7 +535,7 @@ public void testCompletedLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); //MainRunEnd - assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -556,7 +553,7 @@ public void testCompletedLSPScheduling() { assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId()); //DistributionRunStart - assertTrue(eventHandlers.get(4) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(4)); LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4); assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); assertEquals(lspTourStartEventHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -574,7 +571,7 @@ public void testCompletedLSPScheduling() { assertSame(lspTourStartEventHandler.getResourceId(), resources.get(4).getId()); //DistributionServiceStart - assertTrue(eventHandlers.get(5) instanceof DistributionServiceStartEventHandler); + assertInstanceOf(DistributionServiceStartEventHandler.class, eventHandlers.get(5)); DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5); assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); assertEquals(distributionServiceHandler.getCarrierService().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 907bf933..8ad0b1c4 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java @@ -78,7 +78,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -149,7 +148,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -164,7 +163,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -241,19 +240,19 @@ public void testFirstReloadLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); @@ -270,8 +269,8 @@ public void testFirstReloadLSPScheduling() { } } assertTrue(handledByTranshipmentHub); - //This asserts that the shipments waiting for handling have been handled and the queues have been cleared - assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + + assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); } @@ -281,8 +280,8 @@ public void testFirstReloadLSPScheduling() { eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -293,16 +292,16 @@ public void testFirstReloadLSPScheduling() { assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(endHandler.getResourceId(), lsp.getResources().iterator().next().getId()); - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); - assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); + assertSame(serviceHandler.getElement(), planElements.getFirst().getLogisticChainElement()); assertSame(serviceHandler.getElement(), lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(serviceHandler.getLspShipment(), shipment); - assertSame(serviceHandler.getResourceId(), planElements.get(0).getResourceId()); + assertSame(serviceHandler.getResourceId(), planElements.getFirst().getResourceId()); assertSame(serviceHandler.getResourceId(), lsp.getResources().iterator().next().getId()); } 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 f6ba4882..7f6900e6 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java @@ -80,7 +80,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -129,7 +128,6 @@ public void initialize() { CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId, mainRunType); CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -184,7 +182,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -199,7 +197,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -309,18 +307,18 @@ public void testMainRunLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); @@ -350,8 +348,8 @@ public void testMainRunLSPScheduling() { ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements()); ArrayList resources = new ArrayList<>(lsp.getResources()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -359,15 +357,15 @@ public void testMainRunLSPScheduling() { assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); - assertSame(endHandler.getLogisticChainElement(), solutionElements.get(0)); + assertSame(endHandler.getLogisticChainElement(), solutionElements.getFirst()); assertSame(endHandler.getLspShipment(), shipment); assertSame(endHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(endHandler.getResourceId(), resources.get(0).getId()); + assertSame(endHandler.getResourceId(), resources.getFirst().getId()); //CollectionServiceEnd - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); @@ -376,15 +374,15 @@ public void testMainRunLSPScheduling() { assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); - assertSame(serviceHandler.getElement(), solutionElements.get(0)); + assertSame(serviceHandler.getElement(), solutionElements.getFirst()); assertSame(serviceHandler.getLspShipment(), shipment); assertSame(serviceHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(serviceHandler.getResourceId(), resources.get(0).getId()); + assertSame(serviceHandler.getResourceId(), resources.getFirst().getId()); //MainRunTourStart - assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -402,7 +400,7 @@ public void testMainRunLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); //MainRunTourEnd - assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java index 2d361882..458a833b 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java @@ -75,7 +75,6 @@ public void initialize() { CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(vollectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(collectionType); capabilitiesBuilder.addVehicle(carrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities capabilities = capabilitiesBuilder.build(); @@ -83,8 +82,8 @@ public void initialize() { carrier.setCarrierCapabilities(capabilities); - Id adapterId = Id.create("CollectionCarrierResource", LSPResource.class); - CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); + Id.create("CollectionCarrierResource", LSPResource.class); + CollectionCarrierResourceBuilder adapterBuilder = ResourceImplementationUtils.CollectionCarrierResourceBuilder.newInstance(carrier); adapterBuilder.setCollectionScheduler(ResourceImplementationUtils.createDefaultCollectionCarrierScheduler(scenario)); adapterBuilder.setLocationLinkId(collectionLinkId); collectionResource = adapterBuilder.build(); @@ -126,7 +125,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, random); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -189,15 +188,15 @@ public void testCollectionLSPScheduling() { assertEquals(planElements.get(1).getStartTime(), planElements.get(0).getEndTime(), 0.0); assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); assertEquals(2, shipment.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -208,7 +207,7 @@ public void testCollectionLSPScheduling() { assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(endHandler.getResourceId(), collectionLSP.getResources().iterator().next().getId()); - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); 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 a923362b..8b09edd0 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java @@ -86,7 +86,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -138,7 +137,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -188,7 +186,6 @@ public void initialize() { CarrierVehicle distributionCarrierVehicle = CarrierVehicle.newInstance(distributionVehicleId, distributionLinkId, distributionType); CarrierCapabilities.Builder capabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - capabilitiesBuilder.addType(distributionType); capabilitiesBuilder.addVehicle(distributionCarrierVehicle); capabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities distributionCapabilities = capabilitiesBuilder.build(); @@ -250,7 +247,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, rand); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -265,7 +262,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList, rand); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -421,18 +418,18 @@ public void testCompletedLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); while (iter.hasNext()) { @@ -458,8 +455,8 @@ public void testCompletedLSPScheduling() { assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); while (iter.hasNext()) { @@ -489,8 +486,8 @@ public void testCompletedLSPScheduling() { ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -498,15 +495,15 @@ public void testCompletedLSPScheduling() { assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); - assertSame(endHandler.getLogisticChainElement(), solutionElements.get(0)); + assertSame(endHandler.getLogisticChainElement(), solutionElements.getFirst()); assertSame(endHandler.getLspShipment(), shipment); assertSame(endHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(endHandler.getResourceId(), resources.get(0).getId()); + assertSame(endHandler.getResourceId(), resources.getFirst().getId()); //CollectionServiceEnd - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); @@ -515,15 +512,15 @@ public void testCompletedLSPScheduling() { assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); - assertSame(serviceHandler.getElement(), solutionElements.get(0)); + assertSame(serviceHandler.getElement(), solutionElements.getFirst()); assertSame(serviceHandler.getLspShipment(), shipment); assertSame(serviceHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(serviceHandler.getResourceId(), resources.get(0).getId()); + assertSame(serviceHandler.getResourceId(), resources.getFirst().getId()); //MainRunTourStart - assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -541,7 +538,7 @@ public void testCompletedLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); //MainRunTourEnd - assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -559,7 +556,7 @@ public void testCompletedLSPScheduling() { assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId()); //DistributionTourStart - assertTrue(eventHandlers.get(4) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(4)); LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4); assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); assertEquals(lspTourStartEventHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -577,7 +574,7 @@ public void testCompletedLSPScheduling() { assertSame(lspTourStartEventHandler.getResourceId(), resources.get(4).getId()); //DistributionServiceStart - assertTrue(eventHandlers.get(5) instanceof DistributionServiceStartEventHandler); + assertInstanceOf(DistributionServiceStartEventHandler.class, eventHandlers.get(5)); DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5); assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); assertEquals(distributionServiceHandler.getCarrierService().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 28fc6df2..d101b4c9 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java @@ -78,7 +78,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -148,7 +147,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -163,7 +162,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -240,19 +239,19 @@ public void testFirstReloadLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); @@ -269,8 +268,8 @@ public void testFirstReloadLSPScheduling() { } } assertTrue(handledByTranshipmentHub); - //This asserts that the shipments waiting for handling have been handled and the queues have been cleared - assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + + assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); } @@ -280,8 +279,8 @@ public void testFirstReloadLSPScheduling() { eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -292,16 +291,16 @@ public void testFirstReloadLSPScheduling() { assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(endHandler.getResourceId(), lsp.getResources().iterator().next().getId()); - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); - assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); + assertSame(serviceHandler.getElement(), planElements.getFirst().getLogisticChainElement()); assertSame(serviceHandler.getElement(), lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(serviceHandler.getLspShipment(), shipment); - assertSame(serviceHandler.getResourceId(), planElements.get(0).getResourceId()); + assertSame(serviceHandler.getResourceId(), planElements.getFirst().getResourceId()); assertSame(serviceHandler.getResourceId(), lsp.getResources().iterator().next().getId()); } 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 b530b0cd..4f0605cf 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java @@ -80,7 +80,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -129,7 +128,6 @@ public void initialize() { CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(mainRunVehicleId, fromLinkId, mainRunType); CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -184,7 +182,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -199,7 +197,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -309,18 +307,18 @@ public void testMainRunLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); @@ -350,8 +348,8 @@ public void testMainRunLSPScheduling() { ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements()); ArrayList resources = new ArrayList<>(lsp.getResources()); - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -359,15 +357,15 @@ public void testMainRunLSPScheduling() { assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); - assertSame(endHandler.getLogisticChainElement(), solutionElements.get(0)); + assertSame(endHandler.getLogisticChainElement(), solutionElements.getFirst()); assertSame(endHandler.getLspShipment(), shipment); assertSame(endHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(endHandler.getResourceId(), resources.get(0).getId()); + assertSame(endHandler.getResourceId(), resources.getFirst().getId()); //CollectionServiceEnd - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); @@ -376,15 +374,15 @@ public void testMainRunLSPScheduling() { assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); - assertSame(serviceHandler.getElement(), solutionElements.get(0)); + assertSame(serviceHandler.getElement(), solutionElements.getFirst()); assertSame(serviceHandler.getLspShipment(), shipment); assertSame(serviceHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(serviceHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(serviceHandler.getResourceId(), resources.get(0).getId()); + assertSame(serviceHandler.getResourceId(), resources.getFirst().getId()); //MainRunTourStart - assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -402,7 +400,7 @@ public void testMainRunLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); //MainRunEnd - assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().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 0d0fa0c0..4766d616 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -84,7 +84,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -136,7 +135,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -213,7 +211,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -228,7 +226,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -348,79 +346,89 @@ public void testSecondReloadLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } - assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); - ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry + entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), shipment.getFrom()); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : + reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There IS a next element following the 1st hub, so the outgoing shipments does NOT contain the shipment anymore (got handled). + assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } - assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), toLinkId); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There is NO next element following the 2nd hub, so the outgoing shipments remain in the list of the 2nd hub. + assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } for (LspShipment shipment : lsp.getLspShipments()) { assertEquals(4, shipment.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); + ArrayList> eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements()); ArrayList resources = new ArrayList<>(lsp.getResources()); //CollectionTourEnd - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(collectionEndHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(collectionEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -428,15 +436,15 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); - assertSame(collectionEndHandler.getLogisticChainElement(), solutionElements.get(0)); + assertSame(collectionEndHandler.getLogisticChainElement(), solutionElements.getFirst()); assertSame(collectionEndHandler.getLspShipment(), shipment); assertSame(collectionEndHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(collectionEndHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionEndHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(collectionEndHandler.getResourceId(), resources.get(0).getId()); + assertSame(collectionEndHandler.getResourceId(), resources.getFirst().getId()); //CollectionServiceEnd - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler collectionServiceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(collectionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); @@ -445,15 +453,15 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionServiceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(2).getLogisticChainElement()); - assertSame(collectionServiceHandler.getElement(), solutionElements.get(0)); + assertSame(collectionServiceHandler.getElement(), solutionElements.getFirst()); assertSame(collectionServiceHandler.getLspShipment(), shipment); assertSame(collectionServiceHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(collectionServiceHandler.getResourceId(), resources.get(0).getId()); + assertSame(collectionServiceHandler.getResourceId(), resources.getFirst().getId()); //MainRunStart - assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -471,7 +479,7 @@ public void testSecondReloadLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); //MainRunEnd - assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().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 3fc5b72d..f7a32ede 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java @@ -84,7 +84,6 @@ public void initialize() { CarrierVehicle collectionCarrierVehicle = CarrierVehicle.newInstance(collectionVehicleId, collectionLinkId, collectionType); CarrierCapabilities.Builder collectionCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - collectionCapabilitiesBuilder.addType(collectionType); collectionCapabilitiesBuilder.addVehicle(collectionCarrierVehicle); collectionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities collectionCapabilities = collectionCapabilitiesBuilder.build(); @@ -136,7 +135,6 @@ public void initialize() { CarrierCapabilities.Builder mainRunCapabilitiesBuilder = CarrierCapabilities.Builder.newInstance(); - mainRunCapabilitiesBuilder.addType(mainRunType); mainRunCapabilitiesBuilder.addVehicle(mainRunCarrierVehicle); mainRunCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE); CarrierCapabilities mainRunCapabilities = mainRunCapabilitiesBuilder.build(); @@ -213,7 +211,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingToLink = linkList.get(0); + Link pendingToLink = linkList.getFirst(); if ((pendingToLink.getFromNode().getCoord().getX() <= 18000 && pendingToLink.getFromNode().getCoord().getY() <= 4000 && pendingToLink.getFromNode().getCoord().getX() >= 14000 && @@ -228,7 +226,7 @@ public void initialize() { while (true) { Collections.shuffle(linkList); - Link pendingFromLink = linkList.get(0); + Link pendingFromLink = linkList.getFirst(); if (pendingFromLink.getFromNode().getCoord().getX() <= 4000 && pendingFromLink.getFromNode().getCoord().getY() <= 4000 && pendingFromLink.getToNode().getCoord().getX() <= 4000 && @@ -348,79 +346,97 @@ public void testSecondReloadLSPScheduling() { assertEquals("LOAD", planElements.get(0).getElementType()); assertTrue(planElements.get(0).getEndTime() >= (0)); - assertTrue(planElements.get(0).getEndTime() <= (24*3600)); - assertTrue(planElements.get(0).getStartTime() <= planElements.get(0).getEndTime()); - assertTrue(planElements.get(0).getStartTime() >= (0)); - assertTrue(planElements.get(0).getStartTime() <= (24*3600)); - assertSame(planElements.get(0).getResourceId(), collectionResource.getId()); - assertSame(planElements.get(0).getLogisticChainElement(), collectionElement); + assertTrue(planElements.getFirst().getEndTime() <= (24*3600)); + assertTrue(planElements.getFirst().getStartTime() <= planElements.getFirst().getEndTime()); + assertTrue(planElements.getFirst().getStartTime() >= (0)); + assertTrue(planElements.getFirst().getStartTime() <= (24*3600)); + assertSame(planElements.getFirst().getResourceId(), collectionResource.getId()); + assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } - assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); - ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry + entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), shipment.getFrom()); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : + reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There IS a next element following the 1st hub, so the outgoing shipments does NOT contain the shipment anymore (got handled). + assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } - assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); - assertTrue(eventHandlers.iterator().next() instanceof TransshipmentHubTourEndEventHandler); - reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.iterator().next(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = + new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = + (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator< + Entry< + CarrierService, + TransshipmentHubTourEndEventHandler.TransshipmentHubEventHandlerPair>> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry + entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), toLinkId); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : + reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There is NO next element following the 2nd hub, so the outgoing shipments remain in the list of the 2nd hub. + assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } + for (LspShipment shipment : lsp.getLspShipments()) { assertEquals(4, shipment.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); + ArrayList eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements()); ArrayList resources = new ArrayList<>(lsp.getResources()); //CollectionTourEnd - assertTrue(eventHandlers.get(0) instanceof LSPTourEndEventHandler); - LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.get(0); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); + LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(collectionEndHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(collectionEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -428,15 +444,15 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); - assertSame(collectionEndHandler.getLogisticChainElement(), solutionElements.get(0)); + assertSame(collectionEndHandler.getLogisticChainElement(), solutionElements.getFirst()); assertSame(collectionEndHandler.getLspShipment(), shipment); assertSame(collectionEndHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(collectionEndHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionEndHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(collectionEndHandler.getResourceId(), resources.get(0).getId()); + assertSame(collectionEndHandler.getResourceId(), resources.getFirst().getId()); //CollectionServiceEnd - assertTrue(eventHandlers.get(1) instanceof CollectionServiceEndEventHandler); + assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler collectionServiceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(collectionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); @@ -445,15 +461,15 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionServiceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(2).getLogisticChainElement()); - assertSame(collectionServiceHandler.getElement(), solutionElements.get(0)); + assertSame(collectionServiceHandler.getElement(), solutionElements.getFirst()); assertSame(collectionServiceHandler.getLspShipment(), shipment); assertSame(collectionServiceHandler.getResourceId(), planElements.get(0).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), planElements.get(2).getResourceId()); - assertSame(collectionServiceHandler.getResourceId(), resources.get(0).getId()); + assertSame(collectionServiceHandler.getResourceId(), resources.getFirst().getId()); //MainRunStart - assertTrue(eventHandlers.get(2) instanceof LSPTourStartEventHandler); + assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -471,7 +487,7 @@ public void testSecondReloadLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); //MainRunEnd - assertTrue(eventHandlers.get(3) instanceof LSPTourEndEventHandler); + assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0);