Skip to content

Commit

Permalink
Update MATSim (#100)
Browse files Browse the repository at this point in the history
* combined distribution of tour start and duration

* add routing test with multiple same options

* build(deps): bump info.picocli:picocli from 4.7.5 to 4.7.6

Bumps [info.picocli:picocli](https://github.com/remkop/picocli) from 4.7.5 to 4.7.6.
- [Release notes](https://github.com/remkop/picocli/releases)
- [Changelog](https://github.com/remkop/picocli/blob/main/RELEASE-NOTES.md)
- [Commits](remkop/picocli@v4.7.5...v4.7.6)

---
updated-dependencies:
- dependency-name: info.picocli:picocli
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* build(deps-dev): bump net.bytebuddy:byte-buddy from 1.14.14 to 1.14.15

Bumps [net.bytebuddy:byte-buddy](https://github.com/raphw/byte-buddy) from 1.14.14 to 1.14.15.
- [Release notes](https://github.com/raphw/byte-buddy/releases)
- [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md)
- [Commits](raphw/byte-buddy@byte-buddy-1.14.14...byte-buddy-1.14.15)

---
updated-dependencies:
- dependency-name: net.bytebuddy:byte-buddy
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* add javadoc comment to constructor of OTFVisLiveModule

* factor out drt optimization constraint params from drt config group  (matsim-org#3252)

* factor out drt optimization constraint params from drt config group as preparatory work for service differentiation
* ensure backwards compatibility with previous drt config design

* add python script to analysis kid data

* add new events for new times distribution

* add todo

* change format of list creation

* make output files of the class configurable

* add trip filter for trip start OR end in shp area (matsim-org#3269)

* read first 5 lines of csv to check delimiter (matsim-org#3271)

* inline abstract module attributes and get rid of them

* Allow for storing multiple DrtOptimizationConstraintsParams

* recognize EPSG:4326 as equal to WGS84 when using special coordinate transformations (matsim-org#3276)

* Add test

* update to geotools 31 (resolve transitive dependency conflicts) (matsim-org#3272)

* update to geotools 31

* update geotools import statements

* remove gt-opengis as it is discontinued

* build(deps): bump io.grpc:grpc-all from 1.63.0 to 1.64.0

Bumps [io.grpc:grpc-all](https://github.com/grpc/grpc-java) from 1.63.0 to 1.64.0.
- [Release notes](https://github.com/grpc/grpc-java/releases)
- [Commits](grpc/grpc-java@v1.63.0...v1.64.0)

---
updated-dependencies:
- dependency-name: io.grpc:grpc-all
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* build(deps): bump org.mockito:mockito-core from 5.11.0 to 5.12.0

Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.11.0 to 5.12.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v5.11.0...v5.12.0)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* build(deps): bump org.mockito:mockito-junit-jupiter

Bumps [org.mockito:mockito-junit-jupiter](https://github.com/mockito/mockito) from 5.11.0 to 5.12.0.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v5.11.0...v5.12.0)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-junit-jupiter
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* update gtfs2matsim in application contrib (matsim-org#3278)

* build(deps): bump com.google.code.gson:gson from 2.10.1 to 2.11.0

Bumps [com.google.code.gson:gson](https://github.com/google/gson) from 2.10.1 to 2.11.0.
- [Release notes](https://github.com/google/gson/releases)
- [Changelog](https://github.com/google/gson/blob/main/CHANGELOG.md)
- [Commits](google/gson@gson-parent-2.10.1...gson-parent-2.11.0)

---
updated-dependencies:
- dependency-name: com.google.code.gson:gson
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Move optimization constraints params to optimizer package

* add middleman for drt optimization constraints

* re-order replanning parameter comments to make them more understandable (matsim-org#3280)

* ---
updated-dependencies:
- dependency-name: jakarta.validation:jakarta.validation-api
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* ---
updated-dependencies:
- dependency-name: net.bytebuddy:byte-buddy
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump org.apache.commons:commons-compress from 1.26.1 to 1.26.2

Bumps org.apache.commons:commons-compress from 1.26.1 to 1.26.2.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-compress
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump com.google.protobuf:protobuf-java from 4.26.1 to 4.27.0

Bumps [com.google.protobuf:protobuf-java](https://github.com/protocolbuffers/protobuf) from 4.26.1 to 4.27.0.
- [Release notes](https://github.com/protocolbuffers/protobuf/releases)
- [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/protobuf_release.bzl)
- [Commits](https://github.com/protocolbuffers/protobuf/commits)

---
updated-dependencies:
- dependency-name: com.google.protobuf:protobuf-java
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix bug in bicycle score handler (matsim-org#3288)

* fix bicycle score handler

* update test cases

* update events

* use new population comparison

* fix: prebooked drt with variable stop durations and group sizes (matsim-org#3290)

* fix: prebooked drt with variable stop durations and group sizes

* fix logic

* Documentation mode choice + make mode choice analysis standard (matsim-org#3285)

* add comments to clarify configs

* add ModeChoiceCoverageControlerListener as default analysis

* fix tests

* fix tests

* Bump org.assertj:assertj-core from 3.25.3 to 3.26.0

Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.25.3 to 3.26.0.
- [Release notes](https://github.com/assertj/assertj/releases)
- [Commits](assertj/assertj@assertj-build-3.25.3...assertj-build-3.26.0)

---
updated-dependencies:
- dependency-name: org.assertj:assertj-core
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* MATSim Application: Improve network params estimators (matsim-org#3292)

* adding todos for network param improvements

* more flexible reference models

* prepare capacity models, use the new predictor interface

* handle nan values

* Added hbs.py to calculate sapacity

* implemented capacities from HBS

* change parentheses

* update calculation

* update comments

* also create features from link attributes

* adding features useful for intersections

* update features

* handle non existing links

* catch errors in sample network

* round capacity

* also round freespeed factor

* use correct lane attribute

* warn if number of lanes does not match

* add more standard features

* don't classify secondary roads as residential

* use capacity bounds as in the old model

* refactored, option to only decease existing values

* fix calcCurvature bug

* remove TODO

* added curvature to hbs.py (only the structure, not the calculation)

* calculate geh value for traffic counts

* add capacities based on cuvature for landstrassen, add cuvature calculation

---------

Co-authored-by: frievoe97 <[email protected]>

* Added a test scenario for a construction site between Morges and Renens on the line Lausanne - Geneva (matsim-org#3283)

Co-authored-by: u238053 <[email protected]>
Co-authored-by: rakow <[email protected]>

* add corrections for inaccuracies in some of the calculations (matsim-org#3263)

* add backwards compatibility for dvrp matrix and drt zone system configs (matsim-org#3294)

* add backwards compatibility for dvrp matrix and drt zone system config params

* fix test issue

* addresses matsim-org#3173 (comment)

* add back service area filter for drt zones (matsim-org#3295)

* Add late diversion constraint for drt detours (matsim-org#2455)

* fixed approach time for drt dropoffs

* allowDetourBeforeArrivalThreshold

* break early when following stops are above the threshold

* catch case when there are no scheduled stops

* minor config updates

* fix bug

* add test for late detour prohibition

* add one more test

* update detour before arrival threshold

* address review comments

* simplify method, rename to lateDiversionThreshold

* rename method

* Bump net.bytebuddy:byte-buddy from 1.14.16 to 1.14.17

Bumps [net.bytebuddy:byte-buddy](https://github.com/raphw/byte-buddy) from 1.14.16 to 1.14.17.
- [Release notes](https://github.com/raphw/byte-buddy/releases)
- [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md)
- [Commits](raphw/byte-buddy@byte-buddy-1.14.16...byte-buddy-1.14.17)

---
updated-dependencies:
- dependency-name: net.bytebuddy:byte-buddy
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump org.apache.maven.plugins:maven-enforcer-plugin from 3.4.1 to 3.5.0

Bumps [org.apache.maven.plugins:maven-enforcer-plugin](https://github.com/apache/maven-enforcer) from 3.4.1 to 3.5.0.
- [Release notes](https://github.com/apache/maven-enforcer/releases)
- [Commits](apache/maven-enforcer@enforcer-3.4.1...enforcer-3.5.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-enforcer-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* add dependency for geotools-api (matsim-org#3302)

* Bump org.hsqldb:hsqldb from 2.7.2 to 2.7.3

Bumps org.hsqldb:hsqldb from 2.7.2 to 2.7.3.

---
updated-dependencies:
- dependency-name: org.hsqldb:hsqldb
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Bump com.google.errorprone:error_prone_annotations from 2.27.1 to 2.28.0

Bumps [com.google.errorprone:error_prone_annotations](https://github.com/google/error-prone) from 2.27.1 to 2.28.0.
- [Release notes](https://github.com/google/error-prone/releases)
- [Commits](google/error-prone@v2.27.1...v2.28.0)

---
updated-dependencies:
- dependency-name: com.google.errorprone:error_prone_annotations
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* make header of detailed_distance_stats listen to custom delimiter (matsim-org#3309)

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: rakow <[email protected]>
Co-authored-by: Paul Heinrich <[email protected]>
Co-authored-by: Paul Heinrich <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Michal Maciejewski <[email protected]>
Co-authored-by: Kai Nagel <[email protected]>
Co-authored-by: kainagel <[email protected]>
Co-authored-by: Ricardo Ewert <[email protected]>
Co-authored-by: Ricardo Ewert <[email protected]>
Co-authored-by: simei94 <[email protected]>
Co-authored-by: marecabo <[email protected]>
Co-authored-by: rakow <[email protected]>
Co-authored-by: vsp-gleich <[email protected]>
Co-authored-by: Sebastian Hörl <[email protected]>
Co-authored-by: frievoe97 <[email protected]>
Co-authored-by: NicDul <[email protected]>
Co-authored-by: u238053 <[email protected]>
Co-authored-by: Joschka Bischoff <[email protected]>
  • Loading branch information
19 people authored Jun 7, 2024
1 parent 0ab3a61 commit 03877e8
Show file tree
Hide file tree
Showing 47 changed files with 2,843 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ private static int[] sum(int[] a, int[] b) {
return counts;
}

/**
* Calculate the geh value for simulated and reference count
*/
private static double geh(double simulated, double observed) {
final double diff = simulated - observed;
final double sum = simulated + observed;

return Math.sqrt(2 * diff * diff / sum);
}

@Override
public Integer call() throws Exception {

Expand Down Expand Up @@ -114,14 +124,16 @@ private Table writeOutput(Counts<Link> counts, Network network, VolumesAnalyzer
StringColumn.create("road_type"),
IntColumn.create("hour"),
DoubleColumn.create("observed_traffic_volume"),
DoubleColumn.create("simulated_traffic_volume")
DoubleColumn.create("simulated_traffic_volume"),
DoubleColumn.create("geh")
);

Table dailyTrafficVolume = Table.create(StringColumn.create("link_id"),
StringColumn.create("name"),
StringColumn.create("road_type"),
DoubleColumn.create("observed_traffic_volume"),
DoubleColumn.create("simulated_traffic_volume")
DoubleColumn.create("simulated_traffic_volume"),
DoubleColumn.create("geh")
);

for (Map.Entry<Id<Link>, MeasurementLocation<Link>> entry : counts.getMeasureLocations().entrySet()) {
Expand Down Expand Up @@ -170,6 +182,7 @@ private Table writeOutput(Counts<Link> counts, Network network, VolumesAnalyzer
row.setInt("hour", hour);
row.setDouble("observed_traffic_volume", observedTrafficVolumeAtHour);
row.setDouble("simulated_traffic_volume", simulatedTrafficVolumeAtHour);
row.setDouble("geh", geh(simulatedTrafficVolumeAtHour, observedTrafficVolumeAtHour));
}
} else {
// Get the daily values
Expand All @@ -183,6 +196,7 @@ private Table writeOutput(Counts<Link> counts, Network network, VolumesAnalyzer
row.setString("road_type", type);
row.setDouble("observed_traffic_volume", observedTrafficVolumeByDay);
row.setDouble("simulated_traffic_volume", simulatedTrafficVolumeByDay);
row.setDouble("geh", geh(simulatedTrafficVolumeByDay, observedTrafficVolumeByDay));
}

DoubleColumn relError = dailyTrafficVolume.doubleColumn("simulated_traffic_volume")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public interface Predictor {

/**
* Predict value from given features.
* @return predicted value, maybe NaN if no prediction is possible.
*/
double predict(Object2DoubleMap<String> features, Object2ObjectMap<String, String> categories);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public Integer call() throws Exception {

List<? extends Node> list = e.getValue();

// for now only consider traffic lights
if (!e.getKey().equals("traffic_light"))
continue;

log.info("Sampling {} out of {} intersections for type {}", sample, list.size(), e.getKey());

for (int i = 0; i < sample && !list.isEmpty(); i++) {
Expand Down Expand Up @@ -193,7 +197,7 @@ public Integer call() throws Exception {

RandomizedTravelTime tt = new RandomizedTravelTime(rnd);

LeastCostPathCalculator router = createRandomizedRouter(network, tt);
LeastCostPathCalculator router = createRandomizedRouter(cityNetwork, tt);

sampleCityRoutes(cityNetwork, router, tt, rnd);

Expand Down Expand Up @@ -223,9 +227,16 @@ private void sampleCityRoutes(Network network, LeastCostPathCalculator router, R

Link to = NetworkUtils.getNearestLink(network, dest);

// Links could be on the very edge so that nodes are outside the network
if (to == null || !network.getNodes().containsKey(link.getFromNode().getId()) ||
!network.getNodes().containsKey(to.getToNode().getId())) {
i--;
continue;
}

LeastCostPathCalculator.Path path = router.calcLeastCostPath(link.getFromNode(), to.getToNode(), 0, null, null);

if (path.nodes.size() < 2) {
if (path == null || path.nodes.size() < 2) {
i--;
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.unimi.dsi.fastutil.objects.Object2DoubleMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
Expand All @@ -14,12 +13,16 @@
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.InputOptions;
import org.matsim.application.options.OutputOptions;
import org.matsim.application.prepare.Predictor;
import org.matsim.application.prepare.network.params.NetworkParamsOpt.Feature;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.utils.io.IOUtils;
import picocli.CommandLine;

import java.io.BufferedReader;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand All @@ -40,6 +43,7 @@ public class ApplyNetworkParams implements MATSimAppCommand {
@CommandLine.Mixin
private final OutputOptions output = OutputOptions.ofCommand(ApplyNetworkParams.class);


@CommandLine.Parameters(arity = "1..*", description = "Type of parameters to apply. Available: ${COMPLETION-CANDIDATES}")
private Set<NetworkAttribute> params;

Expand All @@ -52,6 +56,19 @@ public class ApplyNetworkParams implements MATSimAppCommand {
@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower,upper bound)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
private double[] speedFactorBounds;

@CommandLine.Option(names = "--capacity-bounds", split = ",", defaultValue = "0.4,0.6,0.8",
description = "Minimum relative capacity against theoretical max (traffic light,right before left, priority)")
private List<Double> capacityBounds;

@CommandLine.Option(names = "--road-types", split = ",", description = "Road types to apply changes to")
private Set<String> roadTypes;

@CommandLine.Option(names = "--junction-types", split = ",", description = "Junction types to apply changes to")
private Set<String> junctionTypes;

@CommandLine.Option(names = "--decrease-only", description = "Only set values if the are lower than the current value", defaultValue = "false")
private boolean decrease;

private NetworkModel model;
private NetworkParams paramsOpt;

Expand All @@ -62,14 +79,14 @@ public static void main(String[] args) {
}

/**
* Theoretical capacity.
* Theoretical capacity assuming fixed car length and headway. This should usually not be exceeded.
*/
private static double capacityEstimate(double v) {
public static double capacityEstimate(double v) {

// headway
double tT = 1.2;

// car length
// car length + buffer
double lL = 7.0;

double Qc = v / (v * tT + lL);
Expand All @@ -94,13 +111,19 @@ public Integer call() throws Exception {
}
}

Map<Id<Link>, Feature> features = NetworkParamsOpt.readFeatures(input.getPath("features.csv"), network.getLinks().size());
Map<Id<Link>, Feature> features = NetworkParamsOpt.readFeatures(input.getPath("features.csv"), network.getLinks());

for (Link link : network.getLinks().values()) {
Feature ft = features.get(link.getId());

if (roadTypes != null && !roadTypes.isEmpty() && !roadTypes.contains(ft.highwayType()))
continue;

if (junctionTypes != null && !junctionTypes.isEmpty() && !junctionTypes.contains(ft.junctionType()))
continue;

try {
applyChanges(link, ft.junctionType(), ft.features());
applyChanges(link, ft);
} catch (IllegalArgumentException e) {
warn++;
log.warn("Error processing link {}", link.getId(), e);
Expand All @@ -117,67 +140,126 @@ public Integer call() throws Exception {
/**
* Apply speed and capacity models and apply changes.
*/
private void applyChanges(Link link, String junctionType, Object2DoubleMap<String> features) {

String type = NetworkUtils.getHighwayType(link);
private void applyChanges(Link link, Feature ft) {

boolean modified = false;

if (params.contains(NetworkAttribute.capacity)) {
modified = applyCapacity(link, ft);
}

if (params.contains(NetworkAttribute.freespeed)) {
modified |= applyFreeSpeed(link, ft);
}

FeatureRegressor capacity = model.capacity(junctionType);
if (modified)
warn++;
}

double perLane = capacity.predict(features);
private boolean applyCapacity(Link link, Feature ft) {

double cap = capacityEstimate(features.getDouble("speed"));
Predictor capacity = model.capacity(ft.junctionType(), ft.highwayType());
// No operation performed if not supported
if (capacity == null) {
return false;
}

// Minimum thresholds
double threshold = switch (junctionType) {
// traffic light can reduce capacity at least to 50% (with equal green split)
case "traffic_light" -> 0.4;
case "right_before_left" -> 0.6;
// Motorways are kept at their max theoretical capacity
case "priority" -> type.startsWith("motorway") ? 1 : 0.8;
default -> 0;
};
double perLane = capacity.predict(ft.features(), ft.categories());
if (Double.isNaN(perLane)) {
return true;
}

if (perLane < cap * threshold) {
log.warn("Increasing capacity per lane on {} ({}, {}) from {} to {}", link.getId(), type, junctionType, perLane, cap * threshold);
perLane = cap * threshold;
modified = true;
}
double cap = capacityEstimate(ft.features().getDouble("speed"));

link.setCapacity(link.getNumberOfLanes() * perLane);
if (capacityBounds.isEmpty())
capacityBounds.add(0.0);

// Fill up to 3 elements if not provided
if (capacityBounds.size() < 3) {
capacityBounds.add(capacityBounds.get(0));
capacityBounds.add(capacityBounds.get(1));
}

// Minimum thresholds
double threshold = switch (ft.junctionType()) {
case "traffic_light" -> capacityBounds.get(0);
case "right_before_left" -> capacityBounds.get(1);
case "priority" -> capacityBounds.get(2);
default -> 0;
};

if (params.contains(NetworkAttribute.freespeed)) {
boolean modified = false;

double speedFactor = 1.0;
FeatureRegressor speedModel = model.speedFactor(junctionType);
if (perLane < cap * threshold) {
log.warn("Increasing capacity per lane on {} ({}, {}) from {} to {}",
link.getId(), ft.highwayType(), ft.junctionType(), perLane, cap * threshold);
perLane = cap * threshold;
modified = true;
}

speedFactor = paramsOpt != null ?
speedModel.predict(features, paramsOpt.getParams(junctionType)) :
speedModel.predict(features);
if (perLane > cap) {
log.warn("Reducing capacity per lane on {} ({}, {}) from {} to {}",
link.getId(), ft.highwayType(), ft.junctionType(), perLane, cap);
perLane = cap;
modified = true;
}

if (speedFactor > speedFactorBounds[1]) {
log.warn("Reducing speed factor on {} from {} to {}", link.getId(), speedFactor, speedFactorBounds[1]);
speedFactor = speedFactorBounds[1];
modified = true;
}
if (ft.features().getOrDefault("num_lanes", link.getNumberOfLanes()) != link.getNumberOfLanes())
log.warn("Number of lanes for link {} does not match the feature file", link.getId());

// Threshold for very low speed factors
if (speedFactor < speedFactorBounds[0]) {
log.warn("Increasing speed factor on {} from {} to {}", link, speedFactor, speedFactorBounds[0]);
speedFactor = speedFactorBounds[0];
modified = true;
}
int totalCap = BigDecimal.valueOf(link.getNumberOfLanes() * perLane).setScale(0, RoundingMode.HALF_UP).intValue();

if (decrease && totalCap > link.getCapacity())
return false;

link.setCapacity(totalCap);

return modified;
}

private boolean applyFreeSpeed(Link link, Feature ft) {

link.setFreespeed((double) link.getAttributes().getAttribute("allowed_speed") * speedFactor);
link.getAttributes().putAttribute("speed_factor", speedFactor);
Predictor speedModel = model.speedFactor(ft.junctionType(), ft.highwayType());

// No operation performed if not supported
if (speedModel == null) {
return false;
}

if (modified)
warn++;
double speedFactor = paramsOpt != null ?
speedModel.predict(ft.features(), ft.categories(), paramsOpt.getParams(ft.junctionType())) :
speedModel.predict(ft.features(), ft.categories());

if (Double.isNaN(speedFactor)) {
return false;
}

boolean modified = false;

if (speedFactor > speedFactorBounds[1]) {
log.warn("Reducing speed factor on {} from {} to {}", link.getId(), speedFactor, speedFactorBounds[1]);
speedFactor = speedFactorBounds[1];
modified = true;
}

// Threshold for very low speed factors
if (speedFactor < speedFactorBounds[0]) {
log.warn("Increasing speed factor on {} from {} to {}", link, speedFactor, speedFactorBounds[0]);
speedFactor = speedFactorBounds[0];
modified = true;
}

double freeSpeed = (double) link.getAttributes().getAttribute("allowed_speed") * speedFactor;

freeSpeed = BigDecimal.valueOf(freeSpeed).setScale(3, RoundingMode.HALF_EVEN).doubleValue();

if (decrease && freeSpeed > link.getFreespeed())
return false;

link.setFreespeed(freeSpeed);
link.getAttributes().putAttribute("speed_factor", freeSpeed);

return modified;
}

}
Loading

0 comments on commit 03877e8

Please sign in to comment.