Skip to content

Commit

Permalink
finish parking capacities
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorRyb committed Jan 23, 2024
1 parent e0aff50 commit 403aeac
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions src/main/java/org/matsim/run/prepare/ParkingCapacities.java
Original file line number Diff line number Diff line change
@@ -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<ParkingCapacities.ParkingCapacityRecord> 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<ParkingCapacities.ParkingCapacityRecord> 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) { }
}

0 comments on commit 403aeac

Please sign in to comment.