From 403aeac4fcbc556ee4df19fa2d066fa75a06ab14 Mon Sep 17 00:00:00 2001 From: GregorRyb Date: Tue, 23 Jan 2024 23:40:29 +0100 Subject: [PATCH] finish parking capacities --- .../matsim/run/prepare/ParkingCapacities.java | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/matsim/run/prepare/ParkingCapacities.java b/src/main/java/org/matsim/run/prepare/ParkingCapacities.java index 517637e..14249dc 100644 --- a/src/main/java/org/matsim/run/prepare/ParkingCapacities.java +++ b/src/main/java/org/matsim/run/prepare/ParkingCapacities.java @@ -1,49 +1,63 @@ package org.matsim.run.prepare; +import org.matsim.analysis.ParkingLocation; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.application.MATSimAppCommand; import org.matsim.core.network.NetworkUtils; +import org.matsim.core.utils.io.IOUtils; import picocli.CommandLine; -public class ParkingCapacities implements MATSimAppCommand { +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +public class ParkingCapacities { - @CommandLine.Option(names = "--network", description = "Path to network file", required = true) - private static String networkFile; - @CommandLine.Option(names = "--output", description = "Output path of the prepared network", required = true) - private String outputPath; + public static void main(String[] args) throws IOException { - public static void main(String[] args) { - Network network = NetworkUtils.readNetwork(networkFile); + Network network = NetworkUtils.readNetwork("https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/leipzig/leipzig-v1.2/input/leipzig-v1.2-network-with-pt.xml.gz"); + List listOfParkingCapacities = new ArrayList<>(); for (Link l: network.getLinks().values()) { - double useAbleLength = (l.getLength() - 10) * 0.9; - double capacity =0; - if (useAbleLength > 0) { - capacity = useAbleLength / 6; - } - - l.getAttributes().putAttribute("parkingCapacity", capacity); + //skip motorways and nn car links + if (l.getAllowedModes().contains(TransportMode.car) && l.getFreespeed()> 55/3.6) { + double usableLength = (l.getLength() - 10) * 0.9; + double capacity =0; + if (usableLength > 0) { + capacity = usableLength / 6; + } + l.getAttributes().putAttribute("parkingCapacity", (int) Math.floor(capacity)); + listOfParkingCapacities.add(new ParkingCapacityRecord(l.getId().toString(), (int) Math.floor(capacity))); + } } + writeResults(Path.of("../"), listOfParkingCapacities); + NetworkUtils.writeNetwork(network, "networkWithParkingCap.xml.gz"); + } + private static void writeResults(Path outputFolder, List listOfParkingCapacities) throws IOException { + BufferedWriter writer = IOUtils.getBufferedWriter(outputFolder.resolve("parkingCapacities.tsv").toString()); + writer.write("linkId\tcapacity"); + writer.newLine(); + for (ParkingCapacities.ParkingCapacityRecord pd : listOfParkingCapacities) { + writer.write(pd.linkId + "\t" + pd.capacity); + writer.newLine(); + } + writer.close(); - - } - - @Override - public Integer call() throws Exception { - return null; } - - Record parkingCapacity(String linkId, int capacity) { - return null; - } + private record ParkingCapacityRecord(String linkId, int capacity) { } }