Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Kohl committed Dec 13, 2024
2 parents ae551f9 + 96a0461 commit d43c2f8
Show file tree
Hide file tree
Showing 649 changed files with 41,622 additions and 4,031 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/deploy-dtds.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: deploy-dtds-on-website

on:
push:
branches:
- master
pull_request:
types:
- closed
paths:
- matsim/src/main/resources/dtd
- 'matsim/src/main/resources/dtd/**'

jobs:
rsync-dtds:
if: github.event.pull_request.merged == true # only if PR closed by merging
name: sync DTDs to website
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: rsync dtds
uses: burnett01/[email protected]
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/full-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
#os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Prepare git
Expand Down
6 changes: 3 additions & 3 deletions contribs/accessibility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>matrixbasedptrouter</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>roadpricing</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>net.sf.trove4j</groupId>
Expand Down Expand Up @@ -70,7 +70,7 @@
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>analysis</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.matsim.contrib</groupId>-->
Expand Down
2 changes: 1 addition & 1 deletion contribs/analysis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>roadpricing</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.osgeo</groupId>
Expand Down
18 changes: 9 additions & 9 deletions contribs/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,37 @@
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>otfvis</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>osm</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>sumo</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>analysis</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>emissions</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>noise</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>freight</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
<exclusions>
<!-- Logging levels are all messed up without this exclusion -->
<exclusion>
Expand All @@ -87,7 +87,7 @@
<dependency>
<groupId>com.github.matsim-org</groupId>
<artifactId>gtfs2matsim</artifactId>
<version>47b0802a29</version>
<version>19f1676fc6</version>
<exclusions>
<!-- Exclude unneeded dependencies and these with known CVE -->
<exclusion>
Expand Down Expand Up @@ -151,7 +151,7 @@
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>dvrp</artifactId>
<version>2025.0-SNAPSHOT</version>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class ApplyNetworkParams implements MATSimAppCommand {
@CommandLine.Option(names = "--model", description = "Reference to the network model class", required = true)
private Class<? extends NetworkModel> modelClazz;

@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower,upper bound)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower, upper bound). " +
"Can be negative to indicate absolute speed bounds (in km/h)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
private double[] speedFactorBounds;

