From 8bf640864e68e09b0c1dd7495433214e505a1c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Fri, 10 Nov 2023 20:09:41 +0100 Subject: [PATCH] extract output step 1 --- .github/workflows/verify-push.yaml | 8 +- .../DrtWithExtensionsConfigGroupTest.java | 94 ---- .../RunDrtWithCompanionExampleIT.java | 95 ---- .../extension/dashboards/DashboardTests.java | 87 ---- .../extension/edrt/run/RunEDrtScenarioIT.java | 36 -- .../extension/fiss/RunFissDrtScenarioIT.java | 192 ------- .../eshifts/run/RunEShiftDrtScenarioIT.java | 176 ------- .../OperationFacilitiesIOTest.java | 83 --- .../operations/shifts/ShiftsIOTest.java | 95 ---- .../efficiency/ShiftEfficiencyTest.java | 75 --- .../run/RunMultiHubShiftDrtScenarioIT.java | 140 ----- .../shifts/run/RunShiftDrtScenarioIT.java | 140 ----- .../prebooking/PrebookingExampleIT.java | 42 +- .../extension/prebooking/PrebookingTest.java | 485 ------------------ .../optimizer/RunPreplannedDrtExampleIT.java | 111 ---- 15 files changed, 9 insertions(+), 1850 deletions(-) delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/DrtWithExtensionsConfigGroupTest.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/dashboards/DashboardTests.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenarioIT.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/operationFacilities/OperationFacilitiesIOTest.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/ShiftsIOTest.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java delete mode 100644 contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/preplanned/optimizer/RunPreplannedDrtExampleIT.java diff --git a/.github/workflows/verify-push.yaml b/.github/workflows/verify-push.yaml index 3a4bd336705..229ca11a994 100644 --- a/.github/workflows/verify-push.yaml +++ b/.github/workflows/verify-push.yaml @@ -20,9 +20,7 @@ jobs: fail-fast: false matrix: module: - - contribs/drt - contribs/drt-extensions - - contribs/dvrp steps: - name: Checkout git repo @@ -55,6 +53,12 @@ jobs: run: mvn verify --batch-mode -Dmatsim.preferLocalDtds=true -Dsource.skip working-directory: ${{matrix.module}} + - name: Get output + uses: actions/upload-artifact@v3 + with: + name: output + path: output/output_events.xml.gz + env: MAVEN_OPTS: -Xmx2g diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/DrtWithExtensionsConfigGroupTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/DrtWithExtensionsConfigGroupTest.java deleted file mode 100644 index bc0f9e22ba3..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/DrtWithExtensionsConfigGroupTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2022 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.drt.extension; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.List; - -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup; -import org.matsim.contrib.drt.extension.companions.DrtCompanionParams; -import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; -import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; - -/** - * - * @author Steffen Axer - * - */ -public class DrtWithExtensionsConfigGroupTest { - private final static double WEIGHT_1 = 4711.; - private final static double WEIGHT_2 = 1337.; - private final static double WEIGHT_3 = 911.; - - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - - - private static Config createConfig(List values) { - Config config = ConfigUtils.createConfig(); - - DrtWithExtensionsConfigGroup configGroup = new DrtWithExtensionsConfigGroup(); - DrtCompanionParams drtCompanionParams = new DrtCompanionParams(); - - DrtOperationsParams operationsParams = new DrtOperationsParams(); - ShiftsParams shiftsParams = new ShiftsParams(); - OperationFacilitiesParams operationFacilitiesParams = new OperationFacilitiesParams(); - - operationsParams.addParameterSet(shiftsParams); - operationsParams.addParameterSet(operationFacilitiesParams); - - drtCompanionParams.setDrtCompanionSamplingWeights(values); - configGroup.addParameterSet(drtCompanionParams); - configGroup.addParameterSet(operationsParams); - config.addModule(configGroup); - return config; - } - - private static Path writeConfig(final TemporaryFolder tempFolder, List weights) throws IOException { - Config config = createConfig(weights); - Path configFile = tempFolder.newFile("config.xml").toPath(); - ConfigUtils.writeConfig(config, configFile.toString()); - return configFile; - } - - @Test - public void loadConfigGroupTest() throws IOException { - - /* Test that exported values are correct imported again */ - Path configFile = writeConfig(tempFolder, List.of(WEIGHT_1,WEIGHT_2,WEIGHT_3)); - Config config = ConfigUtils.createConfig(); - ConfigUtils.loadConfig(config, configFile.toString()); - DrtWithExtensionsConfigGroup loadedCfg = ConfigUtils.addOrGetModule(config, DrtWithExtensionsConfigGroup.class); - Assert.assertTrue(loadedCfg.getDrtCompanionParams().isPresent()); - Assert.assertTrue(loadedCfg.getDrtCompanionParams().get().getDrtCompanionSamplingWeights().get(0).equals(WEIGHT_1)); - Assert.assertTrue(loadedCfg.getDrtCompanionParams().get().getDrtCompanionSamplingWeights().get(1).equals(WEIGHT_2)); - Assert.assertTrue(loadedCfg.getDrtCompanionParams().get().getDrtCompanionSamplingWeights().get(2).equals(WEIGHT_3)); - } - -} 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 deleted file mode 100644 index de5534ab0e7..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/companions/RunDrtWithCompanionExampleIT.java +++ /dev/null @@ -1,95 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2022 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.drt.extension.companions; - - -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.dvrp.run.DvrpConfigGroup; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.utils.io.IOUtils; -import org.matsim.examples.ExamplesUtils; -import org.matsim.testcases.MatsimTestUtils; -import org.matsim.vis.otfvis.OTFVisConfigGroup; - -/** - * @author Steffen Axer - */ -public class RunDrtWithCompanionExampleIT { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - @Test - public void testRunDrtWithCompanions() { - 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(); - drtWithExtensionsConfigGroup.addParameterSet(new DrtCompanionParams()); - - config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); - config.controler().setOutputDirectory(utils.getOutputDirectory()); - - Controler controler = DrtCompanionControlerCreator.createControler(config); - controler.run(); - - int actualRides = getTotalNumberOfDrtRides(); - Assertions.assertThat(actualRides).isEqualTo(471); - } - - private int getTotalNumberOfDrtRides() { - String filename = utils.getOutputDirectory() + "/drt_customer_stats_drt.csv"; - - final List collect; - try { - collect = Files.lines(Paths.get(filename)).collect(Collectors.toList()); - } catch (IOException e) { - throw new RuntimeException(e); - } - - int size = collect.size(); - List keys = List.of(collect.get(0).split(";")); - List lastIterationValues = List.of(collect.get(size - 1).split(";")); - - int index = keys.indexOf("rides"); - String value = lastIterationValues.get(index); - return Integer.parseInt(value); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/dashboards/DashboardTests.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/dashboards/DashboardTests.java deleted file mode 100644 index 43e8f7dfffe..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/dashboards/DashboardTests.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.matsim.contrib.drt.extension.dashboards; - -import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.application.MATSimApplication; -import org.matsim.contrib.drt.extension.DrtTestScenario; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.controler.Controler; -import org.matsim.simwrapper.SimWrapperConfigGroup; -import org.matsim.testcases.MatsimTestUtils; - -import java.nio.file.Path; - -public class DashboardTests { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - private void run() { - - Config config = DrtTestScenario.loadConfig(utils); - config.controler().setLastIteration(4); - config.controler().setWritePlansInterval(4); - config.controler().setWriteEventsInterval(4); - - SimWrapperConfigGroup group = ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class); - group.defaultParams().sampleSize = 0.001; - group.defaultParams().mapCenter = "11.891000, 48.911000"; - - //we have 2 operators ('av' + 'drt'), configure one of them to be areaBased (the other remains stopBased) - MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); - for (DrtConfigGroup drtCfg : multiModeDrtConfigGroup.getModalElements()) { - if (drtCfg.getMode().equals("av")){ - drtCfg.operationalScheme = DrtConfigGroup.OperationalScheme.serviceAreaBased; - drtCfg.drtServiceAreaShapeFile = "drt-zones/drt-zonal-system.shp"; - } - } - - Controler controler = MATSimApplication.prepare(new DrtTestScenario(config), config); - controler.run(); - } - - @Test - public void drtDefaults() { - run(); - - // TODO: add test headers!? - - Path drtOutputPath = Path.of(utils.getOutputDirectory(), "analysis", "drt"); - { - //test general output files - Assertions.assertThat(drtOutputPath) - .isDirectoryContaining("glob:**supply_kpi.csv"); - Assertions.assertThat(drtOutputPath) - .isDirectoryContaining("glob:**demand_kpi.csv"); - } - { - //test output files specific for stopBased services - Assertions.assertThat(drtOutputPath) - .isDirectoryContaining("glob:**stops.shp"); - Assertions.assertThat(drtOutputPath) - .isDirectoryContaining("glob:**trips_per_stop.csv"); - Assertions.assertThat(drtOutputPath) - .isDirectoryContaining("glob:**trips_per_stop.csv"); - } - - Path avOutputPath = Path.of(utils.getOutputDirectory(), "analysis", "drt-av"); - { - //test general output files - Assertions.assertThat(avOutputPath) - .isDirectoryContaining("glob:**supply_kpi.csv"); - Assertions.assertThat(avOutputPath) - .isDirectoryContaining("glob:**demand_kpi.csv"); - } - - { - //test output files specific for stopBased services - Assertions.assertThat(avOutputPath) - .isDirectoryContaining("glob:**serviceArea.shp"); - } - } - -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenarioIT.java deleted file mode 100644 index 49940884fc4..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/edrt/run/RunEDrtScenarioIT.java +++ /dev/null @@ -1,36 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) 2018 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.drt.extension.edrt.run; - -import java.net.URL; - -import org.junit.Test; -import org.matsim.core.utils.io.IOUtils; -import org.matsim.examples.ExamplesUtils; - -/** - * @author michalm - */ -public class RunEDrtScenarioIT { - @Test - public void test() { - URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_edrt_config.xml"); - RunEDrtScenario.run(configUrl, false); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java deleted file mode 100644 index 8e1f14d6531..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/fiss/RunFissDrtScenarioIT.java +++ /dev/null @@ -1,192 +0,0 @@ -package org.matsim.contrib.drt.extension.fiss; - -import org.junit.Assert; -import org.junit.Test; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.events.LinkLeaveEvent; -import org.matsim.api.core.v01.events.handler.LinkLeaveEventHandler; -import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams; -import org.matsim.contrib.drt.extension.operations.DrtOperationsControlerCreator; -import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; -import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; -import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; -import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; -import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; -import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.dvrp.run.DvrpConfigGroup; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigGroup; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup; -import org.matsim.core.config.groups.StrategyConfigGroup; -import org.matsim.core.controler.AbstractModule; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.core.mobsim.qsim.components.QSimComponentsConfigurator; -import org.matsim.examples.ExamplesUtils; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -public class RunFissDrtScenarioIT { - - @Test - public void test() { - - MultiModeDrtConfigGroup multiModeDrtConfigGroup = new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new); - - String fleetFile = "holzkirchenFleet.xml"; - String plansFile = "holzkirchenPlans_car_drt.xml.gz"; - String networkFile = "holzkirchenNetwork.xml.gz"; - String opFacilitiesFile = "holzkirchenOperationFacilities.xml"; - String shiftsFile = "holzkirchenShifts.xml"; - - DrtWithOperationsConfigGroup drtWithShiftsConfigGroup = (DrtWithOperationsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); - - DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; - drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.maxTravelTimeAlpha = 1.5; - drtConfigGroup.maxTravelTimeBeta = 10. * 60.; - drtConfigGroup.stopDuration = 30.; - drtConfigGroup.maxWaitTime = 600.; - drtConfigGroup.rejectRequestIfMaxWaitOrTravelTimeViolated = true; - drtConfigGroup.useModeFilteredSubnetwork = false; - drtConfigGroup.vehiclesFile = fleetFile; - drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtConfigGroup.plotDetailedCustomerStats = true; - drtConfigGroup.maxWalkDistance = 1000.; - drtConfigGroup.idleVehiclesReturnToDepots = false; - - drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); - - ConfigGroup rebalancing = drtConfigGroup.createParameterSet("rebalancing"); - drtConfigGroup.addParameterSet(rebalancing); - ((RebalancingParams) rebalancing).interval = 600; - - MinCostFlowRebalancingStrategyParams strategyParams = new MinCostFlowRebalancingStrategyParams(); - strategyParams.targetAlpha = 0.3; - strategyParams.targetBeta = 0.3; - - drtConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams); - - DrtZonalSystemParams drtZonalSystemParams = new DrtZonalSystemParams(); - drtZonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.GridFromNetwork; - drtZonalSystemParams.cellSize = 500.; - drtZonalSystemParams.targetLinkSelection = DrtZonalSystemParams.TargetLinkSelection.mostCentral; - drtConfigGroup.addParameterSet(drtZonalSystemParams); - - multiModeDrtConfigGroup.addParameterSet(drtWithShiftsConfigGroup); - - final Config config = ConfigUtils.createConfig(multiModeDrtConfigGroup, - new DvrpConfigGroup()); - config.setContext(ExamplesUtils.getTestScenarioURL("holzkirchen")); - - Set modes = new HashSet<>(); - modes.add("drt"); - config.travelTimeCalculator().setAnalyzedModes(modes); - - PlanCalcScoreConfigGroup.ModeParams scoreParams = new PlanCalcScoreConfigGroup.ModeParams("drt"); - config.planCalcScore().addModeParams(scoreParams); - PlanCalcScoreConfigGroup.ModeParams scoreParams2 = new PlanCalcScoreConfigGroup.ModeParams("walk"); - config.planCalcScore().addModeParams(scoreParams2); - - config.plans().setInputFile(plansFile); - config.network().setInputFile(networkFile); - - config.qsim().setSimStarttimeInterpretation(QSimConfigGroup.StarttimeInterpretation.onlyUseStarttime); - config.qsim().setSimEndtimeInterpretation(QSimConfigGroup.EndtimeInterpretation.minOfEndtimeAndMobsimFinished); - - final PlanCalcScoreConfigGroup.ActivityParams home = new PlanCalcScoreConfigGroup.ActivityParams("home"); - home.setTypicalDuration(8 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams other = new PlanCalcScoreConfigGroup.ActivityParams("other"); - other.setTypicalDuration(4 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams education = new PlanCalcScoreConfigGroup.ActivityParams("education"); - education.setTypicalDuration(6 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams shopping = new PlanCalcScoreConfigGroup.ActivityParams("shopping"); - shopping.setTypicalDuration(2 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams work = new PlanCalcScoreConfigGroup.ActivityParams("work"); - work.setTypicalDuration(2 * 3600); - - config.planCalcScore().addActivityParams(home); - config.planCalcScore().addActivityParams(other); - config.planCalcScore().addActivityParams(education); - config.planCalcScore().addActivityParams(shopping); - config.planCalcScore().addActivityParams(work); - - final StrategyConfigGroup.StrategySettings stratSets = new StrategyConfigGroup.StrategySettings(); - stratSets.setWeight(1); - stratSets.setStrategyName("ChangeExpBeta"); - config.strategy().addStrategySettings(stratSets); - - config.controler().setLastIteration(2); - config.controler().setWriteEventsInterval(1); - - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); - config.controler().setOutputDirectory("test/output/holzkirchen_shifts"); - - DrtOperationsParams operationsParams = (DrtOperationsParams) drtWithShiftsConfigGroup.createParameterSet(DrtOperationsParams.SET_NAME); - ShiftsParams shiftsParams = (ShiftsParams) operationsParams.createParameterSet(ShiftsParams.SET_NAME); - OperationFacilitiesParams operationFacilitiesParams = (OperationFacilitiesParams) operationsParams.createParameterSet(OperationFacilitiesParams.SET_NAME); - operationsParams.addParameterSet(shiftsParams); - operationsParams.addParameterSet(operationFacilitiesParams); - - operationFacilitiesParams.operationFacilityInputFile = opFacilitiesFile; - shiftsParams.shiftInputFile = shiftsFile; - shiftsParams.allowInFieldChangeover = true; - drtWithShiftsConfigGroup.addParameterSet(operationsParams); - - - if (!config.qsim().getVehiclesSource() - .equals(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData)) { - config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); - } - - final Controler run = DrtOperationsControlerCreator.createControler(config, false); - - //FISS part - LinkCounter linkCounter = new LinkCounter(); - { - FISSConfigGroup fissConfigGroup = ConfigUtils.addOrGetModule(config, FISSConfigGroup.class); - fissConfigGroup.sampleFactor = 0.1; - fissConfigGroup.sampledModes = Set.of(TransportMode.car); - fissConfigGroup.switchOffFISSLastIteration = true; - FISSConfigurator.configure(run); - - QSimComponentsConfigurator qSimComponentsConfigurator = FISSConfigurator - .activateModes(List.of(), MultiModeDrtConfigGroup.get(config).modes().collect(Collectors.toList())); - - run.configureQSimComponents(qSimComponentsConfigurator); - - run.addOverridingModule(new AbstractModule() { - @Override - public void install() { - addEventHandlerBinding().toInstance(linkCounter); - } - }); - - } - - run.run(); - Assert.assertEquals(23817, linkCounter.getLinkLeaveCount()); - } - - static class LinkCounter implements LinkLeaveEventHandler { - private int counts = 0; - - @Override - public void handleEvent(LinkLeaveEvent event) { - this.counts++; - } - - public int getLinkLeaveCount() { - return this.counts; - } - } - -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java deleted file mode 100644 index 1f57b4d54c7..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/eshifts/run/RunEShiftDrtScenarioIT.java +++ /dev/null @@ -1,176 +0,0 @@ -package org.matsim.contrib.drt.extension.operations.eshifts.run; - -import org.junit.Test; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams; -import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; -import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; -import org.matsim.contrib.drt.extension.operations.EDrtOperationsControlerCreator; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; -import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; -import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; -import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; -import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.dvrp.run.DvrpConfigGroup; -import org.matsim.contrib.ev.EvConfigGroup; -import org.matsim.contrib.ev.charging.*; -import org.matsim.contrib.ev.temperature.TemperatureService; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigGroup; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup; -import org.matsim.core.config.groups.StrategyConfigGroup; -import org.matsim.core.controler.AbstractModule; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.examples.ExamplesUtils; - -import java.util.HashSet; -import java.util.Set; - -public class RunEShiftDrtScenarioIT { - - private static final double MAX_RELATIVE_SOC = 0.9;// charge up to 80% SOC - private static final double MIN_RELATIVE_SOC = 0.15;// send to chargers vehicles below 20% SOC - private static final double TEMPERATURE = 20;// oC - - @Test - public void test() { - - MultiModeDrtConfigGroup multiModeDrtConfigGroup = new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new); - - String fleetFile = "holzkirchenFleet.xml"; - String plansFile = "holzkirchenPlans.xml.gz"; - String networkFile = "holzkirchenNetwork.xml.gz"; - String opFacilitiesFile = "holzkirchenOperationFacilities.xml"; - String shiftsFile = "holzkirchenShifts.xml"; - String chargersFile = "holzkirchenChargers.xml"; - String evsFile = "holzkirchenElectricFleet.xml"; - - DrtWithOperationsConfigGroup drtWithShiftsConfigGroup = (DrtWithOperationsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); - - DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; - drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.maxTravelTimeAlpha = 1.5; - drtConfigGroup.maxTravelTimeBeta = 10. * 60.; - drtConfigGroup.stopDuration = 30.; - drtConfigGroup.maxWaitTime = 600.; - drtConfigGroup.rejectRequestIfMaxWaitOrTravelTimeViolated = true; - drtConfigGroup.useModeFilteredSubnetwork = false; - drtConfigGroup.vehiclesFile = fleetFile; - drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtConfigGroup.plotDetailedCustomerStats = true; - drtConfigGroup.maxWalkDistance = 1000.; - drtConfigGroup.idleVehiclesReturnToDepots = false; - - drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); - - ConfigGroup rebalancing = drtConfigGroup.createParameterSet("rebalancing"); - drtConfigGroup.addParameterSet(rebalancing); - ((RebalancingParams) rebalancing).interval = 600; - - MinCostFlowRebalancingStrategyParams strategyParams = new MinCostFlowRebalancingStrategyParams(); - strategyParams.targetAlpha = 0.3; - strategyParams.targetBeta = 0.3; - - drtConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams); - - DrtZonalSystemParams drtZonalSystemParams = new DrtZonalSystemParams(); - drtZonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.GridFromNetwork; - drtZonalSystemParams.cellSize = 500.; - drtZonalSystemParams.targetLinkSelection = DrtZonalSystemParams.TargetLinkSelection.mostCentral; - drtConfigGroup.addParameterSet(drtZonalSystemParams); - - multiModeDrtConfigGroup.addParameterSet(drtWithShiftsConfigGroup); - - final Config config = ConfigUtils.createConfig(multiModeDrtConfigGroup, - new DvrpConfigGroup()); - config.setContext(ExamplesUtils.getTestScenarioURL("holzkirchen")); - - Set modes = new HashSet<>(); - modes.add("drt"); - config.travelTimeCalculator().setAnalyzedModes(modes); - - PlanCalcScoreConfigGroup.ModeParams scoreParams = new PlanCalcScoreConfigGroup.ModeParams("drt"); - config.planCalcScore().addModeParams(scoreParams); - PlanCalcScoreConfigGroup.ModeParams scoreParams2 = new PlanCalcScoreConfigGroup.ModeParams("walk"); - config.planCalcScore().addModeParams(scoreParams2); - - config.plans().setInputFile(plansFile); - config.network().setInputFile(networkFile); - - config.qsim().setSimStarttimeInterpretation(QSimConfigGroup.StarttimeInterpretation.onlyUseStarttime); - config.qsim().setSimEndtimeInterpretation(QSimConfigGroup.EndtimeInterpretation.minOfEndtimeAndMobsimFinished); - - - final PlanCalcScoreConfigGroup.ActivityParams home = new PlanCalcScoreConfigGroup.ActivityParams("home"); - home.setTypicalDuration(8 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams other = new PlanCalcScoreConfigGroup.ActivityParams("other"); - other.setTypicalDuration(4 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams education = new PlanCalcScoreConfigGroup.ActivityParams("education"); - education.setTypicalDuration(6 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams shopping = new PlanCalcScoreConfigGroup.ActivityParams("shopping"); - shopping.setTypicalDuration(2 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams work = new PlanCalcScoreConfigGroup.ActivityParams("work"); - work.setTypicalDuration(2 * 3600); - - config.planCalcScore().addActivityParams(home); - config.planCalcScore().addActivityParams(other); - config.planCalcScore().addActivityParams(education); - config.planCalcScore().addActivityParams(shopping); - config.planCalcScore().addActivityParams(work); - - final StrategyConfigGroup.StrategySettings stratSets = new StrategyConfigGroup.StrategySettings(); - stratSets.setWeight(1); - stratSets.setStrategyName("ChangeExpBeta"); - config.strategy().addStrategySettings(stratSets); - - config.controler().setLastIteration(1); - config.controler().setWriteEventsInterval(1); - - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); - config.controler().setOutputDirectory("test/output/holzkirchen_eshifts"); - - DrtOperationsParams operationsParams = (DrtOperationsParams) drtWithShiftsConfigGroup.createParameterSet(DrtOperationsParams.SET_NAME); - ShiftsParams shiftsParams = (ShiftsParams) operationsParams.createParameterSet(ShiftsParams.SET_NAME); - OperationFacilitiesParams operationFacilitiesParams = (OperationFacilitiesParams) operationsParams.createParameterSet(OperationFacilitiesParams.SET_NAME); - operationsParams.addParameterSet(shiftsParams); - operationsParams.addParameterSet(operationFacilitiesParams); - - operationFacilitiesParams.operationFacilityInputFile = opFacilitiesFile; - shiftsParams.shiftInputFile = shiftsFile; - shiftsParams.allowInFieldChangeover = true; - - //e shifts - shiftsParams.shiftAssignmentBatteryThreshold= 0.6; - shiftsParams.chargeAtHubThreshold = 0.8; - shiftsParams.outOfShiftChargerType = "slow"; - shiftsParams.breakChargerType = "fast"; - - drtWithShiftsConfigGroup.addParameterSet(operationsParams); - - final EvConfigGroup evConfigGroup = new EvConfigGroup(); - evConfigGroup.chargersFile = chargersFile; - evConfigGroup.minimumChargeTime = 0; - evConfigGroup.timeProfiles = true; - config.addModule(evConfigGroup); - - config.vehicles().setVehiclesFile(evsFile); - - final Controler controler = EDrtOperationsControlerCreator.createControler(config, false); - - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - bind(ChargingLogic.Factory.class).toProvider(new ChargingWithQueueingAndAssignmentLogic.FactoryProvider( - charger -> new ChargeUpToMaxSocStrategy(charger, MAX_RELATIVE_SOC))); - bind(ChargingPower.Factory.class).toInstance(FastThenSlowCharging::new); - bind(TemperatureService.class).toInstance(linkId -> TEMPERATURE); - } - }); - controler.run(); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/operationFacilities/OperationFacilitiesIOTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/operationFacilities/OperationFacilitiesIOTest.java deleted file mode 100644 index d1e2e231a43..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/operationFacilities/OperationFacilitiesIOTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.matsim.contrib.drt.extension.operations.operationFacilities; - -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.drt.extension.operations.shifts.io.OperationFacilitiesReader; -import org.matsim.contrib.drt.extension.operations.shifts.io.OperationFacilitiesWriter; -import org.matsim.contrib.ev.infrastructure.Charger; -import org.matsim.testcases.MatsimTestUtils; - -public class OperationFacilitiesIOTest { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - @Test - public void test() { - - OperationFacilitiesSpecification operationFacilities = new OperationFacilitiesSpecificationImpl(); - - for (int i = 0; i < 10; i++) { - operationFacilities.addOperationFacilitySpecification(OperationFacilitySpecificationImpl.newBuilder()// - .id(Id.create(i, OperationFacility.class)) // - .linkId(Id.createLinkId(i)) // - .coord(new Coord(i,i)) // - .capacity(i) // - .addChargerId(Id.create(i, Charger.class)) // - .addChargerId(Id.create(i+"_2", Charger.class)) // - .type(OperationFacilityType.hub) // - .build()); - } - - for (int i = 10; i < 20; i++) { - operationFacilities.addOperationFacilitySpecification(OperationFacilitySpecificationImpl.newBuilder()// - .id(Id.create(i, OperationFacility.class)) // - .linkId(Id.createLinkId(i)) // - .coord(new Coord(i,i)) // - .capacity(i) // - .addChargerId(Id.create(i, Charger.class)) // - .type(OperationFacilityType.inField) // - .build()); - } - - - new OperationFacilitiesWriter(operationFacilities).writeFile(utils.getOutputDirectory() + "facilities.xml"); - - OperationFacilitiesSpecification copy = new OperationFacilitiesSpecificationImpl(); - new OperationFacilitiesReader(copy).readFile(utils.getOutputDirectory() + "facilities.xml"); - - for (int i = 0; i < 10; i++) { - final Id id = Id.create(i, OperationFacility.class); - Id linkId = Id.createLinkId(i); - Coord coord = new Coord(i,i); - int capacity = i; - Id charger = Id.create(i, Charger.class); - Id charger2 = Id.create(i+"_2", Charger.class); - final OperationFacilitySpecification facility = copy.getOperationFacilitySpecifications().get(id); - Assert.assertEquals(linkId.toString(), facility.getLinkId().toString()); - Assert.assertEquals(coord.getX(), facility.getCoord().getX(), 0); - Assert.assertEquals(coord.getY(), facility.getCoord().getY(), 0); - Assert.assertEquals(capacity, facility.getCapacity()); - Assert.assertEquals(charger.toString(), facility.getChargers().get(0).toString()); - Assert.assertEquals(charger2.toString(), facility.getChargers().get(1).toString()); - } - - for (int i = 10; i < 20; i++) { - final Id id = Id.create(i, OperationFacility.class); - Id linkId = Id.createLinkId(i); - Coord coord = new Coord(i,i); - int capacity = i; - Id charger = Id.create(i, Charger.class); - final OperationFacilitySpecification facility = copy.getOperationFacilitySpecifications().get(id); - Assert.assertEquals(linkId.toString(), facility.getLinkId().toString()); - Assert.assertEquals(coord.getX(), facility.getCoord().getX(), 0); - Assert.assertEquals(coord.getY(), facility.getCoord().getY(), 0); - Assert.assertEquals(capacity, facility.getCapacity()); - Assert.assertEquals(charger.toString(), facility.getChargers().get(0).toString()); - } - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/ShiftsIOTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/ShiftsIOTest.java deleted file mode 100644 index 37a86a85098..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/ShiftsIOTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.matsim.contrib.drt.extension.operations.shifts; - -import static org.junit.Assert.*; - -import java.io.File; -import java.util.Optional; - -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacility; -import org.matsim.contrib.drt.extension.operations.shifts.io.DrtShiftsReader; -import org.matsim.contrib.drt.extension.operations.shifts.io.DrtShiftsWriter; -import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShift; -import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftSpecification; -import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftsSpecification; -import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftsSpecificationImpl; -import org.matsim.testcases.MatsimTestUtils; - -/** - * @author nkuehnel / MOIA - */ -public class ShiftsIOTest { - - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); - - - private static final String TESTSHIFTSINPUT = "testShifts.xml"; - private static final String TESTXMLOUTPUT = "testShiftsOut.xml"; - - private final Id sid11 = Id.create("11", DrtShift.class); - private final Id sid22 = Id.create("22", DrtShift.class); - private final Id sid33 = Id.create("33", DrtShift.class); - private final Id oid1 = Id.create("op1", OperationFacility.class); - private final Id oid2 = Id.create("op2", OperationFacility.class); - - - @Test public void testBasicReaderWriter() { - - DrtShiftsSpecification shiftsSpecification = new DrtShiftsSpecificationImpl(); - - DrtShiftsReader reader = new DrtShiftsReader(shiftsSpecification); - reader.readFile(utils.getPackageInputDirectory() + TESTSHIFTSINPUT); - checkContent(shiftsSpecification); - - DrtShiftsWriter writer = new DrtShiftsWriter(shiftsSpecification); - String outfilename = utils.getOutputDirectory() + TESTXMLOUTPUT; - writer.writeFile(outfilename); - - File outFile = new File(outfilename); - assertTrue(outFile.exists()); - - //read it again to check if the same is read as at the very first beginning of test - shiftsSpecification = new DrtShiftsSpecificationImpl(); - reader = new DrtShiftsReader(shiftsSpecification); - reader.readFile(outfilename); - checkContent(shiftsSpecification); - } - - private void checkContent(DrtShiftsSpecification shiftsSpecification) { - assertEquals(3, shiftsSpecification.getShiftSpecifications().size()); - - DrtShiftSpecification shiftSpecification1 = shiftsSpecification.getShiftSpecifications().get(sid11); - assertNotNull(shiftSpecification1); - assertEquals(sid11, shiftSpecification1.getId()); - assertEquals(14400., shiftSpecification1.getStartTime(), 0); - assertEquals(45000., shiftSpecification1.getEndTime(), 0); - assertTrue(shiftSpecification1.getOperationFacilityId().isPresent()); - assertEquals(oid1, shiftSpecification1.getOperationFacilityId().get()); - assertEquals(1800., shiftSpecification1.getBreak().orElseThrow().getDuration(), 0); - assertEquals(28800., shiftSpecification1.getBreak().orElseThrow().getEarliestBreakStartTime(), 0); - assertEquals(32400., shiftSpecification1.getBreak().orElseThrow().getLatestBreakEndTime(), 0); - - DrtShiftSpecification shiftSpecification2 = shiftsSpecification.getShiftSpecifications().get(sid22); - assertNotNull(shiftSpecification2); - assertEquals(sid22, shiftSpecification2.getId()); - assertEquals(18400., shiftSpecification2.getStartTime(), 0); - assertEquals(49000., shiftSpecification2.getEndTime(), 0); - assertTrue(shiftSpecification2.getOperationFacilityId().isPresent()); - assertEquals(oid2, shiftSpecification2.getOperationFacilityId().get()); - assertEquals(3600., shiftSpecification2.getBreak().orElseThrow().getDuration(), 0); - assertEquals(29200., shiftSpecification2.getBreak().orElseThrow().getEarliestBreakStartTime(), 0); - assertEquals(32800., shiftSpecification2.getBreak().orElseThrow().getLatestBreakEndTime(), 0); - - DrtShiftSpecification shiftSpecification3 = shiftsSpecification.getShiftSpecifications().get(sid33); - assertNotNull(shiftSpecification3); - assertEquals(sid33, shiftSpecification3.getId()); - assertEquals(22400., shiftSpecification3.getStartTime(), 0); - assertEquals(53000., shiftSpecification3.getEndTime(), 0); - assertFalse(shiftSpecification3.getOperationFacilityId().isPresent()); - assertEquals(Optional.empty(), shiftSpecification3.getOperationFacilityId()); - assertTrue(shiftSpecification3.getBreak().isEmpty()); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java deleted file mode 100644 index e40e1331388..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2022 MOIA GmbH - All Rights Reserved - * - * You may use, distribute and modify this code under the terms - * of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. - */ - -package org.matsim.contrib.drt.extension.operations.shifts.analysis.efficiency; - -import org.junit.Assert; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.events.PersonMoneyEvent; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.population.Person; -import org.matsim.contrib.drt.extension.operations.shifts.events.DrtShiftEndedEvent; -import org.matsim.contrib.drt.extension.operations.shifts.events.DrtShiftStartedEvent; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacility; -import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShift; -import org.matsim.contrib.drt.fare.DrtFareHandler; -import org.matsim.contrib.dvrp.fleet.DvrpVehicle; -import org.matsim.contrib.dvrp.optimizer.Request; -import org.matsim.contrib.dvrp.passenger.PassengerDroppedOffEvent; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.events.EventsManagerImpl; -import org.matsim.testcases.MatsimTestUtils; - -/** - * @author nkuehnel / MOIA - */ -public class ShiftEfficiencyTest { - - public static final double FARE = 10.; - - /** - * Test method for {@link ShiftEfficiencyTracker}. - */ - @Test - public void testDrtShiftEfficiency() { - - EventsManager events = new EventsManagerImpl(); - ShiftEfficiencyTracker shiftEfficiencyTracker = new ShiftEfficiencyTracker(); - events.addHandler(shiftEfficiencyTracker); - events.initProcessing(); - - Id shift1 = Id.create("shift1", DrtShift.class); - Id link1 = Id.createLinkId("link1"); - Id vehicle1 = Id.create("vehicle1", DvrpVehicle.class); - Id operationFacility1 = Id.create("operationFacility1", OperationFacility.class); - - events.processEvent(new DrtShiftStartedEvent(10 * 3600, shift1, vehicle1, link1) - ); - // should throw because vehicle is already registered with another shift - Assert.assertThrows(RuntimeException.class, () -> { - events.processEvent(new DrtShiftStartedEvent(10 * 3600, shift1, vehicle1, link1)); - }); - - Id request1 = Id.create("request1", Request.class); - Id person1 = Id.createPersonId("person1"); - - events.processEvent(new PassengerDroppedOffEvent(11 * 3600, "drt", - request1, person1, vehicle1)); - Assert.assertTrue(shiftEfficiencyTracker.getCurrentRecord().getRequestsByShift().get(shift1).contains(request1)); - - events.processEvent(new PersonMoneyEvent(11 * 3600, person1, -FARE, - DrtFareHandler.PERSON_MONEY_EVENT_PURPOSE_DRT_FARE, "drt", request1.toString())); - Assert.assertEquals(FARE, shiftEfficiencyTracker.getCurrentRecord().getRevenueByShift().get(shift1), MatsimTestUtils.EPSILON); - - Assert.assertFalse(shiftEfficiencyTracker.getCurrentRecord().getFinishedShifts().containsKey(shift1)); - events.processEvent(new DrtShiftEndedEvent(20 * 3600, shift1, vehicle1, link1, operationFacility1)); - Assert.assertTrue(shiftEfficiencyTracker.getCurrentRecord().getFinishedShifts().containsKey(shift1)); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java deleted file mode 100644 index 8b0e6b3a179..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunMultiHubShiftDrtScenarioIT.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.matsim.contrib.drt.extension.operations.shifts.run; - -import org.junit.Test; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams; -import org.matsim.contrib.drt.extension.operations.DrtOperationsControlerCreator; -import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; -import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; -import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; -import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; -import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; -import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.dvrp.run.DvrpConfigGroup; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigGroup; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup; -import org.matsim.core.config.groups.StrategyConfigGroup; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.examples.ExamplesUtils; - -import java.util.HashSet; -import java.util.Set; - -public class RunMultiHubShiftDrtScenarioIT { - @Test - public void test() { - - MultiModeDrtConfigGroup multiModeDrtConfigGroup = new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new); - - String fleetFile = "holzkirchenMultiHubFleet.xml"; - String plansFile = "holzkirchenPlans.xml.gz"; - String networkFile = "holzkirchenNetwork.xml.gz"; - String opFacilitiesFile = "holzkirchenMultiHubOperationFacilities.xml"; - String shiftsFile = "holzkirchenMultiHubShifts.xml"; - - DrtWithOperationsConfigGroup drtWithShiftsConfigGroup = (DrtWithOperationsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); - - DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; - drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.maxTravelTimeAlpha = 1.5; - drtConfigGroup.maxTravelTimeBeta = 10. * 60.; - drtConfigGroup.stopDuration = 30.; - drtConfigGroup.maxWaitTime = 600.; - drtConfigGroup.rejectRequestIfMaxWaitOrTravelTimeViolated = true; - drtConfigGroup.useModeFilteredSubnetwork = false; - drtConfigGroup.vehiclesFile = fleetFile; - drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtConfigGroup.plotDetailedCustomerStats = true; - drtConfigGroup.maxWalkDistance = 1000.; - drtConfigGroup.idleVehiclesReturnToDepots = false; - - drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); - - ConfigGroup rebalancing = drtConfigGroup.createParameterSet("rebalancing"); - drtConfigGroup.addParameterSet(rebalancing); - ((RebalancingParams) rebalancing).interval = 600; - - MinCostFlowRebalancingStrategyParams strategyParams = new MinCostFlowRebalancingStrategyParams(); - strategyParams.targetAlpha = 0.3; - strategyParams.targetBeta = 0.3; - - drtConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams); - - DrtZonalSystemParams drtZonalSystemParams = new DrtZonalSystemParams(); - drtZonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.GridFromNetwork; - drtZonalSystemParams.cellSize = 500.; - drtZonalSystemParams.targetLinkSelection = DrtZonalSystemParams.TargetLinkSelection.mostCentral; - drtConfigGroup.addParameterSet(drtZonalSystemParams); - - multiModeDrtConfigGroup.addParameterSet(drtWithShiftsConfigGroup); - - final Config config = ConfigUtils.createConfig(multiModeDrtConfigGroup, - new DvrpConfigGroup()); - config.setContext(ExamplesUtils.getTestScenarioURL("holzkirchen")); - - Set modes = new HashSet<>(); - modes.add("drt"); - config.travelTimeCalculator().setAnalyzedModes(modes); - - PlanCalcScoreConfigGroup.ModeParams scoreParams = new PlanCalcScoreConfigGroup.ModeParams("drt"); - config.planCalcScore().addModeParams(scoreParams); - PlanCalcScoreConfigGroup.ModeParams scoreParams2 = new PlanCalcScoreConfigGroup.ModeParams("walk"); - config.planCalcScore().addModeParams(scoreParams2); - - config.plans().setInputFile(plansFile); - config.network().setInputFile(networkFile); - - config.qsim().setSimStarttimeInterpretation(QSimConfigGroup.StarttimeInterpretation.onlyUseStarttime); - config.qsim().setSimEndtimeInterpretation(QSimConfigGroup.EndtimeInterpretation.minOfEndtimeAndMobsimFinished); - - - final PlanCalcScoreConfigGroup.ActivityParams home = new PlanCalcScoreConfigGroup.ActivityParams("home"); - home.setTypicalDuration(8 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams other = new PlanCalcScoreConfigGroup.ActivityParams("other"); - other.setTypicalDuration(4 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams education = new PlanCalcScoreConfigGroup.ActivityParams("education"); - education.setTypicalDuration(6 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams shopping = new PlanCalcScoreConfigGroup.ActivityParams("shopping"); - shopping.setTypicalDuration(2 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams work = new PlanCalcScoreConfigGroup.ActivityParams("work"); - work.setTypicalDuration(2 * 3600); - - config.planCalcScore().addActivityParams(home); - config.planCalcScore().addActivityParams(other); - config.planCalcScore().addActivityParams(education); - config.planCalcScore().addActivityParams(shopping); - config.planCalcScore().addActivityParams(work); - - final StrategyConfigGroup.StrategySettings stratSets = new StrategyConfigGroup.StrategySettings(); - stratSets.setWeight(1); - stratSets.setStrategyName("ChangeExpBeta"); - config.strategy().addStrategySettings(stratSets); - - config.controler().setLastIteration(1); - config.controler().setWriteEventsInterval(1); - - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); - config.controler().setOutputDirectory("test/output/holzkirchen_shifts_multiHub"); - - DrtOperationsParams operationsParams = (DrtOperationsParams) drtWithShiftsConfigGroup.createParameterSet(DrtOperationsParams.SET_NAME); - ShiftsParams shiftsParams = (ShiftsParams) operationsParams.createParameterSet(ShiftsParams.SET_NAME); - OperationFacilitiesParams operationFacilitiesParams = (OperationFacilitiesParams) operationsParams.createParameterSet(OperationFacilitiesParams.SET_NAME); - operationsParams.addParameterSet(shiftsParams); - operationsParams.addParameterSet(operationFacilitiesParams); - drtWithShiftsConfigGroup.addParameterSet(operationsParams); - - operationFacilitiesParams.operationFacilityInputFile = opFacilitiesFile; - shiftsParams.shiftInputFile = shiftsFile; - shiftsParams.allowInFieldChangeover = true; - - final Controler run = DrtOperationsControlerCreator.createControler(config, false); - run.run(); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java deleted file mode 100644 index 3205bae0a4f..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/run/RunShiftDrtScenarioIT.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.matsim.contrib.drt.extension.operations.shifts.run; - -import org.junit.Test; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams; -import org.matsim.contrib.drt.extension.operations.DrtOperationsControlerCreator; -import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; -import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; -import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; -import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams; -import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; -import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams; -import org.matsim.contrib.drt.optimizer.rebalancing.mincostflow.MinCostFlowRebalancingStrategyParams; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.dvrp.run.DvrpConfigGroup; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigGroup; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup; -import org.matsim.core.config.groups.StrategyConfigGroup; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.examples.ExamplesUtils; - -import java.util.HashSet; -import java.util.Set; - -public class RunShiftDrtScenarioIT { - - @Test - public void test() { - - MultiModeDrtConfigGroup multiModeDrtConfigGroup = new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new); - - String fleetFile = "holzkirchenFleet.xml"; - String plansFile = "holzkirchenPlans.xml.gz"; - String networkFile = "holzkirchenNetwork.xml.gz"; - String opFacilitiesFile = "holzkirchenOperationFacilities.xml"; - String shiftsFile = "holzkirchenShifts.xml"; - - DrtWithOperationsConfigGroup drtWithShiftsConfigGroup = (DrtWithOperationsConfigGroup) multiModeDrtConfigGroup.createParameterSet("drt"); - - DrtConfigGroup drtConfigGroup = drtWithShiftsConfigGroup; - drtConfigGroup.mode = TransportMode.drt; - drtConfigGroup.maxTravelTimeAlpha = 1.5; - drtConfigGroup.maxTravelTimeBeta = 10. * 60.; - drtConfigGroup.stopDuration = 30.; - drtConfigGroup.maxWaitTime = 600.; - drtConfigGroup.rejectRequestIfMaxWaitOrTravelTimeViolated = true; - drtConfigGroup.useModeFilteredSubnetwork = false; - drtConfigGroup.vehiclesFile = fleetFile; - drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; - drtConfigGroup.plotDetailedCustomerStats = true; - drtConfigGroup.maxWalkDistance = 1000.; - drtConfigGroup.idleVehiclesReturnToDepots = false; - - drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams()); - - ConfigGroup rebalancing = drtConfigGroup.createParameterSet("rebalancing"); - drtConfigGroup.addParameterSet(rebalancing); - ((RebalancingParams) rebalancing).interval = 600; - - MinCostFlowRebalancingStrategyParams strategyParams = new MinCostFlowRebalancingStrategyParams(); - strategyParams.targetAlpha = 0.3; - strategyParams.targetBeta = 0.3; - - drtConfigGroup.getRebalancingParams().get().addParameterSet(strategyParams); - - DrtZonalSystemParams drtZonalSystemParams = new DrtZonalSystemParams(); - drtZonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.GridFromNetwork; - drtZonalSystemParams.cellSize = 500.; - drtZonalSystemParams.targetLinkSelection = DrtZonalSystemParams.TargetLinkSelection.mostCentral; - drtConfigGroup.addParameterSet(drtZonalSystemParams); - - multiModeDrtConfigGroup.addParameterSet(drtWithShiftsConfigGroup); - - final Config config = ConfigUtils.createConfig(multiModeDrtConfigGroup, - new DvrpConfigGroup()); - config.setContext(ExamplesUtils.getTestScenarioURL("holzkirchen")); - - Set modes = new HashSet<>(); - modes.add("drt"); - config.travelTimeCalculator().setAnalyzedModes(modes); - - PlanCalcScoreConfigGroup.ModeParams scoreParams = new PlanCalcScoreConfigGroup.ModeParams("drt"); - config.planCalcScore().addModeParams(scoreParams); - PlanCalcScoreConfigGroup.ModeParams scoreParams2 = new PlanCalcScoreConfigGroup.ModeParams("walk"); - config.planCalcScore().addModeParams(scoreParams2); - - config.plans().setInputFile(plansFile); - config.network().setInputFile(networkFile); - - config.qsim().setSimStarttimeInterpretation(QSimConfigGroup.StarttimeInterpretation.onlyUseStarttime); - config.qsim().setSimEndtimeInterpretation(QSimConfigGroup.EndtimeInterpretation.minOfEndtimeAndMobsimFinished); - - final PlanCalcScoreConfigGroup.ActivityParams home = new PlanCalcScoreConfigGroup.ActivityParams("home"); - home.setTypicalDuration(8 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams other = new PlanCalcScoreConfigGroup.ActivityParams("other"); - other.setTypicalDuration(4 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams education = new PlanCalcScoreConfigGroup.ActivityParams("education"); - education.setTypicalDuration(6 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams shopping = new PlanCalcScoreConfigGroup.ActivityParams("shopping"); - shopping.setTypicalDuration(2 * 3600); - final PlanCalcScoreConfigGroup.ActivityParams work = new PlanCalcScoreConfigGroup.ActivityParams("work"); - work.setTypicalDuration(2 * 3600); - - config.planCalcScore().addActivityParams(home); - config.planCalcScore().addActivityParams(other); - config.planCalcScore().addActivityParams(education); - config.planCalcScore().addActivityParams(shopping); - config.planCalcScore().addActivityParams(work); - - final StrategyConfigGroup.StrategySettings stratSets = new StrategyConfigGroup.StrategySettings(); - stratSets.setWeight(1); - stratSets.setStrategyName("ChangeExpBeta"); - config.strategy().addStrategySettings(stratSets); - - config.controler().setLastIteration(1); - config.controler().setWriteEventsInterval(1); - - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); - config.controler().setOutputDirectory("test/output/holzkirchen_shifts"); - - DrtOperationsParams operationsParams = (DrtOperationsParams) drtWithShiftsConfigGroup.createParameterSet(DrtOperationsParams.SET_NAME); - ShiftsParams shiftsParams = (ShiftsParams) operationsParams.createParameterSet(ShiftsParams.SET_NAME); - OperationFacilitiesParams operationFacilitiesParams = (OperationFacilitiesParams) operationsParams.createParameterSet(OperationFacilitiesParams.SET_NAME); - operationsParams.addParameterSet(shiftsParams); - operationsParams.addParameterSet(operationFacilitiesParams); - - operationFacilitiesParams.operationFacilityInputFile = opFacilitiesFile; - shiftsParams.shiftInputFile = shiftsFile; - shiftsParams.allowInFieldChangeover = true; - drtWithShiftsConfigGroup.addParameterSet(operationsParams); - - final Controler run = DrtOperationsControlerCreator.createControler(config, false); - run.run(); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java index 8e9fc8e8100..27b75e2cc28 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingExampleIT.java @@ -2,22 +2,18 @@ import static org.junit.Assert.assertEquals; +import java.io.File; import java.net.URL; import org.junit.Rule; import org.junit.Test; import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.IdMap; import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup; import org.matsim.contrib.drt.extension.edrt.optimizer.EDrtVehicleDataEntryFactory.EDrtVehicleDataEntryFactoryProvider; import org.matsim.contrib.drt.extension.edrt.run.EDrtControlerCreator; import org.matsim.contrib.drt.extension.prebooking.logic.FixedSharePrebookingLogic; -import org.matsim.contrib.drt.passenger.events.DrtRequestSubmittedEvent; -import org.matsim.contrib.drt.passenger.events.DrtRequestSubmittedEventHandler; 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.optimizer.Request; import org.matsim.contrib.dvrp.passenger.PassengerRequestRejectedEvent; import org.matsim.contrib.dvrp.passenger.PassengerRequestRejectedEventHandler; import org.matsim.contrib.dvrp.passenger.PassengerRequestScheduledEvent; @@ -45,40 +41,6 @@ public class PrebookingExampleIT { @Rule public MatsimTestUtils utils = new MatsimTestUtils(); - @Test - public void testDrtWithPrebooking() { - Id.resetCaches(); - - URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); - Config config = ConfigUtils.loadConfig(configUrl, - new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new), new DvrpConfigGroup(), - new OTFVisConfigGroup()); - - for (var drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { - DrtWithExtensionsConfigGroup extensionsConfig = (DrtWithExtensionsConfigGroup) drtCfg; - DrtPrebookingParams prebookingParams = new DrtPrebookingParams(); - extensionsConfig.advanceRequestPlanningHorizon = Double.POSITIVE_INFINITY; - extensionsConfig.addParameterSet(prebookingParams); - } - - config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); - config.controler().setOutputDirectory(utils.getOutputDirectory()); - - Controler controller = DrtControlerCreator.createControler(config, false); - controller.addOverridingModule(new PrebookingModule()); - FixedSharePrebookingLogic.install("drt", 0.5, 4.0 * 3600.0, controller); - - Tracker tracker = new Tracker(); - tracker.install(controller); - - controller.run(); - - assertEquals(157, tracker.immediateScheduled); - assertEquals(205, tracker.prebookedScheduled); - assertEquals(26, tracker.immediateRejected); - assertEquals(0, tracker.prebookedRejected); - } - @Test public void testElectricDrtWithPrebooking() { Id.resetCaches(); @@ -126,6 +88,8 @@ public void install() { tracker.install(controler); controler.run(); + + System.err.println("PATH PATH PATH " + utils.getOutputDirectory()); assertEquals(74, tracker.immediateScheduled); assertEquals(178, tracker.prebookedScheduled); diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java deleted file mode 100644 index 21334a48049..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/prebooking/PrebookingTest.java +++ /dev/null @@ -1,485 +0,0 @@ -package org.matsim.contrib.drt.extension.prebooking; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup; -import org.matsim.contrib.drt.extension.prebooking.PrebookingTestEnvironment.RequestInfo; -import org.matsim.contrib.drt.extension.prebooking.logic.AttributePrebookingLogic; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.core.controler.Controler; - -/** - * @author Sebastian Hörl (sebhoerl) / IRT SystemX - */ -public class PrebookingTest { - @Test - public void withoutPrebookedRequests() { - /*- - * Standard test running with prebooking but without any prebooked requests - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("personA", 0, 0, 5, 5, 2000.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - controller.addOverridingModule(new PrebookingModule()); - controller.run(); - - RequestInfo requestInfo = environment.getRequestInfo().get("personA"); - assertEquals(2000.0, requestInfo.submissionTime, 1e-3); - assertEquals(2146.0, requestInfo.pickupTime, 1e-3); - assertEquals(2357.0, requestInfo.dropoffTime, 1e-3); - - var taskInfo = environment.getTaskInfo().get("vehicleA"); - assertEquals("STAY", taskInfo.get(0).type); - assertEquals("DRIVE", taskInfo.get(1).type); - assertEquals("STOP", taskInfo.get(2).type); - assertEquals("DRIVE", taskInfo.get(3).type); - assertEquals("STOP", taskInfo.get(4).type); - - assertEquals(2001.0, taskInfo.get(1).startTime, 1e-3); - - assertEquals(2086.0, taskInfo.get(2).startTime, 1e-3); - assertEquals(2146.0, taskInfo.get(2).endTime, 1e-3); - } - - private void installPrebooking(Controler controller) { - DrtWithExtensionsConfigGroup drtConfig = (DrtWithExtensionsConfigGroup) MultiModeDrtConfigGroup - .get(controller.getConfig()).getModalElements().stream().findFirst().get(); - DrtPrebookingParams prebookingParams = new DrtPrebookingParams(); - drtConfig.advanceRequestPlanningHorizon = Double.POSITIVE_INFINITY; - drtConfig.addParameterSet(prebookingParams); - controller.addOverridingModule(new PrebookingModule()); - AttributePrebookingLogic.install("drt", controller); - } - - @Test - public void oneRequestArrivingLate() { - /*- - * One request arriving after the requested departure time. Vehicle should wait - * and depart with appropriate delay (taking into account a fixed duration for - * the person to enter instead of a fixed stop duration). - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - // 1800 indicated but only departing 2000 - .addRequest("personA", 0, 0, 5, 5, 2000.0, 0.0, 2000.0 - 200.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - RequestInfo requestInfo = environment.getRequestInfo().get("personA"); - assertEquals(0.0, requestInfo.submissionTime, 1e-3); - assertEquals(2060.0, requestInfo.pickupTime, 1e-3); - assertEquals(2271.0, requestInfo.dropoffTime, 1e-3); - - var taskInfo = environment.getTaskInfo().get("vehicleA"); - assertEquals("STAY", taskInfo.get(0).type); - assertEquals("DRIVE", taskInfo.get(1).type); - assertEquals("WAIT", taskInfo.get(2).type); - assertEquals("STOP", taskInfo.get(3).type); - assertEquals("DRIVE", taskInfo.get(4).type); - assertEquals("STOP", taskInfo.get(5).type); - - assertEquals(1.0, taskInfo.get(1).startTime, 1e-3); // Pickup drive - assertEquals(86.0, taskInfo.get(2).startTime, 1e-3); // Starting to wait - assertEquals(1800.0, taskInfo.get(3).startTime, 1e-3); // Starting stop - assertEquals(2060.0, taskInfo.get(3).endTime, 1e-3); // Ending stop (260s duration) - assertEquals(2060.0, taskInfo.get(4).startTime, 1e-3); // Starting drive (ending stop) - } - - @Test - public void oneRequestArrivingEarly() { - /*- - * One request arriving in advance before the requested departure time. Vehicle - * will pickup up agent and then depart after the duration to enter the vehicle. - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - // 2200 indicated but already departing 2000 - .addRequest("personA", 0, 0, 5, 5, 2000.0, 0.0, 2000.0 + 200.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - RequestInfo requestInfo = environment.getRequestInfo().get("personA"); - assertEquals(0.0, requestInfo.submissionTime, 1e-3); - assertEquals(2260.0 + 1.0, requestInfo.pickupTime, 1e-3); // One second for notifying vehicle - assertEquals(2472.0, requestInfo.dropoffTime, 1e-3); - - var taskInfo = environment.getTaskInfo().get("vehicleA"); - assertEquals("STAY", taskInfo.get(0).type); - assertEquals("DRIVE", taskInfo.get(1).type); - assertEquals("WAIT", taskInfo.get(2).type); - assertEquals("STOP", taskInfo.get(3).type); - assertEquals("DRIVE", taskInfo.get(4).type); - assertEquals("STOP", taskInfo.get(5).type); - - assertEquals(1.0, taskInfo.get(1).startTime, 1e-3); // Pickup drive - assertEquals(86.0, taskInfo.get(2).startTime, 1e-3); // Starting to wait - assertEquals(2200.0, taskInfo.get(3).startTime, 1e-3); // Starting stop - assertEquals(2261.0, taskInfo.get(3).endTime, 1e-3); // Ending stop (60s) - assertEquals(2261.0, taskInfo.get(4).startTime, 1e-3); // Starting drive (ending stop) - } - - @Test - public void twoSequentialRequests() { - /*- - * Two requests that are scheduled in advance. - * - First the early one is submitted, then the late one - * - First the early one is picked up and dropped off, then the late one. - */ - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("earlyRequest", 0, 0, 5, 5, 2000.0, 0.0) // - .addRequest("lateRequest", 2, 2, 3, 3, 4000.0, 1000.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("earlyRequest"); - assertEquals(0.0, requestInfo.submissionTime, 1e-3); - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2272.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("lateRequest"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - assertEquals(4000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(4104.0, requestInfo.dropoffTime, 1e-3); - } - } - - @Test - public void twoSequentialRequests_inverseSubmission() { - /*- - * Two requests that are scheduled in advance. - * - First the late one is submitted, then the early one (inverse of above test). - * - First the early one is picked up and dropped off, then the late one. - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("earlyRequest", 0, 0, 5, 5, 2000.0, 1000.0) // - .addRequest("lateRequest", 2, 2, 3, 3, 4000.0, 0.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("earlyRequest"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2272.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("lateRequest"); - assertEquals(0.0, requestInfo.submissionTime, 1e-3); - assertEquals(4000.0 + 60.0, requestInfo.pickupTime, 1e-3); - assertEquals(4103.0, requestInfo.dropoffTime, 1e-3); - } - } - - @Test - public void sameTrip_differentDepartureTime() { - /*- - * Two requests with the same origin and destination, but distinct departure time. - * - First, early one is submitted, then late one. - * - Vehicle picks up and drops off early one, then late one. - * - In total four stops (P,D,P,D) - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("earlyRequest", 1, 1, 5, 5, 2000.0, 1000.0) // - .addRequest("lateRequest", 1, 1, 5, 5, 4000.0, 1100.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("earlyRequest"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2230.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("lateRequest"); - assertEquals(1100.0, requestInfo.submissionTime, 1e-3); - assertEquals(4000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(4230.0, requestInfo.dropoffTime, 1e-3); - } - - // Four stops, 2x pickup, 2x dropoff - assertEquals(4, environment.getTaskInfo().get("vehicleA").stream().filter(t -> t.type.equals("STOP")).count()); - } - - @Test - public void sameTrip_sameDepartureTime() { - /*- - * Two requests with the same origin and destination, and same departure time. - * - First, A is submitted, then B. - * - Vehicle picks up and A and B, then drops off A and B. - * - In total two stops (P,D) - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("requestA", 1, 1, 5, 5, 2000.0, 1000.0) // - .addRequest("requestB", 1, 1, 5, 5, 2000.0, 1100.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestA"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2230.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestB"); - assertEquals(1100.0, requestInfo.submissionTime, 1e-3); - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2230.0, requestInfo.dropoffTime, 1e-3); - } - - // Two stops, 1x pickup, 1x dropoff - assertEquals(2, environment.getTaskInfo().get("vehicleA").stream().filter(t -> t.type.equals("STOP")).count()); - } - - @Test - public void sameTrip_extendPickupDuration() { - /*- - * Two requests with the same origin and destination, different departure times. - * - First, A is submitted with departure time 2000 - * - Then, B is submitted with departure time 2020 - * - Scheduling A then B would give a total duration of 60 + 60 = 120s stop duration - * - Scheduling A then merging in B gives a total duration of 60 + 20 = 80s stop duration - * - Expected behavior is to merge the requests - * - In total two stops (P,D) - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("requestA", 1, 1, 5, 5, 2000.0, 1000.0) // - .addRequest("requestB", 1, 1, 5, 5, 2020.0, 1100.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestA"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - // We always add 1s for first pickup - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - // We have additional 19s because stop task is extended! - assertEquals(2230.0 + 19.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestB"); - assertEquals(1100.0, requestInfo.submissionTime, 1e-3); - // Second pickup does not have one second offset - assertEquals(2020.0 + 60.0 + 0.0, requestInfo.pickupTime, 1e-3); - assertEquals(2230.0 + 19.0, requestInfo.dropoffTime, 1e-3); - } - - // Two stops, 1x pickup, 1x dropoff - assertEquals(2, environment.getTaskInfo().get("vehicleA").stream().filter(t -> t.type.equals("STOP")).count()); - } - - @Test - public void sameTrip_splitPickup() { - /*- - * Two requests with the same origin and destination, different departure times. - * - First, A is submitted with departure time 2000 - * - Then, B is submitted with departure time 2080 - * - Stop for A goes from 2000 to 2060 - * - Stop for B goes from 2080 to 20140 - * - The requests don't overlap, so we schedule individual stops (in a more extreme use case we could schedule things in between then) - * - In total three stops (P, P, D) - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("requestA", 1, 1, 5, 5, 2000.0, 1000.0) // - .addRequest("requestB", 1, 1, 5, 5, 2080.0, 1100.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestA"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - // Pickup as planned - assertEquals(2000.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - - // Dropoff a bit later than before because we pickup another one on the way - assertEquals(2310.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestB"); - assertEquals(1100.0, requestInfo.submissionTime, 1e-3); - // We insert a later pickup - assertEquals(2080.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - - // Dropoff as planned - assertEquals(2310.0, requestInfo.dropoffTime, 1e-3); - } - - // Three stops, 2x pickup, 1x dropoff - assertEquals(3, environment.getTaskInfo().get("vehicleA").stream().filter(t -> t.type.equals("STOP")).count()); - } - - @Test - public void sameTrip_inverseSubmission_noPrepending() { - /*- - * Two requests with the same origin and destination, different departure times. - * - First, A is submitted with departure time 2020 - * - Then, B is submitted with departure time 2000 - * - * - This is inverse of sameTrip_extendPickupDuration above, the request with the earlier departure - * time is submitted second. - * - We would expect the requests to be merged, but this is not so trivial with the current code base: - * It would be necessary to shift the stop task to the past and extend it. Theoretically, this is - * possible but it would be nice to embed this in a more robust way in the code base. - * - Plus, it may change the current DRT behavior because we have these situations also in non-prebooked - * simulations: We may submit an immediate request and find an insertion for a stop task that starts - * in 5 seconds. This case is treated in standard DRT as any other request (extending the task but - * keeping the start time fixed). - * - We follow this default behaviour here: Instead of *prepending* the task with the new request, we - * *append* it as usual. If there is at least one pickup in the stop task with the standard stop - * durations, there is no additional cost of adding the request, but the person experiences a wait - * delay that could be minimized if we were able to prepend the task. - * - (Then again, do we actually want to do this, it would reserve the vehicle a few seconds more than - * necessary for a stop that is potentially prebooked in a long time). - * - * - Expected behavior in current implementation: Merge new request with the later departing existing - * one, which generates wait time for the customer. - * - * - In total two stops (P, D) - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("requestA", 1, 1, 5, 5, 2020.0, 1000.0) // - .addRequest("requestB", 1, 1, 5, 5, 2000.0, 1100.0) // - .configure(600.0, 1.3, 600.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestA"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - assertEquals(2020.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2250.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestB"); - assertEquals(1100.0, requestInfo.submissionTime, 1e-3); - assertEquals(2000.0 + 20.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2250.0, requestInfo.dropoffTime, 1e-3); - } - - // Three stops, 1x pickup, 1x dropoff - assertEquals(2, environment.getTaskInfo().get("vehicleA").stream().filter(t -> t.type.equals("STOP")).count()); - } - - @Test - public void sameTrip_inverseSubmission_splitPickup() { - /*- - * Two requests with the same origin and destination, different departure times. - * - First, A is submitted with departure time 2020 - * - Then, B is submitted with departure time 1770 - * - B's departure is 250s before A, so appending it to A would lead to more than 300s - * of wait time, which is not a valid insertion - * - Hence, the insertion *after* the pickup of A is not valid - * - But the insertion *before* A is possible (it is usually evaluated but dominated by the insertion after) - * - TODO: May think this through and eliminate these insertion upfront - * - * - Expectation: Standard scheduling a prebooked request before another one (as if they had not the - * same origin link). - * - In total three stops (P,P,D) - */ - - PrebookingTestEnvironment environment = new PrebookingTestEnvironment() // - .addVehicle("vehicleA", 1, 1) // - .addRequest("requestA", 1, 1, 5, 5, 2020.0, 1000.0) // - .addRequest("requestB", 1, 1, 5, 5, 1470.0, 1100.0) // - .configure(300.0, 2.0, 1800.0, 60.0) // - .planningHorizon(7200.0) // - .endTime(10.0 * 3600.0); - - Controler controller = environment.build(); - installPrebooking(controller); - controller.run(); - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestA"); - assertEquals(1000.0, requestInfo.submissionTime, 1e-3); - assertEquals(2020.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2249.0 + 1.0, requestInfo.dropoffTime, 1e-3); - } - - { - RequestInfo requestInfo = environment.getRequestInfo().get("requestB"); - assertEquals(1100.0, requestInfo.submissionTime, 1e-3); - assertEquals(1470.0 + 60.0 + 1.0, requestInfo.pickupTime, 1e-3); - assertEquals(2249.0 + 1.0, requestInfo.dropoffTime, 1e-3); - } - - // Three stops, 2x pickup, 1x dropoff - assertEquals(3, environment.getTaskInfo().get("vehicleA").stream().filter(t -> t.type.equals("STOP")).count()); - } -} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/preplanned/optimizer/RunPreplannedDrtExampleIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/preplanned/optimizer/RunPreplannedDrtExampleIT.java deleted file mode 100644 index 11bd8d5328b..00000000000 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/preplanned/optimizer/RunPreplannedDrtExampleIT.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) 2022 by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** * - */ - -package org.matsim.contrib.drt.extension.preplanned.optimizer; - -import static java.util.stream.Collectors.toMap; -import static org.matsim.contrib.drt.extension.preplanned.optimizer.PreplannedDrtOptimizer.PreplannedRequest; -import static org.matsim.contrib.drt.extension.preplanned.optimizer.PreplannedDrtOptimizer.PreplannedStop; - -import java.net.URL; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.drt.extension.preplanned.optimizer.PreplannedDrtOptimizer.PreplannedRequestKey; -import org.matsim.contrib.drt.extension.preplanned.optimizer.PreplannedDrtOptimizer.PreplannedSchedules; -import org.matsim.contrib.drt.extension.preplanned.run.RunPreplannedDrtExample; -import org.matsim.contrib.dvrp.fleet.DvrpVehicle; -import org.matsim.core.utils.io.IOUtils; -import org.matsim.examples.ExamplesUtils; - -/** - * @author Michal Maciejewski (michalm) - */ -public class RunPreplannedDrtExampleIT { - @Test - public void testRun() { - // scenario with 1 shared taxi (max 2 pax) and 10 requests - URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("dvrp-grid"), "one_shared_taxi_config.xml"); - - // create preplanned requests (they will be mapped to drt requests created during simulation) - var preplannedRequest_0 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_0"), Id.createLinkId("114"), - Id.createLinkId("349")), 0.0, 900.0, 844.4); - var preplannedRequest_1 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_1"), Id.createLinkId("144"), - Id.createLinkId("437")), 300.0, 1200.0, 1011.8); - var preplannedRequest_2 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_2"), Id.createLinkId("223"), - Id.createLinkId("347")), 600.0, 1500.0, 1393.7); - var preplannedRequest_3 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_3"), Id.createLinkId("234"), - Id.createLinkId("119")), 900.0, 1800.0, 1825.0); - var preplannedRequest_4 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_4"), Id.createLinkId("314"), - Id.createLinkId("260")), 1200.0, 2100.0, 1997.6); - var preplannedRequest_5 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_5"), Id.createLinkId("333"), - Id.createLinkId("438")), 1500.0, 2400.0, 2349.6); - var preplannedRequest_6 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_6"), Id.createLinkId("325"), - Id.createLinkId("111")), 1800.0, 2700.0, 2600.2); - var preplannedRequest_7 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_7"), Id.createLinkId("412"), - Id.createLinkId("318")), 2100.0, 3000.0, 2989.9); - var preplannedRequest_8 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_8"), Id.createLinkId("455"), - Id.createLinkId("236")), 2400.0, 3300.0, 3110.5); - var preplannedRequest_9 = new PreplannedRequest( - new PreplannedRequestKey(Id.createPersonId("passenger_9"), Id.createLinkId("139"), - Id.createLinkId("330")), 2700.0, 3600.0, 3410.5); - var preplannedRequests = List.of(preplannedRequest_0, preplannedRequest_1, preplannedRequest_2, - preplannedRequest_3, preplannedRequest_4, preplannedRequest_5, preplannedRequest_6); - - // there is only one shared taxi - var taxiId = Id.create("shared_taxi_one", DvrpVehicle.class); - - // all requests are assigned to that taxi - var preplannedRequestsToVehicleId = preplannedRequests.stream() - .collect(toMap(PreplannedRequest::key, r -> taxiId)); - - // the taxi will serve requests one by one (so actually no sharing, but of course we can change the sequence of stops) - var preplannedStops = preplannedRequests.stream() - .flatMap(r -> Stream.of(new PreplannedStop(r, true), new PreplannedStop(r, false))) - .toList(); - var preplannedStopsByVehicleId = Map.of(taxiId, (Queue)new LinkedList<>(preplannedStops)); - - var unassignedRequests = Stream.of(preplannedRequest_7, preplannedRequest_8, preplannedRequest_9) - .collect(toMap(PreplannedRequest::key, r -> r)); - - // put all input data together - var preplannedSchedules = new PreplannedSchedules(preplannedRequestsToVehicleId, preplannedStopsByVehicleId, - unassignedRequests); - - // run simulation that re-plays the pre-computed vehicle schedules - RunPreplannedDrtExample.run(configUrl, false, 0, Map.of("drt", preplannedSchedules)); - } -}