Skip to content

Commit

Permalink
move sbb-extensions to contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbischoff committed Dec 22, 2020
1 parent 2914636 commit 16e02b7
Show file tree
Hide file tree
Showing 37 changed files with 5,812 additions and 12 deletions.
1 change: 1 addition & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pull_request_rules:
- status-success=build (contribs/hybridsim)
- status-success=build (contribs/otfvis)
- status-success=build (contribs/osm)
- status-success=build (contribs/sbb-extensions)
- "#approved-reviews-by>=0"
- label=automerge
# - status-success=Jenkins@VSP
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ env:
- MODULE=contribs/hybridsim
- MODULE=contribs/otfvis
- MODULE=contribs/osm
- MODULE=contribs/sbb-extensions
global:
- MAVEN_OPTS="-Xmx2g"
17 changes: 5 additions & 12 deletions contribs/dvrp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
<artifactId>dvrp</artifactId>
<name>dvrp</name>

<repositories>
<repository>
<id>SBB</id>
<url>https://schweizerischebundesbahnen.bintray.com/simba.mvn</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -47,6 +40,11 @@
<artifactId>locationchoice</artifactId>
<version>13.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>sbb-extensions</artifactId>
<version>13.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
Expand All @@ -62,11 +60,6 @@
<artifactId>streamex</artifactId>
<version>0.7.2</version>
</dependency>
<dependency>
<groupId>ch.sbb</groupId>
<artifactId>matsim-sbb-extensions</artifactId>
<version>12.13</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
1 change: 1 addition & 0 deletions contribs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<module>protobuf</module>
<module>pseudosimulation</module>
<module>roadpricing</module>
<module>sbb-extensions</module>
<module>signals</module>
<module>socnetsim</module>
<module>sumo</module>
Expand Down
3 changes: 3 additions & 0 deletions contribs/sbb-extensions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/output
/target
/bin
535 changes: 535 additions & 0 deletions contribs/sbb-extensions/README.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions contribs/sbb-extensions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.matsim</groupId>
<artifactId>contrib</artifactId>
<version>13.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.matsim.contrib</groupId>
<artifactId>sbb-extensions</artifactId>
<name>sbb-extensions</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
25 changes: 25 additions & 0 deletions contribs/sbb-extensions/src/main/assembly/assembly-release.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<assembly xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>release</id>
<includeBaseDirectory>true</includeBaseDirectory>
<baseDirectory>${artifactId}-${version}</baseDirectory>
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}.jar</source>
<outputDirectory>/</outputDirectory>
</file>
</files>

<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>/libs/</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>

</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) Schweizerische Bundesbahnen SBB, 2018.
*/

package ch.sbb.matsim;

import ch.sbb.matsim.mobsim.qsim.SBBTransitModule;
import ch.sbb.matsim.mobsim.qsim.pt.SBBTransitEngineQSimModule;
import ch.sbb.matsim.routing.pt.raptor.SwissRailRaptorModule;
import org.apache.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.Controler;
import org.matsim.core.scenario.ScenarioUtils;

/**
* Example script that shows how to use the extensions developed by SBB (Swiss Federal Railway) included in this repository.
*
* @author mrieser / SBB
*/
public class RunSBBExtension {

private static Logger log = Logger.getLogger(RunSBBExtension.class);

public static void main(String[] args) {
String configFilename = args[0];
Config config = ConfigUtils.loadConfig(configFilename);

Scenario scenario = ScenarioUtils.loadScenario(config);
Controler controler = new Controler(scenario);

// To use the deterministic pt simulation (Part 1 of 2):
controler.addOverridingModule(new SBBTransitModule());

// To use the fast pt router (Part 1 of 1)
controler.addOverridingModule(new SwissRailRaptorModule());

// To use the deterministic pt simulation (Part 2 of 2):
controler.configureQSimComponents(components -> {
SBBTransitEngineQSimModule.configure(components);

// if you have other extensions that provide QSim components, call their configure-method here
});

controler.run();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright (C) Schweizerische Bundesbahnen SBB, 2018.
*/

package ch.sbb.matsim.analysis.skims;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.matsim.api.core.v01.Coord;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.core.utils.misc.Counter;

/**
* Calculates a zone-to-zone beeline distance matrix.
* <p>
* Idea of the algorithm: - select n random points per zone - for each zone-to-zone combination, calculate the beeline distance from each point to each other point in the destination zone. - this
* results in n x n distances per zone-to-zone combination. - average the n x n distances and store this value as the zone-to-zone distance.
*
* @author mrieser / SBB
*/
public final class BeelineDistanceMatrix {

private BeelineDistanceMatrix() {
}

public static <T> FloatMatrix<T> calculateBeelineDistanceMatrix(Set<T> zoneIds, Map<T, Coord[]> coordsPerZone, int numberOfThreads) {
// prepare calculation
FloatMatrix<T> matrix = new FloatMatrix<>(zoneIds, 0.0f);

int numberOfPointsPerZone = coordsPerZone.values().iterator().next().length;

// do calculation
ConcurrentLinkedQueue<T> originZones = new ConcurrentLinkedQueue<>(zoneIds);

Counter counter = new Counter("BeelineDistanceMatrix zone ", " / " + zoneIds.size());
Thread[] threads = new Thread[numberOfThreads];
for (int i = 0; i < numberOfThreads; i++) {
BeelineDistanceMatrix.RowWorker<T> worker = new BeelineDistanceMatrix.RowWorker<>(originZones, zoneIds, coordsPerZone, matrix, counter);
threads[i] = new Thread(worker, "BeelineDistanceMatrix-" + i);
threads[i].start();
}

// wait until all threads have finished
for (Thread thread : threads) {
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

matrix.multiply((float) (1.0 / numberOfPointsPerZone / numberOfPointsPerZone));
return matrix;
}

private static class RowWorker<T> implements Runnable {

private final ConcurrentLinkedQueue<T> originZones;
private final Set<T> destinationZones;
private final Map<T, Coord[]> coordsPerZone;
private final FloatMatrix<T> matrix;
private final Counter counter;

RowWorker(ConcurrentLinkedQueue<T> originZones, Set<T> destinationZones, Map<T, Coord[]> coordsPerZone, FloatMatrix<T> matrix, Counter counter) {
this.originZones = originZones;
this.destinationZones = destinationZones;
this.coordsPerZone = coordsPerZone;
this.matrix = matrix;
this.counter = counter;
}

@Override
public void run() {
while (true) {
T fromZoneId = this.originZones.poll();
if (fromZoneId == null) {
return;
}

this.counter.incCounter();
Coord[] fromCoords = this.coordsPerZone.get(fromZoneId);
if (fromCoords != null) {
for (Coord fromCoord : fromCoords) {

for (T toZoneId : this.destinationZones) {
Coord[] toCoords = this.coordsPerZone.get(toZoneId);
if (toCoords != null) {
for (Coord toCoord : toCoords) {
double dist = CoordUtils.calcEuclideanDistance(fromCoord, toCoord);
this.matrix.add(fromZoneId, toZoneId, (float) dist);
}
} else {
// this might happen if a zone has no geometry, for whatever reason...
this.matrix.set(fromZoneId, toZoneId, Float.POSITIVE_INFINITY);
}
}
}
} else {
// this might happen if a zone has no geometry, for whatever reason...
for (T toZoneId : this.destinationZones) {
this.matrix.set(fromZoneId, toZoneId, Float.POSITIVE_INFINITY);
}
}
}
}
}
}
Loading

0 comments on commit 16e02b7

Please sign in to comment.