Skip to content

Commit

Permalink
Merge branch 'master' into TripAnalysis_add-delimiter-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow authored Mar 5, 2024
2 parents 787f938 + d6da7f8 commit 444a1c1
Show file tree
Hide file tree
Showing 30 changed files with 304 additions and 88 deletions.
13 changes: 13 additions & 0 deletions contribs/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<artifactId>gtfs2matsim</artifactId>
<version>master-33809c4f0f-1</version>
<exclusions>
<!-- Exclude unneeded dependencies and these with known CVE -->
<exclusion>
<groupId>org.geotools</groupId>
<artifactId>*</artifactId>
Expand All @@ -87,6 +88,18 @@
<groupId>org.matsim</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.amazonaws</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>com.graphql-java</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.postgresql</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ else if (property.equalsIgnoreCase("false") || property.equals("0"))
public static void applyConfigUpdate(Config config, Path yaml) {

if (!Files.exists(yaml)) {
throw new IllegalArgumentException("Desired run config does not exist:" + yaml);
throw new IllegalArgumentException("Given config yaml does not exist: " + yaml);
}

ObjectMapper mapper = new ObjectMapper(new YAMLFactory()
Expand All @@ -139,8 +139,8 @@ public static void applyConfigUpdate(Config config, Path yaml) {
String configGroupName = aliases.resolveAlias(field.getKey(), emptyStack);
ConfigGroup group = config.getModules().get(configGroupName);
if (group == null) {
log.warn("Config group not found: {}", configGroupName);
continue;
group = new ConfigGroup(configGroupName);
config.addModule(group);
}

applyNodeToConfigGroup(field.getValue(), group);
Expand Down Expand Up @@ -168,7 +168,17 @@ private static void applyNodeToConfigGroup(JsonNode node, ConfigGroup group) {
List<? extends ConfigGroup> params = new ArrayList<>(group.getParameterSets(field.getKey()));

for (JsonNode item : field.getValue()) {
applyNodeAsParameterSet(field.getKey(), item, group, params);


// Special case of parameter sets that have only one entry
if (field.getValue().size() == 1 && params.size() == 1 && field.getValue().get(0).isObject()) {

applyNodeToConfigGroup(field.getValue().get(0), params.get(0));

} else {

applyNodeAsParameterSet(field.getKey(), item, group, params);
}
}
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public static void runWithDefaults(Class<? extends MATSimApplication> clazz, Str
} else {
// Automatically add run command
String[] runArgs = ApplicationUtils.mergeArgs(new String[]{"run"}, defaultArgs);
args = ApplicationUtils.mergeArgs(defaultArgs, runArgs);
args = ApplicationUtils.mergeArgs(runArgs, args);
}

} else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.matsim.application.analysis.traffic;

import com.beust.jcommander.internal.Lists;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleList;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.matsim.application.prepare;

import com.beust.jcommander.internal.Lists;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.geotools.data.DataStore;
Expand All @@ -24,6 +23,7 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -90,7 +90,7 @@ public Integer call() throws Exception {
STRtree index = new STRtree();
boolean built = false;

List<Path> paths = Lists.newArrayList();
List<Path> paths =new ArrayList<>();
if (input.toString().endsWith("zip")) {
FileSystem fs = FileSystems.newFileSystem(input, ClassLoader.getSystemClassLoader());
for (String l : layer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.ReflectiveConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.testcases.MatsimTestUtils;

import java.nio.file.Path;
Expand All @@ -22,6 +24,32 @@ public class ConfigYamlUpdateTest {
@RegisterExtension
private MatsimTestUtils utils = new MatsimTestUtils();

@Test
void params() {

Path input = Path.of(utils.getClassInputDirectory());

Config config = ConfigUtils.loadConfig(input.resolve("config.xml").toString());

ApplicationUtils.applyConfigUpdate(
config, input.resolve("params.yml")
);

ScoringConfigGroup scoring = ConfigUtils.addOrGetModule(config, ScoringConfigGroup.class);

assertThat(scoring.getModes())
.hasSize(7);

assertThat(scoring.getPerforming_utils_hr())
.isEqualTo(6.88);

ScoringConfigGroup.ModeParams car = scoring.getModes().get(TransportMode.car);

assertThat(car.getConstant()).isEqualTo(-0.62);
assertThat(car.getMarginalUtilityOfTraveling()).isEqualTo(0);

}

@Test
void standard() {

Expand Down Expand Up @@ -74,6 +102,22 @@ void createParamSet() {
assertThat(next.getParams().get("extra")).isEqualTo("extra");
}

@Test
void createGroup() {
Config config = ConfigUtils.createConfig();
Path input = Path.of(utils.getClassInputDirectory());

ApplicationUtils.applyConfigUpdate(
config, input.resolve("multiLevel.yml")
);


TestConfigGroup test = ConfigUtils.addOrGetModule(config, TestConfigGroup.class);

assertThat(test.values).containsExactly(1, 2, 3);

}


@Test
void multiLevel() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE config SYSTEM "http://www.matsim.org/files/dtd/config_v2.dtd">
<config>
<module name="scoring">
<param name="fractionOfIterationsToStartScoreMSA" value="0.8"/>
<parameterset type="scoringParameters">
<param name="marginalUtilityOfMoney" value="1.0"/>
<param name="performing" value="6.88"/>

<parameterset type="modeParams">
<param name="constant" value="-0.6269580844054548"/>
<param name="dailyMonetaryConstant" value="-3.0"/>
<param name="dailyUtilityConstant" value="0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="0.0"/>
<param name="monetaryDistanceRate" value="-1.49E-4"/>
<param name="mode" value="car"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="-1.3788242711735"/>
<param name="dailyMonetaryConstant" value="0.0"/>
<param name="dailyUtilityConstant" value="0.0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="-6.88"/>
<param name="monetaryDistanceRate" value="-1.49E-4"/>
<param name="mode" value="ride"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="-0.24909103628514367"/>
<param name="dailyMonetaryConstant" value="-3.0"/>
<param name="dailyUtilityConstant" value="0.0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="0.0"/>
<param name="monetaryDistanceRate" value="0.0"/>
<param name="mode" value="pt"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="-2.2321797854695955"/>
<param name="dailyMonetaryConstant" value="0.0"/>
<param name="dailyUtilityConstant" value="0.0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="0.0"/>
<param name="monetaryDistanceRate" value="0.0"/>
<param name="mode" value="bike"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="0.0"/>
<param name="dailyMonetaryConstant" value="0.0"/>
<param name="dailyUtilityConstant" value="0.0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="0.0"/>
<param name="monetaryDistanceRate" value="0.0"/>
<param name="mode" value="walk"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="0.0"/>
<param name="dailyMonetaryConstant" value="0.0"/>
<param name="dailyUtilityConstant" value="0.0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="0.0"/>
<param name="monetaryDistanceRate" value="-4.0E-4"/>
<param name="mode" value="freight"/>
</parameterset>
<parameterset type="modeParams">
<param name="constant" value="0.0"/>
<param name="dailyMonetaryConstant" value="0.0"/>
<param name="dailyUtilityConstant" value="0.0"/>
<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
<param name="marginalUtilityOfTraveling_util_hr" value="0.0"/>
<param name="monetaryDistanceRate" value="-4.0E-4"/>
<param name="mode" value="truck"/>
</parameterset>
</parameterset>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
scoring:
scoringParameters:
- modeParams:
- mode: walk
constant: 0.0
- mode: car
constant: -0.62
- mode: pt
constant: -0.25
- mode: bike
constant: -2.23
- mode: ride
constant: -1.37
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public int size() {
return entryList.size();
}

public double getTotalWeight() {
return totalWeight;
}

private record Entry<E>(E e, double cumulativeWeight) implements Comparable<Entry<E>> {
public int compareTo(Entry<E> o) {
double diff = this.cumulativeWeight - o.cumulativeWeight;
Expand Down
2 changes: 1 addition & 1 deletion contribs/hybridsim/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<properties>
<protobuf.version>3.25.3</protobuf.version>
<grpc.version>1.61.1</grpc.version>
<grpc.version>1.62.2</grpc.version>
</properties>

<dependencies>
Expand Down
12 changes: 12 additions & 0 deletions contribs/simwrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
<dependency>
<groupId>tech.tablesaw</groupId>
<artifactId>tablesaw-jsplot</artifactId>
<exclusions>
<exclusion>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Pinned this version, as older one is not compatible with java 21, newer ones might be incompatible -->
<dependency>
<groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId>
<version>3.1.6</version>
</dependency>

<dependency>
Expand Down
Loading

0 comments on commit 444a1c1

Please sign in to comment.