Skip to content

Commit

Permalink
Merge pull request #3641 from matsim-org/updateFreightAnalysis
Browse files Browse the repository at this point in the history
Update freight analysis
  • Loading branch information
rewertvsp authored Dec 16, 2024
2 parents d63bd25 + d66b1c5 commit 02d6485
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +52,7 @@ public class CarrierLoadAnalysis implements CarrierShipmentPickupStartEventHandl
final Carriers carriers;

private final Map<Id<Vehicle>, LinkedList<Integer>> vehicle2Load = new LinkedHashMap<>();
private final Map<Id<Vehicle>, Integer> vehicle2DemandPerTour = new HashMap<>();

public CarrierLoadAnalysis(String delimiter, Carriers carriers) {
this.delimiter = delimiter;
Expand All @@ -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);
}
Expand All @@ -98,6 +99,8 @@ void writeLoadPerVehicle(String analysisOutputDirectory, Scenario scenario) thro
"vehicleTypeId",
"capacity",
"maxLoad",
"maxLoadPercentage",
"handledDemand",
"load state during tour"));
bw1.newLine();

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
vehicleId vehicleTypeId capacity maxLoad load state during tour
vehicleId vehicleTypeId capacity maxLoad maxLoadPercentage handledDemand load state during tour
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit 02d6485

Please sign in to comment.