Skip to content

Commit

Permalink
Add intermodal stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
luchengqi7 committed Sep 18, 2024
1 parent cf7467b commit e26c8b1
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,35 @@
<version>${matsim.version}</version>
</dependency>

<dependency>
<groupId>com.github.matsim-vsp</groupId>
<artifactId>pt-extensions</artifactId>
<version>ceef00ef6e</version>
<exclusions>
<!-- Will pull old drt version -->
<exclusion>
<groupId>org.matsim.contrib</groupId>
<artifactId>drt</artifactId>
</exclusion>
<exclusion>
<groupId>org.matsim</groupId>
<artifactId>matsim</artifactId>
</exclusion>
<exclusion>
<groupId>org.matsim</groupId>
<artifactId>matsim-examples</artifactId>
</exclusion>
<exclusion>
<groupId>org.matsim.contrib</groupId>
<artifactId>vsp</artifactId>
</exclusion>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
</exclusion>
</exclusions>
</dependency>


<!-- Custom dependencies -->
<dependency>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/matsim/run/DrtOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.extensions.pt.routing.ptRoutingModes.PtIntermodalRoutingModesConfigGroup;
import org.matsim.run.prepare.PrepareNetwork;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleCapacity;
Expand Down Expand Up @@ -48,6 +49,10 @@ public class DrtOptions {
@CommandLine.Option(names = "--ride-time-std", description = "ride duration standard deviation", defaultValue = "0.3")
protected double rideTimeStd;

@CommandLine.Option(names = "--intermodal", defaultValue = "false", description = "enable intermodality for DRT service")
private boolean intermodal;


/**
* a helper method, which makes all necessary config changes to simulate drt.
*/
Expand Down Expand Up @@ -96,6 +101,10 @@ void configureDrtConfig(Config config) {

// creates a drt staging activity and adds it to the scoring params
DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfigGroup, config.scoring(), config.routing());

if (intermodal) {
ConfigUtils.addOrGetModule(config, PtIntermodalRoutingModesConfigGroup.class);
}
}

/**
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/org/matsim/run/prepare/PrepareTransitSchedule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.matsim.run.prepare;

import org.geotools.api.feature.simple.SimpleFeature;
import org.locationtech.jts.geom.Geometry;
import org.matsim.api.core.v01.Scenario;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.ShpOptions;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.scenario.ProjectionUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.pt.transitSchedule.api.TransitSchedule;
import org.matsim.pt.transitSchedule.api.TransitScheduleWriter;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;
import picocli.CommandLine;

import java.util.List;

@CommandLine.Command(
name = "prepare-transit-schedule",
description = "Tag transit stops for Intermodal trips"
)
public class PrepareTransitSchedule implements MATSimAppCommand {
@CommandLine.Mixin
private ShpOptions shp = new ShpOptions();

@CommandLine.Option(names = "--input", description = "input transit schedule", required = true)
private String input;

@CommandLine.Option(names = "--output", description = "output path of the transit schedule", required = true)
private String output;

public static void main(String[] args) {
new PrepareTransitSchedule().execute(args);
}

@Override
public Integer call() throws Exception {
Geometry intermodalArea = null;
List<SimpleFeature> features = shp.readFeatures();
for (SimpleFeature feature : features) {
if (intermodalArea == null) {
intermodalArea = (Geometry) feature.getDefaultGeometry();
} else {
intermodalArea = intermodalArea.union((Geometry) feature.getDefaultGeometry());
}
}

Config config = ConfigUtils.createConfig();
config.transit().setTransitScheduleFile(input);
config.global().setCoordinateSystem("EPSG:25832");
Scenario scenario = ScenarioUtils.loadScenario(config);
TransitSchedule transitSchedule = scenario.getTransitSchedule();

for (TransitStopFacility stop : transitSchedule.getFacilities().values()) {
if (MGC.coord2Point(stop.getCoord()).within(intermodalArea)) {
// TODO maybe add another filter (e.g. only train station, long distance bus stop...)
stop.getAttributes().putAttribute("allowDrtAccessEgress", "true");
}
}

ProjectionUtils.putCRS(transitSchedule, "EPSG:25832");

TransitScheduleWriter writer = new TransitScheduleWriter(transitSchedule);
writer.writeFile(output);

return 0;
}
}

0 comments on commit e26c8b1

Please sign in to comment.