diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/activity/ActivityCountAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/activity/ActivityCountAnalysis.java new file mode 100644 index 00000000000..b944ee044fb --- /dev/null +++ b/contribs/application/src/main/java/org/matsim/application/analysis/activity/ActivityCountAnalysis.java @@ -0,0 +1,220 @@ +package org.matsim.application.analysis.activity; + +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.geotools.api.feature.Property; +import org.geotools.api.feature.simple.SimpleFeature; +import org.locationtech.jts.geom.Geometry; +import org.matsim.api.core.v01.Coord; +import org.matsim.application.CommandSpec; +import org.matsim.application.MATSimAppCommand; +import org.matsim.application.options.*; +import org.matsim.core.utils.io.IOUtils; +import picocli.CommandLine; +import tech.tablesaw.api.*; +import tech.tablesaw.io.csv.CsvReadOptions; +import tech.tablesaw.selection.Selection; + +import java.util.*; +import java.util.regex.Pattern; + +@CommandSpec( + requires = {"activities.csv"}, + produces = {"activities_%s_per_region.csv"} +) +public class ActivityCountAnalysis implements MATSimAppCommand { + + private static final Logger log = LogManager.getLogger(ActivityCountAnalysis.class); + + @CommandLine.Mixin + private final InputOptions input = InputOptions.ofCommand(ActivityCountAnalysis.class); + @CommandLine.Mixin + private final OutputOptions output = OutputOptions.ofCommand(ActivityCountAnalysis.class); + @CommandLine.Mixin + private ShpOptions shp; + @CommandLine.Mixin + private SampleOptions sample; + @CommandLine.Mixin + private CrsOptions crs; + + /** + * Specifies the column in the shapefile used as the region ID. + */ + @CommandLine.Option(names = "--id-column", description = "Column to use as ID for the shapefile", required = true) + private String idColumn; + + /** + * Maps patterns to merge activity types into a single category. + * Example: `home;work` can merge activities "home1" and "work1" into categories "home" and "work". + */ + @CommandLine.Option(names = "--activity-mapping", description = "Map of patterns to merge activity types", split = ";") + private Map activityMapping; + + /** + * Specifies activity types that should be counted only once per agent per region. + */ + @CommandLine.Option(names = "--single-occurrence", description = "Activity types that are only counted once per agent") + private Set singleOccurrence; + + public static void main(String[] args) { + new ActivityCountAnalysis().execute(args); + } + + /** + * Executes the activity count analysis. + * + * @return Exit code (0 for success). + * @throws Exception if errors occur during execution. + */ + @Override + public Integer call() throws Exception { + + // Prepares the activity mappings and reads input data + HashMap> formattedActivityMapping = new HashMap<>(); + Map regionAreaMap = new HashMap<>(); + + if (this.activityMapping == null) this.activityMapping = new HashMap<>(); + + for (Map.Entry entry : this.activityMapping.entrySet()) { + String pattern = entry.getKey(); + String activity = entry.getValue(); + Set activities = new HashSet<>(Arrays.asList(activity.split(","))); + formattedActivityMapping.put(pattern, activities); + } + + // Reading the input csv + Table activities = Table.read().csv(CsvReadOptions.builder(IOUtils.getBufferedReader(input.getPath("activities.csv"))) + .columnTypesPartial(Map.of("person", ColumnType.TEXT, "activity_type", ColumnType.TEXT)) + .sample(false) + .separator(CsvOptions.detectDelimiter(input.getPath("activities.csv"))).build()); + + // remove the underscore and the number from the activity_type column + TextColumn activityType = activities.textColumn("activity_type"); + activityType.set(Selection.withRange(0, activityType.size()), activityType.replaceAll("_[0-9]{2,}$", "")); + + ShpOptions.Index index = crs.getInputCRS() == null ? shp.createIndex(idColumn) : shp.createIndex(crs.getInputCRS(), idColumn); + + // stores the counts of activities per region + Object2ObjectOpenHashMap> regionActivityCounts = new Object2ObjectOpenHashMap<>(); + // stores the activities that have been counted for each person in each region + Object2ObjectOpenHashMap> personActivityTracker = new Object2ObjectOpenHashMap<>(); + + // iterate over the csv rows + for (Row row : activities) { + String person = row.getString("person"); + String activity = row.getText("activity_type"); + + for (Map.Entry> entry : formattedActivityMapping.entrySet()) { + String pattern = entry.getKey(); + Set activities2 = entry.getValue(); + for (String act : activities2) { + if (Pattern.matches(act, activity)) { + activity = pattern; + break; + } + } + } + + Coord coord = new Coord(row.getDouble("coord_x"), row.getDouble("coord_y")); + + // get the region for the current coordinate + SimpleFeature feature = index.queryFeature(coord); + + if (feature == null) { + continue; + } + + Geometry geometry = (Geometry) feature.getDefaultGeometry(); + + Property prop = feature.getProperty(idColumn); + if (prop == null) + throw new IllegalArgumentException("No property found for column %s".formatted(idColumn)); + + Object region = prop.getValue(); + if (region != null && region.toString().length() > 0) { + + double area = geometry.getArea(); + regionAreaMap.put(region.toString(), area); + + // Add region to the activity counts and person activity tracker if not already present + regionActivityCounts.computeIfAbsent(region, k -> new Object2IntOpenHashMap<>()); + personActivityTracker.computeIfAbsent(region, k -> new HashSet<>()); + + Set trackedActivities = personActivityTracker.get(region); + String personActivityKey = person + "_" + activity; + + // adding activity only if it has not been counted for the person in the region + if (singleOccurrence == null || !singleOccurrence.contains(activity) || !trackedActivities.contains(personActivityKey)) { + Object2IntMap activityCounts = regionActivityCounts.get(region); + activityCounts.mergeInt(activity, 1, Integer::sum); + + // mark the activity as counted for the person in the region + trackedActivities.add(personActivityKey); + } + } + } + + Set uniqueActivities = new HashSet<>(); + + for (Object2IntMap map : regionActivityCounts.values()) { + uniqueActivities.addAll(map.keySet()); + } + + for (String activity : uniqueActivities) { + Table resultTable = Table.create(); + TextColumn regionColumn = TextColumn.create("id"); + DoubleColumn activityColumn = DoubleColumn.create("count"); + DoubleColumn distributionColumn = DoubleColumn.create("relative_density"); + DoubleColumn countRatioColumn = DoubleColumn.create("density"); + DoubleColumn areaColumn = DoubleColumn.create("area"); + + resultTable.addColumns(regionColumn, activityColumn, distributionColumn, countRatioColumn, areaColumn); + for (Map.Entry> entry : regionActivityCounts.entrySet()) { + Object region = entry.getKey(); + double value = 0; + for (Map.Entry entry2 : entry.getValue().object2IntEntrySet()) { + String ect = entry2.getKey(); + if (Pattern.matches(ect, activity)) { + value = entry2.getValue() * sample.getUpscaleFactor(); + break; + } + } + + + Row row = resultTable.appendRow(); + row.setString("id", region.toString()); + row.setDouble("count", value); + } + + for (Row row : resultTable) { + Double area = regionAreaMap.get(row.getString("id")); + if (area != null) { + row.setDouble("area", area); + row.setDouble("density", row.getDouble("count") / area); + } else { + log.warn("Area for region {} is not found", row.getString("id")); + } + } + + Double averageDensity = countRatioColumn.mean(); + + for (Row row : resultTable) { + Double value = row.getDouble("density"); + if (averageDensity != 0) { + row.setDouble("relative_density", value / averageDensity); + } else { + row.setDouble("relative_density", 0.0); + } + } + + + resultTable.write().csv(output.getPath("activities_%s_per_region.csv", activity).toFile()); + log.info("Wrote activity counts for {} to {}", activity, output.getPath("activities_%s_per_region.csv", activity)); + } + + return 0; + } +} diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java b/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java index 3c22fc678a3..41abdbcff54 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/traffic/traveltime/TravelTimeComparison.java @@ -1,5 +1,7 @@ package org.matsim.application.analysis.traffic.traveltime; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; @@ -47,6 +49,8 @@ ) public class TravelTimeComparison implements MATSimAppCommand { + private static final Logger log = LogManager.getLogger(TravelTimeComparison.class); + @CommandLine.Mixin private InputOptions input = InputOptions.ofCommand(TravelTimeComparison.class); @@ -90,6 +94,13 @@ public Integer call() throws Exception { for (Row row : data) { LeastCostPathCalculator.Path congested = computePath(network, congestedRouter, row); + + // Skip if path is not found + if (congested == null) { + row.setDouble("simulated", Double.NaN); + continue; + } + double dist = congested.links.stream().mapToDouble(Link::getLength).sum(); double speed = 3.6 * dist / congested.travelTime; @@ -102,6 +113,8 @@ public Integer call() throws Exception { row.setDouble("free_flow", speed); } + data = data.dropWhere(data.doubleColumn("simulated").isMissing()); + data.addColumns( data.doubleColumn("simulated").subtract(data.doubleColumn("mean")).setName("bias") ); @@ -129,6 +142,16 @@ private LeastCostPathCalculator.Path computePath(Network network, LeastCostPathC Node fromNode = network.getNodes().get(Id.createNodeId(row.getString("from_node"))); Node toNode = network.getNodes().get(Id.createNodeId(row.getString("to_node"))); + if (fromNode == null) { + log.error("Node {} not found in network", row.getString("from_node")); + return null; + } + + if (toNode == null) { + log.error("Node {} not found in network", row.getString("to_node")); + return null; + } + return router.calcLeastCostPath(fromNode, toNode, row.getInt("hour") * 3600, null, null); } diff --git a/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java b/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java index 5d9f8ccec99..55b7e01846e 100644 --- a/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java +++ b/contribs/application/src/main/java/org/matsim/application/options/ShpOptions.java @@ -230,6 +230,7 @@ public Geometry getGeometry() { /** * Return the union of all geometries in the shape file and project it to the target crs. + * * @param toCRS target coordinate system */ public Geometry getGeometry(String toCRS) { diff --git a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java index 63179128cc4..6b2d6c10784 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -655,7 +655,7 @@ else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) { createJobId(scenario, newDemandInformationElement, link.getId(), null), CarrierService.class); CarrierService thisService = CarrierService.Builder.newInstance(idNewService, link.getId()) - .setCapacityDemand(demandForThisLink).setServiceDuration(serviceTime) + .setDemand(demandForThisLink).setServiceDuration(serviceTime) .setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow()) .build(); CarriersUtils.getCarriers(scenario).getCarriers() @@ -696,7 +696,7 @@ else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) { CarrierService.class); if (demandToDistribute > 0 && singleDemandForThisLink > 0) { CarrierService thisService = CarrierService.Builder.newInstance(idNewService, link.getId()) - .setCapacityDemand(singleDemandForThisLink).setServiceDuration(serviceTime) + .setDemand(singleDemandForThisLink).setServiceDuration(serviceTime) .setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow()) .build(); thisCarrier.getServices().put(thisService.getId(), thisService); @@ -747,7 +747,7 @@ else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) { createJobId(scenario, newDemandInformationElement, link.getId(), null), CarrierService.class); if ((demandToDistribute > 0 && singleDemandForThisLink > 0) || demandToDistribute == 0) { CarrierService thisService = CarrierService.Builder.newInstance(idNewService, link.getId()) - .setCapacityDemand(singleDemandForThisLink).setServiceDuration(serviceTime) + .setDemand(singleDemandForThisLink).setServiceDuration(serviceTime) .setServiceStartTimeWindow(newDemandInformationElement.getFirstJobElementTimeWindow()) .build(); CarriersUtils.getCarriers(scenario).getCarriers() @@ -1051,8 +1051,8 @@ private static void createSingleShipment(Scenario scenario, DemandInformationEle CarrierShipment thisShipment = CarrierShipment.Builder .newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), singleDemandForThisLink) - .setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup) - .setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery) + .setPickupDuration(serviceTimePickup).setPickupStartsTimeWindow(timeWindowPickup) + .setDeliveryDuration(serviceTimeDelivery).setDeliveryStartsTimeWindow(timeWindowDelivery) .build(); thisCarrier.getShipments().put(thisShipment.getId(), thisShipment); if (demandForThisLink == 0) @@ -1188,11 +1188,12 @@ private static void combineSimilarJobs(Scenario scenario) { if (!shipmentsToRemove.containsKey(thisShipmentId)) { CarrierShipment thisShipment = thisCarrier.getShipments().get(thisShipmentId); if (baseShipment.getId() != thisShipment.getId() - && baseShipment.getFrom() == thisShipment.getFrom() - && baseShipment.getTo() == thisShipment.getTo() - && baseShipment.getPickupTimeWindow() == thisShipment.getPickupTimeWindow() - && baseShipment.getDeliveryTimeWindow() == thisShipment.getDeliveryTimeWindow()) - shipmentsToConnect.put(thisShipmentId, thisShipment); + && baseShipment.getPickupLinkId() == thisShipment.getPickupLinkId() + && baseShipment.getDeliveryLinkId() == thisShipment.getDeliveryLinkId()) { + if (baseShipment.getPickupStartsTimeWindow() == thisShipment.getPickupStartsTimeWindow()) { + if (baseShipment.getDeliveryStartsTimeWindow() == thisShipment.getDeliveryStartsTimeWindow()) shipmentsToConnect.put(thisShipmentId, thisShipment); + } + } } } Id idNewShipment = baseShipment.getId(); @@ -1200,17 +1201,17 @@ private static void combineSimilarJobs(Scenario scenario) { double serviceTimePickup = 0; double serviceTimeDelivery = 0; for (CarrierShipment carrierShipment : shipmentsToConnect.values()) { - demandForThisLink = demandForThisLink + carrierShipment.getSize(); - serviceTimePickup = serviceTimePickup + carrierShipment.getPickupServiceTime(); - serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryServiceTime(); + demandForThisLink = demandForThisLink + carrierShipment.getDemand(); + serviceTimePickup = serviceTimePickup + carrierShipment.getPickupDuration(); + serviceTimeDelivery = serviceTimeDelivery + carrierShipment.getDeliveryDuration(); shipmentsToRemove.put(carrierShipment.getId(), carrierShipment); } CarrierShipment newShipment = CarrierShipment.Builder - .newInstance(idNewShipment, baseShipment.getFrom(), baseShipment.getTo(), demandForThisLink) - .setPickupServiceTime(serviceTimePickup) - .setPickupTimeWindow(baseShipment.getPickupTimeWindow()) - .setDeliveryServiceTime(serviceTimeDelivery) - .setDeliveryTimeWindow(baseShipment.getDeliveryTimeWindow()).build(); + .newInstance(idNewShipment, baseShipment.getPickupLinkId(), baseShipment.getDeliveryLinkId(), demandForThisLink) + .setPickupDuration(serviceTimePickup) + .setPickupStartsTimeWindow(baseShipment.getPickupStartsTimeWindow()) + .setDeliveryDuration(serviceTimeDelivery) + .setDeliveryStartsTimeWindow(baseShipment.getDeliveryStartsTimeWindow()).build(); shipmentsToAdd.add(newShipment); } } @@ -1236,7 +1237,7 @@ private static void combineSimilarJobs(Scenario scenario) { if (!servicesToRemove.containsKey(thisServiceId)) { CarrierService thisService = thisCarrier.getServices().get(thisServiceId); if (baseService.getId() != thisService.getId() - && baseService.getLocationLinkId() == thisService.getLocationLinkId() && baseService + && baseService.getServiceLinkId() == thisService.getServiceLinkId() && baseService .getServiceStartTimeWindow() == thisService.getServiceStartTimeWindow()) servicesToConnect.put(thisServiceId, thisService); } @@ -1245,15 +1246,15 @@ private static void combineSimilarJobs(Scenario scenario) { int demandForThisLink = 0; double serviceTimeService = 0; for (CarrierService carrierService : servicesToConnect.values()) { - demandForThisLink = demandForThisLink + carrierService.getCapacityDemand(); + demandForThisLink = demandForThisLink + carrierService.getDemand(); serviceTimeService = serviceTimeService + carrierService.getServiceDuration(); servicesToRemove.put(carrierService.getId(), carrierService); } CarrierService newService = CarrierService.Builder - .newInstance(idNewService, baseService.getLocationLinkId()) + .newInstance(idNewService, baseService.getServiceLinkId()) .setServiceDuration(serviceTimeService) .setServiceStartTimeWindow(baseService.getServiceStartTimeWindow()) - .setCapacityDemand(demandForThisLink).build(); + .setDemand(demandForThisLink).build(); servicesToAdd.add(newService); } } diff --git a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGenerationUtils.java b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGenerationUtils.java index ede28ace76d..235789535db 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGenerationUtils.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGenerationUtils.java @@ -130,23 +130,23 @@ static void createDemandLocationsFile(Controler controler) { for (Carrier thisCarrier : CarriersUtils.getCarriers(controler.getScenario()).getCarriers().values()) { for (CarrierService thisService : thisCarrier.getServices().values()) { Coord coord = FreightDemandGenerationUtils - .getCoordOfMiddlePointOfLink(network.getLinks().get(thisService.getLocationLinkId())); + .getCoordOfMiddlePointOfLink(network.getLinks().get(thisService.getServiceLinkId())); writer.write(thisCarrier.getId().toString() + thisService.getId().toString() + " " + coord.getX() + " " + coord.getY() + " " + "Service" + " " - + thisService.getLocationLinkId().toString() + " " + "\n"); + + thisService.getServiceLinkId().toString() + " " + "\n"); } for (CarrierShipment thisShipment : thisCarrier.getShipments().values()) { Coord coordFrom = FreightDemandGenerationUtils - .getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getFrom())); + .getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getPickupLinkId())); Coord coordTo = FreightDemandGenerationUtils - .getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getTo())); + .getCoordOfMiddlePointOfLink(network.getLinks().get(thisShipment.getDeliveryLinkId())); writer.write(thisCarrier.getId().toString() + thisShipment.getId().toString() + " " + coordFrom.getX() + " " + coordFrom.getY() + " " + "Pickup" + " " - + thisShipment.getFrom().toString() + " " + thisShipment.getTo().toString() + "\n"); + + thisShipment.getPickupLinkId().toString() + " " + thisShipment.getDeliveryLinkId().toString() + "\n"); writer.write(thisCarrier.getId().toString() + thisShipment.getId() + " " + coordTo.getX() + " " + coordTo.getY() + " " + "Delivery" + " " - + thisShipment.getFrom() + " " + thisShipment.getTo() + "\n"); + + thisShipment.getPickupLinkId() + " " + thisShipment.getDeliveryLinkId() + "\n"); } } writer.flush(); diff --git a/contribs/application/src/test/java/org/matsim/freightDemandGeneration/DemandReaderFromCSVTest.java b/contribs/application/src/test/java/org/matsim/freightDemandGeneration/DemandReaderFromCSVTest.java index 9cd21c16d9d..32972385d8a 100644 --- a/contribs/application/src/test/java/org/matsim/freightDemandGeneration/DemandReaderFromCSVTest.java +++ b/contribs/application/src/test/java/org/matsim/freightDemandGeneration/DemandReaderFromCSVTest.java @@ -101,17 +101,17 @@ void demandCreationWithSampleWithChangeNumberOfLocations() throws IOException { locationsPerShipmentElement = new HashMap<>(); countDemand = 0; for (CarrierShipment shipment : testCarrier3.getShipments().values()) { - countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum); - countDemand = countDemand + shipment.getSize(); - Assertions.assertEquals(5, shipment.getSize()); - Assertions.assertEquals(2000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(1250, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow()); + countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum); + countDemand = countDemand + shipment.getDemand(); + Assertions.assertEquals(5, shipment.getDemand()); + Assertions.assertEquals(2000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(1250, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); + .add(shipment.getDeliveryLinkId().toString()); } Assertions.assertEquals(20, countDemand); Assertions.assertEquals(4, countShipmentsWithCertainDemand.getInt(5)); @@ -168,17 +168,17 @@ void demandCreationWithSampleWithDemandOnLocation() throws IOException { locationsPerShipmentElement = new HashMap<>(); countDemand = 0; for (CarrierShipment shipment : testCarrier3.getShipments().values()) { - countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum); - countDemand = countDemand + shipment.getSize(); - Assertions.assertEquals(10, shipment.getSize()); - Assertions.assertEquals(4000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(2500, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow()); + countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum); + countDemand = countDemand + shipment.getDemand(); + Assertions.assertEquals(10, shipment.getDemand()); + Assertions.assertEquals(4000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(2500, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); + .add(shipment.getDeliveryLinkId().toString()); } Assertions.assertEquals(20, countDemand); Assertions.assertEquals(2, countShipmentsWithCertainDemand.getInt(10)); @@ -235,17 +235,17 @@ void demandCreationWithSampleWithDemandOnLocationWithCombiningJobs() throws IOEx locationsPerShipmentElement = new HashMap<>(); countDemand = 0; for (CarrierShipment shipment : testCarrier3.getShipments().values()) { - countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum); - countDemand = countDemand + shipment.getSize(); - Assertions.assertEquals(10, shipment.getSize()); - Assertions.assertEquals(4000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(2500, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow()); + countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum); + countDemand = countDemand + shipment.getDemand(); + Assertions.assertEquals(10, shipment.getDemand()); + Assertions.assertEquals(4000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(2500, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); + .add(shipment.getDeliveryLinkId().toString()); } Assertions.assertEquals(20, countDemand); Assertions.assertEquals(2, countShipmentsWithCertainDemand.getInt(10)); @@ -305,17 +305,17 @@ void demandCreationNoSampling() throws IOException { locationsPerShipmentElement = new HashMap<>(); countDemand = 0; for (CarrierShipment shipment : testCarrier3.getShipments().values()) { - countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum); - countDemand = countDemand + shipment.getSize(); - Assertions.assertEquals(10, shipment.getSize()); - Assertions.assertEquals(4000, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(2500, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryTimeWindow()); + countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum); + countDemand = countDemand + shipment.getDemand(); + Assertions.assertEquals(10, shipment.getDemand()); + Assertions.assertEquals(4000, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(2500, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(8000, 50000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(10000, 60000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); + .add(shipment.getDeliveryLinkId().toString()); } Assertions.assertEquals(20, countDemand); Assertions.assertEquals(2, countShipmentsWithCertainDemand.getInt(10)); @@ -474,25 +474,27 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt Map> locationsPerServiceElement = new HashMap<>(); int countDemand = 0; for (CarrierService service : testCarrier1.getServices().values()) { - countServicesWithCertainDemand.merge((Integer) service.getCapacityDemand(), 1, Integer::sum); - countDemand = countDemand + service.getCapacityDemand(); - if (service.getCapacityDemand() == 0) { + countServicesWithCertainDemand.merge((Integer) service.getDemand(), 1, Integer::sum); + countDemand = countDemand + service.getDemand(); + if (service.getDemand() == 0) { Assertions.assertEquals(180, service.getServiceDuration(), MatsimTestUtils.EPSILON); Assertions.assertEquals(TimeWindow.newInstance(3000, 13000), service.getServiceStartTimeWindow()); locationsPerServiceElement.computeIfAbsent("serviceElement1", (k) -> new HashSet<>()) - .add(service.getLocationLinkId().toString()); - } else if (service.getCapacityDemand() == 1) { + .add(service.getServiceLinkId().toString()); + } else if (service.getDemand() == 1) { Assertions.assertEquals(100, service.getServiceDuration(), MatsimTestUtils.EPSILON); Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow()); locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>()) - .add(service.getLocationLinkId().toString()); - } else if (service.getCapacityDemand() == 2) { - Assertions.assertEquals(200, service.getServiceDuration(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow()); - locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>()) - .add(service.getLocationLinkId().toString()); - } else - Assertions.fail("Service has a wrong demand."); + .add(service.getServiceLinkId().toString()); + } else { + if (service.getDemand() == 2) { + Assertions.assertEquals(200, service.getServiceDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow()); + locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>()) + .add(service.getServiceLinkId().toString()); + } else + Assertions.fail("Service has a wrong demand."); + } } Assertions.assertEquals(12, countDemand); Assertions.assertEquals(4, countServicesWithCertainDemand.getInt(0)); @@ -520,37 +522,39 @@ private static void checkCarrier1and2(Scenario scenario, Network network, ShpOpt Map> locationsPerShipmentElement = new HashMap<>(); countDemand = 0; for (CarrierShipment shipment : testCarrier2.getShipments().values()) { - countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum); - countDemand = countDemand + shipment.getSize(); - if (shipment.getSize() == 0) { - Assertions.assertEquals(300, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(350, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryTimeWindow()); + countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum); + countDemand = countDemand + shipment.getDemand(); + if (shipment.getDemand() == 0) { + Assertions.assertEquals(300, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(350, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); - } else if (shipment.getSize() == 2) { - Assertions.assertEquals(400, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(400, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow()); + .add(shipment.getDeliveryLinkId().toString()); + } else if (shipment.getDemand() == 2) { + Assertions.assertEquals(400, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(400, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); - } else if (shipment.getSize() == 3) { - Assertions.assertEquals(600, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(600, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow()); - locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); - locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); - } else - Assertions.fail("Shipment has an unexpected demand."); + .add(shipment.getDeliveryLinkId().toString()); + } else { + if (shipment.getDemand() == 3) { + Assertions.assertEquals(600, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(600, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryStartsTimeWindow()); + locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>()) + .add(shipment.getPickupLinkId().toString()); + locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>()) + .add(shipment.getDeliveryLinkId().toString()); + } else + Assertions.fail("Shipment has an unexpected demand."); + } } Assertions.assertEquals(15, countDemand); Assertions.assertEquals(4, countShipmentsWithCertainDemand.getInt(0)); @@ -579,18 +583,18 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ Map> locationsPerServiceElement = new HashMap<>(); int countDemand = 0; for (CarrierService service : testCarrier1.getServices().values()) { - countServicesWithCertainDemand.merge((Integer) service.getCapacityDemand(), 1, Integer::sum); - countDemand = countDemand + service.getCapacityDemand(); - if (service.getCapacityDemand() == 0) { + countServicesWithCertainDemand.merge((Integer) service.getDemand(), 1, Integer::sum); + countDemand = countDemand + service.getDemand(); + if (service.getDemand() == 0) { Assertions.assertEquals(180, service.getServiceDuration(), MatsimTestUtils.EPSILON); Assertions.assertEquals(TimeWindow.newInstance(3000, 13000), service.getServiceStartTimeWindow()); locationsPerServiceElement.computeIfAbsent("serviceElement1", (k) -> new HashSet<>()) - .add(service.getLocationLinkId().toString()); + .add(service.getServiceLinkId().toString()); } else { - Assertions.assertEquals(service.getCapacityDemand() * 100, service.getServiceDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(service.getDemand() * 100, service.getServiceDuration(), MatsimTestUtils.EPSILON); Assertions.assertEquals(TimeWindow.newInstance(5000, 20000), service.getServiceStartTimeWindow()); locationsPerServiceElement.computeIfAbsent("serviceElement2", (k) -> new HashSet<>()) - .add(service.getLocationLinkId().toString()); + .add(service.getServiceLinkId().toString()); } } Assertions.assertEquals(12, countDemand); @@ -617,26 +621,26 @@ private static void checkCarrier1and2WithCombiningJobs(Scenario scenario, Networ Map> locationsPerShipmentElement = new HashMap<>(); countDemand = 0; for (CarrierShipment shipment : testCarrier2.getShipments().values()) { - countShipmentsWithCertainDemand.merge((Integer) shipment.getSize(), 1, Integer::sum); - countDemand = countDemand + shipment.getSize(); - if (shipment.getSize() == 0) { - Assertions.assertEquals(300, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(350, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryTimeWindow()); + countShipmentsWithCertainDemand.merge((Integer) shipment.getDemand(), 1, Integer::sum); + countDemand = countDemand + shipment.getDemand(); + if (shipment.getDemand() == 0) { + Assertions.assertEquals(300, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(350, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(10000, 45000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement1_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); + .add(shipment.getDeliveryLinkId().toString()); } else { - Assertions.assertEquals(shipment.getSize() * 200, shipment.getPickupServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(shipment.getSize() * 200, shipment.getDeliveryServiceTime(), MatsimTestUtils.EPSILON); - Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupTimeWindow()); - Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryTimeWindow()); + Assertions.assertEquals(shipment.getDemand() * 200, shipment.getPickupDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(shipment.getDemand() * 200, shipment.getDeliveryDuration(), MatsimTestUtils.EPSILON); + Assertions.assertEquals(TimeWindow.newInstance(11000, 44000), shipment.getPickupStartsTimeWindow()); + Assertions.assertEquals(TimeWindow.newInstance(20000, 40000), shipment.getDeliveryStartsTimeWindow()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_pickup", (k) -> new HashSet<>()) - .add(shipment.getFrom().toString()); + .add(shipment.getPickupLinkId().toString()); locationsPerShipmentElement.computeIfAbsent("ShipmentElement2_delivery", (k) -> new HashSet<>()) - .add(shipment.getTo().toString()); + .add(shipment.getDeliveryLinkId().toString()); } } Assertions.assertEquals(15, countDemand); diff --git a/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/DefaultCommercialJobGenerator.java b/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/DefaultCommercialJobGenerator.java index 3327f46292c..2891b802294 100644 --- a/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/DefaultCommercialJobGenerator.java +++ b/contribs/commercialTrafficApplications/src/main/java/org/matsim/contrib/commercialTrafficApplications/jointDemand/DefaultCommercialJobGenerator.java @@ -329,7 +329,7 @@ public void generateIterationServices(Carriers carriers, Population population) double latestStart = Double.parseDouble(commercialJobProperties.get(COMMERCIALJOB_ATTRIBUTE_END_IDX)); CarrierService.Builder serviceBuilder = CarrierService.Builder.newInstance(serviceId, PopulationUtils.decideOnLinkIdForActivity(activity,scenario)); - serviceBuilder.setCapacityDemand(Integer.parseInt(commercialJobProperties.get(COMMERCIALJOB_ATTRIBUTE_AMOUNT_IDX))); + serviceBuilder.setDemand(Integer.parseInt(commercialJobProperties.get(COMMERCIALJOB_ATTRIBUTE_AMOUNT_IDX))); serviceBuilder.setServiceDuration(Double.parseDouble(commercialJobProperties.get(COMMERCIALJOB_ATTRIBUTE_DURATION_IDX))); serviceBuilder.setServiceStartTimeWindow(TimeWindow.newInstance(earliestStart,latestStart)); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierJob.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierJob.java index 1dc1cd32f8d..926c5ae379f 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierJob.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierJob.java @@ -1,5 +1,6 @@ package org.matsim.freight.carriers; +import org.matsim.api.core.v01.Id; import org.matsim.utils.objectattributes.attributable.Attributable; /** @@ -16,4 +17,7 @@ * future) It maybe gets generalized in way, that we only have one job definition with 1 or 2 * location(s). This then defines, if jsprit takes the job as a service or as a shipment. */ -public interface CarrierJob extends Attributable {} +public interface CarrierJob extends Attributable { + Id getId(); + int getDemand(); +} diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanReaderV1.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanReaderV1.java index 4bb90047d86..c22b5928899 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanReaderV1.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanReaderV1.java @@ -116,19 +116,19 @@ public void startTag(String name, Attributes attributes, Stack context) CarrierShipment.Builder shipmentBuilder = CarrierShipment.Builder.newInstance( Id.create( id, CarrierShipment.class ), Id.create( from, Link.class ), Id.create( to, Link.class ), size ); if( startPickup == null ){ - shipmentBuilder.setPickupTimeWindow( TimeWindow.newInstance( 0.0, Integer.MAX_VALUE ) ).setDeliveryTimeWindow( + shipmentBuilder.setPickupStartsTimeWindow( TimeWindow.newInstance( 0.0, Integer.MAX_VALUE ) ).setDeliveryStartsTimeWindow( TimeWindow.newInstance( 0.0, Integer.MAX_VALUE ) ); } else{ - shipmentBuilder.setPickupTimeWindow( TimeWindow.newInstance( getDouble( startPickup ), getDouble( endPickup ) ) ). - setDeliveryTimeWindow( + shipmentBuilder.setPickupStartsTimeWindow( TimeWindow.newInstance( getDouble( startPickup ), getDouble( endPickup ) ) ). + setDeliveryStartsTimeWindow( TimeWindow.newInstance( getDouble( startDelivery ), getDouble( endDelivery ) ) ); } - if( pickupServiceTime != null ) shipmentBuilder.setPickupServiceTime( getDouble( pickupServiceTime ) ); - if( deliveryServiceTime != null ) shipmentBuilder.setDeliveryServiceTime( getDouble( deliveryServiceTime ) ); + if( pickupServiceTime != null ) shipmentBuilder.setPickupDuration( getDouble( pickupServiceTime ) ); + if( deliveryServiceTime != null ) shipmentBuilder.setDeliveryDuration( getDouble( deliveryServiceTime ) ); CarrierShipment shipment = shipmentBuilder.build(); currentShipments.put( attributes.getValue( ID ), shipment ); CarriersUtils.addShipment(currentCarrier, shipment); @@ -208,16 +208,16 @@ public void startTag(String name, Attributes attributes, Stack context) case "pickup" -> { String id = attributes.getValue(SHIPMENT_ID); CarrierShipment s = currentShipments.get(id); - finishLeg(s.getFrom()); + finishLeg(s.getPickupLinkId()); currentTourBuilder.schedulePickup(s); - previousActLoc = s.getFrom(); + previousActLoc = s.getPickupLinkId(); } case "delivery" -> { String id = attributes.getValue(SHIPMENT_ID); CarrierShipment s = currentShipments.get(id); - finishLeg(s.getTo()); + finishLeg(s.getDeliveryLinkId()); currentTourBuilder.scheduleDelivery(s); - previousActLoc = s.getTo(); + previousActLoc = s.getDeliveryLinkId(); } case "end" -> { finishLeg(currentVehicle.getLinkId()); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2.java index 271871b0970..7bbc83c9479 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2.java @@ -117,7 +117,7 @@ public void startTag(String name, Attributes atts, Stack context) { Id to = Id.create(toLocation, Link.class); CarrierService.Builder serviceBuilder = CarrierService.Builder.newInstance(id, to); String capDemandString = atts.getValue("capacityDemand"); - if (capDemandString != null) serviceBuilder.setCapacityDemand(getInt(capDemandString)); + if (capDemandString != null) serviceBuilder.setDemand(getInt(capDemandString)); String startString = atts.getValue("earliestStart"); double start = parseTimeToDouble(startString); double end; @@ -157,13 +157,13 @@ public void startTag(String name, Attributes atts, Stack context) { String deliveryServiceTime = atts.getValue("deliveryServiceTime"); if (startPickup != null && endPickup != null) - shipmentBuilder.setPickupTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startPickup), parseTimeToDouble(endPickup))); + shipmentBuilder.setPickupStartsTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startPickup), parseTimeToDouble(endPickup))); if (startDelivery != null && endDelivery != null) - shipmentBuilder.setDeliveryTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startDelivery), parseTimeToDouble(endDelivery))); + shipmentBuilder.setDeliveryStartsTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startDelivery), parseTimeToDouble(endDelivery))); if (pickupServiceTime != null) - shipmentBuilder.setPickupServiceTime(parseTimeToDouble(pickupServiceTime)); + shipmentBuilder.setPickupDuration(parseTimeToDouble(pickupServiceTime)); if (deliveryServiceTime != null) - shipmentBuilder.setDeliveryServiceTime(parseTimeToDouble(deliveryServiceTime)); + shipmentBuilder.setDeliveryDuration(parseTimeToDouble(deliveryServiceTime)); currentShipment = shipmentBuilder.build(); currentShipments.put(atts.getValue(ID), currentShipment); @@ -261,26 +261,26 @@ public void startTag(String name, Attributes atts, Stack context) { String id = atts.getValue(SHIPMENT_ID); if (id == null) throw new IllegalStateException("pickup.shipmentId is missing."); CarrierShipment s = currentShipments.get(id); - finishLeg(s.getFrom()); + finishLeg(s.getPickupLinkId()); currentTourBuilder.schedulePickup(s); - previousActLoc = s.getFrom(); + previousActLoc = s.getPickupLinkId(); } case "delivery" -> { String id = atts.getValue(SHIPMENT_ID); if (id == null) throw new IllegalStateException("delivery.shipmentId is missing."); CarrierShipment s = currentShipments.get(id); - finishLeg(s.getTo()); + finishLeg(s.getDeliveryLinkId()); currentTourBuilder.scheduleDelivery(s); - previousActLoc = s.getTo(); + previousActLoc = s.getDeliveryLinkId(); } case "service" -> { String id = atts.getValue("serviceId"); if (id == null) throw new IllegalStateException("act.serviceId is missing."); CarrierService s = serviceMap.get(Id.create(id, CarrierService.class)); if (s == null) throw new IllegalStateException("serviceId is not known."); - finishLeg(s.getLocationLinkId()); + finishLeg(s.getServiceLinkId()); currentTourBuilder.scheduleService(s); - previousActLoc = s.getLocationLinkId(); + previousActLoc = s.getServiceLinkId(); } case "end" -> { finishLeg(currentVehicle.getLinkId()); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2_1.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2_1.java index 9c3f2b7a1e6..f439d323ddd 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2_1.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlParserV2_1.java @@ -115,7 +115,7 @@ public void startTag(String name, Attributes atts, Stack context) { Id to = Id.create(toLocation, Link.class); CarrierService.Builder serviceBuilder = CarrierService.Builder.newInstance(id, to); String capDemandString = atts.getValue("capacityDemand"); - if (capDemandString != null) serviceBuilder.setCapacityDemand(getInt(capDemandString)); + if (capDemandString != null) serviceBuilder.setDemand(getInt(capDemandString)); String startString = atts.getValue("earliestStart"); double start = parseTimeToDouble(startString); double end; @@ -155,13 +155,13 @@ public void startTag(String name, Attributes atts, Stack context) { String deliveryServiceTime = atts.getValue("deliveryServiceTime"); if (startPickup != null && endPickup != null) - shipmentBuilder.setPickupTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startPickup), parseTimeToDouble(endPickup))); + shipmentBuilder.setPickupStartsTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startPickup), parseTimeToDouble(endPickup))); if (startDelivery != null && endDelivery != null) - shipmentBuilder.setDeliveryTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startDelivery), parseTimeToDouble(endDelivery))); + shipmentBuilder.setDeliveryStartsTimeWindow(TimeWindow.newInstance(parseTimeToDouble(startDelivery), parseTimeToDouble(endDelivery))); if (pickupServiceTime != null) - shipmentBuilder.setPickupServiceTime(parseTimeToDouble(pickupServiceTime)); + shipmentBuilder.setPickupDuration(parseTimeToDouble(pickupServiceTime)); if (deliveryServiceTime != null) - shipmentBuilder.setDeliveryServiceTime(parseTimeToDouble(deliveryServiceTime)); + shipmentBuilder.setDeliveryDuration(parseTimeToDouble(deliveryServiceTime)); currentShipment = shipmentBuilder.build(); currentShipments.put(atts.getValue(ID), currentShipment); @@ -263,26 +263,26 @@ public void startTag(String name, Attributes atts, Stack context) { String id = atts.getValue(SHIPMENT_ID); if (id == null) throw new IllegalStateException("pickup.shipmentId is missing."); CarrierShipment s = currentShipments.get(id); - finishLeg(s.getFrom()); + finishLeg(s.getPickupLinkId()); currentTourBuilder.schedulePickup(s); - previousActLoc = s.getFrom(); + previousActLoc = s.getPickupLinkId(); } case "delivery" -> { String id = atts.getValue(SHIPMENT_ID); if (id == null) throw new IllegalStateException("delivery.shipmentId is missing."); CarrierShipment s = currentShipments.get(id); - finishLeg(s.getTo()); + finishLeg(s.getDeliveryLinkId()); currentTourBuilder.scheduleDelivery(s); - previousActLoc = s.getTo(); + previousActLoc = s.getDeliveryLinkId(); } case "service" -> { String id = atts.getValue("serviceId"); if (id == null) throw new IllegalStateException("act.serviceId is missing."); CarrierService s = serviceMap.get(Id.create(id, CarrierService.class)); if (s == null) throw new IllegalStateException("serviceId is not known."); - finishLeg(s.getLocationLinkId()); + finishLeg(s.getServiceLinkId()); currentTourBuilder.scheduleService(s); - previousActLoc = s.getLocationLinkId(); + previousActLoc = s.getServiceLinkId(); } case "end" -> { finishLeg(currentVehicle.getLinkId()); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlWriterV2_1.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlWriterV2_1.java index 6195fb3834f..811153ead21 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlWriterV2_1.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierPlanXmlWriterV2_1.java @@ -159,15 +159,15 @@ private void writeShipments(Carrier carrier, BufferedWriter writer) { private void writeShipment(CarrierShipment s, Id shipmentId, boolean closeElement, boolean lineBreak) { this.writeStartTag(SHIPMENT, List.of( createTuple(ID, shipmentId.toString()), - createTuple(FROM, s.getFrom().toString()), - createTuple(TO, s.getTo().toString()), - createTuple(SIZE, s.getSize()), - createTuple(START_PICKUP, getTime(s.getPickupTimeWindow().getStart())), - createTuple(END_PICKUP, getTime(s.getPickupTimeWindow().getEnd())), - createTuple(START_DELIVERY, getTime(s.getDeliveryTimeWindow().getStart())), - createTuple(END_DELIVERY, getTime(s.getDeliveryTimeWindow().getEnd())), - createTuple(PICKUP_SERVICE_TIME, getTime(s.getPickupServiceTime())), - createTuple(DELIVERY_SERVICE_TIME, getTime(s.getDeliveryServiceTime()))), closeElement, lineBreak + createTuple(FROM, s.getPickupLinkId().toString()), + createTuple(TO, s.getDeliveryLinkId().toString()), + createTuple(SIZE, s.getDemand()), + createTuple(START_PICKUP, getTime(s.getPickupStartsTimeWindow().getStart())), + createTuple(END_PICKUP, getTime(s.getPickupStartsTimeWindow().getEnd())), + createTuple(START_DELIVERY, getTime(s.getDeliveryStartsTimeWindow().getStart())), + createTuple(END_DELIVERY, getTime(s.getDeliveryStartsTimeWindow().getEnd())), + createTuple(PICKUP_SERVICE_TIME, getTime(s.getPickupDuration())), + createTuple(DELIVERY_SERVICE_TIME, getTime(s.getDeliveryDuration()))), closeElement, lineBreak ); } @@ -190,8 +190,8 @@ private void writeServices(Carrier carrier, BufferedWriter writer) { private void writeService(CarrierService s, boolean closeElement, boolean lineBreak) { this.writeStartTag(SERVICE, List.of( createTuple(ID, s.getId().toString()), - createTuple(TO, s.getLocationLinkId().toString()), - createTuple(CAPACITY_DEMAND, s.getCapacityDemand()), + createTuple(TO, s.getServiceLinkId().toString()), + createTuple(CAPACITY_DEMAND, s.getDemand()), createTuple(EARLIEST_START, getTime(s.getServiceStartTimeWindow().getStart())), createTuple(LATEST_END, getTime(s.getServiceStartTimeWindow().getEnd())), createTuple(SERVICE_DURATION, getTime(s.getServiceDuration()))), closeElement, lineBreak diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierService.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierService.java index 69a5ce75e42..99be9a2f21f 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierService.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierService.java @@ -23,7 +23,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; -import org.matsim.utils.objectattributes.attributable.Attributable; import org.matsim.utils.objectattributes.attributable.Attributes; import org.matsim.utils.objectattributes.attributable.AttributesImpl; @@ -31,95 +30,127 @@ public final class CarrierService implements CarrierJob { public static class Builder { + private final Id id; + private int demand = 0; + + //IMO we could build a general class (CarrierActivity ???), containing the location, StartTimeWindow and Duration. + //This could be used for both, CarrierService and CarrierShipment (Pickup and Delivery). + //kturner dec'24 + private final Id serviceLinkId; + private TimeWindow serviceStartsTimeWindow = TimeWindow.newInstance(0.0, Integer.MAX_VALUE); + private double serviceDuration = 0.0; + public static Builder newInstance(Id id, Id locationLinkId){ return new Builder(id,locationLinkId); } - private final Id id; - private final Id locationLinkId; - private String name = "service"; - - private double serviceTime = 0.0; - private TimeWindow timeWindow = TimeWindow.newInstance(0.0, Integer.MAX_VALUE); - private int capacityDemand = 0; - - private Builder(Id id, Id locationLinkId) { + private Builder(Id id, Id serviceLinkId) { super(); this.id = id; - this.locationLinkId = locationLinkId; + this.serviceLinkId = serviceLinkId; } - public Builder setName(String name){ - this.name = name; + public CarrierService build(){ + return new CarrierService(this); + } + + + /** + * Sets a time-window for the beginning of the service + * When not set, it is by default [0.0., Integer.MAX_VALUE]. + *

+ * Note that the time-window restricts the start-time of the service (i.e. serviceActivity). If one works with hard time-windows (which means that + * time-windows must be met) than the service is allowed to start between startTimeWindow.getStart() and startTimeWindow.getEnd(). + * + * @param startTimeWindow time-window for the beginning of the service activity + * @return the builder + */ + public Builder setServiceStartTimeWindow(TimeWindow startTimeWindow){ + this.serviceStartsTimeWindow = startTimeWindow; return this; } /** - * By default, it is [0.0,Integer.MaxValue]. + * Sets the duration for the pickup activity. + * When not set, it is by default 0.0. * * @param serviceDuration duration of the service * @return the builder */ public Builder setServiceDuration(double serviceDuration){ - this.serviceTime = serviceDuration; + this.serviceDuration = serviceDuration; return this; } /** - * Sets a time-window for the service. - * - *

Note that the time-window restricts the start-time of the service (i.e. serviceActivity). If one works with hard time-windows (which means that - * time-windows must be met) than the service is allowed to start between startTimeWindow.getStart() and startTimeWindow.getEnd(). + * Sets the demand (size; capacity needed) of the service. + * When not set, it is by default 0. + *

+ * IMO we can put this into the Builder directly instead of a separate method? kturner dec'24 * - * @param startTimeWindow time-window for the service - * @return the builder + * @param demand the demand (size; capacity needed) of the service + * @return the builder */ - public Builder setServiceStartTimeWindow(TimeWindow startTimeWindow){ - this.timeWindow = startTimeWindow; + public Builder setDemand(int demand) { + this.demand = demand; return this; } - public CarrierService build(){ - return new CarrierService(this); - } + /** + * Sets the demand (size; capacity needed) of the service. + * When not set, it is by default 0. + *

+ * IMO we can put this into the Builder directly instead of a separate method? kturner dec'24 + * + * @deprecated please use {@link #setDemand(int)} instead + * + * @param value the demand (size; capacity needed) of the service + * @return the builder + */ + @Deprecated(since = "dec'24") public Builder setCapacityDemand(int value) { - this.capacityDemand = value; - return this; + return setDemand(value); } } private final Id id; + private final int demand; - private final Id locationId; - - private final String name; - + //IMO we could build a general class (CarrierActivity ???), containing the location, StartTimeWindow and Duration. + //This could be used for both, CarrierService and CarrierShipment (Pickup and Delivery). + //kturner dec'24 + private final Id serviceLinkId; + private final TimeWindow serviceStartsTimeWindow; private final double serviceDuration; - private final TimeWindow timeWindow; - - private final int demand; - private final Attributes attributes = new AttributesImpl(); private CarrierService(Builder builder){ id = builder.id; - locationId = builder.locationLinkId; - serviceDuration = builder.serviceTime; - timeWindow = builder.timeWindow; - demand = builder.capacityDemand; - name = builder.name; + serviceLinkId = builder.serviceLinkId; + serviceDuration = builder.serviceDuration; + serviceStartsTimeWindow = builder.serviceStartsTimeWindow; + demand = builder.demand; } + @Override public Id getId() { return id; } + public Id getServiceLinkId() { + return serviceLinkId; + } + + /** + * @deprecated please inline and use {@link #getServiceLinkId()} instead + */ + @Deprecated(since = "dec'24") public Id getLocationLinkId() { - return locationId; + return getServiceLinkId(); } public double getServiceDuration() { @@ -127,28 +158,35 @@ public double getServiceDuration() { } public TimeWindow getServiceStartTimeWindow(){ - return timeWindow; + return serviceStartsTimeWindow; } + /** + * @deprecated please inline and use {@link #getDemand()} instead + */ + @Deprecated(since = "dec'24") public int getCapacityDemand() { + return getDemand(); + } + + /** + * @return the demand (size; capacity needed) of the service. + */ + @Override + public int getDemand() { return demand; } + @Override public Attributes getAttributes() { return attributes; } - /** - * @return the name - */ - public String getType() { - return name; - } @Override public String toString() { - return "[id=" + id + "][locationId=" + locationId + "][capacityDemand=" + demand + "][serviceDuration=" + serviceDuration + "][startTimeWindow=" + timeWindow + "]"; + return "[id=" + id + "][locationId=" + serviceLinkId + "][capacityDemand=" + demand + "][serviceDuration=" + serviceDuration + "][startTimeWindow=" + serviceStartsTimeWindow + "]"; } /* (non-Javadoc) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierShipment.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierShipment.java index 01c8b873e70..a74177246d5 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierShipment.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarrierShipment.java @@ -23,7 +23,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; -import org.matsim.utils.objectattributes.attributable.Attributable; import org.matsim.utils.objectattributes.attributable.Attributes; import org.matsim.utils.objectattributes.attributable.AttributesImpl; @@ -46,152 +45,231 @@ public final class CarrierShipment implements CarrierJob { */ public static class Builder { + private final Id id; + private final int demand; + + //IMO we could build a general class (CarrierActivity ???), containing the location, StartTimeWindow and Duration. + //This could be used for both, CarrierService and CarrierShipment (Pickup and Delivery). + //kturner dec'24 + private final Id pickupLinkId; + private TimeWindow pickupStartsTimeWindow = TimeWindow.newInstance(0.0, Integer.MAX_VALUE); + private double pickupDuration = 0.0; + + //IMO we could build a general class (CarrierActivity ???), containing the location, StartTimeWindow and Duration. + //This could be used for both, CarrierService and CarrierShipment (Pickup and Delivery). + //kturner dec'24 + private final Id deliveryLinkId; + private TimeWindow deliveryStartsTimeWindow = TimeWindow.newInstance(0.0, Integer.MAX_VALUE); + private double deliveryDuration = 0.0; + /** - * @deprecated Please use Builder newInstance(Id id, Id from, Id to, int size) instead. - *

* Returns a new shipment builder. - * - *

The builder is init with the shipment's origin (from), destination (to) and with the shipment's size. + *

+ * The builder is init with the shipment's origin (from), destination (to) and with the shipment's demand. * The default-value for serviceTime is 0.0. The default-value for a timeWindow is [start=0.0, end=Double.maxValue()]. * + * @param id the id of the shipment * @param from the origin * @param to the destination - * @param size size of the shipment + * @param demand demand of the shipment * @return the builder */ - @Deprecated - public static Builder newInstance(Id from, Id to, int size){ - return new Builder(from,to,size); + public static Builder newInstance(Id id, Id from, Id to, int demand){ + return new Builder(id, from, to, demand); + } + + private Builder(Id id, Id pickupLinkId, Id deliveryLinkId, int demand) { + super(); + this.id = id; + this.pickupLinkId = pickupLinkId; + this.deliveryLinkId = deliveryLinkId; + this.demand = demand; } /** - * Returns a new shipment builder. - * - *

The builder is init with the shipment's origin (from), destination (to) and with the shipment's size. - * The default-value for serviceTime is 0.0. The default-value for a timeWindow is [start=0.0, end=Double.maxValue()]. + * Sets a time-window for the beginning of the pickup + * When not set, it is by default [0.0., Integer.MAX_VALUE]. + *

+ * Note that the time-window restricts the start-time of the shipment's pickup . If one works with hard time-windows (which means that + * time-windows must be met) than the pickup is allowed to start between startTimeWindow.getStart() and startTimeWindow.getEnd(). * - * @param id the id of the shipment - * @param from the origin - * @param to the destination - * @param size size of the shipment - * @return the builder + * @param pickupStartsTimeWindow time-window for the beginning of the pickup activity + * @return the builder */ - public static Builder newInstance(Id id, Id from, Id to, int size){ - return new Builder(id, from,to,size); + public Builder setPickupStartsTimeWindow(TimeWindow pickupStartsTimeWindow){ + this.pickupStartsTimeWindow = pickupStartsTimeWindow; + return this; } - Id id; - final Id from; - final Id to; - final int size; - TimeWindow pickTW = TimeWindow.newInstance(0.0, Integer.MAX_VALUE); - TimeWindow delTW = TimeWindow.newInstance(0.0, Integer.MAX_VALUE); - double pickServiceTime = 0.0; - double delServiceTime = 0.0; + /** + * Sets the duration for the pickup activity. + * When not set, it is by default 0.0. + * + * @param pickupDuration Duration of the pickup activity (in seconds). + * @return the Builder + */ + public Builder setPickupDuration(double pickupDuration){ + this.pickupDuration = pickupDuration; + return this; + } /** - * @deprecated Please use Builder (Id id, Id from, Id to, int size) instead. + * Sets a time-window for the beginning of the delivery + * When not set, it is by default [0.0., Integer.MAX_VALUE]. + *

+ * Note that the time-window restricts the start-time of the shipment's delivery . If one works with hard time-windows (which means that + * time-windows must be met) than the delivery is allowed to start between startTimeWindow.getStart() and startTimeWindow.getEnd(). + * + * @param deliveryStartsTimeWindow time-window for the beginning of the delivery activity + * @return the builder */ - @Deprecated - public Builder(Id from, Id to, int size) { - super(); - this.from = from; - this.to = to; - this.size = size; + public Builder setDeliveryStartsTimeWindow(TimeWindow deliveryStartsTimeWindow){ + this.deliveryStartsTimeWindow = deliveryStartsTimeWindow; + return this; } - public Builder(Id id, Id from, Id to, int size) { - super(); - this.id = id; - this.from = from; - this.to = to; - this.size = size; + /** + * Sets the duration for the delivery activity. + * When not set, it is by default 0.0. + * + * @param deliveryDuration Duration of the delivery activity (in seconds). + * @return the Builder + */ + public Builder setDeliveryDuration(double deliveryDuration){ + this.deliveryDuration = deliveryDuration; + return this; } - public Builder setPickupTimeWindow(TimeWindow pickupTW){ - this.pickTW = pickupTW; - return this; + public CarrierShipment build(){ + return new CarrierShipment(this); } - public Builder setDeliveryTimeWindow(TimeWindow deliveryTW){ - this.delTW = deliveryTW; - return this; + //*** deprecated methods *** + + + /** + * @deprecated please inline and use {@link #setPickupStartsTimeWindow(TimeWindow)} instead + */ + @Deprecated(since = "dec'24") + public Builder setPickupTimeWindow(TimeWindow pickupTW){ + return setPickupStartsTimeWindow(pickupTW); } + /** + * @deprecated please inline and use {@link #setPickupDuration(double)} instead + */ + @Deprecated(since = "dec'24") public Builder setPickupServiceTime(double pickupServiceTime){ - this.pickServiceTime = pickupServiceTime; - return this; + return setPickupDuration(pickupServiceTime); } - public Builder setDeliveryServiceTime(double deliveryServiceTime){ - this.delServiceTime = deliveryServiceTime; - return this; + /** + * @deprecated please inline and use {@link #setDeliveryStartsTimeWindow(TimeWindow)} instead + */ + @Deprecated(since = "dec'24") + public Builder setDeliveryTimeWindow(TimeWindow deliveryTW){ + return setDeliveryStartsTimeWindow(deliveryTW); } - public CarrierShipment build(){ - return new CarrierShipment(this); + /** + * @deprecated please inline and use {@link #setDeliveryDuration(double)} instead + */ + @Deprecated(since = "dec'24") + public Builder setDeliveryServiceTime(double deliveryServiceTime){ + return setDeliveryDuration(deliveryServiceTime); } } private final Id id; - private final Id from; - private final Id to; - private final int size; - private final TimeWindow pickupTimeWindow; - private final TimeWindow deliveryTimeWindow; - private double pickupServiceTime; - private double deliveryServiceTime; + private final int demand; + + //IMO we could build a general class (CarrierActivity ???), containing the location, StartTimeWindow and Duration. + //This could be used for both, CarrierService and CarrierShipment (Pickup and Delivery). + //kturner dec'24 + private final Id pickupLinkId; + private final TimeWindow pickupStartsTimeWindow; + private double pickupDuration; + + //IMO we could build a general class (CarrierActivity ???), containing the location, StartTimeWindow and Duration. + //This could be used for both, CarrierService and CarrierShipment (Pickup and Delivery). + //kturner dec'24 + private final Id deliveryLinkId; + private final TimeWindow deliveryStartsTimeWindow; + private double deliveryDuration; + private final Attributes attributes = new AttributesImpl(); private CarrierShipment(Builder builder) { id = builder.id; - from = builder.from; - to = builder.to; - size = builder.size; - pickupServiceTime = builder.pickServiceTime; - deliveryServiceTime = builder.delServiceTime; - pickupTimeWindow = builder.pickTW; - deliveryTimeWindow = builder.delTW; + pickupLinkId = builder.pickupLinkId; + deliveryLinkId = builder.deliveryLinkId; + demand = builder.demand; + pickupDuration = builder.pickupDuration; + deliveryDuration = builder.deliveryDuration; + pickupStartsTimeWindow = builder.pickupStartsTimeWindow; + deliveryStartsTimeWindow = builder.deliveryStartsTimeWindow; } - public double getPickupServiceTime() { - return pickupServiceTime; + //* getters and setters + + public double getPickupDuration() { + return pickupDuration; } - public void setPickupServiceTime(double pickupServiceTime) { - this.pickupServiceTime = pickupServiceTime; + public double getDeliveryDuration() { + return deliveryDuration; } - public double getDeliveryServiceTime() { - return deliveryServiceTime; + /** + * Do we really need the setter? We do have it in the builder. + * I do not see, why we should be able to update it, since most of the values are immutable. + * @deprecated Consider setting it using the Builder. This will maybe be removed and the field gets immutable. + * kturner, dec'24 + */ + @Deprecated(since = "dec'24") + public void setPickupDuration(double pickupDuration) { + this.pickupDuration = pickupDuration; } - public void setDeliveryServiceTime(double deliveryServiceTime) { - this.deliveryServiceTime = deliveryServiceTime; + /** + * Do we really need the setter? We do have it in the builder. + * I do not see, why we should be able to update it, since most of the values are immutable. + * @deprecated Consider setting it using the Builder. This will maybe be removed and the field gets immutable. + * kturner, dec'24 + */ + @Deprecated(since = "dec'24") + public void setDeliveryDuration(double deliveryDuration) { + this.deliveryDuration = deliveryDuration; } + @Override public Id getId() { return id; } - public Id getFrom() { - return from; + + public Id getPickupLinkId() { + return pickupLinkId; } - public Id getTo() { - return to; + public Id getDeliveryLinkId() { + return deliveryLinkId; } - public int getSize() { - return size; + /** + * @return the demand (size; capacity needed) of the shipment. + */ + @Override + public int getDemand() { + return demand; } - public TimeWindow getPickupTimeWindow() { - return pickupTimeWindow; + public TimeWindow getPickupStartsTimeWindow() { + return pickupStartsTimeWindow; } - public TimeWindow getDeliveryTimeWindow() { - return deliveryTimeWindow; + public TimeWindow getDeliveryStartsTimeWindow() { + return deliveryStartsTimeWindow; } @Override @@ -199,10 +277,88 @@ public Attributes getAttributes() { return attributes; } + //*** deprecated methods *** + + /** + * @deprecated please inline and use {@link #getDemand()} instead + */ + @Deprecated(since = "dec'24") + public int getSize() { + return getDemand(); + } + + + /** + * @deprecated please inline and use {@link #getPickupLinkId()} instead + */ + @Deprecated(since = "dec'24") + public Id getFrom() { + return getPickupLinkId(); + } + + /** + * @deprecated please inline and use {@link #getPickupStartsTimeWindow()} instead + */ + @Deprecated(since = "dec'24") + public TimeWindow getPickupTimeWindow() { + return getPickupStartsTimeWindow(); + } + + /** + * @deprecated please inline and use {@link #setPickupDuration(double)} instead + */ + @Deprecated(since = "dec'24") + public void setPickupServiceTime(double pickupDuration) { + setPickupDuration(pickupDuration); + } + + /** + * @deprecated please inline and use {@link #getPickupDuration()} instead + */ + @Deprecated(since = "dec'24") + public double getPickupServiceTime() { + return getPickupDuration(); + } + + + /** + * @deprecated please inline and use {@link #getDeliveryLinkId()} instead + */ + @Deprecated(since = "dec'24") + public Id getTo() { + return getDeliveryLinkId(); + } + + /** + * @deprecated please inline and use {@link #getDeliveryStartsTimeWindow()} instead + */ + @Deprecated(since = "dec'24") + public TimeWindow getDeliveryTimeWindow() { + return getDeliveryStartsTimeWindow(); + } + + /** + * @deprecated please inline and use {@link #getDeliveryDuration()} instead + */ + @Deprecated(since = "dec'24") + public double getDeliveryServiceTime() { + return getDeliveryDuration(); + } + + /** + * @deprecated please inline and use {@link #setDeliveryDuration(double)} instead + */ + @Deprecated(since = "dec'24") + public void setDeliveryServiceTime(double deliveryDuration) { + setDeliveryDuration(deliveryDuration); + } + + // *** general methods *** + @Override public String toString() { - return "[id= "+ id.toString() + "][hash=" + this.hashCode() + "][from=" + from.toString() + "][to=" + to.toString() + "][size=" + size + "][pickupServiceTime=" + pickupServiceTime + "]" + - "[deliveryServiceTime="+deliveryServiceTime+"][pickupTimeWindow="+pickupTimeWindow+"][deliveryTimeWindow="+deliveryTimeWindow+"]"; + return "[id= "+ id.toString() + "][hash=" + this.hashCode() + "][from=" + pickupLinkId.toString() + "][to=" + deliveryLinkId.toString() + "][size=" + demand + "][pickupServiceTime=" + pickupDuration + "]" + + "[deliveryServiceTime="+ deliveryDuration +"][pickupTimeWindow="+ pickupStartsTimeWindow +"][deliveryTimeWindow="+ deliveryStartsTimeWindow +"]"; } /* (non-Javadoc) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarriersUtils.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarriersUtils.java index 1b6a270e65e..d82e2e0ba46 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/CarriersUtils.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/CarriersUtils.java @@ -430,14 +430,14 @@ private static void createShipmentsFromServices(Carrier carrierWS, Carrier carri log.debug("Converting CarrierService to CarrierShipment: {}", carrierService.getId()); CarrierShipment carrierShipment = CarrierShipment.Builder .newInstance(Id.create(carrierService.getId().toString(), CarrierShipment.class), - depotServiceIsDeliveredFrom.get(carrierService.getId()), carrierService.getLocationLinkId(), - carrierService.getCapacityDemand()) - .setDeliveryServiceTime(carrierService.getServiceDuration()) + depotServiceIsDeliveredFrom.get(carrierService.getId()), carrierService.getServiceLinkId(), + carrierService.getDemand()) + .setDeliveryDuration(carrierService.getServiceDuration()) // .setPickupServiceTime(pickupServiceTime) //Not set yet, because in service we // have now time for that. Maybe change it later, kmt sep18 - .setDeliveryTimeWindow(carrierService.getServiceStartTimeWindow()) + .setDeliveryStartsTimeWindow(carrierService.getServiceStartTimeWindow()) // Limited to end of delivery timeWindow (pickup later than the latest delivery is not useful). - .setPickupTimeWindow(TimeWindow.newInstance(0.0, carrierService.getServiceStartTimeWindow().getEnd())) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, carrierService.getServiceStartTimeWindow().getEnd())) .build(); addShipment(carrierWS, carrierShipment); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/Tour.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/Tour.java index 55f72325237..fec5bc60655 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/Tour.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/Tour.java @@ -374,12 +374,12 @@ public CarrierService getService(){ @Override public String getActivityType() { - return service.getType(); + return CarrierConstants.SERVICE; } @Override public Id getLocation() { - return service.getLocationLinkId(); + return service.getServiceLinkId(); } @Override @@ -539,17 +539,17 @@ public String getActivityType() { @Override public TimeWindow getTimeWindow() { - return shipment.getPickupTimeWindow(); + return shipment.getPickupStartsTimeWindow(); } @Override public Id getLocation() { - return shipment.getFrom(); + return shipment.getPickupLinkId(); } @Override public double getDuration() { - return shipment.getPickupServiceTime(); + return shipment.getPickupDuration(); } @Override @@ -592,7 +592,7 @@ public Delivery(CarrierShipment shipment) { @Override public TimeWindow getTimeWindow() { - return shipment.getDeliveryTimeWindow(); + return shipment.getDeliveryStartsTimeWindow(); } @Override @@ -602,12 +602,12 @@ public String getActivityType() { @Override public Id getLocation() { - return shipment.getTo(); + return shipment.getDeliveryLinkId(); } @Override public double getDuration() { - return shipment.getDeliveryServiceTime(); + return shipment.getDeliveryDuration(); } @Override diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierPlanAnalysis.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierPlanAnalysis.java index 362dfaf8793..7c73cb9b551 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierPlanAnalysis.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierPlanAnalysis.java @@ -101,16 +101,16 @@ public void runAnalysisAndWriteStats(String analysisOutputDirectory) throws IOEx int numberOfHandledDemandSize; int notHandledJobs; if (numberOfPlanedShipments > 0) { - numberOfPlanedDemandSize = carrier.getShipments().values().stream().mapToInt(CarrierShipment::getSize).sum(); + numberOfPlanedDemandSize = carrier.getShipments().values().stream().mapToInt(carrierShipment -> carrierShipment.getDemand()).sum(); numberOfHandledDemandSize = carrier.getSelectedPlan().getScheduledTours().stream().mapToInt( t -> t.getTour().getTourElements().stream().filter(te -> te instanceof Tour.Pickup).mapToInt( - te -> (((Tour.Pickup) te).getShipment().getSize())).sum()).sum(); + te -> ((Tour.Pickup) te).getShipment().getDemand()).sum()).sum(); notHandledJobs = numberOfPlanedShipments - numberOfHandledPickups; } else { - numberOfPlanedDemandSize = carrier.getServices().values().stream().mapToInt(CarrierService::getCapacityDemand).sum(); + numberOfPlanedDemandSize = carrier.getServices().values().stream().mapToInt(carrierService -> carrierService.getDemand()).sum(); numberOfHandledDemandSize = carrier.getSelectedPlan().getScheduledTours().stream().mapToInt( t -> t.getTour().getTourElements().stream().filter(te -> te instanceof Tour.ServiceActivity).mapToInt( - te -> ((Tour.ServiceActivity) te).getService().getCapacityDemand()).sum()).sum(); + te -> ((Tour.ServiceActivity) te).getService().getDemand()).sum()).sum(); notHandledJobs = numberOfPlanedServices - nuOfServiceHandled; } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceEndEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceEndEvent.java index f806248471c..17907fe74eb 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceEndEvent.java @@ -42,7 +42,7 @@ public final class CarrierServiceEndEvent extends AbstractCarrierEvent { private final double serviceDuration; public CarrierServiceEndEvent(double time, Id carrierId, CarrierService service, Id vehicleId) { - super(time, carrierId, service.getLocationLinkId(), vehicleId); + super(time, carrierId, service.getServiceLinkId(), vehicleId); this.serviceId = service.getId(); this.serviceDuration = service.getServiceDuration(); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceStartEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceStartEvent.java index d1b4d816ace..f0a2cc0fde6 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierServiceStartEvent.java @@ -44,10 +44,10 @@ public final class CarrierServiceStartEvent extends AbstractCarrierEvent { private final int capacityDemand; public CarrierServiceStartEvent(double time, Id carrierId, CarrierService service, Id vehicleId) { - super(time, carrierId, service.getLocationLinkId(), vehicleId); + super(time, carrierId, service.getServiceLinkId(), vehicleId); this.serviceId = service.getId(); this.serviceDuration = service.getServiceDuration(); - this.capacityDemand = service.getCapacityDemand(); + this.capacityDemand = service.getDemand(); } @Override @@ -85,7 +85,7 @@ public static CarrierServiceStartEvent convert(GenericEvent event) { Id locationLinkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); CarrierService service = CarrierService.Builder.newInstance(carrierServiceId, locationLinkId) .setServiceDuration(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_SERVICE_DURATION))) - .setCapacityDemand(Integer.parseInt(attributes.get(CarrierEventAttributes.ATTRIBUTE_CAPACITYDEMAND))) + .setDemand(Integer.parseInt(attributes.get(CarrierEventAttributes.ATTRIBUTE_CAPACITYDEMAND))) .build(); Id vehicleId = Id.create(attributes.get(ATTRIBUTE_VEHICLE), Vehicle.class); return new CarrierServiceStartEvent(time, carrierId, service, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java index 8f60260a067..2687b550387 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java @@ -44,10 +44,10 @@ public class CarrierShipmentDeliveryEndEvent extends AbstractCarrierEvent { private final double deliveryDuration; private final int capacityDemand; public CarrierShipmentDeliveryEndEvent(double time, Id carrierId, CarrierShipment shipment, Id vehicleId) { - super(time, carrierId, shipment.getTo(), vehicleId); + super(time, carrierId, shipment.getDeliveryLinkId(), vehicleId); this.shipmentId = shipment.getId(); - this.deliveryDuration = shipment.getDeliveryServiceTime(); - this.capacityDemand = shipment.getSize(); + this.deliveryDuration = shipment.getDeliveryDuration(); + this.capacityDemand = shipment.getDemand(); } @Override @@ -83,7 +83,7 @@ public static CarrierShipmentDeliveryEndEvent convert(GenericEvent event) { Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int size = Integer.parseInt(attributes.get(CarrierEventAttributes.ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) - .setDeliveryServiceTime(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_DROPOFF_DURATION))) + .setDeliveryDuration(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_DROPOFF_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentDeliveryEndEvent(time, carrierId, shipment, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java index a30035968c0..ca4a2ec4767 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java @@ -45,10 +45,10 @@ public class CarrierShipmentDeliveryStartEvent extends AbstractCarrierEvent { private final double deliveryDuration; private final int capacityDemand; public CarrierShipmentDeliveryStartEvent(double time, Id carrierId, CarrierShipment shipment, Id vehicleId) { - super(time, carrierId, shipment.getTo(), vehicleId); + super(time, carrierId, shipment.getDeliveryLinkId(), vehicleId); this.shipmentId = shipment.getId(); - this.deliveryDuration = shipment.getDeliveryServiceTime(); - this.capacityDemand = shipment.getSize(); + this.deliveryDuration = shipment.getDeliveryDuration(); + this.capacityDemand = shipment.getDemand(); } @Override @@ -84,7 +84,7 @@ public static CarrierShipmentDeliveryStartEvent convert(GenericEvent event) { Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) - .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_DROPOFF_DURATION))) + .setDeliveryDuration(Double.parseDouble(attributes.get(ATTRIBUTE_DROPOFF_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentDeliveryStartEvent(time, carrierId, shipment, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupEndEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupEndEvent.java index 4316e6f4dfe..97da9f70817 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupEndEvent.java @@ -46,10 +46,10 @@ public class CarrierShipmentPickupEndEvent extends AbstractCarrierEvent { public CarrierShipmentPickupEndEvent(double time, Id carrierId, CarrierShipment shipment, Id vehicleId) { - super(time, carrierId, shipment.getFrom(), vehicleId); + super(time, carrierId, shipment.getPickupLinkId(), vehicleId); this.shipmentId = shipment.getId(); - this.pickupDuration = shipment.getPickupServiceTime(); - this.capacityDemand = shipment.getSize(); + this.pickupDuration = shipment.getPickupDuration(); + this.capacityDemand = shipment.getDemand(); } @@ -79,7 +79,7 @@ public static CarrierShipmentPickupEndEvent convert(GenericEvent event) { Id shipmentFrom = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int shipmentSize = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, shipmentFrom, null, shipmentSize) - .setPickupServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_PICKUP_DURATION))) + .setPickupDuration(Double.parseDouble(attributes.get(ATTRIBUTE_PICKUP_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentPickupEndEvent(time, carrierId, shipment, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupStartEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupStartEvent.java index fe851a10138..7334a9fa8a6 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentPickupStartEvent.java @@ -44,10 +44,10 @@ public class CarrierShipmentPickupStartEvent extends AbstractCarrierEvent { public CarrierShipmentPickupStartEvent(double time, Id carrierId, CarrierShipment shipment, Id vehicleId) { - super(time, carrierId, shipment.getFrom(), vehicleId); + super(time, carrierId, shipment.getPickupLinkId(), vehicleId); this.shipmentId = shipment.getId(); - this.pickupDuration = shipment.getPickupServiceTime(); - this.capacityDemand = shipment.getSize(); + this.pickupDuration = shipment.getPickupDuration(); + this.capacityDemand = shipment.getDemand(); } @@ -77,7 +77,7 @@ public static CarrierShipmentPickupStartEvent convert(GenericEvent event) { Id shipmentFrom = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int shipmentSize = Integer.parseInt(attributes.get(CarrierEventAttributes.ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, shipmentFrom, null, shipmentSize) - .setPickupServiceTime(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_PICKUP_DURATION))) + .setPickupDuration(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_PICKUP_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentPickupStartEvent(time, carrierId, shipment, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/jsprit/MatsimJspritFactory.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/jsprit/MatsimJspritFactory.java index 00cf9347716..11776d0152b 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/jsprit/MatsimJspritFactory.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/jsprit/MatsimJspritFactory.java @@ -88,11 +88,11 @@ static CarrierShipment createCarrierShipment(Shipment jspritShipment) { .newInstance(Id.create(jspritShipment.getId(), CarrierShipment.class), Id.createLinkId(jspritShipment.getPickupLocation().getId()), Id.createLinkId(jspritShipment.getDeliveryLocation().getId()), jspritShipment.getSize().get(0)) - .setDeliveryServiceTime(jspritShipment.getDeliveryServiceTime()) - .setDeliveryTimeWindow(org.matsim.freight.carriers.TimeWindow.newInstance(jspritShipment.getDeliveryTimeWindow().getStart(), + .setDeliveryDuration(jspritShipment.getDeliveryServiceTime()) + .setDeliveryStartsTimeWindow(org.matsim.freight.carriers.TimeWindow.newInstance(jspritShipment.getDeliveryTimeWindow().getStart(), jspritShipment.getDeliveryTimeWindow().getEnd())) - .setPickupServiceTime(jspritShipment.getPickupServiceTime()) - .setPickupTimeWindow(org.matsim.freight.carriers.TimeWindow.newInstance(jspritShipment.getPickupTimeWindow().getStart(), + .setPickupDuration(jspritShipment.getPickupServiceTime()) + .setPickupStartsTimeWindow(org.matsim.freight.carriers.TimeWindow.newInstance(jspritShipment.getPickupTimeWindow().getStart(), jspritShipment.getPickupTimeWindow().getEnd())) .build(); CarriersUtils.setSkills(carrierShipment, jspritShipment.getRequiredSkills().values()); @@ -108,17 +108,17 @@ static CarrierShipment createCarrierShipment(Shipment jspritShipment) { */ static Shipment createJspritShipment(CarrierShipment carrierShipment) { Shipment.Builder shipmentBuilder = Shipment.Builder.newInstance(carrierShipment.getId().toString()) - .setDeliveryLocation(Location.newInstance(carrierShipment.getTo().toString())) - .setDeliveryServiceTime(carrierShipment.getDeliveryServiceTime()) + .setDeliveryLocation(Location.newInstance(carrierShipment.getDeliveryLinkId().toString())) + .setDeliveryServiceTime(carrierShipment.getDeliveryDuration()) .setDeliveryTimeWindow(com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow - .newInstance(carrierShipment.getDeliveryTimeWindow().getStart(), - carrierShipment.getDeliveryTimeWindow().getEnd())) - .setPickupServiceTime(carrierShipment.getPickupServiceTime()) - .setPickupLocation(Location.newInstance(carrierShipment.getFrom().toString())) + .newInstance(carrierShipment.getDeliveryStartsTimeWindow().getStart(), + carrierShipment.getDeliveryStartsTimeWindow().getEnd())) + .setPickupServiceTime(carrierShipment.getPickupDuration()) + .setPickupLocation(Location.newInstance(carrierShipment.getPickupLinkId().toString())) .setPickupTimeWindow(com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow.newInstance( - carrierShipment.getPickupTimeWindow().getStart(), - carrierShipment.getPickupTimeWindow().getEnd())) - .addSizeDimension(0, carrierShipment.getSize()); + carrierShipment.getPickupStartsTimeWindow().getStart(), + carrierShipment.getPickupStartsTimeWindow().getEnd())) + .addSizeDimension(0, carrierShipment.getDemand()); for (String skill : CarriersUtils.getSkills(carrierShipment)) { shipmentBuilder.addRequiredSkill(skill); } @@ -127,29 +127,29 @@ static Shipment createJspritShipment(CarrierShipment carrierShipment) { static Shipment createJspritShipment(CarrierShipment carrierShipment, Coord fromCoord, Coord toCoord) { Location.Builder fromLocationBuilder = Location.Builder.newInstance(); - fromLocationBuilder.setId(carrierShipment.getFrom().toString()); + fromLocationBuilder.setId(carrierShipment.getPickupLinkId().toString()); if (fromCoord != null) { fromLocationBuilder.setCoordinate(Coordinate.newInstance(fromCoord.getX(), fromCoord.getY())); } Location fromLocation = fromLocationBuilder.build(); Location.Builder toLocationBuilder = Location.Builder.newInstance(); - toLocationBuilder.setId(carrierShipment.getTo().toString()); + toLocationBuilder.setId(carrierShipment.getDeliveryLinkId().toString()); if (toCoord != null) { toLocationBuilder.setCoordinate(Coordinate.newInstance(toCoord.getX(), toCoord.getY())); } Location toLocation = toLocationBuilder.build(); Shipment.Builder shipmentBuilder = Shipment.Builder.newInstance(carrierShipment.getId().toString()) - .setDeliveryLocation(toLocation).setDeliveryServiceTime(carrierShipment.getDeliveryServiceTime()) + .setDeliveryLocation(toLocation).setDeliveryServiceTime(carrierShipment.getDeliveryDuration()) .setDeliveryTimeWindow(com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow - .newInstance(carrierShipment.getDeliveryTimeWindow().getStart(), - carrierShipment.getDeliveryTimeWindow().getEnd())) - .setPickupServiceTime(carrierShipment.getPickupServiceTime()).setPickupLocation(fromLocation) + .newInstance(carrierShipment.getDeliveryStartsTimeWindow().getStart(), + carrierShipment.getDeliveryStartsTimeWindow().getEnd())) + .setPickupServiceTime(carrierShipment.getPickupDuration()).setPickupLocation(fromLocation) .setPickupTimeWindow(com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow.newInstance( - carrierShipment.getPickupTimeWindow().getStart(), - carrierShipment.getPickupTimeWindow().getEnd())) - .addSizeDimension(0, carrierShipment.getSize()); + carrierShipment.getPickupStartsTimeWindow().getStart(), + carrierShipment.getPickupStartsTimeWindow().getEnd())) + .addSizeDimension(0, carrierShipment.getDemand()); for (String skill : CarriersUtils.getSkills(carrierShipment)) { shipmentBuilder.addRequiredSkill(skill); } @@ -158,14 +158,14 @@ static Shipment createJspritShipment(CarrierShipment carrierShipment, Coord from static Service createJspritService(CarrierService carrierService, Coord locationCoord) { Location.Builder locationBuilder = Location.Builder.newInstance(); - locationBuilder.setId(carrierService.getLocationLinkId().toString()); + locationBuilder.setId(carrierService.getServiceLinkId().toString()); if (locationCoord != null) { locationBuilder.setCoordinate(Coordinate.newInstance(locationCoord.getX(), locationCoord.getY())); } Location location = locationBuilder.build(); Builder serviceBuilder = Builder.newInstance(carrierService.getId().toString()); - serviceBuilder.addSizeDimension(0, carrierService.getCapacityDemand()); + serviceBuilder.addSizeDimension(0, carrierService.getDemand()); serviceBuilder.setLocation(location).setServiceTime(carrierService.getServiceDuration()) .setTimeWindow(com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow.newInstance( carrierService.getServiceStartTimeWindow().getStart(), @@ -184,7 +184,7 @@ static Service createJspritService(CarrierService carrierService, Coord location static CarrierService createCarrierService(Service jspritService) { CarrierService.Builder serviceBuilder = CarrierService.Builder.newInstance( Id.create(jspritService.getId(), CarrierService.class), Id.create(jspritService.getLocation().getId(), Link.class)); - serviceBuilder.setCapacityDemand(jspritService.getSize().get(0)); + serviceBuilder.setDemand(jspritService.getSize().get(0)); serviceBuilder.setServiceDuration(jspritService.getServiceDuration()); serviceBuilder.setServiceStartTimeWindow( org.matsim.freight.carriers.TimeWindow.newInstance(jspritService.getTimeWindow().getStart(), jspritService.getTimeWindow().getEnd())); @@ -515,11 +515,11 @@ public static VehicleRoutingProblem createRoutingProblem(Carrier carrier, Networ Coord coordinate = null; if (network != null) { - Link link = network.getLinks().get(service.getLocationLinkId()); + Link link = network.getLinks().get(service.getServiceLinkId()); if (link != null) { coordinate = link.getCoord(); } else - log.warn("cannot find linkId {}", service.getLocationLinkId()); + log.warn("cannot find linkId {}", service.getServiceLinkId()); } vrpBuilder.addJob(createJspritService(service, coordinate)); } @@ -530,8 +530,8 @@ public static VehicleRoutingProblem createRoutingProblem(Carrier carrier, Networ Coord fromCoordinate = null; Coord toCoordinate = null; if (network != null) { - Link fromLink = network.getLinks().get(carrierShipment.getFrom()); - Link toLink = network.getLinks().get(carrierShipment.getTo()); + Link fromLink = network.getLinks().get(carrierShipment.getPickupLinkId()); + Link toLink = network.getLinks().get(carrierShipment.getDeliveryLinkId()); if (fromLink != null && toLink != null) { // Shipment to be delivered from specified location to // specified location @@ -540,8 +540,8 @@ public static VehicleRoutingProblem createRoutingProblem(Carrier carrier, Networ vrpBuilder.addJob(createJspritShipment(carrierShipment, fromCoordinate, toCoordinate)); } else throw new IllegalStateException( - "cannot create shipment since neither fromLinkId " + carrierShipment.getTo() - + " nor toLinkId " + carrierShipment.getTo() + " exists in network."); + "cannot create shipment since neither fromLinkId " + carrierShipment.getDeliveryLinkId() + + " nor toLinkId " + carrierShipment.getDeliveryLinkId() + " exists in network."); } vrpBuilder.addJob(createJspritShipment(carrierShipment, fromCoordinate, toCoordinate)); @@ -611,9 +611,9 @@ public static VehicleRoutingProblem.Builder createRoutingProblemBuilder(Carrier log.debug("Handle CarrierService: {}", service.toString()); Coord coordinate = null; if (network != null) { - Link link = network.getLinks().get(service.getLocationLinkId()); + Link link = network.getLinks().get(service.getServiceLinkId()); if (link == null) { - throw new IllegalStateException("cannot create service since linkId " + service.getLocationLinkId() + throw new IllegalStateException("cannot create service since linkId " + service.getServiceLinkId() + " does not exists in network."); } else coordinate = link.getCoord(); @@ -628,8 +628,8 @@ public static VehicleRoutingProblem.Builder createRoutingProblemBuilder(Carrier Coord fromCoordinate = null; Coord toCoordinate = null; if (network != null) { - Link fromLink = network.getLinks().get(carrierShipment.getFrom()); - Link toLink = network.getLinks().get(carrierShipment.getTo()); + Link fromLink = network.getLinks().get(carrierShipment.getPickupLinkId()); + Link toLink = network.getLinks().get(carrierShipment.getDeliveryLinkId()); if (fromLink != null && toLink != null) { // Shipment to be delivered from specified location to // specified location @@ -638,8 +638,8 @@ public static VehicleRoutingProblem.Builder createRoutingProblemBuilder(Carrier toCoordinate = toLink.getCoord(); } else throw new IllegalStateException("cannot create shipment " + carrierShipment.getId().toString() - + " since either fromLinkId " + carrierShipment.getFrom() + " or toLinkId " - + carrierShipment.getTo() + " exists in network."); + + " since either fromLinkId " + carrierShipment.getPickupLinkId() + " or toLinkId " + + carrierShipment.getDeliveryLinkId() + " exists in network."); } vrpBuilder.addJob(createJspritShipment(carrierShipment, fromCoordinate, toCoordinate)); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/usecases/chessboard/FreightScenarioCreator.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/usecases/chessboard/FreightScenarioCreator.java index 3d291829b77..44a4dda7a5f 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/usecases/chessboard/FreightScenarioCreator.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/usecases/chessboard/FreightScenarioCreator.java @@ -101,7 +101,7 @@ private static void createCustomers(Carrier carrier, Network network) { for(int i=0;i<20;i++){ CarrierService.Builder serviceBuilder = CarrierService.Builder.newInstance(Id.create((i + 1),CarrierService.class), drawLocationLinkId(innerCityLinks, outerCityLinks)); - serviceBuilder.setCapacityDemand(1); + serviceBuilder.setDemand(1); serviceBuilder.setServiceDuration(5*60); serviceBuilder.setServiceStartTimeWindow(TimeWindow.newInstance(6*60*60, 15*60*60)); CarrierService carrierService = serviceBuilder.build(); diff --git a/contribs/freight/src/main/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsUtils.java b/contribs/freight/src/main/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsUtils.java index 30517805da5..8670ad977ea 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsUtils.java +++ b/contribs/freight/src/main/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsUtils.java @@ -59,13 +59,13 @@ public static Collection createLSPShipmentsFromCarrierShipments(Car LspShipmentUtils.LspShipmentBuilder builder = LspShipmentUtils.LspShipmentBuilder.newInstance( Id.create(shipment.getId().toString(), LspShipment.class)); - builder.setCapacityDemand(shipment.getSize()); - builder.setFromLinkId(shipment.getFrom()); - builder.setToLinkId(shipment.getTo()); - builder.setStartTimeWindow(shipment.getPickupTimeWindow()); - builder.setEndTimeWindow(shipment.getDeliveryTimeWindow()); - builder.setPickupServiceTime(shipment.getPickupServiceTime()); - builder.setDeliveryServiceTime(shipment.getDeliveryServiceTime()); + builder.setCapacityDemand(shipment.getDemand()); + builder.setFromLinkId(shipment.getPickupLinkId()); + builder.setToLinkId(shipment.getDeliveryLinkId()); + builder.setStartTimeWindow(shipment.getPickupStartsTimeWindow()); + builder.setEndTimeWindow(shipment.getDeliveryStartsTimeWindow()); + builder.setPickupServiceTime(shipment.getPickupDuration()); + builder.setDeliveryServiceTime(shipment.getDeliveryDuration()); shipmentList.add(builder.build()); } return shipmentList; diff --git a/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index d91bf1c94f5..f6473a6fcad 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -84,7 +84,7 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()) .setServiceStartTimeWindow(TimeWindow.newInstance(lspShipment.getPickupTimeWindow().getStart(), lspShipment.getPickupTimeWindow().getEnd())) - .setCapacityDemand(lspShipment.getSize()) + .setDemand(lspShipment.getSize()) .setServiceDuration(lspShipment.getDeliveryServiceTime()) .build(); //ensure that the ids of the lspShipment and the carrierService are the same. This is needed for updating the LSPShipmentPlan diff --git a/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java b/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java index 90abf00ea67..f3814a036e6 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -184,7 +184,7 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()) //TODO TimeWindows are not set. This seems to be a problem. KMT'Aug'24 //If added here, we also need to decide what happens, if the vehicles StartTime (plus TT) is > TimeWindowEnd .... - .setCapacityDemand(lspShipment.getSize()) + .setDemand(lspShipment.getSize()) .setServiceDuration(lspShipment.getDeliveryServiceTime()) .build(); //ensure that the ids of the lspShipment and the carrierService are the same. This is needed for updating the LSPShipmentPlan @@ -207,7 +207,7 @@ private CarrierShipment convertToCarrierShipment(LspShipment lspShipment) { CarrierShipment carrierShipment = CarrierShipment.Builder.newInstance(serviceId, lspShipment.getFrom(), lspShipment.getTo(), lspShipment.getSize()) //TODO TimeWindows are not set. This seems to be a problem. KMT'Aug'24 //If added here, we also need to decide what happens, if the vehicles StartTime (plus TT) is > TimeWindowEnd .... - .setDeliveryServiceTime(lspShipment.getDeliveryServiceTime()) + .setDeliveryDuration(lspShipment.getDeliveryServiceTime()) .build(); //ensure that the ids of the lspShipment and the carrierShipment are the same. This is needed for updating the LSPShipmentPlan if (! Objects.equals(lspShipment.getId().toString(), carrierShipment.getId().toString())) { diff --git a/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java b/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java index 99f49186e11..abcc023fa20 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java @@ -229,7 +229,7 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, resource.getEndLinkId()); - builder.setCapacityDemand(lspShipment.getSize()); + builder.setDemand(lspShipment.getSize()); builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); return builder.build(); } diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java index fe0428621e0..839f2cceaef 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarriersUtilsTest.java @@ -68,21 +68,21 @@ void testAddAndGetServiceToCarrier() { Carrier carrier = new CarrierImpl(Id.create("carrier", Carrier.class)); Id serviceId = Id.create("testVehicle", CarrierService.class); CarrierService service1 = CarrierService.Builder.newInstance(serviceId,Id.createLinkId("link0") ) - .setName("service1").setCapacityDemand(15).setServiceDuration(30).build(); + .setDemand(15).setServiceDuration(30).build(); //add Service CarriersUtils.addService(carrier, service1); Assertions.assertEquals(1, carrier.getServices().size()); CarrierService cs1a = (CarrierService) carrier.getServices().values().toArray()[0]; Assertions.assertEquals(service1, cs1a); - Assertions.assertEquals(Id.createLinkId("link0"), cs1a.getLocationLinkId()); + Assertions.assertEquals(Id.createLinkId("link0"), cs1a.getServiceLinkId()); //get Service CarrierService cs1b = CarriersUtils.getService(carrier, serviceId ); assert cs1b != null; Assertions.assertEquals(serviceId, cs1b.getId()); Assertions.assertEquals(service1.getId(), cs1b.getId()); - Assertions.assertEquals(Id.createLinkId("link0"), cs1b.getLocationLinkId()); + Assertions.assertEquals(Id.createLinkId("link0"), cs1b.getServiceLinkId()); Assertions.assertEquals(30, cs1b.getServiceDuration(), EPSILON); } @@ -97,15 +97,15 @@ void testAddAndGetShipmentToCarrier() { Assertions.assertEquals(1, carrier.getShipments().size()); CarrierShipment carrierShipment1a = (CarrierShipment) carrier.getShipments().values().toArray()[0]; Assertions.assertEquals(service1, carrierShipment1a); - Assertions.assertEquals(Id.createLinkId("link0"), carrierShipment1a.getFrom()); + Assertions.assertEquals(Id.createLinkId("link0"), carrierShipment1a.getPickupLinkId()); //get Shipment CarrierShipment carrierShipment1b = CarriersUtils.getShipment(carrier, shipmentId ); assert carrierShipment1b != null; Assertions.assertEquals(shipmentId, carrierShipment1b.getId()); Assertions.assertEquals(service1.getId(), carrierShipment1b.getId()); - Assertions.assertEquals(Id.createLinkId("link0"), carrierShipment1b.getFrom()); - Assertions.assertEquals(20, carrierShipment1b.getSize(), EPSILON); + Assertions.assertEquals(Id.createLinkId("link0"), carrierShipment1b.getPickupLinkId()); + Assertions.assertEquals(20, carrierShipment1b.getDemand(), EPSILON); } @Test diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintFromVehiclesFileTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintFromVehiclesFileTest.java index 43557b37a2a..e729e5360d6 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintFromVehiclesFileTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintFromVehiclesFileTest.java @@ -421,14 +421,14 @@ private static Carrier addTwoServicesToCarrier(Carrier carrier) { CarrierService service1 = CarrierService.Builder .newInstance(Id.create("Service1", CarrierService.class), Id.createLinkId("j(3,8)")) .setServiceDuration(20).setServiceStartTimeWindow(TimeWindow.newInstance(8 * 3600, 10 * 3600)) - .setCapacityDemand(40).build(); + .setDemand(40).build(); CarriersUtils.addService(carrier, service1); // Service 2 CarrierService service2 = CarrierService.Builder .newInstance(Id.create("Service2", CarrierService.class), Id.createLinkId("j(0,3)R")) .setServiceDuration(20).setServiceStartTimeWindow(TimeWindow.newInstance(8 * 3600, 10 * 3600)) - .setCapacityDemand(40).build(); + .setDemand(40).build(); CarriersUtils.addService(carrier, service2); return carrier; @@ -442,7 +442,7 @@ private static Carrier addThreeServicesToCarrier(Carrier carrier) { CarrierService service3 = CarrierService.Builder .newInstance(Id.create("Service3", CarrierService.class), Id.createLinkId("j(9,2)")) .setServiceDuration(20).setServiceStartTimeWindow(TimeWindow.newInstance(8 * 3600, 10 * 3600)) - .setCapacityDemand(40).build(); + .setDemand(40).build(); CarriersUtils.addService(carrier, service3); return carrier; diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintTest.java index a375cceac46..3747a98a882 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/DistanceConstraintTest.java @@ -614,14 +614,14 @@ private static Carrier addTwoServicesToCarrier(Carrier carrier) { CarrierService service1 = CarrierService.Builder .newInstance(Id.create("Service1", CarrierService.class), Id.createLinkId("j(3,8)")) .setServiceDuration(20).setServiceStartTimeWindow(TimeWindow.newInstance(8 * 3600, 10 * 3600)) - .setCapacityDemand(40).build(); + .setDemand(40).build(); CarriersUtils.addService(carrier, service1); // Service 2 CarrierService service2 = CarrierService.Builder .newInstance(Id.create("Service2", CarrierService.class), Id.createLinkId("j(0,3)R")) .setServiceDuration(20).setServiceStartTimeWindow(TimeWindow.newInstance(8 * 3600, 10 * 3600)) - .setCapacityDemand(40).build(); + .setDemand(40).build(); CarriersUtils.addService(carrier, service2); return carrier; @@ -631,14 +631,14 @@ private static Carrier addTwoShipmentsToCarrier(Carrier carrier) { // Shipment 1 CarrierShipment shipment1 = CarrierShipment.Builder .newInstance(Id.create("Shipment1", CarrierShipment.class), Id.createLinkId("i(1,8)"), Id.createLinkId("j(3,8)"), 40) - .setDeliveryServiceTime(20).setDeliveryTimeWindow(TimeWindow.newInstance(8 * 3600, 12 * 3600)) + .setDeliveryDuration(20).setDeliveryStartsTimeWindow(TimeWindow.newInstance(8 * 3600, 12 * 3600)) .build(); CarriersUtils.addShipment(carrier, shipment1); // Shipment 2 CarrierShipment shipment2 = CarrierShipment.Builder .newInstance(Id.create("Shipment2", CarrierShipment.class),Id.createLinkId("i(1,8)"), Id.createLinkId("j(0,3)R"), 40) - .setDeliveryServiceTime(20).setDeliveryTimeWindow(TimeWindow.newInstance(8 * 3600, 12 * 3600)) + .setDeliveryDuration(20).setDeliveryStartsTimeWindow(TimeWindow.newInstance(8 * 3600, 12 * 3600)) .build(); CarriersUtils.addShipment(carrier, shipment2); @@ -653,7 +653,7 @@ private static Carrier addThreeServicesToCarrier(Carrier carrier) { CarrierService service3 = CarrierService.Builder .newInstance(Id.create("Service3", CarrierService.class), Id.createLinkId("j(9,2)")) .setServiceDuration(20).setServiceStartTimeWindow(TimeWindow.newInstance(8 * 3600, 10 * 3600)) - .setCapacityDemand(40).build(); + .setDemand(40).build(); CarriersUtils.addService(carrier, service3); return carrier; diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/FixedCostsTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/FixedCostsTest.java index cf5060bf772..494c9f106e6 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/FixedCostsTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/FixedCostsTest.java @@ -200,7 +200,7 @@ final void test_carrier3CostsAreCorrectly() { private static CarrierService createMatsimService(String id, String to, int size) { return CarrierService.Builder.newInstance(Id.create(id, CarrierService.class), Id.create(to, Link.class)) - .setCapacityDemand(size) + .setDemand(size) .setServiceDuration(31.0) .setServiceStartTimeWindow(TimeWindow.newInstance(3601.0, 36001.0)) .build(); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/MatsimTransformerTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/MatsimTransformerTest.java index 5025334cc5e..2882cec1336 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/MatsimTransformerTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/MatsimTransformerTest.java @@ -122,7 +122,7 @@ void whenTransforming_matsimVehicle2jspritVehicle_itIsMadeCorrectly() { void whenTransforming_matsimService2jspritService_isMadeCorrectly() { CarrierService carrierService = CarrierService.Builder .newInstance(Id.create("serviceId", CarrierService.class), Id.create("locationId", Link.class)) - .setCapacityDemand(50).setServiceDuration(30.0) + .setDemand(50).setServiceDuration(30.0) .setServiceStartTimeWindow(TimeWindow.newInstance(10.0, 20.0)).build(); Service service = MatsimJspritFactory.createJspritService(carrierService, null); assertNotNull(service); @@ -146,9 +146,9 @@ void whenTransforming_jspritService2matsimService_isMadeCorrectly() { CarrierService service = MatsimJspritFactory.createCarrierService(carrierService); assertNotNull(service); - assertEquals("locationId", service.getLocationLinkId().toString()); + assertEquals("locationId", service.getServiceLinkId().toString()); assertEquals(30.0, service.getServiceDuration(), 0.01); - assertEquals(50, service.getCapacityDemand()); + assertEquals(50, service.getDemand()); assertEquals(10.0, service.getServiceStartTimeWindow().getStart(), 0.01); CarrierService service2 = MatsimJspritFactory.createCarrierService(carrierService); @@ -161,8 +161,8 @@ void whenTransforming_matsimShipment2jspritShipment_isMadeCorrectly() { CarrierShipment carrierShipment = CarrierShipment.Builder .newInstance(Id.create("ShipmentId", CarrierShipment.class), Id.createLinkId("PickupLocationId"), Id.createLinkId("DeliveryLocationId"), 50) - .setPickupServiceTime(30.0).setPickupTimeWindow(TimeWindow.newInstance(10.0, 20.0)) - .setDeliveryServiceTime(40.0).setDeliveryTimeWindow(TimeWindow.newInstance(50.0, 60.0)).build(); + .setPickupDuration(30.0).setPickupStartsTimeWindow(TimeWindow.newInstance(10.0, 20.0)) + .setDeliveryDuration(40.0).setDeliveryStartsTimeWindow(TimeWindow.newInstance(50.0, 60.0)).build(); Shipment shipment = MatsimJspritFactory.createJspritShipment(carrierShipment); assertNotNull(shipment); assertEquals("PickupLocationId", shipment.getPickupLocation().getId()); @@ -193,15 +193,15 @@ void whenTransforming_jspritShipment2matsimShipment_isMadeCorrectly() { CarrierShipment carrierShipment = MatsimJspritFactory.createCarrierShipment(shipment); assertNotNull(carrierShipment); - assertEquals("PickupLocationId", carrierShipment.getFrom().toString()); - assertEquals(30.0, carrierShipment.getPickupServiceTime(), 0.01); - assertEquals(10.0, carrierShipment.getPickupTimeWindow().getStart(), 0.01); - assertEquals(20.0, carrierShipment.getPickupTimeWindow().getEnd(), 0.01); - assertEquals("DeliveryLocationId", carrierShipment.getTo().toString()); - assertEquals(40.0, carrierShipment.getDeliveryServiceTime(), 0.01); - assertEquals(50.0, carrierShipment.getDeliveryTimeWindow().getStart(), 0.01); - assertEquals(60.0, carrierShipment.getDeliveryTimeWindow().getEnd(), 0.01); - assertEquals(50, carrierShipment.getSize()); + assertEquals("PickupLocationId", carrierShipment.getPickupLinkId().toString()); + assertEquals(30.0, carrierShipment.getPickupDuration(), 0.01); + assertEquals(10.0, carrierShipment.getPickupStartsTimeWindow().getStart(), 0.01); + assertEquals(20.0, carrierShipment.getPickupStartsTimeWindow().getEnd(), 0.01); + assertEquals("DeliveryLocationId", carrierShipment.getDeliveryLinkId().toString()); + assertEquals(40.0, carrierShipment.getDeliveryDuration(), 0.01); + assertEquals(50.0, carrierShipment.getDeliveryStartsTimeWindow().getStart(), 0.01); + assertEquals(60.0, carrierShipment.getDeliveryStartsTimeWindow().getEnd(), 0.01); + assertEquals(50, carrierShipment.getDemand()); CarrierShipment carrierShipment2 = MatsimJspritFactory.createCarrierShipment(shipment); assertNotSame(carrierShipment, carrierShipment2); @@ -234,7 +234,7 @@ private Collection getJobsFrom(ScheduledTour sTour) { CarrierService carrierService = ((Tour.ServiceActivity) e) .getService(); Service service = Service.Builder.newInstance(carrierService.getId().toString()) - .setLocation(Location.newInstance(carrierService.getLocationLinkId().toString())).build(); + .setLocation(Location.newInstance(carrierService.getServiceLinkId().toString())).build(); services.add(service); } } @@ -333,10 +333,10 @@ void whenTransforming_matsimPlan2vehicleRouteSolution_itIsMadeCorrectly() { private ScheduledTour getMatsimServiceTour() { CarrierService s1 = CarrierService.Builder .newInstance(Id.create("serviceId", CarrierService.class), Id.create("to1", Link.class)) - .setCapacityDemand(20).build(); + .setDemand(20).build(); CarrierService s2 = CarrierService.Builder .newInstance(Id.create("serviceId2", CarrierService.class), Id.create("to2", Link.class)) - .setCapacityDemand(10).build(); + .setDemand(10).build(); CarrierVehicle matsimVehicle = getMatsimVehicle("matsimVehicle", "loc", getMatsimVehicleType()); double startTime = 15.0; Tour.Builder sTourBuilder = Tour.Builder.newInstance(Id.create("testTour", Tour.class)); @@ -391,8 +391,8 @@ private CarrierShipment getMatsimShipment(String id, String from, String to, int return CarrierShipment.Builder .newInstance(Id.create(id, CarrierShipment.class), Id.create(from, Link.class), Id.create(to, Link.class), size) - .setDeliveryServiceTime(30.0).setDeliveryTimeWindow(TimeWindow.newInstance(10.0, 20.0)) - .setPickupServiceTime(15.0).setPickupTimeWindow(TimeWindow.newInstance(1.0, 5.0)).build(); + .setDeliveryDuration(30.0).setDeliveryStartsTimeWindow(TimeWindow.newInstance(10.0, 20.0)) + .setPickupDuration(15.0).setPickupStartsTimeWindow(TimeWindow.newInstance(1.0, 5.0)).build(); } @Test @@ -503,11 +503,11 @@ private Carrier createCarrierWithServices() { carrier.setCarrierCapabilities(ccBuilder.build()); CarrierService carrierService1 = CarrierService.Builder .newInstance(Id.create("serviceId", CarrierService.class), Id.create("i(7,4)R", Link.class)) - .setCapacityDemand(20).setServiceDuration(10.0).build(); + .setDemand(20).setServiceDuration(10.0).build(); CarriersUtils.addService(carrier, carrierService1); CarrierService carrierService2 = CarrierService.Builder .newInstance(Id.create("serviceId2", CarrierService.class), Id.create("i(3,9)", Link.class)) - .setCapacityDemand(10).setServiceDuration(20.0).build(); + .setDemand(10).setServiceDuration(20.0).build(); CarriersUtils.addService(carrier, carrierService2); return carrier; } diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/SkillsIT.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/SkillsIT.java index 7da556872c2..379fb15486c 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/SkillsIT.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/jsprit/SkillsIT.java @@ -161,10 +161,10 @@ private void addShipmentsRequiringDifferentSkills(Scenario scenario) { carrierLocation, Id.createLinkId("i(10,10)R"), 1) - .setPickupTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setPickupServiceTime(Time.parseTime("00:05:00")) - .setDeliveryTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setDeliveryServiceTime(Time.parseTime("00:05:00")) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setPickupDuration(Time.parseTime("00:05:00")) + .setDeliveryStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setDeliveryDuration(Time.parseTime("00:05:00")) .build(); CarriersUtils.addSkill(shipmentOne, "skill 1"); CarriersUtils.addShipment(carrier, shipmentOne); @@ -174,10 +174,10 @@ private void addShipmentsRequiringDifferentSkills(Scenario scenario) { carrierLocation, Id.createLinkId("i(10,10)R"), 1) - .setPickupTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setPickupServiceTime(Time.parseTime("00:05:00")) - .setDeliveryTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setDeliveryServiceTime(Time.parseTime("00:05:00")) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setPickupDuration(Time.parseTime("00:05:00")) + .setDeliveryStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setDeliveryDuration(Time.parseTime("00:05:00")) .build(); CarriersUtils.addSkill(shipmentTwo, "skill 2"); CarriersUtils.addShipment(carrier, shipmentTwo); @@ -190,10 +190,10 @@ private void addShipmentsRequiringSameSkills(Scenario scenario) { carrierLocation, Id.createLinkId("i(10,10)R"), 1) - .setPickupTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setPickupServiceTime(Time.parseTime("00:05:00")) - .setDeliveryTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setDeliveryServiceTime(Time.parseTime("00:05:00")) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setPickupDuration(Time.parseTime("00:05:00")) + .setDeliveryStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setDeliveryDuration(Time.parseTime("00:05:00")) .build(); CarriersUtils.addSkill(shipmentOne, "skill 1"); CarriersUtils.addShipment(carrier, shipmentOne); @@ -203,10 +203,10 @@ private void addShipmentsRequiringSameSkills(Scenario scenario) { carrierLocation, Id.createLinkId("i(10,10)R"), 1) - .setPickupTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setPickupServiceTime(Time.parseTime("00:05:00")) - .setDeliveryTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) - .setDeliveryServiceTime(Time.parseTime("00:05:00")) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setPickupDuration(Time.parseTime("00:05:00")) + .setDeliveryStartsTimeWindow(TimeWindow.newInstance(0.0, Time.parseTime("24:00:00"))) + .setDeliveryDuration(Time.parseTime("00:05:00")) .build(); CarriersUtils.addSkill(shipmentTwo, "skill 1"); CarriersUtils.addShipment(carrier, shipmentTwo); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java index d7127bc80bf..249da6bf44b 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsIT.java @@ -44,7 +44,6 @@ import org.matsim.freight.carriers.jsprit.NetworkRouter; import org.matsim.testcases.MatsimTestUtils; import org.matsim.vehicles.*; -import org.matsim.vehicles.EngineInformation.FuelType; //TODO: length of routes (legs) AND end time of route are missing. /** @@ -286,16 +285,16 @@ private static CarrierShipment createMatsimShipment(String id, String from, Stri } return CarrierShipment.Builder.newInstance(shipmentId, fromLinkId, toLinkId, size) - .setDeliveryServiceTime(30.0) - .setDeliveryTimeWindow(TimeWindow.newInstance(0.0, 36000.0)) - .setPickupServiceTime(5.0) - .setPickupTimeWindow(TimeWindow.newInstance(0.0, 7200.0)) + .setDeliveryDuration(30.0) + .setDeliveryStartsTimeWindow(TimeWindow.newInstance(0.0, 36000.0)) + .setPickupDuration(5.0) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, 7200.0)) .build(); } private static CarrierService createMatsimService(String id, String to, int size) { return CarrierService.Builder.newInstance(Id.create(id, CarrierService.class), Id.create(to, Link.class)) - .setCapacityDemand(size) + .setDemand(size) .setServiceDuration(31.0) .setServiceStartTimeWindow(TimeWindow.newInstance(0.0, 36001.0)) .build(); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java index 1896021e805..393f73088a3 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/utils/CarrierControllerUtilsTest.java @@ -165,7 +165,7 @@ void numberOfInitialServicesIsCorrect() { int demandServices = 0; for (CarrierService carrierService : carrierWServices.getServices().values()) { - demandServices += carrierService.getCapacityDemand(); + demandServices += carrierService.getDemand(); } Assertions.assertEquals(4, demandServices); @@ -180,7 +180,7 @@ void numberOfInitialShipmentsIsCorrect() { Assertions.assertEquals(2, carrierWShipments.getShipments().size()); int demandShipments = 0; for (CarrierShipment carrierShipment : carrierWShipments.getShipments().values()) { - demandShipments += carrierShipment.getSize(); + demandShipments += carrierShipment.getDemand(); } Assertions.assertEquals(3, demandShipments); } @@ -192,7 +192,7 @@ void numberOfShipmentsFromCopiedShipmentsIsCorrect() { Assertions.assertEquals(2, carrierWShipmentsOnlyFromCarrierWShipments.getShipments().size()); int demandShipments = 0; for (CarrierShipment carrierShipment : carrierWShipmentsOnlyFromCarrierWServices.getShipments().values()) { - demandShipments += carrierShipment.getSize(); + demandShipments += carrierShipment.getDemand(); } Assertions.assertEquals(4, demandShipments); } @@ -204,7 +204,7 @@ void numberOfShipmentsFromConvertedServicesIsCorrect() { Assertions.assertEquals(2, carrierWShipmentsOnlyFromCarrierWServices.getShipments().size()); int demandShipments = 0; for (CarrierShipment carrierShipment : carrierWShipmentsOnlyFromCarrierWServices.getShipments().values()) { - demandShipments += carrierShipment.getSize(); + demandShipments += carrierShipment.getDemand(); } Assertions.assertEquals(4, demandShipments); } @@ -244,30 +244,30 @@ void copyingOfShipmentsIsDoneCorrectly() { if (carrierShipment1.getId() == Id.create("shipment1", CarrierShipment.class)) { System.out.println("Found Shipment1"); foundShipment1 = true; - Assertions.assertEquals(Id.createLinkId("i(1,0)"), carrierShipment1.getFrom()); - Assertions.assertEquals(Id.createLinkId("i(7,6)R"), carrierShipment1.getTo()); - Assertions.assertEquals(1, carrierShipment1.getSize()); - Assertions.assertEquals(30.0, carrierShipment1.getDeliveryServiceTime(), 0); - Assertions.assertEquals(3600.0, carrierShipment1.getDeliveryTimeWindow().getStart(), 0); - Assertions.assertEquals(36000.0, carrierShipment1.getDeliveryTimeWindow().getEnd(), 0); - Assertions.assertEquals(5.0, carrierShipment1.getPickupServiceTime(), 0); - Assertions.assertEquals(0.0, carrierShipment1.getPickupTimeWindow().getStart(), 0); - Assertions.assertEquals(7200.0, carrierShipment1.getPickupTimeWindow().getEnd(), 0); + Assertions.assertEquals(Id.createLinkId("i(1,0)"), carrierShipment1.getPickupLinkId()); + Assertions.assertEquals(Id.createLinkId("i(7,6)R"), carrierShipment1.getDeliveryLinkId()); + Assertions.assertEquals(1, carrierShipment1.getDemand()); + Assertions.assertEquals(30.0, carrierShipment1.getDeliveryDuration(), 0); + Assertions.assertEquals(3600.0, carrierShipment1.getDeliveryStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(36000.0, carrierShipment1.getDeliveryStartsTimeWindow().getEnd(), 0); + Assertions.assertEquals(5.0, carrierShipment1.getPickupDuration(), 0); + Assertions.assertEquals(0.0, carrierShipment1.getPickupStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(7200.0, carrierShipment1.getPickupStartsTimeWindow().getEnd(), 0); } CarrierShipment carrierShipment2 = CarriersUtils.getShipment(carrierWShipmentsOnlyFromCarrierWShipments, Id.create("shipment2", CarrierShipment.class)); assert carrierShipment2 != null; if (carrierShipment2.getId() == Id.create("shipment2", CarrierShipment.class)) { System.out.println("Found Shipment2"); foundShipment2 = true; - Assertions.assertEquals(Id.createLinkId("i(3,0)"), carrierShipment2.getFrom()); - Assertions.assertEquals(Id.createLinkId("i(3,7)"), carrierShipment2.getTo()); - Assertions.assertEquals(2, carrierShipment2.getSize()); - Assertions.assertEquals(30.0, carrierShipment2.getDeliveryServiceTime(), 0); - Assertions.assertEquals(3600.0, carrierShipment2.getDeliveryTimeWindow().getStart(), 0); - Assertions.assertEquals(36000.0, carrierShipment2.getDeliveryTimeWindow().getEnd(), 0); - Assertions.assertEquals(5.0, carrierShipment2.getPickupServiceTime(), 0); - Assertions.assertEquals(0.0, carrierShipment2.getPickupTimeWindow().getStart(), 0); - Assertions.assertEquals(7200.0, carrierShipment2.getPickupTimeWindow().getEnd(), 0); + Assertions.assertEquals(Id.createLinkId("i(3,0)"), carrierShipment2.getPickupLinkId()); + Assertions.assertEquals(Id.createLinkId("i(3,7)"), carrierShipment2.getDeliveryLinkId()); + Assertions.assertEquals(2, carrierShipment2.getDemand()); + Assertions.assertEquals(30.0, carrierShipment2.getDeliveryDuration(), 0); + Assertions.assertEquals(3600.0, carrierShipment2.getDeliveryStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(36000.0, carrierShipment2.getDeliveryStartsTimeWindow().getEnd(), 0); + Assertions.assertEquals(5.0, carrierShipment2.getPickupDuration(), 0); + Assertions.assertEquals(0.0, carrierShipment2.getPickupStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(7200.0, carrierShipment2.getPickupStartsTimeWindow().getEnd(), 0); } Assertions.assertTrue(foundShipment1, "Not found Shipment1 after copying"); Assertions.assertTrue(foundShipment2, "Not found Shipment2 after copying"); @@ -282,29 +282,29 @@ void convertionOfServicesIsDoneCorrectly() { assert carrierShipment1 != null; if (carrierShipment1.getId() == Id.create("Service1", CarrierShipment.class)) { foundService1 = true; - Assertions.assertEquals(Id.createLinkId("i(6,0)"), carrierShipment1.getFrom()); - Assertions.assertEquals(Id.createLinkId("i(3,9)"), carrierShipment1.getTo()); - Assertions.assertEquals(2, carrierShipment1.getSize()); - Assertions.assertEquals(31.0, carrierShipment1.getDeliveryServiceTime(), 0); - Assertions.assertEquals(3601.0, carrierShipment1.getDeliveryTimeWindow().getStart(), 0); - Assertions.assertEquals(36001.0, carrierShipment1.getDeliveryTimeWindow().getEnd(), 0); - Assertions.assertEquals(0.0, carrierShipment1.getPickupServiceTime(), 0); - Assertions.assertEquals(0.0, carrierShipment1.getPickupTimeWindow().getStart(), 0); - Assertions.assertEquals(36001.0, carrierShipment1.getPickupTimeWindow().getEnd(), 0); + Assertions.assertEquals(Id.createLinkId("i(6,0)"), carrierShipment1.getPickupLinkId()); + Assertions.assertEquals(Id.createLinkId("i(3,9)"), carrierShipment1.getDeliveryLinkId()); + Assertions.assertEquals(2, carrierShipment1.getDemand()); + Assertions.assertEquals(31.0, carrierShipment1.getDeliveryDuration(), 0); + Assertions.assertEquals(3601.0, carrierShipment1.getDeliveryStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(36001.0, carrierShipment1.getDeliveryStartsTimeWindow().getEnd(), 0); + Assertions.assertEquals(0.0, carrierShipment1.getPickupDuration(), 0); + Assertions.assertEquals(0.0, carrierShipment1.getPickupStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(36001.0, carrierShipment1.getPickupStartsTimeWindow().getEnd(), 0); } CarrierShipment carrierShipment2 = CarriersUtils.getShipment(carrierWShipmentsOnlyFromCarrierWServices, Id.create("Service2", CarrierShipment.class)); assert carrierShipment2 != null; if (carrierShipment2.getId() == Id.create("Service2", CarrierShipment.class)) { foundService2 = true; - Assertions.assertEquals(Id.createLinkId("i(6,0)"), carrierShipment2.getFrom()); - Assertions.assertEquals(Id.createLinkId("i(4,9)"), carrierShipment2.getTo()); - Assertions.assertEquals(2, carrierShipment2.getSize()); - Assertions.assertEquals(31.0, carrierShipment2.getDeliveryServiceTime(), 0); - Assertions.assertEquals(3601.0, carrierShipment2.getDeliveryTimeWindow().getStart(), 0); - Assertions.assertEquals(36001.0, carrierShipment2.getDeliveryTimeWindow().getEnd(), 0); - Assertions.assertEquals(0.0, carrierShipment2.getPickupServiceTime(), 0); - Assertions.assertEquals(0.0, carrierShipment2.getPickupTimeWindow().getStart(), 0); - Assertions.assertEquals(36001.0, carrierShipment2.getPickupTimeWindow().getEnd(), 0); + Assertions.assertEquals(Id.createLinkId("i(6,0)"), carrierShipment2.getPickupLinkId()); + Assertions.assertEquals(Id.createLinkId("i(4,9)"), carrierShipment2.getDeliveryLinkId()); + Assertions.assertEquals(2, carrierShipment2.getDemand()); + Assertions.assertEquals(31.0, carrierShipment2.getDeliveryDuration(), 0); + Assertions.assertEquals(3601.0, carrierShipment2.getDeliveryStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(36001.0, carrierShipment2.getDeliveryStartsTimeWindow().getEnd(), 0); + Assertions.assertEquals(0.0, carrierShipment2.getPickupDuration(), 0); + Assertions.assertEquals(0.0, carrierShipment2.getPickupStartsTimeWindow().getStart(), 0); + Assertions.assertEquals(36001.0, carrierShipment2.getPickupStartsTimeWindow().getEnd(), 0); } Assertions.assertTrue(foundService1, "Not found converted Service1 after converting"); Assertions.assertTrue(foundService2, "Not found converted Service2 after converting"); @@ -343,16 +343,16 @@ private static CarrierShipment createMatsimShipment(String id, String from, Stri } return CarrierShipment.Builder.newInstance(shipmentId, fromLinkId, toLinkId, size) - .setDeliveryServiceTime(30.0) - .setDeliveryTimeWindow(TimeWindow.newInstance(3600.0, 36000.0)) - .setPickupServiceTime(5.0) - .setPickupTimeWindow(TimeWindow.newInstance(0.0, 7200.0)) + .setDeliveryDuration(30.0) + .setDeliveryStartsTimeWindow(TimeWindow.newInstance(3600.0, 36000.0)) + .setPickupDuration(5.0) + .setPickupStartsTimeWindow(TimeWindow.newInstance(0.0, 7200.0)) .build(); } private static CarrierService createMatsimService(String id, String to, int size) { return CarrierService.Builder.newInstance(Id.create(id, CarrierService.class), Id.create(to, Link.class)) - .setCapacityDemand(size) + .setDemand(size) .setServiceDuration(31.0) .setServiceStartTimeWindow(TimeWindow.newInstance(3601.0, 36001.0)) .build(); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java index e72394b24ea..b1d60e9665a 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/examples/simulationTrackers/CollectionTrackerTest.java @@ -56,7 +56,6 @@ import org.matsim.freight.logistics.shipment.LspShipment; import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.testcases.MatsimTestUtils; -import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; import org.matsim.vehicles.VehicleUtils; @@ -238,7 +237,7 @@ public void testCollectionTracker() { if (element instanceof ServiceActivity activity) { scheduledCosts += activity.getService().getServiceDuration() * scheduledTour.getVehicle().getType().getCostInformation().getCostsPerSecond(); totalScheduledCosts += scheduledCosts; - totalScheduledWeight += activity.getService().getCapacityDemand(); + totalScheduledWeight += activity.getService().getDemand(); totalNumberOfScheduledShipments++; } } diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java index 5e071b894d4..ba6d1fd35e7 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java @@ -196,8 +196,8 @@ public void testCollectionLSPScheduling() { { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -211,8 +211,8 @@ public void testCollectionLSPScheduling() { { assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java index c4fd34c0fd3..11d49bd6c0b 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java @@ -433,8 +433,8 @@ public void testCompletedLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -460,8 +460,8 @@ public void testCompletedLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), toLinkId); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -484,8 +484,8 @@ public void testCompletedLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -502,8 +502,8 @@ public void testCompletedLSPScheduling() { //CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -520,9 +520,9 @@ public void testCompletedLSPScheduling() { //MainRunStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); - assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunStartHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunStartHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunStartHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -538,9 +538,9 @@ public void testCompletedLSPScheduling() { //MainRunEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); - assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunEndHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunEndHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -556,9 +556,9 @@ public void testCompletedLSPScheduling() { //DistributionRunStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(4)); LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4); - assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); + assertSame(lspTourStartEventHandler.getCarrierService().getServiceLinkId(), shipment.getTo()); assertEquals(lspTourStartEventHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(lspTourStartEventHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(lspTourStartEventHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, lspTourStartEventHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, lspTourStartEventHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(lspTourStartEventHandler.getLogisticChainElement(), planElements.get(8).getLogisticChainElement()); @@ -574,9 +574,9 @@ public void testCompletedLSPScheduling() { //DistributionServiceStart assertInstanceOf(DistributionServiceStartEventHandler.class, eventHandlers.get(5)); DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5); - assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); + assertSame(distributionServiceHandler.getCarrierService().getServiceLinkId(), shipment.getTo()); assertEquals(distributionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(distributionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(distributionServiceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(distributionServiceHandler.getLogisticChainElement(), planElements.get(8).getLogisticChainElement()); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java index 3cead4c873c..76191192a70 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java @@ -259,8 +259,8 @@ public void testFirstReloadLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -283,8 +283,8 @@ public void testFirstReloadLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -296,8 +296,8 @@ public void testFirstReloadLSPScheduling() { assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java index 4a39f6c6170..ce0a83639a8 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java @@ -324,8 +324,8 @@ public void testMainRunLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -350,8 +350,8 @@ public void testMainRunLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -368,8 +368,8 @@ public void testMainRunLSPScheduling() { //CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -386,9 +386,9 @@ public void testMainRunLSPScheduling() { //MainRunTourStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); - assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunStartHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunStartHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunStartHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -404,9 +404,9 @@ public void testMainRunLSPScheduling() { //MainRunTourEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); - assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunEndHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunEndHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java index d30d608f985..d3fe9b5214d 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java @@ -198,8 +198,8 @@ public void testCollectionLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -211,8 +211,8 @@ public void testCollectionLSPScheduling() { assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java index f27a1e08219..1a584b463b5 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java @@ -436,8 +436,8 @@ public void testCompletedLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -463,8 +463,8 @@ public void testCompletedLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), toLinkId); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -487,8 +487,8 @@ public void testCompletedLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -505,8 +505,8 @@ public void testCompletedLSPScheduling() { //CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -523,9 +523,9 @@ public void testCompletedLSPScheduling() { //MainRunTourStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); - assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunStartHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunStartHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunStartHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -541,9 +541,9 @@ public void testCompletedLSPScheduling() { //MainRunTourEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); - assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunEndHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunEndHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -559,9 +559,9 @@ public void testCompletedLSPScheduling() { //DistributionTourStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(4)); LSPTourStartEventHandler lspTourStartEventHandler = (LSPTourStartEventHandler) eventHandlers.get(4); - assertSame(lspTourStartEventHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); + assertSame(lspTourStartEventHandler.getCarrierService().getServiceLinkId(), shipment.getTo()); assertEquals(lspTourStartEventHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(lspTourStartEventHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(lspTourStartEventHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, lspTourStartEventHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, lspTourStartEventHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(lspTourStartEventHandler.getLogisticChainElement(), planElements.get(8).getLogisticChainElement()); @@ -577,9 +577,9 @@ public void testCompletedLSPScheduling() { //DistributionServiceStart assertInstanceOf(DistributionServiceStartEventHandler.class, eventHandlers.get(5)); DistributionServiceStartEventHandler distributionServiceHandler = (DistributionServiceStartEventHandler) eventHandlers.get(5); - assertSame(distributionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getTo()); + assertSame(distributionServiceHandler.getCarrierService().getServiceLinkId(), shipment.getTo()); assertEquals(distributionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(distributionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(distributionServiceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, distributionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(distributionServiceHandler.getLogisticChainElement(), planElements.get(8).getLogisticChainElement()); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java index e1661887039..4d41d635e10 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java @@ -258,8 +258,8 @@ public void testFirstReloadLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -282,8 +282,8 @@ public void testFirstReloadLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -295,8 +295,8 @@ public void testFirstReloadLSPScheduling() { assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java index c9811f9e03d..b63c6d854d4 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java @@ -222,16 +222,16 @@ public void initialize() { @Test public void testMainRunLSPScheduling() { - + /*for(LSPShipment shipment : lsp.getShipments()) { ArrayList scheduleElements = new ArrayList(shipment.getSchedule().getPlanElements().values()); Collections.sort(scheduleElements, new AbstractShipmentPlanElementComparator()); - + System.out.println(); for(int i = 0; i < shipment.getSchedule().getPlanElements().size(); i++) { System.out.println("Scheduled: " + scheduleElements.get(i).getSolutionElement().getId() + " " + scheduleElements.get(i).getResourceId() +" "+ scheduleElements.get(i).getElementType() + " Start: " + scheduleElements.get(i).getStartTime() + " End: " + scheduleElements.get(i).getEndTime()); } - System.out.println(); + System.out.println(); }*/ @@ -324,8 +324,8 @@ public void testMainRunLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -350,8 +350,8 @@ public void testMainRunLSPScheduling() { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(endHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(endHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -368,8 +368,8 @@ public void testMainRunLSPScheduling() { //CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(serviceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(serviceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -386,9 +386,9 @@ public void testMainRunLSPScheduling() { //MainRunTourStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); - assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunStartHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunStartHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunStartHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -404,9 +404,9 @@ public void testMainRunLSPScheduling() { //MainRunEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); - assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunEndHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunEndHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java index 23ee9f61e86..03f374b15f0 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -251,14 +251,14 @@ public void initialize() { @Test public void testSecondReloadLSPScheduling() { - + /*for(LSPShipment shipment : lsp.getShipments()) { ArrayList elementList = new ArrayList(shipment.getSchedule().getPlanElements().values()); Collections.sort(elementList, new AbstractShipmentPlanElementComparator()); System.out.println(); for(AbstractShipmentPlanElement element : elementList) { - System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); - } + System.out.println(element.getSolutionElement().getId() + " " + element.getResourceId() + " " + element.getElementType() + " " + element.getStartTime() + " " + element.getEndTime()); + } System.out.println(); }*/ @@ -368,8 +368,8 @@ public void testSecondReloadLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : @@ -400,8 +400,8 @@ public void testSecondReloadLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), toLinkId); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { @@ -430,8 +430,8 @@ public void testSecondReloadLSPScheduling() { { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(collectionEndHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(collectionEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(collectionEndHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(collectionEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(collectionEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -449,8 +449,8 @@ public void testSecondReloadLSPScheduling() { {//CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler collectionServiceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(collectionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(collectionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(collectionServiceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(collectionServiceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(collectionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -468,9 +468,9 @@ public void testSecondReloadLSPScheduling() { {//MainRunStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); - assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunStartHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunStartHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunStartHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -487,9 +487,9 @@ public void testSecondReloadLSPScheduling() { {//MainRunEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); - assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunEndHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunEndHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); diff --git a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java index 6a37cd65697..66a30fa10d4 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java @@ -368,8 +368,8 @@ public void testSecondReloadLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), shipment.getFrom()); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : @@ -406,8 +406,8 @@ public void testSecondReloadLSPScheduling() { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; LogisticChainElement element = entry.getValue().logisticChainElement; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertSame(service.getServiceLinkId(), toLinkId); + assertEquals(service.getDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); boolean handledByTranshipmentHub = false; for (LogisticChainElement clientElement : @@ -437,8 +437,8 @@ public void testSecondReloadLSPScheduling() { {//CollectionTourEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); - assertSame(collectionEndHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(collectionEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(collectionEndHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(collectionEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(collectionEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -456,8 +456,8 @@ public void testSecondReloadLSPScheduling() { {//CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler collectionServiceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); - assertSame(collectionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); - assertEquals(collectionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertSame(collectionServiceHandler.getCarrierService().getServiceLinkId(), shipment.getFrom()); + assertEquals(collectionServiceHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(collectionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); @@ -475,9 +475,9 @@ public void testSecondReloadLSPScheduling() { {//MainRunStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); - assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunStartHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunStartHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunStartHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunStartHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunStartHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunStartHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); @@ -494,9 +494,9 @@ public void testSecondReloadLSPScheduling() { {//MainRunEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); - assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); + assertSame(mainRunEndHandler.getCarrierService().getServiceLinkId(), toLinkId); assertEquals(mainRunEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertEquals(mainRunEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); + assertEquals(mainRunEndHandler.getCarrierService().getDemand(), shipment.getSize()); assertEquals(0, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), 0.0); assertEquals(Integer.MAX_VALUE, mainRunEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), 0.0); assertSame(mainRunEndHandler.getLogisticChainElement(), planElements.get(4).getLogisticChainElement()); diff --git a/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverControlerListener.java b/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverControlerListener.java index 852452663a6..a35dddecc24 100644 --- a/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverControlerListener.java +++ b/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverControlerListener.java @@ -178,7 +178,7 @@ private void linkReceiverTimeWindowToCarrierTourPosition() throws IOException { String shipmentId = act.getShipment().getId().toString(); if (act.getActivityType().equalsIgnoreCase("delivery")) { - Id linkId = act.getShipment().getTo(); + Id linkId = act.getShipment().getDeliveryLinkId(); if (!receiverLinkMap.containsKey(linkId)) { LOG.error("Woops, the carrier is delivering a shipment to an unknown receiver!"); throw new RuntimeException("Don't know to whom delivery is."); diff --git a/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverTriggersCarrierReplanningListener.java b/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverTriggersCarrierReplanningListener.java index 2b8c4a6dfb9..28820157125 100644 --- a/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverTriggersCarrierReplanningListener.java +++ b/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/ReceiverTriggersCarrierReplanningListener.java @@ -81,12 +81,12 @@ public void notifyIterationStarts(IterationStartsEvent event) { order.getReceiver().getLinkId(), (int) (Math.round(order.getDailyOrderQuantity()*order.getProduct().getProductType().getRequiredCapacity())) ); CarrierShipment newShipment = builder - .setDeliveryServiceTime( order.getServiceDuration() ) - .setDeliveryTimeWindow( receiverPlan.getTimeWindows().get( 0 ) ) + .setDeliveryDuration( order.getServiceDuration() ) + .setDeliveryStartsTimeWindow( receiverPlan.getTimeWindows().get( 0 ) ) // TODO This only looks at the FIRST time window. This may need revision once we handle multiple // time windows. .build(); - if (newShipment.getSize() != 0) { + if (newShipment.getDemand() != 0) { receiverOrder.getCarrier().getShipments().put(newShipment.getId(), newShipment ); } } diff --git a/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/run/chessboard/ReceiverChessboardScenario.java b/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/run/chessboard/ReceiverChessboardScenario.java index fd036695370..34b74c242d4 100644 --- a/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/run/chessboard/ReceiverChessboardScenario.java +++ b/contribs/freightreceiver/src/main/java/org/matsim/freight/receiver/run/chessboard/ReceiverChessboardScenario.java @@ -228,8 +228,8 @@ public static void convertReceiverOrdersToInitialCarrierShipments(Carriers carri LOG.warn("Multiple time windows set. Only the first is used"); } - CarrierShipment shipment = shpBuilder.setDeliveryServiceTime(order.getServiceDuration()) - .setDeliveryTimeWindow(receiverPlan.getTimeWindows().get(0)) + CarrierShipment shipment = shpBuilder.setDeliveryDuration(order.getServiceDuration()) + .setDeliveryStartsTimeWindow(receiverPlan.getTimeWindows().get(0)) .build(); carriers.getCarriers().get(receiverOrder.getCarrierId()).getShipments().put(shipment.getId(), shipment); } diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java index c2c9bc8d039..0833d66f019 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/NoiseConfigGroup.java @@ -43,7 +43,7 @@ * Provides the parameters required to build a simple grid with some basic spatial functionality. * Provides the parameters required to compute noise emissions, immissions and damages. * - * @author ikaddoura + * @author ikaddoura, nkuehnel */ public final class NoiseConfigGroup extends ReflectiveConfigGroup { @@ -81,6 +81,7 @@ public final class NoiseConfigGroup extends ReflectiveConfigGroup { private static final String RECEIVER_POINT_GAP_CMT = "horizontal and vertical distance between receiver points in x-/y-coordinate units"; private static final String WRITE_OUTPUT_ITERATION_CMT = "Specifies how often the noise-specific output is written out."; private static final String CONSIDER_NOISE_BARRIERS = "considerNoiseBarriers"; + private static final String CONSIDER_NOISE_REFLECTION = "considerNoiseReflection"; private static final String NOISE_BARRIERS_GEOJSON_FILE = "noiseBarriersGeojsonPath"; private static final String NOISE_BARRIERS_SOURCE_CRS = "source coordinate reference system of noise barriers geojson file"; private static final String NETWORK_MODES_TO_IGNORE = "networkModesToIgnore"; @@ -142,6 +143,7 @@ public enum NoiseAllocationApproach { private double noiseTollFactor = 1.0; private boolean considerNoiseBarriers = false; + private boolean considerNoiseReflection = false; private String noiseBarriersFilePath = null; private String noiseBarriersSourceCrs = null; @@ -204,6 +206,7 @@ public Map getComments() { comments.put(NOISE_TOLL_FACTOR, "To be used for sensitivity analysis. Default: 1.0 (= the parameter has no effect)"); comments.put(CONSIDER_NOISE_BARRIERS, "Set to 'true' if noise barriers / building shielding should be considered. Otherwise set to 'false'."); + comments.put(CONSIDER_NOISE_REFLECTION, "Set to 'true' if reflections should be considered. Otherwise set to 'false'. Has a considerable performance impact."); comments.put(NOISE_BARRIERS_GEOJSON_FILE, "Path to the geojson file for noise barriers."); comments.put(NOISE_BARRIERS_SOURCE_CRS, "Source coordinate reference system of noise barriers geojson file."); @@ -308,6 +311,14 @@ private void checkNoiseParametersForConsistency(Config config) { + " It is therefore recommended not to use speeds outside of the range of valid parameters!"); } + if(considerNoiseReflection) { + if (!this.considerNoiseBarriers) { + if (this.noiseBarriersFilePath == null || "".equals(this.noiseBarriersFilePath)) { + log.warn("Cannot consider noise reflection without a specified file path to the geojson file of barriers / buildings."); + this.considerNoiseBarriers = false; + } + } + } if (this.considerNoiseBarriers) { if (this.noiseBarriersFilePath == null || "".equals(this.noiseBarriersFilePath)) { log.warn("Cannot consider noise barriers without a specified file path to the geojson file of barriers / buildings."); @@ -782,6 +793,16 @@ public void setConsiderNoiseBarriers(boolean considerNoiseBarriers) { this.considerNoiseBarriers = considerNoiseBarriers; } + @StringGetter(CONSIDER_NOISE_REFLECTION) + public boolean isConsiderNoiseReflection() { + return this.considerNoiseReflection; + } + + @StringSetter(CONSIDER_NOISE_REFLECTION) + public void setConsiderNoiseReflection(boolean considerNoiseReflection) { + this.considerNoiseReflection = considerNoiseReflection; + } + @StringGetter(NOISE_BARRIERS_GEOJSON_FILE) public String getNoiseBarriersFilePath() { return this.noiseBarriersFilePath; diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/RLS19NoiseImmission.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/RLS19NoiseImmission.java index 1e8f1cd2563..e0bb566141c 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/RLS19NoiseImmission.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/RLS19NoiseImmission.java @@ -101,7 +101,9 @@ public double calculateCorrection(double projectedDistance, NoiseReceiverPoint n @Override public void setCurrentRp(NoiseReceiverPoint nrp) { - reflection.setCurrentReceiver(nrp); + if(noiseParams.isConsiderNoiseReflection()) { + reflection.setCurrentReceiver(nrp); + } } private double getSectionsCorrection(NoiseReceiverPoint nrp, Link link) { @@ -127,10 +129,12 @@ private double getSubSectionsCorrection(Coordinate nrpCoordinate, LineSegment se final double sectionCorrection = 10 * Math.log10(length) - calculateCorrection(nrpCoordinate, segment, null); correctionTemp += Math.pow(10, 0.1*sectionCorrection); - final Set reflectionLinks = reflection.getReflections(segment); - for(ReflectionContext.ReflectionTuple reflection: reflectionLinks) { - double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink.getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink, reflection.facade); - correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection); + if(noiseParams.isConsiderNoiseReflection()) { + final Set reflectionLinks = reflection.getReflections(segment); + for (ReflectionContext.ReflectionTuple reflection : reflectionLinks) { + double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink().getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink(), reflection.facade()); + correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection); + } } } else { double lMid = length / 2; @@ -149,10 +153,12 @@ private double getSubSectionsCorrection(Coordinate nrpCoordinate, LineSegment se final double sectionCorrection = 10 * Math.log10(central.getLength()) - calculateCorrection(nrpCoordinate, central, null); correctionTemp += Math.pow(10, 0.1 * sectionCorrection); - final Set reflectionLinks = reflection.getReflections(central); - for(ReflectionContext.ReflectionTuple reflection: reflectionLinks) { - double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink.getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink, reflection.facade); - correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection); + if(noiseParams.isConsiderNoiseReflection()) { + final Set reflectionLinks = reflection.getReflections(central); + for (ReflectionContext.ReflectionTuple reflection : reflectionLinks) { + double sectionCorrectionReflection = 10 * Math.log10(reflection.reflectionLink().getLength()) - calculateCorrection(nrpCoordinate, reflection.reflectionLink(), reflection.facade()); + correctionTemp += Math.pow(10, 0.1 * sectionCorrectionReflection); + } } correctionTemp += getSubSectionsCorrection(nrpCoordinate, leftRemaining); @@ -174,7 +180,10 @@ private double calculateCorrection(Coordinate nrp, LineSegment segment, LineSegm //to maintain the correct signs. nk, Sep'20 double intersectionCorrection = intersection.calculateIntersectionCorrection(coordinate); - double multipleReflectionCorrection = reflection.getMultipleReflectionCorrection(segment); + double multipleReflectionCorrection = 0; + if(noiseParams.isConsiderNoiseReflection()) { + multipleReflectionCorrection = reflection.getMultipleReflectionCorrection(segment); + } double geometricDivergence = 20 * Math.log10(distance) + 10 * Math.log10(2 * Math.PI); double airDampeningFactor = distance / 200.; @@ -191,11 +200,6 @@ private double calculateCorrection(Coordinate nrp, LineSegment segment, LineSegm } else { return geometricDivergence + airDampeningFactor - intersectionCorrection + groundDampening ; } - - //TODO: implement reflection - if someone is looking for a (bachelor) thesis... -// double firstReflectionCorrection = 0; -// double secondReflectionCorrection = 0; -// return dampeningCorrection + firstReflectionCorrection + secondReflectionCorrection; } diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/ReflectionContext.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/ReflectionContext.java index 02639ac3d3b..145367afee6 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/ReflectionContext.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/ReflectionContext.java @@ -1,5 +1,6 @@ package org.matsim.contrib.noise; +import jakarta.inject.Inject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.locationtech.jts.algorithm.Angle; @@ -7,7 +8,6 @@ import org.locationtech.jts.geom.util.AffineTransformation; import org.matsim.core.config.Config; -import jakarta.inject.Inject; import java.util.*; /** @@ -15,18 +15,19 @@ * * @author nkuehnel */ -public class ReflectionContext { +public final class ReflectionContext { static final double SCAN_LINE_LENGTH = 1; - private final static Logger logger = LogManager.getLogger(org.matsim.contrib.noise.ShieldingContext.class); + private final static Logger logger = LogManager.getLogger(ReflectionContext.class); private Set visibleEdges; private Coordinate receiver; - private BarrierContext barrierContext; - private GeometryFactory geomFactory = new GeometryFactory(); + private final BarrierContext barrierContext; + private final GeometryFactory geomFactory = new GeometryFactory(); + record ReflectionTuple(LineSegment facade, LineSegment reflectionLink) { } @Inject ReflectionContext(BarrierContext barrierContext) { @@ -38,6 +39,7 @@ public class ReflectionContext { } void setCurrentReceiver(NoiseReceiverPoint nrp) { + receiver = new Coordinate(nrp.getCoord().getX(), nrp.getCoord().getY()); final Collection candidates = @@ -60,7 +62,7 @@ void setCurrentReceiver(NoiseReceiverPoint nrp) { } - Set findVisibleEdgesOfPolygon(List polygonEdges, Coordinate coordinate) { + private Set findVisibleEdgesOfPolygon(List polygonEdges, Coordinate coordinate) { Coordinate coordXinc = new Coordinate(coordinate.x + 1, coordinate.y); @@ -155,13 +157,9 @@ Set getReflections(LineSegment originalLink) { } } return reflections; -// return Collections.EMPTY_SET; } double getMultipleReflectionCorrection(LineSegment segment) { - if(this.receiver.x == 1420 && this.receiver.y == 20) { - System.out.println("jo"); - } final Coordinate coordinate = segment.midPoint(); Coordinate candidateRight = getReflectionSegment(coordinate, segment, 400); @@ -174,7 +172,7 @@ Set getReflections(LineSegment originalLink) { } else { return 0; } - if (candidateLeft != null && candidateRight != null){ + if (candidateLeft != null){ double w = candidateLeft.distance(candidateRight); return Math.min(2 * Math.min(candidateLeft.z, candidateRight.z) / w, 1.6); } @@ -265,7 +263,7 @@ private boolean hit(LineSegment facade, LineSegment originalLink) { return true; } - static boolean intersects(LineSegment segment1, LineSegment segment2) { + private static boolean intersects(LineSegment segment1, LineSegment segment2) { double dx0 = segment1.p1.x - segment1.p0.x; double dx1 = segment2.p1.x - segment2.p0.x; @@ -277,17 +275,6 @@ static boolean intersects(LineSegment segment1, LineSegment segment2) { double p1 = dy1 * (segment2.p1.x - segment1.p1.x) - dx1 * (segment2.p1.y - segment1.p1.y); double p2 = dy0 * (segment1.p1.x - segment2.p0.x) - dx0 * (segment1.p1.y - segment2.p0.y); double p3 = dy0 * (segment1.p1.x - segment2.p1.x) - dx0 * (segment1.p1.y - segment2.p1.y); - return (p0 * p1 <= 0) & (p2 * p3 <= 0); - } - - - static class ReflectionTuple { - final LineSegment facade; - final LineSegment reflectionLink; - - public ReflectionTuple(LineSegment facade, LineSegment reflectionLink) { - this.facade = facade; - this.reflectionLink = reflectionLink; - } + return (p0 * p1 <= 0) && (p2 * p3 <= 0); } } diff --git a/contribs/noise/src/main/java/org/matsim/contrib/noise/ShieldingContext.java b/contribs/noise/src/main/java/org/matsim/contrib/noise/ShieldingContext.java index 97af40ce515..ea4e97ca7e6 100644 --- a/contribs/noise/src/main/java/org/matsim/contrib/noise/ShieldingContext.java +++ b/contribs/noise/src/main/java/org/matsim/contrib/noise/ShieldingContext.java @@ -24,8 +24,6 @@ final class ShieldingContext { private final static Logger logger = LogManager.getLogger(ShieldingContext.class); - //STRtree increases performance by ~40% by reducing the amount of potential - //obstruction candidates. nkuehnel, mar '20 private final static double GROUND_HEIGHT = 0.5; private final ShieldingCorrection shieldingCorrection; @@ -35,7 +33,6 @@ final class ShieldingContext { ShieldingContext(Config config, ShieldingCorrection shieldingCorrection, BarrierContext barrierContext) { this.shieldingCorrection = shieldingCorrection; this.barrierContext = barrierContext; - NoiseConfigGroup noiseParams = ConfigUtils.addOrGetModule(config, NoiseConfigGroup.class); } ShieldingContext(ShieldingCorrection shieldingCorrection, BarrierContext barrierContext) { @@ -51,83 +48,73 @@ final class ShieldingContext { final Coordinate midPoint = segment.midPoint(); midPoint.z = GROUND_HEIGHT; -// final Point fromPoint = GeometryUtils.createGeotoolsPoint(link.getFromNode().getCoord()); -// final Point toPoint = GeometryUtils.createGeotoolsPoint(link.getToNode().getCoord()); - - Coordinate from = segment.p0; - Coordinate to = segment.p1; - LineString projectedLineOfSight = constructLineOfSight(rpPoint, midPoint); -// LineString fromLineOfSight = constructLineOfSight(rpPoint, from); -// LineString toLineOfSight = constructLineOfSight(rpPoint, to); NavigableMap edgeCandidates = getObstructionEdges(rpPoint, midPoint, projectedLineOfSight); edgeCandidates.put(projectedLineOfSight.getLength(), midPoint); - if (!edgeCandidates.isEmpty()) { - Coordinate lastFixedEdge = rpPoint; - Coordinate tmpEdge = rpPoint; - double currentHeight = GROUND_HEIGHT; + Coordinate lastFixedEdge = rpPoint; + Coordinate tmpEdge = rpPoint; + double currentHeight = GROUND_HEIGHT; - List consideredEdges = new ArrayList<>(); + List consideredEdges = new ArrayList<>(); - double distToCurrentEdge = 0; - while (lastFixedEdge != midPoint) { - if (edgeCandidates.isEmpty()) { - logger.warn("Skipping obstacle as distance appears to be 0."); - return correctionTermShielding; - } - Iterator edgesIterator = edgeCandidates.values().iterator(); - double maxSlope = Double.NEGATIVE_INFINITY; - double tmpDistance = 0; - while (edgesIterator.hasNext()) { - Coordinate edge = edgesIterator.next(); - double distance = lastFixedEdge.distance(edge); - double slope = (edge.z - currentHeight) / distance; - if (slope >= maxSlope) { - maxSlope = slope; - tmpEdge = edge; - tmpDistance = distance; - } + double distToCurrentEdge = 0; + while (lastFixedEdge != midPoint) { + if (edgeCandidates.isEmpty()) { + logger.warn("Skipping obstacle as distance appears to be 0."); + return correctionTermShielding; + } + Iterator edgesIterator = edgeCandidates.values().iterator(); + double maxSlope = Double.NEGATIVE_INFINITY; + double tmpDistance = 0; + while (edgesIterator.hasNext()) { + Coordinate edge = edgesIterator.next(); + double distance = lastFixedEdge.distance(edge); + double slope = (edge.z - currentHeight) / distance; + if (slope >= maxSlope) { + maxSlope = slope; + tmpEdge = edge; + tmpDistance = distance; } - lastFixedEdge = tmpEdge; - distToCurrentEdge += tmpDistance; - currentHeight = tmpEdge.z; - consideredEdges.add(lastFixedEdge); - edgeCandidates = edgeCandidates.tailMap(distToCurrentEdge, false); } + lastFixedEdge = tmpEdge; + distToCurrentEdge += tmpDistance; + currentHeight = tmpEdge.z; + consideredEdges.add(lastFixedEdge); + edgeCandidates = edgeCandidates.tailMap(distToCurrentEdge, false); + } - consideredEdges.remove(midPoint); + consideredEdges.remove(midPoint); - if (consideredEdges.isEmpty()) { - return correctionTermShielding; - } + if (consideredEdges.isEmpty()) { + return correctionTermShielding; + } - final double firstEdgeYDiff = GROUND_HEIGHT - consideredEdges.get(0).z; - double firstEdgeDistance = rpPoint.distance(consideredEdges.get(0)); - double receiverToFirstEdgeDistance - = Math.sqrt(firstEdgeYDiff * firstEdgeYDiff + firstEdgeDistance * firstEdgeDistance); - - double shieldingDepth = 0; - - Iterator it = consideredEdges.iterator(); - Coordinate edgeTemp = it.next(); - while (it.hasNext()) { - Coordinate edge = it.next(); - double xyDiff = edgeTemp.distance(edge); - double zDiff = edgeTemp.z - edge.z; - shieldingDepth += Math.sqrt(xyDiff * xyDiff + zDiff * zDiff); - edgeTemp = edge; - } + final double firstEdgeYDiff = GROUND_HEIGHT - consideredEdges.get(0).z; + double firstEdgeDistance = rpPoint.distance(consideredEdges.get(0)); + double receiverToFirstEdgeDistance + = Math.sqrt(firstEdgeYDiff * firstEdgeYDiff + firstEdgeDistance * firstEdgeDistance); + + double shieldingDepth = 0; + + Iterator it = consideredEdges.iterator(); + Coordinate edgeTemp = it.next(); + while (it.hasNext()) { + Coordinate edge = it.next(); + double xyDiff = edgeTemp.distance(edge); + double zDiff = edgeTemp.z - edge.z; + shieldingDepth += Math.sqrt(xyDiff * xyDiff + zDiff * zDiff); + edgeTemp = edge; + } - final double lastEdgeSourceXYDiff = midPoint.distance(edgeTemp); - final double lastEdgeSourceZDiff = GROUND_HEIGHT - edgeTemp.z; - double lastEdgeToSourceDistance = Math.sqrt(lastEdgeSourceXYDiff * lastEdgeSourceXYDiff - + lastEdgeSourceZDiff * lastEdgeSourceZDiff); + final double lastEdgeSourceXYDiff = midPoint.distance(edgeTemp); + final double lastEdgeSourceZDiff = GROUND_HEIGHT - edgeTemp.z; + double lastEdgeToSourceDistance = Math.sqrt(lastEdgeSourceXYDiff * lastEdgeSourceXYDiff + + lastEdgeSourceZDiff * lastEdgeSourceZDiff); - correctionTermShielding = shieldingCorrection.calculateShieldingCorrection( - rpPoint.distance(midPoint), lastEdgeToSourceDistance, receiverToFirstEdgeDistance, shieldingDepth); - } + correctionTermShielding = shieldingCorrection.calculateShieldingCorrection( + rpPoint.distance(midPoint), lastEdgeToSourceDistance, receiverToFirstEdgeDistance, shieldingDepth); return correctionTermShielding; } @@ -170,7 +157,6 @@ private ConcurrentSkipListMap getObstructionEdges(Coordinate //using intersects() and intersection() directly on the jts geometry. nkuehnel, aug '20 final Set intersections = intersection((Polygon) noiseBarrier.getGeometry().getGeometry(), directLineOfSight.getCoordinates()); - for (Coordinate coordinate : intersections) { coordinate.z = noiseBarrier.getHeight(); final double distance = receiver.distance(coordinate); @@ -226,25 +212,7 @@ private LineString constructLineOfSight(Coordinate receiver, Coordinate source) private Set intersection(Polygon polygon, Coordinate[] coords) { - - Set externalIntersections = intersection(polygon.getExteriorRing(), coords); - -// Set internalIntersections = null; -// for (int i = 0; i < polygon.getNumInteriorRing(); i++) { -// Set intersects = intersection(polygon.getInteriorRingN(i), coords); -// if (!intersects.isEmpty()) { -// if (internalIntersections == null) { -// internalIntersections = new HashSet<>(); -// } -// internalIntersections.addAll(intersects); -// } -// } - -// if(internalIntersections != null) { -// externalIntersections.addAll(internalIntersections); -// } - - return externalIntersections; + return intersection(polygon.getExteriorRing(), coords); } private Set intersection(LineString ring, Coordinate[] coords) { @@ -285,7 +253,6 @@ private static boolean intersects(Polygon polygon, LineString string) { } - /** * determines the shielding value z for a receiver point for a given link emission source */ @@ -305,70 +272,68 @@ private static boolean intersects(Polygon polygon, LineString string) { NavigableMap edgeCandidates = getObstructionEdges(rpPoint, projectedPoint, projectedLineOfSight, fromLineOfSight, toLineOfSight); edgeCandidates.put(projectedLineOfSight.getLength(), projectedPoint.getCoordinate()); - if (!edgeCandidates.isEmpty()) { - Coordinate lastFixedEdge = rpPoint.getCoordinate(); - Coordinate tmpEdge = rpPoint.getCoordinate(); - double currentHeight = GROUND_HEIGHT; + Coordinate lastFixedEdge = rpPoint.getCoordinate(); + Coordinate tmpEdge = rpPoint.getCoordinate(); + double currentHeight = GROUND_HEIGHT; - List consideredEdges = new ArrayList<>(); + List consideredEdges = new ArrayList<>(); - double distToCurrentEdge = 0; - while (lastFixedEdge != projectedPoint.getCoordinate()) { - if (edgeCandidates.isEmpty()) { - logger.warn("Skipping obstacle as distance appears to be 0."); - return correctionTermShielding; - } - Iterator edgesIterator = edgeCandidates.values().iterator(); - double maxSlope = Double.NEGATIVE_INFINITY; - double tmpDistance = 0; - while (edgesIterator.hasNext()) { - Coordinate edge = edgesIterator.next(); - double distance = lastFixedEdge.distance(edge); - double slope = (edge.z - currentHeight) / distance; - if (slope >= maxSlope) { - maxSlope = slope; - tmpEdge = edge; - tmpDistance = distance; - } + double distToCurrentEdge = 0; + while (lastFixedEdge != projectedPoint.getCoordinate()) { + if (edgeCandidates.isEmpty()) { + logger.warn("Skipping obstacle as distance appears to be 0."); + return correctionTermShielding; + } + Iterator edgesIterator = edgeCandidates.values().iterator(); + double maxSlope = Double.NEGATIVE_INFINITY; + double tmpDistance = 0; + while (edgesIterator.hasNext()) { + Coordinate edge = edgesIterator.next(); + double distance = lastFixedEdge.distance(edge); + double slope = (edge.z - currentHeight) / distance; + if (slope >= maxSlope) { + maxSlope = slope; + tmpEdge = edge; + tmpDistance = distance; } - lastFixedEdge = tmpEdge; - distToCurrentEdge += tmpDistance; - currentHeight = tmpEdge.z; - consideredEdges.add(lastFixedEdge); - edgeCandidates = edgeCandidates.tailMap(distToCurrentEdge, false); } + lastFixedEdge = tmpEdge; + distToCurrentEdge += tmpDistance; + currentHeight = tmpEdge.z; + consideredEdges.add(lastFixedEdge); + edgeCandidates = edgeCandidates.tailMap(distToCurrentEdge, false); + } - consideredEdges.remove(projectedPoint.getCoordinate()); + consideredEdges.remove(projectedPoint.getCoordinate()); - if (consideredEdges.isEmpty()) { - return correctionTermShielding; - } + if (consideredEdges.isEmpty()) { + return correctionTermShielding; + } - final double firstEdgeYDiff = GROUND_HEIGHT - consideredEdges.get(0).z; - double firstEdgeDistance = rpPoint.getCoordinate().distance(consideredEdges.get(0)); - double receiverToFirstEdgeDistance - = Math.sqrt(firstEdgeYDiff * firstEdgeYDiff + firstEdgeDistance * firstEdgeDistance); - - double shieldingDepth = 0; - - Iterator it = consideredEdges.iterator(); - Coordinate edgeTemp = it.next(); - while (it.hasNext()) { - Coordinate edge = it.next(); - double xyDiff = edgeTemp.distance(edge); - double zDiff = edgeTemp.z - edge.z; - shieldingDepth += Math.sqrt(xyDiff * xyDiff + zDiff * zDiff); - edgeTemp = edge; - } + final double firstEdgeYDiff = GROUND_HEIGHT - consideredEdges.getFirst().z; + double firstEdgeDistance = rpPoint.getCoordinate().distance(consideredEdges.getFirst()); + double receiverToFirstEdgeDistance + = Math.sqrt(firstEdgeYDiff * firstEdgeYDiff + firstEdgeDistance * firstEdgeDistance); + + double shieldingDepth = 0; + + Iterator it = consideredEdges.iterator(); + Coordinate edgeTemp = it.next(); + while (it.hasNext()) { + Coordinate edge = it.next(); + double xyDiff = edgeTemp.distance(edge); + double zDiff = edgeTemp.z - edge.z; + shieldingDepth += Math.sqrt(xyDiff * xyDiff + zDiff * zDiff); + edgeTemp = edge; + } - final double lastEdgeSourceXYDiff = projectedPoint.getCoordinate().distance(edgeTemp); - final double lastEdgeSourceZDiff = GROUND_HEIGHT - edgeTemp.z; - double lastEdgeToSourceDistance = Math.sqrt(lastEdgeSourceXYDiff * lastEdgeSourceXYDiff - + lastEdgeSourceZDiff * lastEdgeSourceZDiff); + final double lastEdgeSourceXYDiff = projectedPoint.getCoordinate().distance(edgeTemp); + final double lastEdgeSourceZDiff = GROUND_HEIGHT - edgeTemp.z; + double lastEdgeToSourceDistance = Math.sqrt(lastEdgeSourceXYDiff * lastEdgeSourceXYDiff + + lastEdgeSourceZDiff * lastEdgeSourceZDiff); - correctionTermShielding = shieldingCorrection.calculateShieldingCorrection( - rpPoint.distance(projectedPoint), lastEdgeToSourceDistance, receiverToFirstEdgeDistance, shieldingDepth); - } + correctionTermShielding = shieldingCorrection.calculateShieldingCorrection( + rpPoint.distance(projectedPoint), lastEdgeToSourceDistance, receiverToFirstEdgeDistance, shieldingDepth); return correctionTermShielding; } } diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/Data.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/Data.java index d13bbc48ae4..16029040d47 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/Data.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/Data.java @@ -3,8 +3,10 @@ import org.apache.commons.io.FilenameUtils; import org.matsim.application.CommandRunner; import org.matsim.application.MATSimAppCommand; +import org.matsim.core.utils.io.IOUtils; import javax.annotation.Nullable; +import java.io.UncheckedIOException; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Path; @@ -154,13 +156,40 @@ public String subcommand(String command, String file) { */ public String resource(String name) { - URL resource = this.getClass().getResource(name); + String path = resolveResource(name, true); + + // Handle shape files separately, copy additional files that are known to belong to shp files + if (name.endsWith(".shp")) { + resolveResource(name.replace(".shp", ".cpg"), false); + resolveResource(name.replace(".shp", ".dbf"), false); + resolveResource(name.replace(".shp", ".qix"), false); + resolveResource(name.replace(".shp", ".qmd"), false); + resolveResource(name.replace(".shp", ".prj"), false); + resolveResource(name.replace(".shp", ".shx"), false); + } + + return path; + } + + private String resolveResource(String name, boolean required) { + URL resource = null; + + try { + resource = IOUtils.resolveFileOrResource(name); + } catch (UncheckedIOException e) { + // Nothing to do + } if (resource == null) { // Try to prefix / automatically resource = this.getClass().getResource("/" + name); - if (resource == null) + } + + if (resource == null) { + if (required) throw new IllegalArgumentException("Resource '" + name + "' not found!"); + else + return null; } String baseName = FilenameUtils.getName(resource.getPath()); diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperConfigGroup.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperConfigGroup.java index 6bb420d1292..0914fda1eb7 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperConfigGroup.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperConfigGroup.java @@ -1,5 +1,6 @@ package org.matsim.simwrapper; +import org.matsim.core.config.Config; import org.matsim.core.config.ConfigGroup; import org.matsim.core.config.ReflectiveConfigGroup; @@ -28,6 +29,10 @@ public class SimWrapperConfigGroup extends ReflectiveConfigGroup { @Comment("Set of simple class names or fully qualified class names of dashboards to exclude") public Set exclude = new HashSet<>(); + @Parameter + @Comment("Set of simple class names or fully qualified class names of dashboards to include. Any none included dashboard will be excluded.") + public Set include = new HashSet<>(); + @Parameter @Comment("Sample size of the run, which may be required by certain analysis functions.") public Double sampleSize = 1.0d; @@ -83,6 +88,15 @@ public void addParameterSet(ConfigGroup set) { } } + @Override + protected void checkConsistency(Config config) { + super.checkConsistency(config); + + if (!include.isEmpty() && !exclude.isEmpty()) { + throw new IllegalStateException("Include and exclude option can't be set both."); + } + } + /** * Mode how default dashboards are loaded. */ diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperListener.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperListener.java index 1270c938ee4..b9bd8c261a3 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperListener.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/SimWrapperListener.java @@ -34,8 +34,8 @@ public class SimWrapperListener implements StartupListener, ShutdownListener { @Inject public SimWrapperListener(SimWrapper simWrapper, Set bindings, Config config) { this.simWrapper = simWrapper; - this.bindings = bindings; - this.config = config; + this.bindings = bindings; + this.config = config; } /** @@ -105,6 +105,9 @@ private void addFromProvider(SimWrapperConfigGroup config, Iterable exclude; + @CommandLine.Option(names = "--include", split = ",", description = "Use only the dashboards which classnames match.") + private Set include; + public static void main(String[] args) { new SimWrapperRunner().execute(args); } @@ -58,6 +61,8 @@ public Integer call() throws Exception { if (exclude != null) simWrapperConfigGroup.exclude.addAll(exclude); + if (include != null) + simWrapperConfigGroup.include.addAll(include); SimWrapperListener listener = new SimWrapperListener(SimWrapper.create(config), config); try { diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/ActivityDashboard.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/ActivityDashboard.java new file mode 100644 index 00000000000..5561ea641e8 --- /dev/null +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/dashboard/ActivityDashboard.java @@ -0,0 +1,185 @@ +package org.matsim.simwrapper.dashboard; + +import org.apache.commons.lang3.StringUtils; +import org.matsim.application.analysis.activity.ActivityCountAnalysis; +import org.matsim.simwrapper.Dashboard; +import org.matsim.simwrapper.Header; +import org.matsim.simwrapper.Layout; +import org.matsim.simwrapper.viz.ColorScheme; +import org.matsim.simwrapper.viz.MapPlot; +import org.matsim.simwrapper.viz.TextBlock; + +import javax.annotation.Nullable; +import java.util.*; +import java.util.stream.Collectors; + +/** + * Dashboard to show activity related statistics aggregated by type and location. + *

+ * Note that {@link #addActivityType(String, List, List, boolean, String)} needs to be called for each activity type. + * There is no default configuration. + */ +public class ActivityDashboard implements Dashboard { + + private static final String ID_COLUMN = "id"; + private static final String REF_JOIN = "id"; + + private final String shpFile; + private final Map activityMapping = new LinkedHashMap<>(); + private final Map refCsvs = new LinkedHashMap<>(); + private final Set countMultipleOccurrencesSet = new HashSet<>(); + private List indicators = new ArrayList<>(); + + public ActivityDashboard(String shpFile) { + this.shpFile = Objects.requireNonNull(shpFile, "Shapefile can not be null!"); + } + + /** + * Convenience method to add an activity type with default configuration. + */ + public ActivityDashboard addActivityType(String name, List activities, List indicators) { + return addActivityType(name, activities, indicators, true, null); + } + + /** + * Add an activity type to the dashboard. + * + * @param name name to show in the dashboard + * @param activities List of activity names to include in this type + * @param indicators List of indicators to show + * @param countMultipleOccurrences Whether multiple occurrences of the same activity for one person should be counted. + * Can be used to count home or workplaces only once. + * @param refCsv Reference CSV file to compare the activities to. Can be null. + */ + public ActivityDashboard addActivityType(String name, List activities, List indicators, + boolean countMultipleOccurrences, @Nullable String refCsv) { + activityMapping.put(name, String.join(",", activities)); + refCsvs.put(name, refCsv); + + if (countMultipleOccurrences) { + countMultipleOccurrencesSet.add(name); + } + + this.indicators = indicators; + return this; + } + + @Override + public void configure(Header header, Layout layout) { + + header.title = "Activities"; + header.description = "Displays the activities by type and location."; + + List args = new ArrayList<>(List.of("--id-column", ID_COLUMN, "--shp", shpFile)); + args.add("--activity-mapping"); + args.add(activityMapping.entrySet().stream() + .map(e -> "%s=%s".formatted(e.getKey(), e.getValue())) + .collect(Collectors.joining(";"))); + + args.add("--single-occurrence"); + if (!countMultipleOccurrencesSet.isEmpty()) { + args.add(String.join(";", countMultipleOccurrencesSet)); + } + + + for (Map.Entry activity : activityMapping.entrySet()) { + + String activityName = StringUtils.capitalize(activity.getKey()); + + layout.row("category_header_" + activity.getKey()) + .el(TextBlock.class, (viz, data) -> { + viz.content = "## **" + activityName + "**"; + viz.backgroundColor = "transparent"; + }); + + for (Indicator ind : Indicator.values()) { + + if (indicators.contains(ind)) { + + Layout.Row row = layout.row(activity.getKey() + "_" + ind.name) + .el(MapPlot.class, (viz, data) -> { + viz.title = "Simulated %s Activities (%s)".formatted(activityName, ind.displayName); + viz.height = 8.; + String shp = data.resource(shpFile); + viz.setShape(shp, ID_COLUMN); + viz.addDataset("transit-trips", data.computeWithPlaceholder(ActivityCountAnalysis.class, "activities_%s_per_region.csv", activity.getKey(), args.toArray(new String[0]))); + viz.display.fill.columnName = ind.name; + viz.display.fill.dataset = "transit-trips"; + viz.display.fill.join = REF_JOIN; + if (ind == Indicator.RELATIVE_DENSITY) { + viz.display.fill.setColorRamp(ColorScheme.RdBu, 11, false, "0.2, 0.25, 0.33, 0.5, 0.67, 1.5, 2.0, 3.0, 4.0, 5.0"); + } + }); + + if (refCsvs.get(activity.getKey()) != null) { + row.el(MapPlot.class, (viz, data) -> { + + viz.title = "Reference %s Activities (%s)".formatted(activityName, ind.displayName); + viz.height = 8.; + + String shp = data.resource(shpFile); + viz.setShape(shp, ID_COLUMN); + + viz.addDataset("transit-trips", data.resource(refCsvs.get(activity.getKey()))); + + viz.display.fill.dataset = "transit-trips"; + viz.display.fill.join = REF_JOIN; + + if (ind == Indicator.RELATIVE_DENSITY) { + viz.display.fill.columnName = "relative_density"; + viz.display.fill.setColorRamp(ColorScheme.RdBu, 11, false, "0.2, 0.25, 0.33, 0.5, 0.67, 1.5, 2.0, 3.0, 4.0, 5.0"); + } else if (ind == Indicator.DENSITY) { + viz.display.fill.columnName = "density"; + } else { + viz.display.fill.columnName = "count"; + } + }); + } + } + } + } + } + + /** + * Metric to show in the dashboard. + */ + public enum Indicator { + COUNTS("count", "Counts"), + DENSITY("density", "Density"), + RELATIVE_DENSITY("relative_density", "Relative Density"); + + private final String name; + private final String displayName; + + Indicator(String name, String displayName) { + this.name = name; + this.displayName = displayName; + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/MapPlot.java b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/MapPlot.java index ac675cc6381..96ea10d5d94 100644 --- a/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/MapPlot.java +++ b/contribs/simwrapper/src/main/java/org/matsim/simwrapper/viz/MapPlot.java @@ -10,15 +10,14 @@ */ public final class MapPlot extends Viz { + private final Map datasets = new HashMap<>(); public double[] center; public Double zoom; - public Display display = new Display(); public Double minValue; public Double maxValue; @JsonProperty(required = true) private Object shapes; - private Map datasets = new HashMap<>(); public MapPlot() { super("map"); @@ -77,6 +76,9 @@ public static final class DisplaySettings { @JsonProperty(required = true) public String columnName; + @JsonProperty(required = true) + public String normalize; + @JsonProperty(required = true) public String join; diff --git a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java index e3e92fa87a7..a741dfeba78 100644 --- a/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java +++ b/contribs/simwrapper/src/test/java/org/matsim/simwrapper/dashboard/DashboardTests.java @@ -20,11 +20,12 @@ import java.io.IOException; import java.nio.file.Path; +import java.util.List; import java.util.Set; public class DashboardTests { @RegisterExtension - private MatsimTestUtils utils = new MatsimTestUtils(); + private final MatsimTestUtils utils = new MatsimTestUtils(); private void run(Dashboard... dashboards) { @@ -153,4 +154,20 @@ void ptCustom() { Assertions.assertThat(out) .isDirectoryContaining("glob:**pt_pax_volumes.csv.gz"); } + + @Test + void activity() { + ActivityDashboard ad = new ActivityDashboard("kehlheim_shape.shp"); + + ad.addActivityType( + "work", + List.of("work"), + List.of(ActivityDashboard.Indicator.COUNTS, ActivityDashboard.Indicator.RELATIVE_DENSITY, ActivityDashboard.Indicator.DENSITY), true, + "kehlheim_ref.csv" + ); + + run(ad); + } + + } diff --git a/contribs/simwrapper/src/test/resources/kehlheim_ref.csv b/contribs/simwrapper/src/test/resources/kehlheim_ref.csv new file mode 100644 index 00000000000..1b3ba9c3824 --- /dev/null +++ b/contribs/simwrapper/src/test/resources/kehlheim_ref.csv @@ -0,0 +1,12 @@ +id;count;area;density;relative_density +2;12000.0;1743518.43;0.006882634;1.07723188785 +6;11000.0;350075.92;0.031421756;3.91795945 +4;2000.0;545791.40;0.003664404;0.5735321986 +8;13000.0;2121061.25;0.006129007;0.9592783427 +9;15000.0;3785838.06;0.003962135;0.6201314016 +10;7000.0;5744728.89;0.001218508;0.19071418629999998 +1;2000.0;1981892.09;0.001009137;0.19071418629999998 +3;12000.0;1955593.52;0.006136245;0.9604110622400001 +7;7000.0;942460.23;0.007427369;1.1624907459 +5;1000.0;876651.07;0.001140705;0.1785367932 +0;8000.0;6205676.03;0.001289142;0.2017694383 \ No newline at end of file diff --git a/contribs/simwrapper/src/test/resources/kehlheim_shape.cpg b/contribs/simwrapper/src/test/resources/kehlheim_shape.cpg new file mode 100644 index 00000000000..3ad133c048f --- /dev/null +++ b/contribs/simwrapper/src/test/resources/kehlheim_shape.cpg @@ -0,0 +1 @@ +UTF-8 \ No newline at end of file diff --git a/contribs/simwrapper/src/test/resources/kehlheim_shape.dbf b/contribs/simwrapper/src/test/resources/kehlheim_shape.dbf new file mode 100644 index 00000000000..d3b37577b5d Binary files /dev/null and b/contribs/simwrapper/src/test/resources/kehlheim_shape.dbf differ diff --git a/contribs/simwrapper/src/test/resources/kehlheim_shape.prj b/contribs/simwrapper/src/test/resources/kehlheim_shape.prj new file mode 100644 index 00000000000..bd846aeb220 --- /dev/null +++ b/contribs/simwrapper/src/test/resources/kehlheim_shape.prj @@ -0,0 +1 @@ +PROJCS["ETRS_1989_UTM_Zone_32N",GEOGCS["GCS_ETRS_1989",DATUM["D_ETRS_1989",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",9.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]] \ No newline at end of file diff --git a/contribs/simwrapper/src/test/resources/kehlheim_shape.qmd b/contribs/simwrapper/src/test/resources/kehlheim_shape.qmd new file mode 100644 index 00000000000..53f5af5ac96 --- /dev/null +++ b/contribs/simwrapper/src/test/resources/kehlheim_shape.qmd @@ -0,0 +1,44 @@ + + + + + + dataset + + + + + + + + + + + + + + + + + + GEOGCRS["WGS 84",ENSEMBLE["World Geodetic System 1984 ensemble",MEMBER["World Geodetic System 1984 (Transit)"],MEMBER["World Geodetic System 1984 (G730)"],MEMBER["World Geodetic System 1984 (G873)"],MEMBER["World Geodetic System 1984 (G1150)"],MEMBER["World Geodetic System 1984 (G1674)"],MEMBER["World Geodetic System 1984 (G1762)"],ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],AXIS["geodetic latitude (Lat)",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],AXIS["geodetic longitude (Lon)",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]],USAGE[SCOPE["Horizontal component of 3D system."],AREA["World."],BBOX[-90,-180,90,180]],ID["EPSG",4326]] + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + EPSG:7030 + true + + + + + + + + + + + + diff --git a/contribs/simwrapper/src/test/resources/kehlheim_shape.shp b/contribs/simwrapper/src/test/resources/kehlheim_shape.shp new file mode 100644 index 00000000000..ff0f9b67afd Binary files /dev/null and b/contribs/simwrapper/src/test/resources/kehlheim_shape.shp differ diff --git a/contribs/simwrapper/src/test/resources/kehlheim_shape.shx b/contribs/simwrapper/src/test/resources/kehlheim_shape.shx new file mode 100644 index 00000000000..1be796e8141 Binary files /dev/null and b/contribs/simwrapper/src/test/resources/kehlheim_shape.shx differ diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/DefaultIntegrateExistingTrafficToSmallScaleCommercialImpl.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/DefaultIntegrateExistingTrafficToSmallScaleCommercialImpl.java index 6652c17b955..052fb62b9f1 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/DefaultIntegrateExistingTrafficToSmallScaleCommercialImpl.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/DefaultIntegrateExistingTrafficToSmallScaleCommercialImpl.java @@ -372,8 +372,8 @@ public void reduceDemandBasedOnExistingCarriers(Scenario scenario, Map createListOfCarrierWithUnhandledJobs(Scenario scenario){ private void redrawAllServiceDurations(Carrier carrier, GenerateSmallScaleCommercialTrafficDemand.CarrierAttributes carrierAttributes, int additionalTravelBufferPerIterationInMinutes) { for (CarrierService service : carrier.getServices().values()) { double newServiceDuration = generator.getServiceTimePerStop(carrier, carrierAttributes, additionalTravelBufferPerIterationInMinutes); - CarrierService redrawnService = CarrierService.Builder.newInstance(service.getId(), service.getLocationLinkId()) + CarrierService redrawnService = CarrierService.Builder.newInstance(service.getId(), service.getServiceLinkId()) .setServiceDuration(newServiceDuration).setServiceStartTimeWindow(service.getServiceStartTimeWindow()).build(); carrier.getServices().put(redrawnService.getId(), redrawnService); } diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java index 2f322e8640f..3b159189bda 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java @@ -391,8 +391,8 @@ public void exportShipmentInfo(String path, Boolean exportGuesses) { if (shipmentTracker == null) { continue; } - Id from = shipment.getFrom(); - Id toLink = shipment.getTo(); + Id from = shipment.getPickupLinkId(); + Id toLink = shipment.getDeliveryLinkId(); // if info is not certain, export the guess if that is wanted. String carrierIdString = id2String(carrier.getId()); String shipmentIdString = id2String(shipment.getId()); diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisServiceTracking.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisServiceTracking.java index 88ee09b7b5c..b0e668fdc2f 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisServiceTracking.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisServiceTracking.java @@ -57,7 +57,7 @@ public void addTracker(CarrierService service, Id id) { public void trackServiceActivityStart(ActivityStartEvent activityStartEvent) { for (ServiceTracker.CarrierServiceTracker cst: carrierServiceTrackers.values()) { for (ServiceTracker service : cst.serviceTrackers.values()) { - if (service.service.getLocationLinkId().equals(activityStartEvent.getLinkId())) { + if (service.service.getServiceLinkId().equals(activityStartEvent.getLinkId())) { if (service.driverId == null) { // if there is no driver, but there is a service which is to be performed at the moment at this place, we guess this could be the event for it. // (Does not work well obviously as soon as there are multiple services at a location that have generous time windows, like e.g. at stores). diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisShipmentTracking.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisShipmentTracking.java index e7126cca05e..5673a46b530 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisShipmentTracking.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisShipmentTracking.java @@ -57,12 +57,14 @@ public void trackDeliveryActivity(ActivityStartEvent activityStartEvent) { for (ShipmentTracker shipment: shipments.values()){ if (shipment.to==activityStartEvent.getLinkId() ){ if(shipment.driverId == null){ - if(shipment.shipment.getDeliveryTimeWindow().getStart()<=activityStartEvent.getTime() && activityStartEvent.getTime()<=shipment.shipment.getDeliveryTimeWindow().getEnd()){ - if (shipment.possibleDrivers.contains(activityStartEvent.getPersonId().toString())) { - shipment.driverIdGuess = activityStartEvent.getPersonId(); - shipment.deliveryTimeGuess=activityStartEvent.getTime(); - } - } + if(shipment.shipment.getDeliveryStartsTimeWindow().getStart() <= activityStartEvent.getTime()) { + if (activityStartEvent.getTime()<= shipment.shipment.getDeliveryStartsTimeWindow().getEnd()) { + if (shipment.possibleDrivers.contains(activityStartEvent.getPersonId().toString())) { + shipment.driverIdGuess = activityStartEvent.getPersonId(); + shipment.deliveryTimeGuess=activityStartEvent.getTime(); + } + } + } } else if (shipment.driverId.toString().equals(activityStartEvent.getPersonId().toString())){ shipment.deliveryTime=activityStartEvent.getTime(); } @@ -75,8 +77,10 @@ public void trackPickupActivity(ActivityStartEvent activityStartEvent) { for (ShipmentTracker shipmentTracker: shipments.values()){ if (shipmentTracker.from==activityStartEvent.getLinkId()){ if (shipmentTracker.driverId==null){ - if(shipmentTracker.shipment.getPickupTimeWindow().getStart()<=activityStartEvent.getTime() && activityStartEvent.getTime()<=shipmentTracker.shipment.getPickupTimeWindow().getEnd()){ - shipmentTracker.possibleDrivers.add(activityStartEvent.getPersonId().toString()); + if(shipmentTracker.shipment.getPickupStartsTimeWindow().getStart() <= activityStartEvent.getTime()) { + if (activityStartEvent.getTime()<= shipmentTracker.shipment.getPickupStartsTimeWindow().getEnd()) { + shipmentTracker.possibleDrivers.add(activityStartEvent.getPersonId().toString()); + } } } } @@ -124,8 +128,8 @@ class ShipmentTracker { public ShipmentTracker(CarrierShipment shipment) { this.id = shipment.getId(); - this.from = shipment.getFrom(); - this.to=shipment.getTo(); + this.from = shipment.getPickupLinkId(); + this.to=shipment.getDeliveryLinkId(); this.shipment=shipment; }