diff --git a/src/main/java/org/matsim/run/DrtOptions.java b/src/main/java/org/matsim/run/DrtOptions.java index e29b319..400a69a 100644 --- a/src/main/java/org/matsim/run/DrtOptions.java +++ b/src/main/java/org/matsim/run/DrtOptions.java @@ -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; @@ -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") @@ -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 drtTypeId = Id.create(TransportMode.drt, VehicleType.class); if (!scenario.getVehicles().getVehicleTypes().containsKey(drtTypeId)) { diff --git a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java index fbbaf52..ade17b5 100644 --- a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java +++ b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java @@ -125,6 +125,5 @@ public static void prepareDrtNetwork(Network network, String drtAreaShp) { } } new MultimodalNetworkCleaner(network).run(Set.of(TransportMode.drt)); - } } diff --git a/src/test/java/org/matsim/run/RunIntegrationTest.java b/src/test/java/org/matsim/run/RunIntegrationTest.java index 7824a4b..30e2941 100644 --- a/src/test/java/org/matsim/run/RunIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunIntegrationTest.java @@ -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; @@ -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; @@ -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; @@ -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