Skip to content

Commit

Permalink
complete drt test
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Sep 3, 2024
1 parent e894ee8 commit ff66b9a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/matsim/run/DrtOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.run.prepare.PrepareNetwork;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleCapacity;
Expand All @@ -29,7 +30,7 @@
* This class bundles some run parameter options and functionalities connected to drt-scenarios.
*/
public class DrtOptions {
@CommandLine.Option(names = "--drt-shp", description = "Path to shp file for adding drt not network links as an allowed mode.", defaultValue = "./input/v1.1/drt-area/nord-bautzen-waiting-times_utm32N.shp")
@CommandLine.Option(names = "--drt-shp", description = "Path to shp file for adding drt not network links as an allowed mode.", defaultValue = "./drt-area/nord-bautzen-waiting-times_utm32N.shp")
private String drtAreaShp;

@CommandLine.Option(names = "--typ-wt", description = "typical waiting time", defaultValue = "300")
Expand Down Expand Up @@ -109,7 +110,8 @@ void configureDrtScenario(Scenario scenario) {
.setRouteFactory(DrtRoute.class, new DrtRouteFactory());

// prepare network for drt
PrepareNetwork.prepareDrtNetwork(scenario.getNetwork(), getDrtAreaShp());
// preparation needs to be done with lausitz shp not service area shp
PrepareNetwork.prepareDrtNetwork(scenario.getNetwork(), IOUtils.extendUrl(scenario.getConfig().getContext(), "../shp/lausitz.shp").toString());
// add drt veh type if not already existing
Id<VehicleType> drtTypeId = Id.create(TransportMode.drt, VehicleType.class);
if (!scenario.getVehicles().getVehicleTypes().containsKey(drtTypeId)) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/matsim/run/prepare/PrepareNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,5 @@ public static void prepareDrtNetwork(Network network, String drtAreaShp) {
}
}
new MultimodalNetworkCleaner(network).run(Set.of(TransportMode.drt));

}
}
35 changes: 27 additions & 8 deletions src/test/java/org/matsim/run/RunIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.matsim.run;

import com.univocity.parsers.common.input.EOFException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -12,11 +13,12 @@
import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.*;
import org.matsim.application.ApplicationUtils;
import org.matsim.application.MATSimApplication;
import org.matsim.application.options.CsvOptions;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.SubtourModeChoiceConfigGroup;
import org.matsim.core.events.EventsUtils;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.population.PersonUtils;
Expand All @@ -25,7 +27,12 @@
import org.matsim.pt.transitSchedule.api.*;
import org.matsim.simwrapper.SimWrapperConfigGroup;
import org.matsim.testcases.MatsimTestUtils;
import tech.tablesaw.api.ColumnType;
import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.Table;
import tech.tablesaw.io.csv.CsvReadOptions;

import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -57,26 +64,38 @@ void runScenario() {

@Test
void runScenarioIncludingDrt() {

Config config = ConfigUtils.loadConfig(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION));
ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

SubtourModeChoiceConfigGroup smc = ConfigUtils.addOrGetModule(config, SubtourModeChoiceConfigGroup.class);
smc.setModes(new String[]{TransportMode.drt});

config.replanning().setFractionOfIterationsToDisableInnovation(1.);

Path inputPath = p.resolve("drt-test-population.xml.gz");

createTestPopulation(config, inputPath, TransportMode.drt, new Coord(838300.95,5711890.36));

assert MATSimApplication.execute(RunLausitzDrtScenario.class, config,
"--1pct",
"--drt-shp", "C:/Users/Simon/Documents/vsp-projects/matsim-lausitz/input/shp/lausitz.shp",
"--iterations", "1",
"--config:plans.inputPlansFile", inputPath.toString(),
"--output", utils.getOutputDirectory(),
"--config:controller.overwriteFiles=deleteDirectoryIfExists") == 0 : "Must return non error code";

//read customer stats
Path customerStatsPath = ApplicationUtils.matchInput("drt_customer_stats_" + TransportMode.drt + ".csv", Path.of(utils.getOutputDirectory()));
try {
Table customerStats = Table.read()
.csv(CsvReadOptions.builder(customerStatsPath.toFile())
.columnTypes(columnHeader -> columnHeader.equals("runId") ? ColumnType.STRING : ColumnType.DOUBLE)
.separator(CsvOptions.detectDelimiter(customerStatsPath.toString()))
.build());

Assertions.assertEquals(2, customerStats.rowCount());

DoubleColumn rideCol = customerStats.doubleColumn("rides");

// there should be exactly 2 drt rides
Assertions.assertEquals(2, rideCol.get(rideCol.size() - 1));
} catch (IOException e) {
throw new EOFException();
}
}

@Test
Expand Down

0 comments on commit ff66b9a

Please sign in to comment.