From 9d7491b338ee625969f606418f46d2466049f1a7 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Mon, 16 Dec 2024 13:32:24 +0100 Subject: [PATCH 1/3] add columns for load analysis --- .../carriers/analysis/CarrierLoadAnalysis.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierLoadAnalysis.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierLoadAnalysis.java index 760ce513035..652d0740975 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierLoadAnalysis.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/CarrierLoadAnalysis.java @@ -27,10 +27,8 @@ import java.io.FileWriter; import java.io.IOException; import java.nio.file.Path; -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -54,6 +52,7 @@ public class CarrierLoadAnalysis implements CarrierShipmentPickupStartEventHandl final Carriers carriers; private final Map, LinkedList> vehicle2Load = new LinkedHashMap<>(); + private final Map, Integer> vehicle2DemandPerTour = new HashMap<>(); public CarrierLoadAnalysis(String delimiter, Carriers carriers) { this.delimiter = delimiter; @@ -69,9 +68,11 @@ public void handleEvent(CarrierShipmentPickupStartEvent event) { if (! vehicle2Load.containsKey(vehicleId)){ list = new LinkedList<>(); list.add(demand); + vehicle2DemandPerTour.put(vehicleId, demand); } else { list = vehicle2Load.get(vehicleId); list.add(list.getLast() + demand); + vehicle2DemandPerTour.put(vehicleId, vehicle2DemandPerTour.get(vehicleId) + demand); } vehicle2Load.put(vehicleId, list); } @@ -98,6 +99,8 @@ void writeLoadPerVehicle(String analysisOutputDirectory, Scenario scenario) thro "vehicleTypeId", "capacity", "maxLoad", + "maxLoadPercentage", + "handledDemand", "load state during tour")); bw1.newLine(); @@ -109,10 +112,15 @@ void writeLoadPerVehicle(String analysisOutputDirectory, Scenario scenario) thro final VehicleType vehicleType = VehicleUtils.findVehicle(vehicleId, scenario).getType(); final Double capacity = vehicleType.getCapacity().getOther(); + final Integer demand = vehicle2DemandPerTour.get(vehicleId); + final double maxLoadPercentage = Math.round(maxLoad / capacity * 10000)/100.0;; + bw1.write(vehicleId.toString()); bw1.write(delimiter + vehicleType.getId().toString()); bw1.write(delimiter + capacity); bw1.write(delimiter + maxLoad); + bw1.write(delimiter + maxLoadPercentage); + bw1.write(delimiter + demand); bw1.write(delimiter + load); bw1.newLine(); } From 9e014f2c40c338418294bf8647dfacc0c2a33022 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Mon, 16 Dec 2024 13:33:50 +0100 Subject: [PATCH 2/3] add logging --- .../freight/carriers/analysis/RunFreightAnalysisEventBased.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/RunFreightAnalysisEventBased.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/RunFreightAnalysisEventBased.java index 0502ae2e1c4..00c1f1dea61 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/RunFreightAnalysisEventBased.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/analysis/RunFreightAnalysisEventBased.java @@ -124,6 +124,8 @@ public RunFreightAnalysisEventBased(Carriers carriers, String analysisOutputPath private void createScenarioForFreightAnalysis(String vehiclesPath, String networkPath, String carriersPath, String carriersVehicleTypesPath, String globalCrs) { + log.info("########## Starting Freight Analysis ##########"); + Config config = ConfigUtils.createConfig(); config.vehicles().setVehiclesFile(vehiclesPath); config.network().setInputFile(networkPath); From d66b1c5e96a0c1e774eb8b5a449c8defc7a13dbe Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Mon, 16 Dec 2024 13:52:08 +0100 Subject: [PATCH 3/3] adjust resulting test --- .../runServiceEventTest/Load_perVehicle.tsv | 2 +- .../runShipmentEventTest/Load_perVehicle.tsv | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runServiceEventTest/Load_perVehicle.tsv b/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runServiceEventTest/Load_perVehicle.tsv index a1e0058ce5b..3d861e42d95 100644 --- a/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runServiceEventTest/Load_perVehicle.tsv +++ b/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runServiceEventTest/Load_perVehicle.tsv @@ -1 +1 @@ -vehicleId vehicleTypeId capacity maxLoad load state during tour +vehicleId vehicleTypeId capacity maxLoad maxLoadPercentage handledDemand load state during tour diff --git a/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runShipmentEventTest/Load_perVehicle.tsv b/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runShipmentEventTest/Load_perVehicle.tsv index d61ddd36308..4216eeed0f3 100644 --- a/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runShipmentEventTest/Load_perVehicle.tsv +++ b/contribs/freight/test/input/org/matsim/freight/carriers/analysis/FreightAnalysisEventBasedTest/runShipmentEventTest/Load_perVehicle.tsv @@ -1,2 +1,2 @@ -vehicleId vehicleTypeId capacity maxLoad load state during tour -freight_carrier1_veh_freight_carrier1_veh_heavyVehicle_1_1 heavy 50.0 26 [3, 8, 18, 25, 26, 23, 13, 12, 7, 0] +vehicleId vehicleTypeId capacity maxLoad maxLoadPercentage handledDemand load state during tour +freight_carrier1_veh_freight_carrier1_veh_heavyVehicle_1_1 heavy 50.0 26 52.0 26 [3, 8, 18, 25, 26, 23, 13, 12, 7, 0]