Skip to content

Commit a92bd23

Browse files
authored
Merge pull request #118 from moia-oss/master
update matsim 2024-09-11-11-06
2 parents dac8f06 + 7a610be commit a92bd23

File tree

33 files changed

+1388
-273
lines changed

33 files changed

+1388
-273
lines changed

contribs/application/pom.xml

+8-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,14 @@
148148
<artifactId>xercesImpl</artifactId>
149149
<version>2.12.2</version>
150150
</dependency>
151-
152-
</dependencies>
151+
<dependency>
152+
<groupId>org.matsim.contrib</groupId>
153+
<artifactId>dvrp</artifactId>
154+
<version>2025.0-SNAPSHOT</version>
155+
<scope>compile</scope>
156+
</dependency>
157+
158+
</dependencies>
153159

154160
<build>
155161
<plugins>

contribs/application/src/main/java/org/matsim/application/analysis/noise/MergeNoiseOutput.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.apache.logging.log4j.Logger;
1919
import org.matsim.api.core.v01.Coord;
2020
import org.matsim.application.avro.XYTData;
21+
import org.matsim.application.options.CsvOptions;
2122
import org.matsim.core.config.Config;
2223
import org.matsim.core.utils.io.IOUtils;
2324
import org.matsim.core.utils.misc.Time;
@@ -92,7 +93,7 @@ public void setMaxTime(int maxTime) {
9293
/**
9394
* Merges noise data from multiple files into one file.
9495
*/
95-
public void run() {
96+
public void run() throws IOException {
9697
mergeReceiverPointData(outputDirectory + "/immissions/", "immission");
9798
mergeReceiverPointData(outputDirectory + "/damages_receiverPoint/", "damages_receiverPoint");
9899
mergeLinkData(outputDirectory.toString() + "/emissions/", "emission");
@@ -116,7 +117,7 @@ private void writeAvro(XYTData xytData, File output) {
116117
}
117118
}
118119

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

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

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

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

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

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

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

289291
// Loop over all rows in the file
290292
for (Row row : table) {

contribs/application/src/main/java/org/matsim/application/prepare/network/params/NetworkParamsOpt.java

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ private static Feature createDefaultFeature(Link link) {
113113

114114
String highwayType = NetworkUtils.getHighwayType(link);
115115
categories.put("highway_type", highwayType);
116+
ft.put("idx", link.getId().index());
116117
ft.put("speed", NetworkUtils.getAllowedSpeed(link));
117118
ft.put("num_lanes", link.getNumberOfLanes());
118119
ft.put("length", link.getLength());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.matsim.application.prepare.network.params.ref;
2+
3+
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
4+
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
5+
import org.matsim.application.prepare.Predictor;
6+
import org.matsim.application.prepare.network.params.NetworkModel;
7+
8+
/**
9+
* Reference model that uses one specific speed factor for each link.
10+
*/
11+
public final class IndividualParams implements NetworkModel {
12+
13+
private static final Predictor INSTANCE = new Model();
14+
15+
@Override
16+
public Predictor speedFactor(String junctionType, String highwayType) {
17+
return INSTANCE;
18+
}
19+
20+
private static final class Model implements Predictor {
21+
22+
@Override
23+
public double predict(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories) {
24+
return predict(features, categories, new double[0]);
25+
}
26+
27+
@Override
28+
public double predict(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories, double[] params) {
29+
if (params.length == 0)
30+
return 1;
31+
32+
return params[(int) features.getDouble("idx")];
33+
}
34+
35+
@Override
36+
public double[] getData(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories) {
37+
return new double[]{
38+
features.getDouble("idx")
39+
};
40+
}
41+
}
42+
43+
}

0 commit comments

Comments
 (0)