-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2914636
commit 16e02b7
Showing
37 changed files
with
5,812 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/output | ||
/target | ||
/bin |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
contribs/sbb-extensions/src/main/assembly/assembly-release.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
49 changes: 49 additions & 0 deletions
49
contribs/sbb-extensions/src/main/java/ch/sbb/matsim/RunSBBExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
...ribs/sbb-extensions/src/main/java/ch/sbb/matsim/analysis/skims/BeelineDistanceMatrix.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.