Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/com.google.guava-guava-33…
Browse files Browse the repository at this point in the history
….3.0-jre
  • Loading branch information
jfbischoff authored Sep 9, 2024
2 parents baafbd7 + 7d206a7 commit a765c59
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Coord;
import org.matsim.application.avro.XYTData;
import org.matsim.application.options.CsvOptions;
import org.matsim.core.config.Config;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.core.utils.misc.Time;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void setMaxTime(int maxTime) {
/**
* Merges noise data from multiple files into one file.
*/
public void run() {
public void run() throws IOException {
mergeReceiverPointData(outputDirectory + "/immissions/", "immission");
mergeReceiverPointData(outputDirectory + "/damages_receiverPoint/", "damages_receiverPoint");
mergeLinkData(outputDirectory.toString() + "/emissions/", "emission");
Expand All @@ -116,7 +117,7 @@ private void writeAvro(XYTData xytData, File output) {
}
}

private void mergeLinkData(String pathParameter, String label) {
private void mergeLinkData(String pathParameter, String label) throws IOException {
log.info("Merging emissions data for label {}", label);
Object2DoubleMap<String> mergedData = new Object2DoubleOpenHashMap<>();
Table csvOutputMerged = Table.create(TextColumn.create("Link Id"), DoubleColumn.create("value"));
Expand All @@ -126,9 +127,10 @@ private void mergeLinkData(String pathParameter, String label) {

// Read the file
Table table = Table.read().csv(CsvReadOptions.builder(IOUtils.getBufferedReader(path))
.columnTypesPartial(Map.of("Link Id", ColumnType.TEXT))
.columnTypesPartial(Map.of("Link Id", ColumnType.TEXT,
"Noise Emission " + Time.writeTime(time, Time.TIMEFORMAT_HHMMSS), ColumnType.DOUBLE))
.sample(false)
.separator(';').build());
.separator(CsvOptions.detectDelimiter(path)).build());

for (Row row : table) {
String linkId = row.getString("Link Id");
Expand Down Expand Up @@ -157,7 +159,7 @@ private void mergeLinkData(String pathParameter, String label) {
* @param outputDir path to the receiverPoint data
* @param label label for the receiverPoint data (which kind of data)
*/
private void mergeReceiverPointData(String outputDir, String label) {
private void mergeReceiverPointData(String outputDir, String label) throws IOException {

// data per time step, maps coord to value
Int2ObjectMap<Object2FloatMap<FloatFloatPair>> data = new Int2ObjectOpenHashMap<>();
Expand Down Expand Up @@ -188,7 +190,7 @@ private void mergeReceiverPointData(String outputDir, String label) {
"t", ColumnType.DOUBLE,
valueHeader, ColumnType.DOUBLE))
.sample(false)
.separator(';').build());
.separator(CsvOptions.detectDelimiter(timeDataFile)).build());

// Loop over all rows in the data file
for (Row row : dataTable) {
Expand Down Expand Up @@ -265,7 +267,7 @@ private void mergeReceiverPointData(String outputDir, String label) {
// Merges the immissions data

@Deprecated
private void mergeImmissionsCSV(String pathParameter, String label) {
private void mergeImmissionsCSV(String pathParameter, String label) throws IOException {
log.info("Merging immissions data for label {}", label);
Object2DoubleMap<Coord> mergedData = new Object2DoubleOpenHashMap<>();

Expand All @@ -284,7 +286,7 @@ private void mergeImmissionsCSV(String pathParameter, String label) {
"Receiver Point Id", ColumnType.INTEGER,
"t", ColumnType.DOUBLE))
.sample(false)
.separator(';').build());
.separator(CsvOptions.detectDelimiter(path)).build());

// Loop over all rows in the file
for (Row row : table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private static Feature createDefaultFeature(Link link) {

String highwayType = NetworkUtils.getHighwayType(link);
categories.put("highway_type", highwayType);
ft.put("idx", link.getId().index());
ft.put("speed", NetworkUtils.getAllowedSpeed(link));
ft.put("num_lanes", link.getNumberOfLanes());
ft.put("length", link.getLength());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.matsim.application.prepare.network.params.ref;

import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import org.matsim.application.prepare.Predictor;
import org.matsim.application.prepare.network.params.NetworkModel;

/**
* Reference model that uses one specific speed factor for each link.
*/
public final class IndividualParams implements NetworkModel {

private static final Predictor INSTANCE = new Model();

@Override
public Predictor speedFactor(String junctionType, String highwayType) {
return INSTANCE;
}

private static final class Model implements Predictor {

@Override
public double predict(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories) {
return predict(features, categories, new double[0]);
}

@Override
public double predict(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories, double[] params) {
if (params.length == 0)
return 1;

return params[(int) features.getDouble("idx")];
}

@Override
public double[] getData(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories) {
return new double[]{
features.getDouble("idx")
};
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
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.api.core.v01.network.NetworkWriter;
Expand Down Expand Up @@ -199,7 +200,7 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
Scenario scenario = builder.build();

// add pseudo network for pt
new CreatePseudoNetwork(scenario.getTransitSchedule(), scenario.getNetwork(), "pt_", 0.1, 100000.0).createNetwork();
new CreatePseudoNetwork(scenario.getTransitSchedule(), scenario.getNetwork(), ptNetworkIdentifier, 0.1, 100000.0).createNetwork();

// create TransitVehicle types
// see https://svn.vsp.tu-berlin.de/repos/public-svn/publications/vspwp/2014/14-24/ for veh capacities
Expand All @@ -219,7 +220,6 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setEgressTime(reRbVehicleType, 1.0 / 10.0); // 1s per alighting agent, distributed on 10 doors

addHbefaMapping(reRbVehicleType, HbefaVehicleCategory.NON_HBEFA_VEHICLE);

scenario.getTransitVehicles().addVehicleType(reRbVehicleType);
}
VehicleType sBahnVehicleType = vehicleFactory.createVehicleType(Id.create("S-Bahn_veh_type", VehicleType.class));
Expand All @@ -230,6 +230,8 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setDoorOperationMode(sBahnVehicleType, VehicleType.DoorOperationMode.serial); // first finish boarding, then start alighting
VehicleUtils.setAccessTime(sBahnVehicleType, 1.0 / 24.0); // 1s per boarding agent, distributed on 8*3 doors
VehicleUtils.setEgressTime(sBahnVehicleType, 1.0 / 24.0); // 1s per alighting agent, distributed on 8*3 doors

addHbefaMapping(sBahnVehicleType, HbefaVehicleCategory.NON_HBEFA_VEHICLE);
scenario.getTransitVehicles().addVehicleType(sBahnVehicleType);
}
VehicleType uBahnVehicleType = vehicleFactory.createVehicleType(Id.create("U-Bahn_veh_type", VehicleType.class));
Expand All @@ -240,9 +242,9 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setDoorOperationMode(uBahnVehicleType, VehicleType.DoorOperationMode.serial); // first finish boarding, then start alighting
VehicleUtils.setAccessTime(uBahnVehicleType, 1.0 / 18.0); // 1s per boarding agent, distributed on 6*3 doors
VehicleUtils.setEgressTime(uBahnVehicleType, 1.0 / 18.0); // 1s per alighting agent, distributed on 6*3 doors
scenario.getTransitVehicles().addVehicleType(uBahnVehicleType);

addHbefaMapping(uBahnVehicleType, HbefaVehicleCategory.NON_HBEFA_VEHICLE);
scenario.getTransitVehicles().addVehicleType(uBahnVehicleType);

}
VehicleType tramVehicleType = vehicleFactory.createVehicleType(Id.create("Tram_veh_type", VehicleType.class));
Expand All @@ -253,6 +255,8 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setDoorOperationMode(tramVehicleType, VehicleType.DoorOperationMode.serial); // first finish boarding, then start alighting
VehicleUtils.setAccessTime(tramVehicleType, 1.0 / 5.0); // 1s per boarding agent, distributed on 5 doors
VehicleUtils.setEgressTime(tramVehicleType, 1.0 / 5.0); // 1s per alighting agent, distributed on 5 doors

addHbefaMapping(tramVehicleType, HbefaVehicleCategory.NON_HBEFA_VEHICLE);
scenario.getTransitVehicles().addVehicleType(tramVehicleType);
}
VehicleType busVehicleType = vehicleFactory.createVehicleType(Id.create("Bus_veh_type", VehicleType.class));
Expand All @@ -263,7 +267,10 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setDoorOperationMode(busVehicleType, VehicleType.DoorOperationMode.serial); // first finish boarding, then start alighting
VehicleUtils.setAccessTime(busVehicleType, 1.0 / 3.0); // 1s per boarding agent, distributed on 3 doors
VehicleUtils.setEgressTime(busVehicleType, 1.0 / 3.0); // 1s per alighting agent, distributed on 3 doors

addHbefaMapping(busVehicleType, HbefaVehicleCategory.URBAN_BUS);
scenario.getTransitVehicles().addVehicleType(busVehicleType);

}
VehicleType ferryVehicleType = vehicleFactory.createVehicleType(Id.create("Ferry_veh_type", VehicleType.class));
{
Expand All @@ -273,6 +280,8 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setDoorOperationMode(ferryVehicleType, VehicleType.DoorOperationMode.serial); // first finish boarding, then start alighting
VehicleUtils.setAccessTime(ferryVehicleType, 1.0 / 1.0); // 1s per boarding agent, distributed on 1 door
VehicleUtils.setEgressTime(ferryVehicleType, 1.0 / 1.0); // 1s per alighting agent, distributed on 1 door

addHbefaMapping(ferryVehicleType, HbefaVehicleCategory.NON_HBEFA_VEHICLE);
scenario.getTransitVehicles().addVehicleType(ferryVehicleType);
}

Expand All @@ -284,6 +293,8 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
VehicleUtils.setDoorOperationMode(ptVehicleType, VehicleType.DoorOperationMode.serial); // first finish boarding, then start alighting
VehicleUtils.setAccessTime(ptVehicleType, 1.0 / 1.0); // 1s per boarding agent, distributed on 1 door
VehicleUtils.setEgressTime(ptVehicleType, 1.0 / 1.0); // 1s per alighting agent, distributed on 1 door

addHbefaMapping(ptVehicleType, HbefaVehicleCategory.NON_HBEFA_VEHICLE);
scenario.getTransitVehicles().addVehicleType(ptVehicleType);
}

Expand Down Expand Up @@ -432,6 +443,7 @@ private static void addHbefaMapping(VehicleType vehicleType, HbefaVehicleCategor
VehicleUtils.setHbefaTechnology(carEngineInformation, "average");
VehicleUtils.setHbefaSizeClass(carEngineInformation, "average");
VehicleUtils.setHbefaEmissionsConcept(carEngineInformation, "average");
vehicleType.setNetworkMode(TransportMode.pt);
}

private static void increaseLinkFreespeedIfLower(Link link, double newFreespeed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void run() {
"--network", network.toString(),
"--target-crs", "EPSG:4326",
"--date", "2019-01-01",
"--validate=true",
"--output", output
);

Expand Down

0 comments on commit a765c59

Please sign in to comment.