Skip to content

Commit

Permalink
Add testRunDrtWithCompanionsMultiThreaded
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenaxer committed Jan 20, 2024
1 parent 1fb5a37 commit a24b2a9
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand All @@ -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";

Expand Down

0 comments on commit a24b2a9

Please sign in to comment.