Skip to content

Commit

Permalink
quick setup to perform local runs
Browse files Browse the repository at this point in the history
  • Loading branch information
luchengqi7 committed Jan 29, 2024
1 parent 2b58976 commit 1ebaf49
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>matsim-all</artifactId>

<!-- PR-labelled release -->
<version>16.0-PR2878</version>
<version>16.0-PR2997</version>

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<!-- <version>16.0-SNAPSHOT</matsim.version>-->
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/org/matsim/run/RunDetourConstraintsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.matsim.run;

import org.matsim.application.MATSimAppCommand;
import org.matsim.contrib.drt.passenger.DrtOfferAcceptor;
import org.matsim.contrib.drt.passenger.MaxDetourOfferAcceptor;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.DrtControlerCreator;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.VspExperimentalConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import picocli.CommandLine;

public class RunDetourConstraintsTest implements MATSimAppCommand {
@CommandLine.Option(names = "--config", description = "path to config file", required = true)
private String configFile;
@CommandLine.Option(names = "--plans", description = "path to input plans", required = true)
private String inputPlans;
@CommandLine.Option(names = "--output", description = "path of output folder", required = true)
private String output;

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

@Override
public Integer call() throws Exception {
Config config = ConfigUtils.loadConfig(configFile, new MultiModeDrtConfigGroup(), new DvrpConfigGroup());
config.plans().setInputFile(inputPlans);
config.controller().setOutputDirectory(output);
config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.info);
config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);

Controler controler = DrtControlerCreator.createControler(config, false);

MultiModeDrtConfigGroup multiModeDrtConfig = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);
for (DrtConfigGroup drtCfg : multiModeDrtConfig.getModalElements()) {
controler.addOverridingQSimModule(new AbstractDvrpModeQSimModule(drtCfg.mode) {
@Override
protected void configureQSim() {
bindModal(DrtOfferAcceptor.class).toProvider(modalProvider(getter -> new MaxDetourOfferAcceptor(drtCfg.maxAllowedPickupDelay)));
}
});
}

controler.run();

return 0;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/matsim/run/RunKelheimScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected Config prepareConfig(Config config) {
sw.defaultParams().shp = "../shp/dilutionArea.shp";
sw.defaultParams().mapCenter = "11.89,48.91";
sw.defaultParams().mapZoomLevel = 11d;
sw.defaultParams().sampleSize = sample.getSample();
// sw.defaultParams().sampleSize = sample.getSample();

if (intermodal) {
ConfigUtils.addOrGetModule(config, PtIntermodalRoutingModesConfigGroup.class);
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/org/matsim/run/prepare/PrepareRealDrtDemand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.population.*;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.CrsOptions;
Expand Down Expand Up @@ -58,26 +57,33 @@ public Integer call() throws Exception {
// Map<String, Coord> stationCoordMap = loadStationCoordinates();

try (CSVParser parser = new CSVParser(Files.newBufferedReader(Path.of(demands)),
CSVFormat.DEFAULT.withDelimiter(',').withFirstRecordAsHeader())) {
CSVFormat.DEFAULT.withDelimiter(';').withFirstRecordAsHeader())) {
int counter = 0;
for (CSVRecord row : parser) {
double fromX = Double.parseDouble(row.get("from_x"));
double fromY = Double.parseDouble(row.get("from_y"));
double toX = Double.parseDouble(row.get("to_x"));
double toY = Double.parseDouble(row.get("to_y"));
double fromX = Double.parseDouble(row.get("fromX"));
double fromY = Double.parseDouble(row.get("fromY"));
double toX = Double.parseDouble(row.get("toX"));
double toY = Double.parseDouble(row.get("toY"));
// double fromX = Double.parseDouble(row.get("from_x"));
// double fromY = Double.parseDouble(row.get("from_y"));
// double toX = Double.parseDouble(row.get("to_x"));
// double toY = Double.parseDouble(row.get("to_y"));
Coord fromCoord = new Coord(fromX, fromY);
Coord transformedFromCoord = crs.getTransformation().transform(fromCoord);
Coord toCoord = new Coord(toX, toY);
Coord transformedToCoord = crs.getTransformation().transform(toCoord);
double departureTime = Double.parseDouble(row.get("time_in_seconds"));
int numberOfPassengers = Integer.parseInt(row.get("number_of_passengers"));
// double departureTime = Double.parseDouble(row.get("time_in_seconds"));
double departureTime = Double.parseDouble(row.get("departureTime"));
// int numberOfPassengers = Integer.parseInt(row.get("number_of_passengers"));
int numberOfPassengers = 1;

for (int i = 0; i < numberOfPassengers; i++) {
Person person = populationFactory.createPerson(Id.createPersonId("drt_person_" + counter));
Plan plan = populationFactory.createPlan();
Activity activity0 = populationFactory.createActivityFromCoord("dummy", transformedFromCoord);
activity0.setEndTime(departureTime);
Leg leg = populationFactory.createLeg(TransportMode.drt);
Leg leg = populationFactory.createLeg("av");
// Leg leg = populationFactory.createLeg(TransportMode.drt);
Activity activity1 = populationFactory.createActivityFromCoord("dummy", transformedToCoord);
plan.addActivity(activity0);
plan.addLeg(leg);
Expand Down

0 comments on commit 1ebaf49

Please sign in to comment.