From cc78ba440e53577464f0110abddd6b7021968778 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 20 Jun 2024 17:36:51 +0200 Subject: [PATCH 01/15] fix wrong sum calculation --- .../DemandReaderFromCSV.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 a301fe8dcf1..7b241d3d910 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -661,8 +661,7 @@ else if (samplingOption.equals("changeDemandOnLocation")) { if (numberOfServiceLocations != null) throw new RuntimeException( "Because the demand is higher than the number of links, the demand will be distributed evenly over all links. You selected a certain number of service locations, which is not possible here!"); - double sumOfPossibleLinkLength = 0; - possibleLinksForService.values().forEach(l -> Double.sum(l.getLength(), sumOfPossibleLinkLength)); + double sumOfPossibleLinkLength = possibleLinksForService.values().stream().mapToDouble(Link::getLength).sum(); for (Link link : possibleLinksForService.values()) { int demandForThisLink; if (countOfLinks == scenario.getNetwork().getLinks().size()) { @@ -937,10 +936,8 @@ else if (population == null) boolean pickupIsDemandBase = true; Link linkPickup; Link linkDelivery; - double sumOfPossibleLinkLengthPickup = 0; - double sumOfPossibleLinkLengthDelivery = 0; - possibleLinksPickup.values().forEach(l -> Double.sum(l.getLength(), sumOfPossibleLinkLengthPickup)); - possibleLinksDelivery.values().forEach(l -> Double.sum(l.getLength(), sumOfPossibleLinkLengthDelivery)); + double sumOfPossibleLinkLengthPickup = possibleLinksPickup.values().stream().mapToDouble(Link::getLength).sum(); + double sumOfPossibleLinkLengthDelivery = possibleLinksDelivery.values().stream().mapToDouble(Link::getLength).sum(); if (numberOfPickupLocations == null && numberOfDeliveryLocations == null) if (possibleLinksPickup.size() > possibleLinksDelivery.size()) { demandBasesLinks = possibleLinksPickup; @@ -1269,15 +1266,16 @@ private static HashMap, Link> findAllPossibleLinks(Scenario scenario, } } else { Link newPossibleLink; - while (possibleLinks.size() < numberOfLocations) { + while (possibleLinks.size() < numberOfLocations) { //TODO check if number of locations is higher than possible links newPossibleLink = findPossibleLinkForDemand(possibleLinks, possiblePersons, nearestLinkPerPerson, indexShape, areasForLocations, numberOfLocations, scenario, setLocations, crsTransformationNetworkAndShape); if (!possibleLinks.containsKey(newPossibleLink.getId())) possibleLinks.put(newPossibleLink.getId(), newPossibleLink); + if (nearestLinkPerPerson.size() == possiblePersons.size()) + break; } } - return possibleLinks; } From 04746571ef44e7b176273b8f41f456b894794695 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 20 Jun 2024 22:06:28 +0200 Subject: [PATCH 02/15] fix wrong map selection --- .../org/matsim/freightDemandGeneration/DemandReaderFromCSV.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7b241d3d910..1558cf15dd4 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -866,7 +866,7 @@ else if (population == null) setLocationsOfPickup, possiblePersonsPickup, nearestLinkPerPersonPickup); HashMap, Link> possibleLinksDelivery = findAllPossibleLinks(scenario, indexShape, crsTransformationNetworkAndShape, numberOfDeliveryLocations, areasForDeliveryLocations, - setLocationsOfDelivery, possiblePersonsDelivery, nearestLinkPerPersonPickup); + setLocationsOfDelivery, possiblePersonsDelivery, nearestLinkPerPersonDelivery); if (possibleLinksPickup.isEmpty()) throw new RuntimeException( From 728fc28bf2e60838a23472544559d6232f51017c Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 20 Jun 2024 22:37:52 +0200 Subject: [PATCH 03/15] add reduction of numberOfJobs --- .../freightDemandGeneration/DemandReaderFromCSV.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 1558cf15dd4..b63592c01af 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -1034,9 +1034,11 @@ else if (numberOfPickupLocations != null) { { for (int i = 0; i < numberOfJobs; i++) { - if (demandToDistribute != 0 && demandToDistribute < numberOfJobs) - throw new RuntimeException( - "The resulting number of jobs is not feasible, because the demand is smaller then the number of jobs. Please check!"); + if (demandToDistribute != 0 && demandToDistribute < numberOfJobs) { + numberOfJobs = demandToDistribute; + log.warn( + "The resulting number of jobs is not feasible, because the demand is smaller then the number of jobs. Number of jobs is reduced to demand!"); + } Link linkPickup = findNextUsedLink(scenario, indexShape, possibleLinksPickup, numberOfPickupLocations, areasForPickupLocations, setLocationsOfPickup, usedPickupLocations, possiblePersonsPickup, nearestLinkPerPersonPickup, crsTransformationNetworkAndShape, i); From 10b884b68c3b4bcb0edf7ec4e0ab35ff524049b8 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 09:45:57 +0200 Subject: [PATCH 04/15] add comments and format log massages --- .../CarrierReaderFromCSV.java | 49 +++--- .../DemandReaderFromCSV.java | 153 +++++++++--------- .../FreightDemandGeneration.java | 92 +++++------ .../FreightDemandGenerationUtils.java | 32 ++-- 4 files changed, 162 insertions(+), 164 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java index 19dc604a32c..1dddc82cf55 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java @@ -234,14 +234,14 @@ public void setFixedNumberOfVehiclePerTypeAndLocation(int fixedNumberOfVehiclePe /** * Reads and create the carriers with reading the information from the csv file. * - * @param scenario - * @param freightCarriersConfigGroup - * @param csvLocationCarrier - * @param indexShape - * @param defaultJspritIterations - * @param crsTransformationNetworkAndShape - * @param shapeCategory - * @throws IOException + * @param scenario Scenario + * @param freightCarriersConfigGroup FreightCarriersConfigGroup + * @param csvLocationCarrier Path to the csv file with the carrier information + * @param indexShape ShpOptions.Index for the shape file + * @param defaultJspritIterations Default number of jsprit iterations + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape + * @param shapeCategory Column name in the shape file for the data connection in the csv files + * @throws IOException IOException */ public static void readAndCreateCarrierFromCSV(Scenario scenario, FreightCarriersConfigGroup freightCarriersConfigGroup, Path csvLocationCarrier, ShpOptions.Index indexShape, int defaultJspritIterations, @@ -255,12 +255,12 @@ public static void readAndCreateCarrierFromCSV(Scenario scenario, FreightCarrier } /** - * @param csvLocationCarrier - * @return - * @throws IOException + * @param csvLocationCarrier Path to the csv file with the carrier information + * @return Set Set of CarrierInformationElements + * @throws IOException IOException */ static Set readCarrierInformation(Path csvLocationCarrier) throws IOException { - log.info("Start reading carrier csv file: " + csvLocationCarrier); + log.info("Start reading carrier csv file: {}", csvLocationCarrier); Set allNewCarrierInformation = new HashSet<>(); CSVParser parse = new CSVParser(Files.newBufferedReader(csvLocationCarrier), CSVFormat.Builder.create(CSVFormat.TDF).setHeader().setSkipHeaderRecord(true).build()); @@ -305,11 +305,11 @@ else if (!record.get("fleetSize").isBlank()) /** * Checks if the read carrier information is consistent. * - * @param allNewCarrierInformation - * @param freightCarriersConfigGroup - * @param scenario - * @param indexShape - * @param shapeCategory + * @param allNewCarrierInformation Set of CarrierInformationElements + * @param freightCarriersConfigGroup FreightCarriersConfigGroup + * @param scenario Scenario + * @param indexShape ShpOptions.Index for the shape file + * @param shapeCategory Column name in the shape file for the data connection in the csv files */ static void checkNewCarrier(Set allNewCarrierInformation, FreightCarriersConfigGroup freightCarriersConfigGroup, Scenario scenario, ShpOptions.Index indexShape, String shapeCategory) { @@ -407,12 +407,12 @@ static void checkNewCarrier(Set allNewCarrierInformat /** * Read and creates the carrier and the vehicle types. * - * @param scenario - * @param allNewCarrierInformation - * @param freightCarriersConfigGroup - * @param indexShape - * @param defaultJspritIterations - * @param crsTransformationNetworkAndShape + * @param scenario Scenario + * @param allNewCarrierInformation Set of CarrierInformationElements + * @param freightCarriersConfigGroup FreightCarriersConfigGroup + * @param indexShape ShpOptions.Index for the shape file + * @param defaultJspritIterations Default number of jsprit iterations + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape */ static void createNewCarrierAndAddVehicleTypes(Scenario scenario, Set allNewCarrierInformation, FreightCarriersConfigGroup freightCarriersConfigGroup, @@ -498,8 +498,7 @@ static void createNewCarrierAndAddVehicleTypes(Scenario scenario, for (Carrier carrier : carriers.getCarriers().values()) { if (CarriersUtils.getJspritIterations(carrier) == Integer.MIN_VALUE) { CarriersUtils.setJspritIterations(carrier, defaultJspritIterations); - log.warn("The jspritIterations are now set to the default value of " + defaultJspritIterations - + " in this simulation!"); + log.warn("The jspritIterations are now set to the default value of {} in this simulation!", defaultJspritIterations); } } } 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 b63592c01af..aa8b5a86252 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -316,14 +316,14 @@ public String getTypeOfDemand() { * Reads the csv with the demand information and adds this demand to the related * carriers. * - * @param scenario - * @param csvLocationDemand - * @param indexShape - * @param combineSimilarJobs - * @param crsTransformationNetworkAndShape - * @param population - * @param shapeCategory - * @throws IOException + * @param scenario Scenario + * @param csvLocationDemand Path to the csv file with the demand information + * @param indexShape ShpOptions.Index for the shape file + * @param combineSimilarJobs boolean if the jobs of the same carrier with same location and time will be combined + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file + * @param population Population + * @param shapeCategory Column name in the shape file for the data connection in the csv files + * @throws IOException if the csv file cannot be read */ static void readAndCreateDemand(Scenario scenario, Path csvLocationDemand, ShpOptions.Index indexShape, boolean combineSimilarJobs, @@ -339,9 +339,9 @@ static void readAndCreateDemand(Scenario scenario, Path csvLocationDemand, * Reads the demand information from the csv file and checks if the information * is consistent * - * @param csvLocationDemand - * @return - * @throws IOException + * @param csvLocationDemand Path to the csv file with the demand information + * @return Set + * @throws IOException if the csv file cannot be read */ static Set readDemandInformation(Path csvLocationDemand) throws IOException { @@ -403,10 +403,10 @@ static Set readDemandInformation(Path csvLocationDeman * Checks if the read demand information are useful to create the shipment or * service demands * - * @param scenario - * @param demandInformation - * @param indexShape - * @param shapeCategory + * @param scenario Scenario + * @param demandInformation Set + * @param indexShape ShpOptions.Index for the shape file + * @param shapeCategory Column name in the shape file for the data connection in the csv files */ static void checkNewDemand(Scenario scenario, Set demandInformation, ShpOptions.Index indexShape, String shapeCategory) { @@ -537,12 +537,12 @@ static void checkNewDemand(Scenario scenario, Set dema /** * Creates for every demand information the services/shipments for the carriers * - * @param scenario - * @param indexShape - * @param demandInformation - * @param population - * @param combineSimilarJobs - * @param crsTransformationNetworkAndShape + * @param scenario Scenario + * @param indexShape ShpOptions.Index for the shape file + * @param demandInformation Set with the demand information + * @param population Population + * @param combineSimilarJobs boolean if the jobs of the same carrier with same location and time will be combined + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file */ static void createDemandForCarriers(Scenario scenario, ShpOptions.Index indexShape, Set demandInformation, Population population, boolean combineSimilarJobs, @@ -562,12 +562,12 @@ else if (newDemandInformationElement.getTypeOfDemand().equals("shipment")) /** * Creates the services. * - * @param scenario - * @param newDemandInformationElement - * @param indexShape - * @param population - * @param combineSimilarJobs - * @param crsTransformationNetworkAndShape + * @param scenario Scenario + * @param newDemandInformationElement single DemandInformationElement + * @param indexShape ShpOptions.Index + * @param population Population + * @param combineSimilarJobs boolean if the jobs of the same carrier with same location and time will be combined + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file */ private static void createServices(Scenario scenario, DemandInformationElement newDemandInformationElement, ShpOptions.Index indexShape, Population population, boolean combineSimilarJobs, @@ -753,12 +753,12 @@ else if (samplingOption.equals("changeDemandOnLocation")) { /** * Creates the shipments of a carrier. * - * @param scenario - * @param newDemandInformationElement - * @param indexShape - * @param population - * @param combineSimilarJobs - * @param crsTransformationNetworkAndShape + * @param scenario Scenario + * @param newDemandInformationElement single DemandInformationElement + * @param indexShape ShpOptions.Index for the shape file + * @param population Population + * @param combineSimilarJobs boolean if the jobs of the same carrier with same location and time will be combined + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file */ private static void createShipments(Scenario scenario, DemandInformationElement newDemandInformationElement, ShpOptions.Index indexShape, Population population, boolean combineSimilarJobs, @@ -1029,7 +1029,6 @@ else if (numberOfPickupLocations != null) { } } } else - // if a certain number of shipments is selected { for (int i = 0; i < numberOfJobs; i++) { @@ -1094,11 +1093,11 @@ else if (numberOfPickupLocations != null) { * Creates a job Id for a new job. * If a certain Id is already used, a number will be added at the end until no existing job was the same Id. * - * @param scenario - * @param newDemandInformationElement - * @param linkPickup - * @param linkDelivery - * @return + * @param scenario Scenario + * @param newDemandInformationElement single DemandInformationElement + * @param linkPickup Link for the pickup + * @param linkDelivery Link for the delivery + * @return New Job Id */ private static String createJobId(Scenario scenario, DemandInformationElement newDemandInformationElement, Id linkPickup, Id linkDelivery) { @@ -1133,8 +1132,8 @@ private static String createJobId(Scenario scenario, DemandInformationElement ne * If jobs of a carrier have the same characteristics (time window, location), * they will be combined to one job. * - * @param scenario - * @param newDemandInformationElement + * @param scenario Scenario + * @param newDemandInformationElement single DemandInformationElement */ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario, DemandInformationElement newDemandInformationElement) { @@ -1242,15 +1241,15 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario, /** * Finds and returns all possible links for this job. * - * @param scenario - * @param indexShape - * @param crsTransformationNetworkAndShape - * @param numberOfLocations - * @param areasForLocations - * @param setLocations - * @param possiblePersons - * @param nearestLinkPerPerson - * @return + * @param scenario Scenario + * @param indexShape ShpOptions.Index for the shape file + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file + * @param numberOfLocations Number of locations for this demand + * @param areasForLocations Areas for the locations + * @param setLocations Selected locations + * @param possiblePersons Persons that are possible for this demand + * @param nearestLinkPerPerson Nearest link for each person + * @return HashMap with all possible links */ private static HashMap, Link> findAllPossibleLinks(Scenario scenario, ShpOptions.Index indexShape, CoordinateTransformation crsTransformationNetworkAndShape, @@ -1284,18 +1283,18 @@ private static HashMap, Link> findAllPossibleLinks(Scenario scenario, /** * Finds the next link which can be used as a location. * - * @param scenario - * @param indexShape - * @param possibleLinks - * @param selectedNumberOfLocations - * @param areasForLocations - * @param selectedLocations - * @param usedLocations - * @param possiblePersons - * @param nearestLinkPerPerson - * @param crsTransformationNetworkAndShape - * @param i - * @return + * @param scenario Scenario + * @param indexShape ShpOptions.Index for the shape file + * @param possibleLinks All possible links + * @param selectedNumberOfLocations Number of locations for this demand + * @param areasForLocations Areas for the locations + * @param selectedLocations Selected locations + * @param usedLocations Already used locations for this demand + * @param possiblePersons Persons that are possible for this demand + * @param nearestLinkPerPerson Nearest link for each person + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file + * @param i Counter for the number of locations + * @return Next link for the demand */ private static Link findNextUsedLink(Scenario scenario, ShpOptions.Index indexShape, HashMap, Link> possibleLinks, Integer selectedNumberOfLocations, String[] areasForLocations, @@ -1350,9 +1349,9 @@ private static HashMap, Person> findPossiblePersons(Population popula /** * Finds the nearest link for one person. * - * @param scenario - * @param nearestLinkPerPerson - * @param person + * @param scenario Scenario + * @param nearestLinkPerPerson HashMap with the nearest link for each person + * @param person Person for which the nearest link should be found */ static void findLinksForPerson(Scenario scenario, HashMap, HashMap> nearestLinkPerPerson, Person person) { @@ -1376,8 +1375,8 @@ static void findLinksForPerson(Scenario scenario, * The default is to get the home coordinate from one home activity of the selected plan. * If the selected plan does not contain a home activity, the home coordinate is read from the attributes of the person. * - * @param person The person for which the home coordinate should be returned. - * @return + * @param person The person for which the home coordinate should be returned. + * @return The home coordinate of the person. */ private static Coord getHomeCoord(Person person) { Coord homeCoord = null; @@ -1398,16 +1397,16 @@ private static Coord getHomeCoord(Person person) { /** * Searches a possible link for the demand. * - * @param possibleLinks - * @param possiblePersons - * @param nearestLinkPerPerson - * @param indexShape - * @param areasForTheDemand - * @param selectedNumberOfLocations - * @param scenario - * @param selectedLocations - * @param crsTransformationNetworkAndShape - * @return + * @param possibleLinks HashMap with all possible links + * @param possiblePersons HashMap with all possible persons + * @param nearestLinkPerPerson Nearest link for each person + * @param indexShape ShpOptions.Index for the shape file + * @param areasForTheDemand Areas for the demand + * @param selectedNumberOfLocations Number of locations for this demand + * @param scenario Scenario + * @param selectedLocations Selected locations + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file + * @return The selected link for the demand */ private static Link findPossibleLinkForDemand(HashMap, Link> possibleLinks, HashMap, Person> possiblePersons, diff --git a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java index d43ee64522e..47ad4f2fb50 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java @@ -179,7 +179,7 @@ public Integer call() throws IOException, InvalidAttributeValueException, Execut setNetworkAndNetworkChangeEvents(config, networkPathOfOtherNetwork, networkChangeEventsFilePath); // load or create carrierVehicle - log.info("Start creating carriers. Selected option: " + selectedCarrierInputOption); + log.info("Start creating carriers. Selected option: {}", selectedCarrierInputOption); prepareVehicles(config, vehicleTypesFileLocation); // load or create carrier @@ -188,16 +188,16 @@ public Integer call() throws IOException, InvalidAttributeValueException, Execut ShpOptions.Index indexShape = null; shp = new ShpOptions(shapeFilePath, shapeCRS, null); if (shp.isDefined()) { - log.warn("Use of shpFile. Locations for the carriers and the demand only in shp: " + shp.getShapeFile()); + log.warn("Use of shpFile. Locations for the carriers and the demand only in shp: {}", shp.getShapeFile()); indexShape = shp.createIndex(shapeCategory); crsTransformationFromNetworkToShape = shp.createTransformation(networkCRS); } - log.info("Start creating carriers. Selected option: " + selectedCarrierInputOption); + log.info("Start creating carriers. Selected option: {}", selectedCarrierInputOption); createCarrier(scenario, selectedCarrierInputOption, csvCarrierPath, indexShape, defaultJspritIterations, crsTransformationFromNetworkToShape); // create the demand - log.info("Start creating the demand. Selected option: " + selectedCarrierInputOption); + log.info("Start creating the demand. Selected option: {}", selectedCarrierInputOption); createDemand(selectedDemandGenerationOption, scenario, csvDemandPath, indexShape, populationFilePath, selectedPopulationSamplingOption, selectedPopulationOption, Boolean.getBoolean(combineSimilarJobs), crsTransformationFromNetworkToShape); @@ -216,9 +216,9 @@ public Integer call() throws IOException, InvalidAttributeValueException, Execut /** * Deletes the existing output file and sets the number of the last iteration * - * @param lastMATSimIteration - * @param coordinateSystem - * @return + * @param lastMATSimIteration the last iteration of MATSim + * @param coordinateSystem global coordinate system + * @return Config */ private Config prepareConfig(int lastMATSimIteration, String coordinateSystem) { Config config = ConfigUtils.createConfig(); @@ -243,10 +243,10 @@ private Config prepareConfig(int lastMATSimIteration, String coordinateSystem) { /** * Sets the network and the networkChangeEvents if they are available. * - * @param config - * @param networkPathOfOtherNetwork - * @param networkChangeEventsFileLocation - * @throws RuntimeException + * @param config Config + * @param networkPathOfOtherNetwork path to the network + * @param networkChangeEventsFileLocation path to the networkChangeEvents + * @throws RuntimeException if the networkPathOfOtherNetwork is empty */ private static void setNetworkAndNetworkChangeEvents(Config config, String networkPathOfOtherNetwork, String networkChangeEventsFileLocation) throws RuntimeException { @@ -255,11 +255,11 @@ private static void setNetworkAndNetworkChangeEvents(Config config, String netwo throw new RuntimeException("no correct network path network"); else { config.network().setInputFile(networkPathOfOtherNetwork); - log.info("The following input network is selected: imported network from " + networkPathOfOtherNetwork); + log.info("The following input network is selected: imported network from {}", networkPathOfOtherNetwork); if (networkChangeEventsFileLocation.isEmpty()) log.info("No networkChangeEvents selected"); else { - log.info("Setting networkChangeEventsInput file: " + networkChangeEventsFileLocation); + log.info("Setting networkChangeEventsInput file: {}", networkChangeEventsFileLocation); config.network().setTimeVariantNetwork(true); config.network().setChangeEventsInputFile(networkChangeEventsFileLocation); } @@ -269,8 +269,8 @@ private static void setNetworkAndNetworkChangeEvents(Config config, String netwo /** * Reads the carrier vehicle file. * - * @param config - * @param vehicleTypesFileLocation + * @param config Config + * @param vehicleTypesFileLocation path to the vehicleTypes */ private static void prepareVehicles(Config config, String vehicleTypesFileLocation) { @@ -279,20 +279,20 @@ private static void prepareVehicles(Config config, String vehicleTypesFileLocati throw new RuntimeException("No path to the vehicleTypes selected"); else { freightCarriersConfigGroup.setCarriersVehicleTypesFile(vehicleTypesFileLocation); - log.info("Get vehicleTypes from: " + vehicleTypesFileLocation); + log.info("Get vehicleTypes from: {}", vehicleTypesFileLocation); } } /** * Differs between the different options of creating the carrier. * - * @param scenario - * @param selectedCarrierInputOption - * @param csvLocationCarrier - * @param indexShape - * @param defaultJspritIterations - * @param crsTransformationNetworkAndShape - * @throws IOException + * @param scenario Scenario + * @param selectedCarrierInputOption selected carrier input option + * @param csvLocationCarrier path to the carrier csv + * @param indexShape shape index of the shape file + * @param defaultJspritIterations default number of jsprit iterations + * @param crsTransformationNetworkAndShape transformation of the network and shape + * @throws IOException if the carrier file is not found */ private void createCarrier(Scenario scenario, CarrierInputOptions selectedCarrierInputOption, Path csvLocationCarrier, ShpOptions.Index indexShape, @@ -333,16 +333,16 @@ private void createCarrier(Scenario scenario, CarrierInputOptions selectedCarrie /** * Differs between the different options of creating the demand. * - * @param selectedDemandGenerationOption - * @param scenario - * @param csvLocationDemand - * @param indexShape - * @param populationFilePath - * @param selectedSamplingOption - * @param selectedPopulationOption - * @param combineSimilarJobs - * @param crsTransformationNetworkAndShape - * @throws IOException + * @param selectedDemandGenerationOption selected demand generation option + * @param scenario Scenario + * @param csvLocationDemand path to the demand csv + * @param indexShape shape index of the shape file + * @param populationFilePath path to the population file + * @param selectedSamplingOption selected population sampling option + * @param selectedPopulationOption selected population option + * @param combineSimilarJobs boolean if the jobs of the same carrier with same location and time will be combined + * @param crsTransformationNetworkAndShape transformation of the network and shape + * @throws IOException if the demand file is not found */ private void createDemand(DemandGenerationOptions selectedDemandGenerationOption, Scenario scenario, Path csvLocationDemand, ShpOptions.Index indexShape, String populationFilePath, @@ -407,10 +407,10 @@ private void createDemand(DemandGenerationOptions selectedDemandGenerationOption boolean oneCarrierHasJobs = false; for (Carrier carrier : CarriersUtils.getCarriers(scenario).getCarriers().values()) if (carrier.getServices().isEmpty() && carrier.getShipments().isEmpty()) - log.warn(carrier.getId().toString() + " has no jobs which can be used"); + log.warn("{} has no jobs which can be used", carrier.getId().toString()); else { oneCarrierHasJobs = true; - log.info("Used the demand of the carrier " + carrier.getId().toString() + " from the carrierFile!"); + log.info("Used the demand of the carrier {} from the carrierFile!", carrier.getId().toString()); } if (!oneCarrierHasJobs) throw new RuntimeException("Minimum one carrier has no jobs"); @@ -422,8 +422,8 @@ private void createDemand(DemandGenerationOptions selectedDemandGenerationOption /** * Prepares the controller. * - * @param scenario - * @return + * @param scenario Scenario + * @return Controler */ private static Controler prepareControler(Scenario scenario) { Controler controler = new Controler(scenario); @@ -440,11 +440,11 @@ public void install() { /** * Differs between the different options for solving the VRP problem. * - * @param selectedSolution - * @param config - * @param controler - * @throws ExecutionException - * @throws InterruptedException + * @param selectedSolution selected solution option + * @param config Config + * @param controler Controler + * @throws ExecutionException if the execution of the jsprit fails + * @throws InterruptedException if the execution of the jsprit is interrupted */ private static void solveSelectedSolution(OptionsOfVRPSolutions selectedSolution, Config config, Controler controler) throws ExecutionException, InterruptedException { @@ -506,10 +506,10 @@ private static void solveSelectedSolution(OptionsOfVRPSolutions selectedSolution /** * Runs jsprit. * - * @param controler - * @param usingRangeRestriction - * @throws ExecutionException - * @throws InterruptedException + * @param controler Controller + * @param usingRangeRestriction boolean if the range restriction is used + * @throws ExecutionException if the execution of the jsprit fails + * @throws InterruptedException if the execution of the jsprit is interrupted */ private static void runJsprit(Controler controler, boolean usingRangeRestriction) throws ExecutionException, InterruptedException { 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 234d657c0b6..c60a8a39390 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGenerationUtils.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGenerationUtils.java @@ -58,10 +58,10 @@ public class FreightDemandGenerationUtils { /** * Adds the home coordinates to attributes and removes plans * - * @param population - * @param sampleSizeInputPopulation - * @param sampleTo - * @param samplingOption + * @param population The population to be prepared + * @param sampleSizeInputPopulation The sample size of the input population + * @param sampleTo The sample to which the population should be prepared + * @param samplingOption The sampling option to be used for the population */ static void preparePopulation(Population population, double sampleSizeInputPopulation, double sampleTo, String samplingOption) { @@ -107,7 +107,7 @@ static void preparePopulation(Population population, double sampleSizeInputPopul person.getAttributes().putAttribute("homeX", homeCoord.getX()); person.getAttributes().putAttribute("homeY", homeCoord.getY()); } else { - log.warn("No home found for person " + person.getId()); + log.warn("No home found for person {}", person.getId()); } person.removePlan(person.getSelectedPlan()); } @@ -118,7 +118,7 @@ static void preparePopulation(Population population, double sampleSizeInputPopul /** * Creates a tsv file with the locations of all created demand elements. * - * @param controler + * @param controler The controller to get the network from */ static void createDemandLocationsFile(Controler controler) { @@ -160,8 +160,8 @@ static void createDemandLocationsFile(Controler controler) { /** * Reduces the population to all persons having their home in the shape * - * @param population - * @param index + * @param population The population to be reduced + * @param index The index of the shape */ static void reducePopulationToShapeArea(Population population, ShpOptions.Index index) { @@ -187,12 +187,12 @@ static void reducePopulationToShapeArea(Population population, ShpOptions.Index /** * Checks if a link is one of the possible areas. * - * @param link - * @param givenCoord - * @param indexShape - * @param possibleAreas - * @param crsTransformationNetworkAndShape - * @return + * @param link The link to be checked + * @param givenCoord The coord to be checked + * @param indexShape The index of the shape + * @param possibleAreas The possible areas + * @param crsTransformationNetworkAndShape The transformation to be used for the network and the shape + * @return True if the link is in one of the possible areas */ static boolean checkPositionInShape(Link link, Coord givenCoord, ShpOptions.Index indexShape, String[] possibleAreas, CoordinateTransformation crsTransformationNetworkAndShape) { @@ -221,8 +221,8 @@ static boolean checkPositionInShape(Link link, Coord givenCoord, ShpOptions.Inde /** * Creates the middle coord of a link. * - * @param link - * @return Middle coord of the Link + * @param link The link to be used + * @return Middle coord of the Link */ static Coord getCoordOfMiddlePointOfLink(Link link) { From 22ba33e13a8c92fa570a41049b38baf513b2be34 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 09:46:16 +0200 Subject: [PATCH 05/15] combine --- .../CarrierReaderFromCSV.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java index 1dddc82cf55..da86aa03763 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/CarrierReaderFromCSV.java @@ -346,15 +346,12 @@ static void checkNewCarrier(Set allNewCarrierInformat throw new RuntimeException( "If a vehicle type is selected in the input file, numberOfDepots or selectedVehicleDepots should be set. Please check carrier " + carrierElement.getName()); - if (carrierElement.getVehicleDepots() != null - && (carrierElement.getNumberOfDepotsPerType() > carrierElement.getVehicleDepots().size()) - && carrierElement.getAreaOfAdditionalDepots() == null) + if ((carrierElement.getVehicleDepots() != null + && (carrierElement.getNumberOfDepotsPerType() > carrierElement.getVehicleDepots().size()) + && carrierElement.getAreaOfAdditionalDepots() == null) || (carrierElement.getVehicleDepots() == null && (carrierElement.getNumberOfDepotsPerType() > 0) + && carrierElement.getAreaOfAdditionalDepots() == null)) log.warn( - "No possible area for additional depot given. Random choice in the hole network of a possible position"); - if (carrierElement.getVehicleDepots() == null && (carrierElement.getNumberOfDepotsPerType() > 0) - && carrierElement.getAreaOfAdditionalDepots() == null) - log.warn( - "No possible area for additional depot given. Random choice in the hole network of a possible position"); + "No possible area for additional depot given. Random choice in the hole network of a possible position"); if (carrierElement.getAreaOfAdditionalDepots() != null) { if (indexShape == null) throw new RuntimeException("For carrier " + carrierElement.getName() From d08b85a4b049cc716647f798c8b2cf3275443531 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 09:46:32 +0200 Subject: [PATCH 06/15] rename parameter --- .../DemandReaderFromCSV.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 aa8b5a86252..0c7c6b85643 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -1322,14 +1322,14 @@ private static Link findNextUsedLink(Scenario scenario, ShpOptions.Index indexSh /** * Finds all persons that are possible for the demand. * - * @param population - * @param areasForServiceLocations - * @param indexShape - * @param crsTransformationNetworkAndShape - * @return + * @param population Population + * @param areasForJobElementLocations Areas for the locations + * @param indexShape ShpOptions.Index for the shape file + * @param crsTransformationNetworkAndShape CoordinateTransformation for the network and shape file + * @return HashMap with all possible persons */ private static HashMap, Person> findPossiblePersons(Population population, - String[] areasForServiceLocations, ShpOptions.Index indexShape, + String[] areasForJobElementLocations, ShpOptions.Index indexShape, CoordinateTransformation crsTransformationNetworkAndShape) { HashMap, Person> possiblePersons = new HashMap, Person>(); @@ -1340,7 +1340,7 @@ private static HashMap, Person> findPossiblePersons(Population popula coord = crsTransformationNetworkAndShape.transform(coord); if (FreightDemandGenerationUtils.checkPositionInShape(null, coord, indexShape, - areasForServiceLocations, crsTransformationNetworkAndShape)) + areasForJobElementLocations, crsTransformationNetworkAndShape)) possiblePersons.put(person.getId(), person); } return possiblePersons; From 27b61733a0454a53ee006e3b856328120babb01f Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 09:46:54 +0200 Subject: [PATCH 07/15] reduce code --- .../FreightDemandGeneration.java | 72 ++++++------------- 1 file changed, 21 insertions(+), 51 deletions(-) diff --git a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java index 47ad4f2fb50..76dda11fc9b 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/FreightDemandGeneration.java @@ -448,59 +448,29 @@ public void install() { */ private static void solveSelectedSolution(OptionsOfVRPSolutions selectedSolution, Config config, Controler controler) throws ExecutionException, InterruptedException { + new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) + .write(config.controller().getOutputDirectory() + "/output_carriersNoPlans.xml"); + if (Objects.requireNonNull(selectedSolution) == OptionsOfVRPSolutions.createNoSolutionAndOnlyWriteCarrierFile) { + log.warn( + "##Finished without solution of the VRP. If you also want to run jsprit and/or MATSim, please change case of optionsOfVRPSolutions"); + System.exit(0); + } + boolean runMatSim = false; switch (selectedSolution) { - case runJspritAndMATSim -> { - // solves the VRP with jsprit and runs MATSim afterward - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersNoPlans.xml"); - runJsprit(controler, false); - controler.run(); - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersWithPlans.xml"); - } - case runJspritAndMATSimWithDistanceConstraint -> { - // solves the VRP with jsprit by using the distance constraint and runs MATSim afterward - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersNoPlans.xml"); - runJsprit(controler, true); - controler.run(); - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersWithPlans.xml"); - } - case runJsprit -> { - // solves only the VRP with jsprit - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersNoPlans.xml"); - runJsprit(controler, false); - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersWithPlans.xml"); - log.warn( - "##Finished with the jsprit solution. If you also want to run MATSim, please change case of optionsOfVRPSolutions"); - System.exit(0); - } - case runJspritWithDistanceConstraint -> { - // solves only the VRP with jsprit by using the distance constraint - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersNoPlans.xml"); - runJsprit(controler, true); - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersWithPlans.xml"); - log.warn( - "##Finished with the jsprit solution. If you also want to run MATSim, please change case of optionsOfVRPSolutions"); - System.exit(0); - } - case createNoSolutionAndOnlyWriteCarrierFile -> { - // creates no solution of the VRP and only writes the carrier file with the - // generated carriers and demands - new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) - .write(config.controller().getOutputDirectory() + "/output_carriersNoPlans.xml"); - log.warn( - "##Finished without solution of the VRP. If you also want to run jsprit and/or MATSim, please change case of optionsOfVRPSolutions"); - System.exit(0); - } - default -> { - } + case runJspritAndMATSim, runJspritAndMATSimWithDistanceConstraint -> runMatSim = true; + } + boolean useDistanceConstraint = false; + switch (selectedSolution) { + case runJspritWithDistanceConstraint, runJspritAndMATSimWithDistanceConstraint -> useDistanceConstraint = true; } + runJsprit(controler, useDistanceConstraint); + if (runMatSim) + controler.run(); + else + log.warn( + "##Finished with the jsprit solution. If you also want to run MATSim, please change case of optionsOfVRPSolutions"); + new CarrierPlanWriter((Carriers) controler.getScenario().getScenarioElement("carriers")) + .write(config.controller().getOutputDirectory() + "/output_carriersWithPlans.xml"); } /** From fa70df152d0f3fb3102d24cba0abbf6ac2832a84 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 10:40:58 +0200 Subject: [PATCH 08/15] format logging --- .../matsim/freightDemandGeneration/DemandReaderFromCSV.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 0c7c6b85643..d693e93d6a3 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -1190,7 +1190,7 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario, for (CarrierShipment carrierShipment : shipmentsToAdd) { thisCarrier.getShipments().put(carrierShipment.getId(), carrierShipment); } - log.warn("Number of reduced shipments: " + connectedJobs); + log.warn("Number of reduced shipments: {}", connectedJobs); } if (newDemandInformationElement.getTypeOfDemand().equals("service")) { HashMap, CarrierService> servicesToRemove = new HashMap, CarrierService>(); @@ -1234,7 +1234,7 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario, for (CarrierService carrierService : servicesToAdd) { thisCarrier.getServices().put(carrierService.getId(), carrierService); } - log.warn("Number of reduced shipments: " + connectedJobs); + log.warn("Number of reduced shipments: {}", connectedJobs); } } From 1856d07818cb86b90dab9dc5f645dc3bd3fe27fd Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 10:43:58 +0200 Subject: [PATCH 09/15] use method for demand calculating --- .../DemandReaderFromCSV.java | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) 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 d693e93d6a3..0de0a1ba3e1 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -53,6 +53,7 @@ public final class DemandReaderFromCSV { private static final Logger log = LogManager.getLogger(DemandReaderFromCSV.class); private static final Random rand = new Random(4711); + private static double roundingError; /** * DemandInformationElement is a set of information being read from the input @@ -575,7 +576,7 @@ private static void createServices(Scenario scenario, DemandInformationElement n int countOfLinks = 1; int distributedDemand = 0; - double roundingError = 0; + roundingError = 0; Double shareOfPopulationWithThisService = newDemandInformationElement.getShareOfPopulationWithFirstJobElement(); Integer numberOfJobs; Integer demandToDistribute = newDemandInformationElement.getDemandToDistribute(); @@ -714,17 +715,8 @@ else if (samplingOption.equals("changeDemandOnLocation")) { link = scenario.getNetwork().getLinks().get(Id.createLinkId(usedServiceLocations.stream() .skip(rand.nextInt(usedServiceLocations.size() - 1)).findFirst().get())); } - int demandForThisLink = (int) Math.ceil((double) demandToDistribute / (double) numberOfJobs); - if (numberOfJobs == (i + 1)) { - demandForThisLink = demandToDistribute - distributedDemand; - } else { - roundingError = roundingError - + ((double) demandForThisLink - ((double) demandToDistribute / (double) numberOfJobs)); - if (roundingError > 1) { - demandForThisLink = demandForThisLink - 1; - roundingError = roundingError - 1; - } - } + int demandForThisLink = calculateDemandForThisLink(demandToDistribute, numberOfJobs, distributedDemand, i); + double serviceTime; if (demandToDistribute == 0) serviceTime = newDemandInformationElement.getFirstJobElementTimePerUnit(); @@ -766,7 +758,7 @@ private static void createShipments(Scenario scenario, DemandInformationElement int countOfLinks = 1; int distributedDemand = 0; - double roundingError = 0; + roundingError = 0; Double shareOfPopulationWithThisPickup = newDemandInformationElement.getShareOfPopulationWithFirstJobElement(); Double shareOfPopulationWithThisDelivery = newDemandInformationElement .getShareOfPopulationWithSecondJobElement(); @@ -1045,17 +1037,8 @@ else if (numberOfPickupLocations != null) { numberOfDeliveryLocations, areasForDeliveryLocations, setLocationsOfDelivery, usedDeliveryLocations, possiblePersonsDelivery, nearestLinkPerPersonDelivery, crsTransformationNetworkAndShape, i); - int demandForThisLink = (int) Math.ceil((double) demandToDistribute / (double) numberOfJobs); - if (numberOfJobs == (i + 1)) - demandForThisLink = demandToDistribute - distributedDemand; - else { - roundingError = roundingError - + ((double) demandForThisLink - ((double) demandToDistribute / (double) numberOfJobs)); - if (roundingError > 1) { - demandForThisLink = demandForThisLink - 1; - roundingError = roundingError - 1; - } - } + int demandForThisLink = calculateDemandForThisLink(demandToDistribute, numberOfJobs, distributedDemand, i); + if (!usedPickupLocations.contains(linkPickup.getId().toString())) usedPickupLocations.add(linkPickup.getId().toString()); if (!usedDeliveryLocations.contains(linkDelivery.getId().toString())) @@ -1128,6 +1111,29 @@ private static String createJobId(Scenario scenario, DemandInformationElement ne return newJobId; } + /** Calculates the demand for this link including checking the rounding error. + * @param demandToDistribute Demand to distribute + * @param numberOfJobs Number of jobs + * @param distributedDemand Already Distributed demand + * @param i Counter + * @return Demand for this link + */ + private static int calculateDemandForThisLink(int demandToDistribute, int numberOfJobs, int distributedDemand, int i) { + + int demandForThisLink = (int) Math.ceil((double) demandToDistribute / (double) numberOfJobs); + if (numberOfJobs == (i + 1)) { + demandForThisLink = demandToDistribute - distributedDemand; + } else { + roundingError = roundingError + + ((double) demandForThisLink - ((double) demandToDistribute / (double) numberOfJobs)); + if (roundingError > 1) { + demandForThisLink = demandForThisLink - 1; + roundingError = roundingError - 1; + } + } + return demandForThisLink; + } + /** * If jobs of a carrier have the same characteristics (time window, location), * they will be combined to one job. From 9cc13cf687e3fd20a921e16d1322e01dd403ced0 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 10:44:48 +0200 Subject: [PATCH 10/15] use method for shipment creation --- .../DemandReaderFromCSV.java | 95 +++++++++---------- 1 file changed, 43 insertions(+), 52 deletions(-) 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 0de0a1ba3e1..f7bd0e5cab1 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -897,25 +897,13 @@ else if (population == null) usedDeliveryLocations, possiblePersonsDelivery, nearestLinkPerPersonDelivery, crsTransformationNetworkAndShape, i); - double serviceTimePickup = newDemandInformationElement.getFirstJobElementTimePerUnit(); - double serviceTimeDelivery = newDemandInformationElement.getSecondJobElementTimePerUnit(); - TimeWindow timeWindowPickup = newDemandInformationElement.getFirstJobElementTimeWindow(); - TimeWindow timeWindowDelivery = newDemandInformationElement.getSecondJobElementTimeWindow(); int demandForThisLink = 1; if (!usedPickupLocations.contains(linkPickup.getId().toString())) usedPickupLocations.add(linkPickup.getId().toString()); if (!usedDeliveryLocations.contains(linkDelivery.getId().toString())) usedDeliveryLocations.add(linkDelivery.getId().toString()); - Id idNewShipment = Id.create(createJobId(scenario, newDemandInformationElement, - linkPickup.getId(), linkDelivery.getId()), CarrierShipment.class); - CarrierShipment thisShipment = CarrierShipment.Builder - .newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), demandForThisLink) - .setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup) - .setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery) - .build(); - CarriersUtils.getCarriers(scenario).getCarriers() - .get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments() - .put(thisShipment.getId(), thisShipment); + + createSingleShipment(scenario, newDemandInformationElement, linkPickup, linkDelivery, demandForThisLink); } } else // creates a demand on each link, demand depends on the length of the link @@ -999,23 +987,10 @@ else if (numberOfPickupLocations != null) { usedPickupLocations.add(linkPickup.getId().toString()); if (!usedDeliveryLocations.contains(linkDelivery.getId().toString())) usedDeliveryLocations.add(linkDelivery.getId().toString()); - double serviceTimePickup = newDemandInformationElement.getFirstJobElementTimePerUnit() - * demandForThisLink; - double serviceTimeDelivery = newDemandInformationElement.getSecondJobElementTimePerUnit() - * demandForThisLink; - TimeWindow timeWindowPickup = newDemandInformationElement.getFirstJobElementTimeWindow(); - TimeWindow timeWindowDelivery = newDemandInformationElement.getSecondJobElementTimeWindow(); - Id idNewShipment = Id.create(createJobId(scenario, newDemandInformationElement, - linkPickup.getId(), linkDelivery.getId()), CarrierShipment.class); + if (demandForThisLink > 0) { - CarrierShipment thisShipment = CarrierShipment.Builder - .newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), demandForThisLink) - .setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup) - .setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery) - .build(); - CarriersUtils.getCarriers(scenario).getCarriers() - .get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)) - .getShipments().put(thisShipment.getId(), thisShipment); + createSingleShipment(scenario, newDemandInformationElement, linkPickup, linkDelivery, + demandForThisLink); } distributedDemand = distributedDemand + demandForThisLink; } @@ -1043,28 +1018,9 @@ else if (numberOfPickupLocations != null) { usedPickupLocations.add(linkPickup.getId().toString()); if (!usedDeliveryLocations.contains(linkDelivery.getId().toString())) usedDeliveryLocations.add(linkDelivery.getId().toString()); - double serviceTimePickup; - double serviceTimeDelivery; - if (demandForThisLink == 0) { - serviceTimePickup = newDemandInformationElement.getFirstJobElementTimePerUnit(); - serviceTimeDelivery = newDemandInformationElement.getSecondJobElementTimePerUnit(); - } else { - serviceTimePickup = newDemandInformationElement.getFirstJobElementTimePerUnit() * demandForThisLink; - serviceTimeDelivery = newDemandInformationElement.getSecondJobElementTimePerUnit() - * demandForThisLink; - } - TimeWindow timeWindowPickup = newDemandInformationElement.getFirstJobElementTimeWindow(); - TimeWindow timeWindowDelivery = newDemandInformationElement.getSecondJobElementTimeWindow(); - Id idNewShipment = Id.create( - createJobId(scenario, newDemandInformationElement, linkPickup.getId(), linkDelivery.getId()), - CarrierShipment.class); - CarrierShipment thisShipment = CarrierShipment.Builder - .newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), demandForThisLink) - .setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup) - .setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery).build(); - CarriersUtils.getCarriers(scenario).getCarriers() - .get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments() - .put(thisShipment.getId(), thisShipment); + + createSingleShipment(scenario, newDemandInformationElement, linkPickup, linkDelivery, + demandForThisLink); distributedDemand = distributedDemand + demandForThisLink; } } @@ -1072,6 +1028,41 @@ else if (numberOfPickupLocations != null) { reduceNumberOfJobsIfSameCharacteristics(scenario, newDemandInformationElement); } + /** Creates a single shipment. + * @param scenario Scenario + * @param newDemandInformationElement single DemandInformationElement + * @param linkPickup Link for the pickup + * @param linkDelivery Link for the delivery + * @param demandForThisLink Demand for this link + */ + private static void createSingleShipment(Scenario scenario, DemandInformationElement newDemandInformationElement, + Link linkPickup, Link linkDelivery, int demandForThisLink) { + + Id idNewShipment = Id.create(createJobId(scenario, newDemandInformationElement, + linkPickup.getId(), linkDelivery.getId()), CarrierShipment.class); + + TimeWindow timeWindowPickup = newDemandInformationElement.getFirstJobElementTimeWindow(); + TimeWindow timeWindowDelivery = newDemandInformationElement.getSecondJobElementTimeWindow(); + + double serviceTimePickup; + double serviceTimeDelivery; + if (demandForThisLink == 0) { + serviceTimePickup = newDemandInformationElement.getFirstJobElementTimePerUnit(); + serviceTimeDelivery = newDemandInformationElement.getSecondJobElementTimePerUnit(); + } else { + serviceTimePickup = newDemandInformationElement.getFirstJobElementTimePerUnit() * demandForThisLink; + serviceTimeDelivery = newDemandInformationElement.getSecondJobElementTimePerUnit() * demandForThisLink; + } + CarrierShipment thisShipment = CarrierShipment.Builder + .newInstance(idNewShipment, linkPickup.getId(), linkDelivery.getId(), demandForThisLink) + .setPickupServiceTime(serviceTimePickup).setPickupTimeWindow(timeWindowPickup) + .setDeliveryServiceTime(serviceTimeDelivery).setDeliveryTimeWindow(timeWindowDelivery) + .build(); + CarriersUtils.getCarriers(scenario).getCarriers() + .get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)).getShipments() + .put(thisShipment.getId(), thisShipment); + } + /** * Creates a job Id for a new job. * If a certain Id is already used, a number will be added at the end until no existing job was the same Id. From 89d24bf5cf94b48fc78b74d92f93505017ee21bf Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 10:45:01 +0200 Subject: [PATCH 11/15] remove todo --- .../org/matsim/freightDemandGeneration/DemandReaderFromCSV.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f7bd0e5cab1..329a6eca7e8 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -1264,7 +1264,7 @@ private static HashMap, Link> findAllPossibleLinks(Scenario scenario, } } else { Link newPossibleLink; - while (possibleLinks.size() < numberOfLocations) { //TODO check if number of locations is higher than possible links + while (possibleLinks.size() < numberOfLocations) { newPossibleLink = findPossibleLinkForDemand(possibleLinks, possiblePersons, nearestLinkPerPerson, indexShape, areasForLocations, numberOfLocations, scenario, setLocations, crsTransformationNetworkAndShape); From b6efcbeee75f6ed37594a64f7fff1f9fb0a37741 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 11:21:22 +0200 Subject: [PATCH 12/15] use method to calculate demand based on link lengths --- .../DemandReaderFromCSV.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) 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 329a6eca7e8..35c26d9e1d2 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -664,20 +664,9 @@ else if (samplingOption.equals("changeDemandOnLocation")) { "Because the demand is higher than the number of links, the demand will be distributed evenly over all links. You selected a certain number of service locations, which is not possible here!"); double sumOfPossibleLinkLength = possibleLinksForService.values().stream().mapToDouble(Link::getLength).sum(); for (Link link : possibleLinksForService.values()) { - int demandForThisLink; - if (countOfLinks == scenario.getNetwork().getLinks().size()) { - demandForThisLink = demandToDistribute - distributedDemand; - } else { - demandForThisLink = (int) Math - .ceil(link.getLength() / sumOfPossibleLinkLength * (double) demandToDistribute); - roundingError = roundingError + ((double) demandForThisLink - - (link.getLength() / sumOfPossibleLinkLength * (double) demandToDistribute)); - if (roundingError > 1) { - demandForThisLink = demandForThisLink - 1; - roundingError = roundingError - 1; - } - countOfLinks++; - } + int demandForThisLink = calculateDemandBasedOnLinkLength(countOfLinks, distributedDemand, demandToDistribute, possibleLinksForService.size(), + sumOfPossibleLinkLength, link); + countOfLinks++; double serviceTime = newDemandInformationElement.getFirstJobElementTimePerUnit() * demandForThisLink; Id idNewService = Id.create( @@ -936,19 +925,8 @@ else if (numberOfPickupLocations != null) { sumOfDemandBasedLinks = sumOfPossibleLinkLengthPickup; } for (Link demandBasedLink : demandBasesLinks.values()) { - int demandForThisLink; - if (countOfLinks == demandBasesLinks.size()) { - demandForThisLink = demandToDistribute - distributedDemand; - } else { - demandForThisLink = (int) Math.ceil( - demandBasedLink.getLength() / sumOfDemandBasedLinks * (double) demandToDistribute); - roundingError = roundingError + ((double) demandForThisLink - - (demandBasedLink.getLength() / sumOfDemandBasedLinks * (double) demandToDistribute)); - if (roundingError > 1) { - demandForThisLink = demandForThisLink - 1; - roundingError = roundingError - 1; - } - } + int demandForThisLink = calculateDemandBasedOnLinkLength(countOfLinks, distributedDemand, demandToDistribute, demandBasesLinks.size(), sumOfDemandBasedLinks, + demandBasedLink); if (pickupIsDemandBase) { linkPickup = demandBasedLink; linkDelivery = findNextUsedLink(scenario, indexShape, possibleLinksDelivery, @@ -1125,6 +1103,32 @@ private static int calculateDemandForThisLink(int demandToDistribute, int number return demandForThisLink; } + /** + * @param countOfLinks counter + * @param distributedDemand Already distributed demand + * @param demandToDistribute Demand to distribute + * @param maxLinks Maximum of possible links for demand + * @param sumOfPossibleLinkLength Sum of all lengths of the links + * @param link this link + * @return Demand for this link + */ + private static int calculateDemandBasedOnLinkLength(int countOfLinks, int distributedDemand, Integer demandToDistribute, + int maxLinks, double sumOfPossibleLinkLength, Link link) { + int demandForThisLink; + if (countOfLinks == maxLinks) { + demandForThisLink = demandToDistribute - distributedDemand; + } else { + demandForThisLink = (int) Math + .ceil(link.getLength() / sumOfPossibleLinkLength * (double) demandToDistribute); + roundingError = roundingError + ((double) demandForThisLink + - (link.getLength() / sumOfPossibleLinkLength * (double) demandToDistribute)); + if (roundingError > 1) { + demandForThisLink = demandForThisLink - 1; + roundingError = roundingError - 1; + } + } + return demandForThisLink; + } /** * If jobs of a carrier have the same characteristics (time window, location), * they will be combined to one job. From 46463283d7dbce6e104ada19a0750826f222eb9b Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 11:22:14 +0200 Subject: [PATCH 13/15] introduce parameter --- .../DemandReaderFromCSV.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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 35c26d9e1d2..8c323946cb5 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -797,6 +797,8 @@ else if (population == null) numberPossibleJobsDelivery = (int) Math .round(shareOfPopulationWithThisDelivery * possiblePersonsDelivery.size()); + int sampledNumberPossibleJobsPickup = (int)Math.round((sampleTo / sampleSizeInputPopulation) * numberPossibleJobsPickup); + int sampledNumberPossibleJobsDelivery = (int) Math.round((sampleTo / sampleSizeInputPopulation) * numberPossibleJobsDelivery); if (numberPossibleJobsPickup > numberPossibleJobsDelivery) { if (sampleSizeInputPopulation == sampleTo) { numberOfJobs = (int) Math.round(shareOfPopulationWithThisPickup * numberPossibleJobsPickup); @@ -805,11 +807,10 @@ else if (population == null) numberPossibleJobsDelivery = (int) Math .round(shareOfPopulationWithThisDelivery * numberPossibleJobsDelivery); } else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) { - numberOfJobs = (int) Math.round((sampleTo / sampleSizeInputPopulation) * numberPossibleJobsPickup); + numberOfJobs = sampledNumberPossibleJobsPickup; numberPossibleJobsPickup = numberOfJobs; if (shareOfPopulationWithThisDelivery != null) - numberPossibleJobsDelivery = (int) Math - .round((sampleTo / sampleSizeInputPopulation) * numberPossibleJobsDelivery); + numberPossibleJobsDelivery = sampledNumberPossibleJobsDelivery; } else if (samplingOption.equals("changeDemandOnLocation")) { demandToDistribute = (int) Math.round((sampleTo / sampleSizeInputPopulation) * demandToDistribute); numberOfJobs = numberPossibleJobsPickup; @@ -823,12 +824,10 @@ else if (population == null) numberPossibleJobsPickup = (int) Math .round(shareOfPopulationWithThisPickup * numberPossibleJobsPickup); } else if (samplingOption.equals("changeNumberOfLocationsWithDemand")) { - numberOfJobs = (int) Math - .round((sampleTo / sampleSizeInputPopulation) * numberPossibleJobsDelivery); + numberOfJobs = sampledNumberPossibleJobsDelivery; numberPossibleJobsDelivery = numberOfJobs; if (shareOfPopulationWithThisDelivery != null) - numberPossibleJobsPickup = (int) Math - .round((sampleTo / sampleSizeInputPopulation) * numberPossibleJobsPickup); + numberPossibleJobsPickup = sampledNumberPossibleJobsPickup; } else if (samplingOption.equals("changeDemandOnLocation")) { demandToDistribute = (int) Math.round((sampleTo / sampleSizeInputPopulation) * demandToDistribute); numberOfJobs = numberPossibleJobsDelivery; From ef954c172ca50696894334734eb054ecf3bf7bf3 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 11:22:59 +0200 Subject: [PATCH 14/15] simplify --- .../DemandReaderFromCSV.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) 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 8c323946cb5..15af77ce3f5 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -902,8 +902,8 @@ else if (population == null) HashMap, Link> demandBasesLinks; double sumOfDemandBasedLinks; boolean pickupIsDemandBase = true; - Link linkPickup; - Link linkDelivery; + Link linkPickup = null; + Link linkDelivery= null; double sumOfPossibleLinkLengthPickup = possibleLinksPickup.values().stream().mapToDouble(Link::getLength).sum(); double sumOfPossibleLinkLengthDelivery = possibleLinksDelivery.values().stream().mapToDouble(Link::getLength).sum(); if (numberOfPickupLocations == null && numberOfDeliveryLocations == null) @@ -928,11 +928,7 @@ else if (numberOfPickupLocations != null) { demandBasedLink); if (pickupIsDemandBase) { linkPickup = demandBasedLink; - linkDelivery = findNextUsedLink(scenario, indexShape, possibleLinksDelivery, - numberOfDeliveryLocations, areasForDeliveryLocations, setLocationsOfDelivery, - usedDeliveryLocations, possiblePersonsDelivery, nearestLinkPerPersonDelivery, - crsTransformationNetworkAndShape, countOfLinks - 1); - while (usedDeliveryLocations.contains(linkDelivery.getId().toString())) { + while (linkDelivery == null || usedDeliveryLocations.contains(linkDelivery.getId().toString())) { linkDelivery = findNextUsedLink(scenario, indexShape, possibleLinksDelivery, numberOfDeliveryLocations, areasForDeliveryLocations, setLocationsOfDelivery, usedDeliveryLocations, possiblePersonsDelivery, nearestLinkPerPersonDelivery, @@ -944,11 +940,7 @@ else if (numberOfPickupLocations != null) { } } else { linkDelivery = demandBasedLink; - linkPickup = findNextUsedLink(scenario, indexShape, possibleLinksPickup, - numberOfPickupLocations, areasForPickupLocations, setLocationsOfPickup, - usedPickupLocations, possiblePersonsPickup, nearestLinkPerPersonPickup, - crsTransformationNetworkAndShape, countOfLinks - 1); - while (usedPickupLocations.contains(linkPickup.getId().toString())) { + while (linkPickup == null || usedPickupLocations.contains(linkPickup.getId().toString())) { linkPickup = findNextUsedLink(scenario, indexShape, possibleLinksPickup, numberOfPickupLocations, areasForPickupLocations, setLocationsOfPickup, usedPickupLocations, possiblePersonsPickup, nearestLinkPerPersonPickup, From a127feef74996c661f527dce1a4b94950e0a7b4c Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 21 Jun 2024 11:24:14 +0200 Subject: [PATCH 15/15] cleanup --- .../DemandReaderFromCSV.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 15af77ce3f5..126eff63188 100644 --- a/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java +++ b/contribs/application/src/main/java/org/matsim/freightDemandGeneration/DemandReaderFromCSV.java @@ -1134,14 +1134,14 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario, "The number of Jobs will be reduced if jobs have the same characteristics (e.g. time, location, carrier)"); int connectedJobs = 0; if (newDemandInformationElement.getTypeOfDemand().equals("shipment")) { - HashMap, CarrierShipment> shipmentsToRemove = new HashMap, CarrierShipment>(); - ArrayList shipmentsToAdd = new ArrayList(); + HashMap, CarrierShipment> shipmentsToRemove = new HashMap<>(); + ArrayList shipmentsToAdd = new ArrayList<>(); Carrier thisCarrier = CarriersUtils.getCarriers(scenario).getCarriers() .get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)); for (Id baseShipmentId : thisCarrier.getShipments().keySet()) { if (!shipmentsToRemove.containsKey(baseShipmentId)) { CarrierShipment baseShipment = thisCarrier.getShipments().get(baseShipmentId); - HashMap, CarrierShipment> shipmentsToConnect = new HashMap, CarrierShipment>(); + HashMap, CarrierShipment> shipmentsToConnect = new HashMap<>(); shipmentsToConnect.put(baseShipmentId, baseShipment); for (Id thisShipmentId : thisCarrier.getShipments().keySet()) { if (!shipmentsToRemove.containsKey(thisShipmentId)) { @@ -1185,14 +1185,14 @@ private static void reduceNumberOfJobsIfSameCharacteristics(Scenario scenario, log.warn("Number of reduced shipments: {}", connectedJobs); } if (newDemandInformationElement.getTypeOfDemand().equals("service")) { - HashMap, CarrierService> servicesToRemove = new HashMap, CarrierService>(); - ArrayList servicesToAdd = new ArrayList(); + HashMap, CarrierService> servicesToRemove = new HashMap<>(); + ArrayList servicesToAdd = new ArrayList<>(); Carrier thisCarrier = CarriersUtils.getCarriers(scenario).getCarriers() .get(Id.create(newDemandInformationElement.getCarrierName(), Carrier.class)); for (Id baseServiceId : thisCarrier.getServices().keySet()) { if (!servicesToRemove.containsKey(baseServiceId)) { CarrierService baseService = thisCarrier.getServices().get(baseServiceId); - HashMap, CarrierService> servicesToConnect = new HashMap, CarrierService>(); + HashMap, CarrierService> servicesToConnect = new HashMap<>(); servicesToConnect.put(baseServiceId, baseService); for (Id thisServiceId : thisCarrier.getServices().keySet()) { if (!servicesToRemove.containsKey(thisServiceId)) { @@ -1248,7 +1248,7 @@ private static HashMap, Link> findAllPossibleLinks(Scenario scenario, Integer numberOfLocations, String[] areasForLocations, String[] setLocations, HashMap, Person> possiblePersons, HashMap, HashMap> nearestLinkPerPerson) { - HashMap, Link> possibleLinks = new HashMap, Link>(); + HashMap, Link> possibleLinks = new HashMap<>(); if (numberOfLocations == null) { for (Link link : scenario.getNetwork().getLinks().values()) if (!link.getId().toString().contains("pt") && (!link.getAttributes().getAsMap().containsKey( @@ -1324,7 +1324,7 @@ private static HashMap, Person> findPossiblePersons(Population popula String[] areasForJobElementLocations, ShpOptions.Index indexShape, CoordinateTransformation crsTransformationNetworkAndShape) { - HashMap, Person> possiblePersons = new HashMap, Person>(); + HashMap, Person> possiblePersons = new HashMap<>(); for (Person person : population.getPersons().values()) { Coord coord = getHomeCoord(person); @@ -1406,7 +1406,7 @@ private static Link findPossibleLinkForDemand(HashMap, Link> possibleLi ShpOptions.Index indexShape, String[] areasForTheDemand, Integer selectedNumberOfLocations, Scenario scenario, String[] selectedLocations, CoordinateTransformation crsTransformationNetworkAndShape) { Link selectedlink = null; - Link newLink = null; + Link newLink; if (selectedNumberOfLocations == null) selectedNumberOfLocations = 0; while (selectedlink == null) {