Skip to content

Commit

Permalink
Parking capacities (#41)
Browse files Browse the repository at this point in the history
* update shape file to be consistent with the car cost calculation

* start parking capacities implementation

* finish parking capacities

* finish parking capacities

* satisfy checkstyle

* Formatting

* implement suggestion from pull request

* fix check style

---------

Co-authored-by: GregorRyb <[email protected]>
  • Loading branch information
GregorRyb and GregorRyb authored Jan 25, 2024
1 parent 7829d46 commit 4054f6a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
Binary file modified input/v1.3/parkingCostArea/Bewohnerparken_2020.dbf
Binary file not shown.
58 changes: 58 additions & 0 deletions src/main/java/org/matsim/run/prepare/ParkingCapacities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.matsim.run.prepare;

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.core.network.NetworkUtils;
import org.matsim.core.utils.io.IOUtils;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
/**
* This class writes out a network and a tsv file with the parking capacites of Leipzig according to a simplified calculation based on the RASt.
*/

public final class ParkingCapacities {

private static 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");
private static List<ParkingCapacities.ParkingCapacityRecord> listOfParkingCapacities = new ArrayList<>();
private ParkingCapacities() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

public static void main(String[] args) throws IOException {
for (Link l: network.getLinks().values()) {
//skip motorways and non car links
if (l.getAllowedModes().contains(TransportMode.car) && l.getFreespeed() < 55/3.6) {
double usableLength = (l.getLength() - 10) * 0.9;
int maxCapacity = 0;
int minCapacity = 0;
if (usableLength > 0) {
maxCapacity = (int) Math.floor(usableLength / 6);
minCapacity = (int) Math.floor(usableLength /50);
}

l.getAttributes().putAttribute("maxParkingCapacity", maxCapacity);
l.getAttributes().putAttribute("minParkingCapacity", minCapacity);
listOfParkingCapacities.add(new ParkingCapacityRecord(l.getId().toString(), maxCapacity, minCapacity));
}
}
writeResults(Path.of("../"), listOfParkingCapacities);
NetworkUtils.writeNetwork(network, "networkWithParkingCap.xml.gz");
}

private static void writeResults(Path outputFolder, List<ParkingCapacities.ParkingCapacityRecord> listOfParkingCapacities) throws IOException {
BufferedWriter writer = IOUtils.getBufferedWriter(outputFolder.resolve("parkingCapacities.tsv").toString());
writer.write("linkId\tmaxCapacity\tminCapacity");
writer.newLine();
for (ParkingCapacities.ParkingCapacityRecord pd : listOfParkingCapacities) {
writer.write(pd.linkId + "\t" + pd.maxCapacity + "\t" + pd.minCapacity);
writer.newLine();
}
writer.close();
}

private record ParkingCapacityRecord(String linkId, int maxCapacity, int minCapacity) { }
}

0 comments on commit 4054f6a

Please sign in to comment.