@CommandLine.Option(names = "--capacity-bounds", split = ",", defaultValue = "0.4,0.6,0.8",
Expand Down Expand Up @@ -234,23 +235,40 @@ private boolean applyFreeSpeed(Link link, Feature ft) {
return false;
}

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

boolean modified = false;

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

// Use absolute bound for speed
if (freeSpeed > -speedFactorBounds[1]/3.6 && speedFactorBounds[1] < 0) {
log.warn("Reducing speed on {} from {} to {}", link.getId(), freeSpeed, -speedFactorBounds[1]/3.6);
speedFactor = (-speedFactorBounds[1] / 3.6) / allowedSpeed;
modified = true;
}

// Threshold for very low speed factors
if (speedFactor < speedFactorBounds[0]) {
if (speedFactor < speedFactorBounds[0] && speedFactorBounds[0] >= 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;
// Absolute negative speed factor
if (freeSpeed < -speedFactorBounds[0]/3.6 && speedFactorBounds[0] < 0) {
log.warn("Increasing speed on {} from {} to {}", link, freeSpeed, -speedFactorBounds[0]/3.6);
speedFactor = (-speedFactorBounds[0] / 3.6) / allowedSpeed;
modified = true;
}

// Recalculate with updated speed factor
freeSpeed = allowedSpeed * speedFactor;
freeSpeed = BigDecimal.valueOf(freeSpeed).setScale(3, RoundingMode.HALF_EVEN).doubleValue();

if (decrease && freeSpeed > link.getFreespeed())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,27 @@ static Result applyAndEvaluateParams(
speedFactor = speedModel.predict(ft.features(), ft.categories());

// apply lower and upper bound
speedFactor = Math.max(speedFactorBounds[0], speedFactor);
speedFactor = Math.min(speedFactorBounds[1], speedFactor);
if (speedFactorBounds[0] >= 0)
speedFactor = Math.max(speedFactorBounds[0], speedFactor);

if (speedFactorBounds[1] >= 0)
speedFactor = Math.min(speedFactorBounds[1], speedFactor);

attributes.put(link.getId(), speedModel.getData(ft.features(), ft.categories()));

link.setFreespeed(allowedSpeed * speedFactor);
double freespeed = allowedSpeed * speedFactor;

// Check absolute bounds on the freespeed
if (speedFactorBounds[0] < 0 && freespeed < -speedFactorBounds[0]/3.6) {
freespeed = -speedFactorBounds[0]/3.6;
speedFactor = freespeed / allowedSpeed;
}
if (speedFactorBounds[1] < 0 && freespeed > -speedFactorBounds[1]/3.6) {
freespeed = -speedFactorBounds[1]/3.6;
speedFactor = freespeed / allowedSpeed;
}

link.setFreespeed(freespeed);
link.getAttributes().putAttribute("speed_factor", speedFactor);

} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class FreespeedOptServer implements MATSimAppCommand {
@CommandLine.Parameters(arity = "1..*", description = "Input validation files loaded from APIs")
private List<String> validationFiles;

@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower,upper bound)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower, upper bound). " +
"Can be negative to indicate absolute speed bounds (in km/h)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
private double[] speedFactorBounds;

@CommandLine.Option(names = "--ref-hours", description = "Reference hours", defaultValue = "3,21", split = ",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.matsim.core.utils.io.IOUtils;
import org.matsim.pt.transitSchedule.api.*;
import org.matsim.pt.utils.CreatePseudoNetwork;
import org.matsim.pt.utils.CreatePseudoNetworkWithLoopLinks;
import org.matsim.pt.utils.TransitScheduleValidator;
import org.matsim.vehicles.*;
import picocli.CommandLine;
Expand Down Expand Up @@ -85,8 +86,8 @@ public class CreateTransitScheduleFromGtfs implements MATSimAppCommand {
@CommandLine.Option(names = "--transform-schedule", description = "Fully qualified class name to a Consumer<TransitSchedule> to be executed after the schedule was created", arity = "0..*", split = ",")
private List<Class<?>> transformSchedule;

@CommandLine.Option(names = "--merge-stops", description = "Whether stops should be merged by coordinate")
private boolean mergeStops;
@CommandLine.Option(names = "--merge-stops", description = "Whether stops should be merged by coordinate", defaultValue = "doNotMerge")
private GtfsConverter.MergeGtfsStops mergeStops;

@CommandLine.Option(names = "--prefix", description = "Prefixes to add to the gtfs ids. Required if multiple inputs are used and ids are not unique.", split = ",")
private List<String> prefixes = new ArrayList<>();
Expand All @@ -100,10 +101,29 @@ public class CreateTransitScheduleFromGtfs implements MATSimAppCommand {
@CommandLine.Option(names = "--shp-crs", description = "Overwrite coordinate system of the shape file")
private String shpCrs;

@CommandLine.Option(names = "--pseudo-network", description = "Define how the pseudo network should be created", defaultValue = "singleLinkBetweenStops")
private PseudoNetwork pseudoNetwork;


public static void main(String[] args) {
System.exit(new CommandLine(new CreateTransitScheduleFromGtfs()).execute(args));
}

private static void addHbefaMapping(VehicleType vehicleType, HbefaVehicleCategory category) {
EngineInformation carEngineInformation = vehicleType.getEngineInformation();
VehicleUtils.setHbefaVehicleCategory(carEngineInformation, String.valueOf(category));
VehicleUtils.setHbefaTechnology(carEngineInformation, "average");
VehicleUtils.setHbefaSizeClass(carEngineInformation, "average");
VehicleUtils.setHbefaEmissionsConcept(carEngineInformation, "average");
vehicleType.setNetworkMode(TransportMode.pt);
}

private static void increaseLinkFreespeedIfLower(Link link, double newFreespeed) {
if (link.getFreespeed() < newFreespeed) {
link.setFreespeed(newFreespeed);
}
}

@Override
public Integer call() throws Exception {

Expand Down Expand Up @@ -183,6 +203,13 @@ public Integer call() throws Exception {

Scenario ptScenario = getScenarioWithPseudoPtNetworkAndTransitVehicles(network, scenario.getTransitSchedule(), "pt_");

for (TransitLine line : new ArrayList<>(scenario.getTransitSchedule().getTransitLines().values())) {
if (line.getRoutes().isEmpty()) {
log.warn("Line {} with no routes removed.", line.getId());
scenario.getTransitSchedule().removeTransitLine(line);
}
}

if (validate) {
//Check schedule and network
TransitScheduleValidator.ValidationResult checkResult = TransitScheduleValidator.validateAll(ptScenario.getTransitSchedule(), ptScenario.getNetwork());
Expand Down Expand Up @@ -237,14 +264,19 @@ private Predicate<Stop> createFilter(int i) throws Exception {
/**
* Creates the pt scenario and network.
*/
private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network network, TransitSchedule schedule, String ptNetworkIdentifier) {
private Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network network, TransitSchedule schedule, String ptNetworkIdentifier) {
ScenarioUtils.ScenarioBuilder builder = new ScenarioUtils.ScenarioBuilder(ConfigUtils.createConfig());
builder.setNetwork(network);
builder.setTransitSchedule(schedule);
Scenario scenario = builder.build();

// add pseudo network for pt
new CreatePseudoNetwork(scenario.getTransitSchedule(), scenario.getNetwork(), ptNetworkIdentifier, 0.1, 100000.0).createNetwork();
switch (pseudoNetwork) {
case singleLinkBetweenStops ->
new CreatePseudoNetwork(scenario.getTransitSchedule(), scenario.getNetwork(), ptNetworkIdentifier, 0.1, 100000.0).createNetwork();
case withLoopLinks ->
new CreatePseudoNetworkWithLoopLinks(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 Down Expand Up @@ -449,8 +481,12 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
// so we need to add time for passengers to board and alight
double minStopTime = 30.0;

List<Id<Link>> routeIds = new LinkedList<>();
routeIds.add(route.getRoute().getStartLinkId());
routeIds.addAll(route.getRoute().getLinkIds());
routeIds.add(route.getRoute().getEndLinkId());

for (int i = 1; i < routeStops.size(); i++) {
// TODO cater for loop link at first stop? Seems to just work without.
TransitRouteStop routeStop = routeStops.get(i);
// if there is no departure offset set (or infinity), it is the last stop of the line,
// so we don't need to care about the stop duration
Expand All @@ -462,8 +498,23 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
// Math.max to avoid negative values of travelTime
double travelTime = Math.max(1, routeStop.getArrivalOffset().seconds() - lastDepartureOffset - 1.0 -
(stopDuration >= minStopTime ? 0 : (minStopTime - stopDuration)));
Link link = network.getLinks().get(routeStop.getStopFacility().getLinkId());
increaseLinkFreespeedIfLower(link, link.getLength() / travelTime);


Id<Link> stopLink = routeStop.getStopFacility().getLinkId();
List<Id<Link>> subRoute = new LinkedList<>();
do {
Id<Link> linkId = routeIds.removeFirst();
subRoute.add(linkId);
} while (!subRoute.contains(stopLink));

List<? extends Link> links = subRoute.stream().map(scenario.getNetwork().getLinks()::get)
.toList();

double length = links.stream().mapToDouble(Link::getLength).sum();

for (Link link : links) {
increaseLinkFreespeedIfLower(link, length / travelTime);
}
lastDepartureOffset = routeStop.getDepartureOffset().seconds();
}

Expand All @@ -481,20 +532,15 @@ private static Scenario getScenarioWithPseudoPtNetworkAndTransitVehicles(Network
return scenario;
}

private static void addHbefaMapping(VehicleType vehicleType, HbefaVehicleCategory category) {
EngineInformation carEngineInformation = vehicleType.getEngineInformation();
VehicleUtils.setHbefaVehicleCategory(carEngineInformation, String.valueOf(category));
VehicleUtils.setHbefaTechnology(carEngineInformation, "average");
VehicleUtils.setHbefaSizeClass(carEngineInformation, "average");
VehicleUtils.setHbefaEmissionsConcept(carEngineInformation, "average");
vehicleType.setNetworkMode(TransportMode.pt);
}

private static void increaseLinkFreespeedIfLower(Link link, double newFreespeed) {
if (link.getFreespeed() < newFreespeed) {
link.setFreespeed(newFreespeed);
}
public enum PseudoNetwork {
/**
* Create links between all stops and possibly duplicate stops.
*/
singleLinkBetweenStops,
/**
* Create a pseudo network with loop links at each stop.
*/
withLoopLinks,
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,12 @@ public void run(Person person) {
}

// Remove all unselected plans because these are not handled
person.getPlans().stream()
.filter(p -> p != person.getSelectedPlan())
.forEach(person::removePlan);
List<Plan> plans = new ArrayList<>(person.getPlans());
for(Plan p : plans){
if (p != person.getSelectedPlan()){
person.removePlan(p);
}
}
}


Expand Down
Loading

0 comments on commit d43c2f8

Please sign in to comment.