From db13a2c65eed7ff1f190054d366b989221238303 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Wed, 17 Apr 2024 14:44:56 +0200 Subject: [PATCH] add reduction of unused vehicleTypes --- .../GenerateSmallScaleCommercialTrafficDemand.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java index 00c5496cf8a..e33e6248b16 100644 --- a/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java +++ b/contribs/small-scale-traffic-generation/src/main/java/org/matsim/smallScaleCommercialTrafficGeneration/GenerateSmallScaleCommercialTrafficDemand.java @@ -200,6 +200,17 @@ public Integer call() throws Exception { freightCarriersConfigGroup.setCarriersVehicleTypesFile(config.vehicles().getVehiclesFile()); log.info("Load carriers from: {}", freightCarriersConfigGroup.getCarriersFile()); CarriersUtils.loadCarriersAccordingToFreightConfig(scenario); + + // Remove vehicle types which are not used by the carriers + Map, VehicleType> readVehicleTypes = CarriersUtils.getCarrierVehicleTypes(scenario).getVehicleTypes(); + List> usedCarrierVehicleTypes = CarriersUtils.getCarriers(scenario).getCarriers().values().stream() + .flatMap(carrier -> carrier.getCarrierCapabilities().getCarrierVehicles().values().stream()) + .map(vehicle -> vehicle.getType().getId()) + .distinct() + .toList(); + + readVehicleTypes.keySet().removeIf(vehicleType -> !usedCarrierVehicleTypes.contains(vehicleType)); + if (Objects.requireNonNull(usedCreationOption) == CreationOption.useExistingCarrierFileWithoutSolution) { solveSeparatedVRPs(scenario, null); }