From a24b2a924db6836cfac0b444079739e5680e7a80 Mon Sep 17 00:00:00 2001 From: steffenaxer <26229392+steffenaxer@users.noreply.github.com> Date: Sat, 20 Jan 2024 12:10:14 +0100 Subject: [PATCH] Add testRunDrtWithCompanionsMultiThreaded --- .../RunDrtWithCompanionExampleIT.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java index 8ba86ac28d7..4a7cb879f50 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java @@ -38,6 +38,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.gbl.MatsimRandom; import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; import org.matsim.testcases.MatsimTestUtils; @@ -53,6 +54,7 @@ public class RunDrtWithCompanionExampleIT { @Test void testRunDrtWithCompanions() { + MatsimRandom.reset(); Id.resetCaches(); URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); Config config = ConfigUtils.loadConfig(configUrl, new OTFVisConfigGroup(), new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new), new DvrpConfigGroup()); @@ -76,6 +78,33 @@ void testRunDrtWithCompanions() { Assertions.assertThat(actualRides).isEqualTo(706); } + @Test + void testRunDrtWithCompanionsMultiThreaded() { + MatsimRandom.reset(); + Id.resetCaches(); + URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); + Config config = ConfigUtils.loadConfig(configUrl, new OTFVisConfigGroup(), new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new), new DvrpConfigGroup()); + + // Add DrtCompanionParams with some default values into existing Drt configurations + MultiModeDrtConfigGroup multiModeDrtConfigGroup = MultiModeDrtConfigGroup.get(config); + DrtWithExtensionsConfigGroup drtWithExtensionsConfigGroup = (DrtWithExtensionsConfigGroup) multiModeDrtConfigGroup.getModalElements().iterator().next(); + + DrtCompanionParams crtCompanionParams = new DrtCompanionParams(); + crtCompanionParams.setDrtCompanionSamplingWeights(List.of(0.5,0.2,0.1,0.1,0.1)); + + drtWithExtensionsConfigGroup.addParameterSet(crtCompanionParams); + + config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOutputDirectory(utils.getOutputDirectory()); + config.qsim().setNumberOfThreads(2); + + Controler controler = DrtCompanionControlerCreator.createControler(config); + controler.run(); + + int actualRides = getTotalNumberOfDrtRides(); + Assertions.assertThat(actualRides).isEqualTo(699); + } + private int getTotalNumberOfDrtRides() { String filename = utils.getOutputDirectory() + "/drt_customer_stats_drt.csv";