diff --git a/contribs/carsharing/src/test/java/org/matsim/contrib/carsharing/runExample/RunCarsharingRelocationIT.java b/contribs/carsharing/src/test/java/org/matsim/contrib/carsharing/runExample/RunCarsharingRelocationIT.java deleted file mode 100644 index 64f0d96606b..00000000000 --- a/contribs/carsharing/src/test/java/org/matsim/contrib/carsharing/runExample/RunCarsharingRelocationIT.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.matsim.contrib.carsharing.runExample; - -public class RunCarsharingRelocationIT { - - - - - -} diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterFactory.java b/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterFactory.java deleted file mode 100644 index 7fba53c4198..00000000000 --- a/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.matsim.contrib.common.randomizedtransitrouter;/* *********************************************************************** * - * project: org.matsim.* - * RandomizedTransitRouterFacotry - * * - * *********************************************************************** * - * * - * copyright : (C) 2013 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 * - * * - * *********************************************************************** */ - -import org.matsim.core.config.Config; -import org.matsim.pt.router.*; -import org.matsim.pt.transitSchedule.api.TransitSchedule; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; - - -/** - * @author dgrether - * - */ -public class RandomizingTransitRouterFactory implements Provider { - - private TransitRouterConfig trConfig; - private TransitSchedule schedule; - private TransitRouterNetwork routerNetwork; - - @Inject - RandomizingTransitRouterFactory(Config config, TransitSchedule schedule) { - this.trConfig = new TransitRouterConfig(config); - this.schedule = schedule; - this.routerNetwork = TransitRouterNetwork.createFromSchedule(schedule, trConfig.getBeelineWalkConnectionDistance()); - } - - @Override - public TransitRouter get() { - RandomizingTransitRouterTravelTimeAndDisutility ttCalculator = new RandomizingTransitRouterTravelTimeAndDisutility(trConfig); - ttCalculator.setDataCollection(RandomizingTransitRouterTravelTimeAndDisutility.DataCollection.randomizedParameters, true) ; - ttCalculator.setDataCollection(RandomizingTransitRouterTravelTimeAndDisutility.DataCollection.additionalInformation, false) ; - return new TransitRouterImpl(trConfig, new PreparedTransitSchedule(schedule), routerNetwork, ttCalculator, ttCalculator); - } - -} diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterModule.java b/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterModule.java deleted file mode 100644 index 1dc0dec0300..00000000000 --- a/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterModule.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.matsim.contrib.common.randomizedtransitrouter;/* - * *********************************************************************** * - * * project: org.matsim.* - * * RandomizedTransitRouterModule.java - * * * - * * *********************************************************************** * - * * * - * * copyright : (C) 2015 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 * - * * * - * * *********************************************************************** - */ - -import org.matsim.core.controler.AbstractModule; -import org.matsim.pt.router.TransitRouter; - -public class RandomizingTransitRouterModule extends AbstractModule { - @Override - public void install() { - bind(TransitRouter.class).toProvider(RandomizingTransitRouterFactory.class); - } -} diff --git a/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterTravelTimeAndDisutility.java b/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterTravelTimeAndDisutility.java deleted file mode 100644 index d75e386838e..00000000000 --- a/contribs/common/src/main/java/org/matsim/contrib/common/randomizedtransitrouter/RandomizingTransitRouterTravelTimeAndDisutility.java +++ /dev/null @@ -1,207 +0,0 @@ -package org.matsim.contrib.common.randomizedtransitrouter;/* *********************************************************************** * - * project: org.matsim.* - * RandomizedTransitRouterNetworkTravelTimeAndDisutility2 - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 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 * - * * - * *********************************************************************** */ - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -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.api.core.v01.population.Person; -import org.matsim.core.gbl.MatsimRandom; -import org.matsim.pt.router.CustomDataManager; -import org.matsim.pt.router.TransitRouterConfig; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink; -import org.matsim.pt.router.TransitRouterNetworkTravelTimeAndDisutility; -import org.matsim.vehicles.Vehicle; - -import java.util.HashMap; -import java.util.Map; - - -/** - * When plugged into the transit router, will switch to a different, randomly generated combination of - * marginal utilities every time it is called for a new agent. - *

- * Comments: - * @author kai - * @author dgrether - * - */ -public class RandomizingTransitRouterTravelTimeAndDisutility extends TransitRouterNetworkTravelTimeAndDisutility { - - public enum DataCollection {randomizedParameters, additionalInformation} - private Id cachedPersonId = null ; - private final TransitRouterConfig originalTransitRouterConfig ; - - private double localMarginalUtilityOfTravelTimeWalk_utl_s = Double.NaN ; - private double localMarginalUtilityOfWaitingPt_utl_s = Double.NaN ; - private double localUtilityOfLineSwitch_utl = Double.NaN ; - private double localMarginalUtilityOfTravelTimePt_utl_s = Double.NaN ; - private double localMarginalUtilityOfTravelDistancePt_utl_m = Double.NaN ; - - private Map dataCollectionConfig = new HashMap() ; - private Map dataCollectionStrings = new HashMap() ; - - public RandomizingTransitRouterTravelTimeAndDisutility(TransitRouterConfig routerConfig) { - super(routerConfig); - - prepareDataCollection(); - - // make sure that some parameters are not zero since otherwise the randomization will not work: - - // marg utl time wlk should be around -3/h or -(3/3600)/sec. Give warning if not at least 1/3600: - if ( -routerConfig.getMarginalUtilityOfTravelTimeWalk_utl_s() < 1./3600. ) { - LogManager.getLogger(this.getClass()).warn( "marg utl of walk rather close to zero; randomization may not work") ; - } - // utl of line switch should be around -300sec or -0.5u. Give warning if not at least 0.1u: - if ( -routerConfig.getUtilityOfLineSwitch_utl() < 0.1 ) { - LogManager.getLogger(this.getClass()).warn( "utl of line switch rather close to zero; randomization may not work") ; - } - - this.originalTransitRouterConfig = routerConfig ; - - this.localMarginalUtilityOfTravelDistancePt_utl_m = routerConfig.getMarginalUtilityOfTravelDistancePt_utl_m(); - this.localMarginalUtilityOfTravelTimePt_utl_s = routerConfig.getMarginalUtilityOfTravelTimePt_utl_s() ; - this.localMarginalUtilityOfTravelTimeWalk_utl_s = routerConfig.getMarginalUtilityOfTravelTimeWalk_utl_s() ; -// this.localMarginalUtilityOfWaitingPt_utl_s = routerConfig.getMarginalUtilityOfTravelTimePt_utl_s() ; - this.localMarginalUtilityOfWaitingPt_utl_s = routerConfig.getMarginalUtilityOfWaitingPt_utl_s() ; - this.localUtilityOfLineSwitch_utl = routerConfig.getUtilityOfLineSwitch_utl() ; - } - public final String getDataCollectionString( DataCollection item ) { - return dataCollectionStrings.get(item).toString() ; - } - - @Override - public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, - final CustomDataManager dataManager) { - - regenerateUtilityParametersIfPersonHasChanged(person); - - double disutl; - if (((TransitRouterNetworkLink) link).getRoute() == null) { - // (this means that it is a transfer link (walk)) - - double transfertime = getLinkTravelTime(link, time, person, vehicle); - double waittime = this.originalTransitRouterConfig.getAdditionalTransferTime(); - - // say that the effective walk time is the transfer time minus some "buffer" - double walktime = transfertime - waittime; - - disutl = - walktime * localMarginalUtilityOfTravelTimeWalk_utl_s - - waittime * localMarginalUtilityOfWaitingPt_utl_s - - localUtilityOfLineSwitch_utl; - - } else { - - double offVehWaitTime = offVehicleWaitTime(link, time); - - double inVehTime = getLinkTravelTime(link,time, person, vehicle) - offVehWaitTime ; - - disutl = -inVehTime * this.localMarginalUtilityOfTravelTimePt_utl_s - - offVehWaitTime * this.localMarginalUtilityOfWaitingPt_utl_s - - link.getLength() * this.localMarginalUtilityOfTravelDistancePt_utl_m; - } - - if ( this.dataCollectionConfig.get(DataCollection.additionalInformation )) { - StringBuffer strb = this.dataCollectionStrings.get(DataCollection.additionalInformation ) ; - strb.append("also collecting additional information") ; - } - - return disutl; - } - - @Override - public double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord) { - regenerateUtilityParametersIfPersonHasChanged(person); - return - getWalkTravelTime(person, coord, toCoord) * localMarginalUtilityOfTravelTimeWalk_utl_s ; - } - - public final void setDataCollection( DataCollection item, Boolean bbb ) { - LogManager.getLogger(this.getClass()).info( " settin data collection of " + item.toString() + " to " + bbb.toString() ) ; - dataCollectionConfig.put( item, bbb ) ; - } - - private void prepareDataCollection() { - for ( DataCollection dataCollection : DataCollection.values() ) { - switch ( dataCollection ) { - case randomizedParameters: - dataCollectionConfig.put( dataCollection, false ) ; - dataCollectionStrings.put( dataCollection, new StringBuffer() ) ; - break; - case additionalInformation: - dataCollectionConfig.put( dataCollection, false ) ; - dataCollectionStrings.put( dataCollection, new StringBuffer() ) ; - break; - } - } - } - - private void regenerateUtilityParametersIfPersonHasChanged(final Person person) { - if ( !person.getId().equals(this.cachedPersonId)) { - // yyyyyy probably not thread safe (?!?!) - - // person has changed, so ... - - // ... memorize new person id: - this.cachedPersonId = person.getId() ; - - // ... generate new random parameters: - { - double tmp = this.originalTransitRouterConfig.getMarginalUtilityOfTravelTimeWalk_utl_s() ; - tmp *= 5. * MatsimRandom.getRandom().nextDouble() ; - localMarginalUtilityOfTravelTimeWalk_utl_s = tmp ; - // yy if this becomes too small, they may walk the whole way (is it really clear why this can happen?) - } - { - double tmp = this.originalTransitRouterConfig.getUtilityOfLineSwitch_utl() ; - tmp *= 5. * MatsimRandom.getRandom().nextDouble() ; - localUtilityOfLineSwitch_utl = tmp ; - } - { - double tmp = this.originalTransitRouterConfig.getMarginalUtilityOfWaitingPt_utl_s(); - tmp *= 5. * MatsimRandom.getRandom().nextDouble(); - localMarginalUtilityOfWaitingPt_utl_s = tmp; - } - { - // (Conceptually, the following is not necessary, but empirically, it seems to help. kai, jan'13) - double tmp = this.originalTransitRouterConfig.getMarginalUtilityOfTravelTimePt_utl_s() ; - tmp *= 5. * MatsimRandom.getRandom().nextDouble(); - localMarginalUtilityOfTravelTimePt_utl_s = tmp; - } - - if ( this.dataCollectionConfig.get(DataCollection.randomizedParameters) ) { -// StringBuffer strb = this.dataCollectionStrings.get(DataCollection.randomizedParameters) ; -// strb.append - System.out.println("personId: " + person.getId() + - "; margUtlOfTimeWlk_h: " + this.localMarginalUtilityOfTravelTimeWalk_utl_s*3600. + - "; utlOfLineSwitch: " + this.localUtilityOfLineSwitch_utl + - "; margUtlOfWait_h: " + this.localMarginalUtilityOfWaitingPt_utl_s*3600. + - "; margUtlOfTimePt_h: " + this.localMarginalUtilityOfTravelTimePt_utl_s*3600. ) ; - } - } - } - -} diff --git a/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java b/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java deleted file mode 100644 index 46baae254fd..00000000000 --- a/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java +++ /dev/null @@ -1,161 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* * - * * - * *********************************************************************** * - * * - * copyright : (C) 2008 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.common.randomizingtransitrouter; - -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; -import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; -import org.matsim.contrib.common.randomizedtransitrouter.RandomizingTransitRouterModule; -import org.matsim.core.config.Config; -import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; -import org.matsim.core.config.groups.QSimConfigGroup.TrafficDynamics; -import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; -import org.matsim.core.config.groups.VspExperimentalConfigGroup.VspDefaultsCheckingLevel; -import org.matsim.core.controler.Controler; -import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule.DefaultSelector; -import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule.DefaultStrategy; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.pt.config.TransitConfigGroup.TransitRoutingAlgorithmType; -import org.matsim.testcases.MatsimTestUtils; -import org.matsim.vehicles.Vehicle; - - -/** - * @author nagel - * - */ -public class RandomizingTransitRouterIT { - private static final Logger log = LogManager.getLogger( RandomizingTransitRouterIT.class ) ; - - private static final class MyObserver implements PersonEntersVehicleEventHandler { -// private enum ObservedVehicle{ pt_1009_1 /*direct, fast, with wait*/, pt_2009_1 /*direct, slow*/, pt_3009_1 /*with interchange*/} ; - - Map,Double> cnts = new HashMap<>() ; - - @Override public void reset(int iteration) { - cnts.clear(); - } - - @Override public void handleEvent(PersonEntersVehicleEvent event) { - cnts.merge( event.getVehicleId() , 1. , Double::sum ); - } - - void printCounts() { - for ( Entry, Double> entry : cnts.entrySet() ) { - log.info( "Vehicle id: " + entry.getKey() + "; number of boards: " + entry.getValue() ) ; - } - } - - Map< Id, Double> getCounts() { - return this.cnts ; - } - } - - @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; - - @Test -// @Ignore - public final void test() { - String outputDir = utils.getOutputDirectory() ; - - Config config = utils.createConfigWithPackageInputResourcePathAsContext(); - - config.network().setInputFile("network.xml"); - config.plans().setInputFile("population.xml"); - - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); - config.transit().setTransitScheduleFile("transitschedule.xml"); - config.transit().setVehiclesFile("transitVehicles.xml"); - config.transit().setUseTransit(true); - - config.controller().setOutputDirectory( outputDir ); - config.controller().setLastIteration(20); - config.controller().setCreateGraphs(false); - config.controller().setDumpDataAtEnd(false); - - config.global().setNumberOfThreads(1); - - config.scoring().addActivityParams( new ActivityParams("home").setTypicalDuration( 6*3600. ) ); - config.scoring().addActivityParams( new ActivityParams("education_100").setTypicalDuration( 6*3600. ) ); - -// config.strategy().addStrategySettings( new StrategySettings( ConfigUtils.createAvailableStrategyId(config)).setStrategyName(DefaultStrategy.ReRoute ).setWeight(0.1 ) ); -// config.strategy().addStrategySettings( new StrategySettings( ConfigUtils.createAvailableStrategyId(config)).setStrategyName(DefaultSelector.ChangeExpBeta ).setWeight(0.9 ) ); - config.replanning().addStrategySettings( new StrategySettings().setStrategyName(DefaultStrategy.ReRoute ).setWeight(0.1 ) ); - config.replanning().addStrategySettings( new StrategySettings().setStrategyName(DefaultSelector.ChangeExpBeta ).setWeight(0.9 ) ); - // yy changing the above (= no longer using createAvailableStrategyId) changes the results. :-( :-( :-( - - config.qsim().setEndTime(18.*3600.); - - config.timeAllocationMutator().setMutationRange(7200); - config.timeAllocationMutator().setAffectingDuration(false); - config.plans().setRemovingUnneccessaryPlanAttributes(true); - config.qsim().setTrafficDynamics( TrafficDynamics.withHoles ); - config.qsim().setUsingFastCapacityUpdate(true); - -// config.facilities().setFacilitiesSource( FacilitiesConfigGroup.FacilitiesSource.none ); - // yyyy changing this setting changes result. Possible reasons: - // * The implicit activity coordinates may be elsewhere. - // * The "fudged" walk distances may be different. - // * It uses getNearestLinkEXACTLY, and thus activities may be attached to other links. - - config.vspExperimental().setWritingOutputEvents(true); - config.vspExperimental().setVspDefaultsCheckingLevel( VspDefaultsCheckingLevel.warn ); - - // --- - - Scenario scenario = ScenarioUtils.loadScenario( config ) ; - - // --- - - Controler controler = new Controler( scenario ) ; - - controler.addOverridingModule( new RandomizingTransitRouterModule() ); - - final MyObserver observer = new MyObserver(); - controler.getEvents().addHandler(observer); - - controler.run(); - - // --- - - observer.printCounts(); - - // yyyy the following is just a regression test, making sure that results remain stable. In general, the randomized transit router - // could be improved, for example along the lines of the randomized regular router, which uses a (hopefully unbiased) lognormal - // distribution rather than a biased uniform distribution as is used here. kai, jul'15 - - Assert.assertEquals(36., observer.getCounts().get( Id.create("1009", Vehicle.class) ), 0.1 ); - Assert.assertEquals( 8. /*6.*/ , observer.getCounts().get( Id.create("1012", Vehicle.class) ) , 0.1 ); - Assert.assertEquals(22. /*21.*/, observer.getCounts().get( Id.create("2009", Vehicle.class) ) , 0.1 ); - Assert.assertEquals(36., observer.getCounts().get( Id.create("3009", Vehicle.class) ) , 0.1 ); - - - } - -} diff --git a/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java b/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java index 89e444ca0c4..567d5fb1fe4 100644 --- a/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java +++ b/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java @@ -28,7 +28,6 @@ public void testSiouxFallsWithSubtourModeChoiceReplacement() { URL scenarioURL = ExamplesUtils.getTestScenarioURL("siouxfalls-2014"); Config config = ConfigUtils.loadConfig(IOUtils.extendUrl(scenarioURL, "config_default.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); DiscreteModeChoiceConfigurator.configureAsSubtourModeChoiceReplacement(config); config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); @@ -57,9 +56,9 @@ public void install() { controller.run(); - assertEquals(42395, (int) listener.counts.get("pt")); - assertEquals(132284, (int) listener.counts.get("car")); - assertEquals(78809, (int) listener.counts.get("walk")); + assertEquals(44196, (int) listener.counts.get("pt")); + assertEquals(132316, (int) listener.counts.get("car")); + assertEquals(82140, (int) listener.counts.get("walk")); // assertEquals(42520, (int) listener.counts.get("pt")); // assertEquals(132100, (int) listener.counts.get("car")); // assertEquals(79106, (int) listener.counts.get("walk")); diff --git a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java index c188c22fae6..b2c7576ae7e 100644 --- a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java +++ b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java @@ -58,7 +58,6 @@ public class SubsidyTestIT implements TabularFileHandler { public final void testSubsidyPControler() { Config config = ConfigUtils.loadConfig( utils.getClassInputDirectory() + "config.xml", new PConfigGroup() ) ; - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); PConfigGroup pConfig = (PConfigGroup) config.getModules().get(PConfigGroup.GROUP_NAME); pConfig.setSubsidyApproach("perPassenger"); @@ -105,7 +104,7 @@ public final void testSubsidyPControler() { new TabularFileParser().parse(tabFileParserConfig, this); // Check final iteration - Assert.assertEquals("Number of budget (final iteration)", "202319997.4909444700", this.pStatsResults.get(2)[9]); + Assert.assertEquals("Number of budget (final iteration)", "174413625.6239444000", this.pStatsResults.get(2)[9]); } @Override diff --git a/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java b/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java index b386b1d914c..08c4ca3cba5 100644 --- a/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java +++ b/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java @@ -46,7 +46,6 @@ public class RunPSimTest { */ @Test public void testA() { - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); config.controller().setCreateGraphs(false); PSimConfigGroup pSimConfigGroup = new PSimConfigGroup(); @@ -108,10 +107,7 @@ public void install() { Population popActual = PopulationUtils.createPopulation( config ); PopulationUtils.readPopulation( popActual, outDir + "/output_plans.xml.gz" ); new PopulationComparison().compare( popExpected, popActual ) ; - Assert.assertEquals("RunPsim score changed.", 138.88379880881348, psimScore, MatsimTestUtils.EPSILON); -// Assert.assertEquals("RunPsim score changed.", 134.54001491094124d, psimScore, MatsimTestUtils.EPSILON); -// Assert.assertEquals("RunPsim score changed.", 134.52369453719413d, psimScore, MatsimTestUtils.EPSILON); -// Assert.assertEquals("RunPsim score changed.", 132.73129073101293d, psimScore, MatsimTestUtils.EPSILON); + Assert.assertEquals("RunPsim score changed.", 138.88788052033888, psimScore, MatsimTestUtils.EPSILON); } /** @@ -123,7 +119,6 @@ public void install() { */ @Test public void testB() { - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); config.controller().setOutputDirectory(utils.getOutputDirectory()); config.controller().setLastIteration(2); config.controller().setCreateGraphs(false); @@ -135,9 +130,8 @@ public void testB() { controler.run(); double qsimScore = execScoreTracker.executedScore; - logger.info("Default controler score was " + qsimScore ); -// Assert.assertEquals("Default controler score changed.", 131.84309487251033d, qsimScore, MatsimTestUtils.EPSILON); - Assert.assertEquals("Default controler score changed.", 131.84350487113088d, qsimScore, MatsimTestUtils.EPSILON); + logger.info("Default controller score was " + qsimScore ); + Assert.assertEquals("Default controller score changed.", 131.85545404187428, qsimScore, MatsimTestUtils.EPSILON); } class ExecScoreTracker implements ShutdownListener { diff --git a/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java b/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java index af460a53229..37df0aa0811 100644 --- a/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java +++ b/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java @@ -53,7 +53,6 @@ import org.matsim.pt.UmlaufInterpolator; import org.matsim.pt.config.TransitConfigGroup; import org.matsim.pt.router.TransitRouterConfig; -import org.matsim.pt.router.TransitRouterImpl; import org.matsim.pt.transitSchedule.TransitScheduleWriterV1; import org.matsim.pt.transitSchedule.api.TransitLine; import org.matsim.pt.transitSchedule.api.TransitScheduleWriter; @@ -184,39 +183,43 @@ protected void routePopulation() { } protected void visualizeRouterNetwork() { - - TransitRouterConfig transitRouterConfig = new TransitRouterConfig(this.scenario.getConfig().scoring() - , this.scenario.getConfig().routing(), this.scenario.getConfig().transitRouter(), - this.scenario.getConfig().vspExperimental()); - - TransitRouterImpl router = new TransitRouterImpl(transitRouterConfig, this.scenario.getTransitSchedule() ); - Network routerNet = router.getTransitRouterNetwork(); - - log.info("create vis network"); - MutableScenario visScenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); - Network visNet = visScenario.getNetwork(); - - for (Node node : routerNet.getNodes().values()) { - visNet.getFactory().createNode(node.getId(), node.getCoord()); - visNet.addNode(node); - } - for (Link link : routerNet.getLinks().values()) { - Link l = visNet.getFactory().createLink(link.getId(), visNet.getNodes().get(link.getFromNode().getId()), visNet.getNodes().get(link.getToNode().getId())); - l.setLength(link.getLength()); - l.setFreespeed(link.getFreespeed()); - l.setCapacity(link.getCapacity()); - l.setNumberOfLanes(link.getNumberOfLanes()); - } - - log.info("write routerNet.xml"); - new NetworkWriter(visNet).write("visNet.xml"); - - log.info("start visualizer"); - EventsManager events = EventsUtils.createEventsManager(); - QSim otfVisQSim = new QSimBuilder(visScenario.getConfig()).useDefaults().build(visScenario, events); - OnTheFlyServer server = OTFVis.startServerAndRegisterWithQSim(visScenario.getConfig(), visScenario, events, otfVisQSim); - OTFClientLive.run(visScenario.getConfig(), server); - otfVisQSim.run(); + throw new RuntimeException("this works no longer, sorry."); + + /* I commented this code out, as it directly refers to the old and inefficient TransitRouterImpl + which got removed at the Code Sprint 2023 in Berlin. // mrieser, 2023oct09 + */ + +// TransitRouterConfig transitRouterConfig = new TransitRouterConfig(this.scenario.getConfig().planCalcScore() +// , this.scenario.getConfig().plansCalcRoute(), this.scenario.getConfig().transitRouter(), +// this.scenario.getConfig().vspExperimental()); +// TransitRouterImpl router = new TransitRouterImpl(transitRouterConfig, this.scenario.getTransitSchedule() ); +// Network routerNet = router.getTransitRouterNetwork(); +// +// log.info("create vis network"); +// MutableScenario visScenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); +// Network visNet = visScenario.getNetwork(); +// +// for (Node node : routerNet.getNodes().values()) { +// visNet.getFactory().createNode(node.getId(), node.getCoord()); +// visNet.addNode(node); +// } +// for (Link link : routerNet.getLinks().values()) { +// Link l = visNet.getFactory().createLink(link.getId(), visNet.getNodes().get(link.getFromNode().getId()), visNet.getNodes().get(link.getToNode().getId())); +// l.setLength(link.getLength()); +// l.setFreespeed(link.getFreespeed()); +// l.setCapacity(link.getCapacity()); +// l.setNumberOfLanes(link.getNumberOfLanes()); +// } +// +// log.info("write routerNet.xml"); +// new NetworkWriter(visNet).write("visNet.xml"); +// +// log.info("start visualizer"); +// EventsManager events = EventsUtils.createEventsManager(); +// QSim otfVisQSim = new QSimBuilder(visScenario.getConfig()).useDefaults().build(visScenario, events); +// OnTheFlyServer server = OTFVis.startServerAndRegisterWithQSim(visScenario.getConfig(), visScenario, events, otfVisQSim); +// OTFClientLive.run(visScenario.getConfig(), server); +// otfVisQSim.run(); } private void buildUmlaeufe() { diff --git a/contribs/vsp/src/main/java/playground/vsp/randomizedtransitrouter/RunOTFVisDebugRandomizedTransitRouterTravelTimeAndDisutility.java b/contribs/vsp/src/main/java/playground/vsp/randomizedtransitrouter/RunOTFVisDebugRandomizedTransitRouterTravelTimeAndDisutility.java deleted file mode 100644 index 6f38b251bf5..00000000000 --- a/contribs/vsp/src/main/java/playground/vsp/randomizedtransitrouter/RunOTFVisDebugRandomizedTransitRouterTravelTimeAndDisutility.java +++ /dev/null @@ -1,101 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * RunOTFVisDebugRandomizedTransitRouter - * * - * *********************************************************************** * - * * - * copyright : (C) 2013 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 playground.vsp.randomizedtransitrouter; - -import org.matsim.api.core.v01.Scenario; -import org.matsim.contrib.common.randomizedtransitrouter.RandomizingTransitRouterModule; -import org.matsim.contrib.otfvis.OTFVis; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.controler.AbstractModule; -import org.matsim.core.controler.Controler; -import org.matsim.core.controler.OutputDirectoryHierarchy; -import org.matsim.core.mobsim.framework.Mobsim; -import org.matsim.core.mobsim.framework.MobsimFactory; -import org.matsim.core.mobsim.qsim.QSim; -import org.matsim.core.mobsim.qsim.QSimBuilder; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.vis.otfvis.OTFClientLive; -import org.matsim.vis.otfvis.OTFVisConfigGroup; -import org.matsim.vis.otfvis.OnTheFlyServer; - -import com.google.inject.Provider; - - -/** - * @author dgrether - * - */ -public class RunOTFVisDebugRandomizedTransitRouterTravelTimeAndDisutility { - - - public static void main(String[] args) { - final Config config = ConfigUtils.loadConfig(args[0]) ; - - boolean doVisualization = true; - - config.scoring().setWriteExperiencedPlans(true) ; - - ConfigUtils.addOrGetModule(config, OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class).setDrawTransitFacilities(true) ; // this DOES work - ConfigUtils.addOrGetModule(config, OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class).setDrawTransitFacilityIds(false); - ConfigUtils.addOrGetModule(config, OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class).setShowTeleportedAgents(true) ; - ConfigUtils.addOrGetModule(config, OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class).setDrawNonMovingItems(true); - ConfigUtils.addOrGetModule(config, OTFVisConfigGroup.GROUP_NAME, OTFVisConfigGroup.class).setScaleQuadTreeRect(true); - - final Scenario scenario = ScenarioUtils.loadScenario(config) ; - - final Controler ctrl = new Controler(scenario) ; - - ctrl.getConfig().controller().setOverwriteFileSetting( - true ? - OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles : - OutputDirectoryHierarchy.OverwriteFileSetting.failIfDirectoryExists ); - - ctrl.addOverridingModule(new RandomizingTransitRouterModule()); - - if (doVisualization){ - ctrl.addOverridingModule(new AbstractModule() { - @Override - public void install() { - bindMobsim().toProvider(new Provider() { - @Override - public Mobsim get() { - return new MobsimFactory() { - - @Override - public Mobsim createMobsim(final Scenario sc, final EventsManager eventsManager) { - final QSim qSim = new QSimBuilder(sc.getConfig()).useDefaults().build(sc, eventsManager); - - final OnTheFlyServer server = OTFVis.startServerAndRegisterWithQSim(sc.getConfig(), sc, eventsManager, qSim); - OTFClientLive.run(sc.getConfig(), server); - - return qSim; - } - }.createMobsim(ctrl.getScenario(), ctrl.getEvents()); - } - }); - } - }); - } - ctrl.run() ; - - } -} diff --git a/contribs/vsp/src/main/java/playground/vsp/randomizedtransitrouter/package-info.java b/contribs/vsp/src/main/java/playground/vsp/randomizedtransitrouter/package-info.java deleted file mode 100644 index ce2cbb4e8ff..00000000000 --- a/contribs/vsp/src/main/java/playground/vsp/randomizedtransitrouter/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * package-info - * * - * *********************************************************************** * - * * - * copyright : (C) 2013 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 providing functionality for transit routing with randomized utility parameters. - * - * @author dgrether - * - */ -package playground.vsp.randomizedtransitrouter; \ No newline at end of file diff --git a/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java b/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java index d56ed2539a7..c9e063abf12 100644 --- a/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java @@ -158,7 +158,6 @@ public void testAgentLeavesStop() { HashMap, Double> arrivalTimes = new HashMap<>(); HashMap, List> trips = new HashMap<>(); Config config = ConfigUtils.loadConfig(configURL); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); String outputDirectory = utils.getOutputDirectory(); config.controller().setOutputDirectory(outputDirectory); Scenario scenario = ScenarioUtils.loadScenario(config); @@ -171,20 +170,16 @@ public void testAgentLeavesStop() { double travelTime = arrivalTimes.get(person.getId()) - activityEndTime; List trip = trips.get(person.getId()); - assertEquals("Travel time has changed", 2990.0, travelTime, MatsimTestUtils.EPSILON); - assertEquals("Number of trip elements has changed", 11 ,trip.size()); + assertEquals("Travel time has changed", 1344.0, travelTime, MatsimTestUtils.EPSILON); + assertEquals("Number of trip elements has changed", 7 ,trip.size()); assertEquals("Trip element has changed", "dummy@car_17bOut", trip.get(0)); assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(1)); assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(2)); - assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(3)); - assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(4)); - assertEquals("Trip element has changed", "pt interaction@pt7", trip.get(5)); - assertEquals("Trip element has changed", "pt interaction@pt7", trip.get(6)); - assertEquals("Trip element has changed", "tr_334", trip.get(7)); - assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(8)); - assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(9)); - assertEquals("Trip element has changed", "dummy@work0", trip.get(10)); + assertEquals("Trip element has changed", "tr_333", trip.get(3)); + assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(4)); + assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(5)); + assertEquals("Trip element has changed", "dummy@work0", trip.get(6)); } @@ -277,7 +272,6 @@ public void testAgentIsAtTeleportLegAndLeavesStop() { HashMap, Double> arrivalTimes = new HashMap<>(); HashMap, List> trips = new HashMap<>(); Config config = ConfigUtils.loadConfig(configURL); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); String outputDirectory = utils.getOutputDirectory(); config.controller().setOutputDirectory(outputDirectory); Scenario scenario = ScenarioUtils.loadScenario(config); @@ -296,8 +290,8 @@ public void testAgentIsAtTeleportLegAndLeavesStop() { assertEquals("Trip element has changed", "dummy@car_17bOut", trip.get(0)); assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(1)); assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(2)); - assertEquals("Trip element has changed", "pt interaction@pt7", trip.get(3)); - assertEquals("Trip element has changed", "pt interaction@pt7", trip.get(4)); + assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(3)); + assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(4)); assertEquals("Trip element has changed", "tr_334", trip.get(5)); assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(6)); assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(7)); @@ -356,7 +350,6 @@ public void testAgentIsAtTeleportLegAndWaitsAtStop() { HashMap, Double> arrivalTimes = new HashMap<>(); HashMap, List> trips = new HashMap<>(); Config config = ConfigUtils.loadConfig(configURL); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); String outputDirectory = utils.getOutputDirectory(); config.controller().setOutputDirectory(outputDirectory); Scenario scenario = ScenarioUtils.loadScenario(config); @@ -375,8 +368,8 @@ public void testAgentIsAtTeleportLegAndWaitsAtStop() { assertEquals("Trip element has changed", "dummy@car_17bOut", trip.get(0)); assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(1)); assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(2)); - assertEquals("Trip element has changed", "pt interaction@pt7", trip.get(3)); - assertEquals("Trip element has changed", "pt interaction@pt7", trip.get(4)); + assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(3)); + assertEquals("Trip element has changed", "pt interaction@pt6c", trip.get(4)); assertEquals("Trip element has changed", "tr_334", trip.get(5)); assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(6)); assertEquals("Trip element has changed", "pt interaction@pt8", trip.get(7)); diff --git a/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java b/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java index 742ef7d945a..fa2be75da28 100644 --- a/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java +++ b/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java @@ -51,7 +51,7 @@ public class TransitConfigGroup extends ReflectiveConfigGroup { private static final String INSISTING_ON_USING_DEPRECATED_ATTRIBUTE_FILE = "insistingOnUsingDeprecatedAttributeFiles" ; private static final String USING_TRANSIT_IN_MOBSIM = "usingTransitInMobsim" ; - public enum TransitRoutingAlgorithmType {DijkstraBased, SwissRailRaptor} + public enum TransitRoutingAlgorithmType {@Deprecated DijkstraBased, SwissRailRaptor} public static final String TRANSIT_ATTRIBUTES_DEPRECATION_MESSAGE = "using the separate transit stops and lines attribute files is deprecated." + " Add the information directly into each stop or line, using " + @@ -67,7 +67,7 @@ public enum TransitRoutingAlgorithmType {DijkstraBased, SwissRailRaptor} private Set transitModes; private TransitRoutingAlgorithmType routingAlgorithmType = TransitRoutingAlgorithmType.SwissRailRaptor; - + // --- private static final String USE_TRANSIT = "useTransit"; private boolean useTransit = false; @@ -159,7 +159,7 @@ public Set getTransitModes() { public String getTransitLinesAttributesFile() { return transitLinesAttributesFile; } - + @StringSetter( TRANSIT_LINES_ATTRIBUTES ) public void setTransitLinesAttributesFile(final String transitLinesAttributesFile) { this.transitLinesAttributesFile = transitLinesAttributesFile; @@ -172,12 +172,12 @@ public String getTransitStopsAttributesFile() { public URL getTransitStopsAttributesFileURL(URL context) { return ConfigGroup.getInputFileURL(context, getTransitStopsAttributesFile()) ; } - + @StringSetter( TRANSIT_STOPS_ATTRIBUTES ) public void setTransitStopsAttributesFile(final String transitStopsAttributesFile) { this.transitStopsAttributesFile = transitStopsAttributesFile; } - + @StringGetter( USE_TRANSIT ) public boolean isUseTransit() { return this.useTransit; @@ -207,7 +207,7 @@ public String getInputScheduleCRS() { public void setInputScheduleCRS(String inputScheduleCRS) { this.inputScheduleCRS = inputScheduleCRS; } - + public static final String BOARDING_ACCEPTANCE_CMT="under which conditions agent boards transit vehicle" ; public enum BoardingAcceptance { checkLineAndStop, checkStopOnly } private BoardingAcceptance boardingAcceptance = BoardingAcceptance.checkLineAndStop ; @@ -217,7 +217,7 @@ public BoardingAcceptance getBoardingAcceptance() { public void setBoardingAcceptance(BoardingAcceptance boardingAcceptance) { this.boardingAcceptance = boardingAcceptance; } - + private boolean usingTransitInMobsim = true ; @StringSetter( USING_TRANSIT_IN_MOBSIM ) public final void setUsingTransitInMobsim( boolean val ) { diff --git a/matsim/src/main/java/org/matsim/pt/router/AbstractTransitRouter.java b/matsim/src/main/java/org/matsim/pt/router/AbstractTransitRouter.java deleted file mode 100644 index 87639032e8f..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/AbstractTransitRouter.java +++ /dev/null @@ -1,208 +0,0 @@ - -/* *********************************************************************** * - * project: org.matsim.* - * AbstractTransitRouter.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2019 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.pt.router; - -import java.util.ArrayList; -import java.util.List; - -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.population.Leg; -import org.matsim.api.core.v01.population.Person; -import org.matsim.api.core.v01.population.Route; -import org.matsim.core.network.NetworkUtils; -import org.matsim.core.population.PopulationUtils; -import org.matsim.core.population.routes.RouteUtils; -import org.matsim.core.router.TripStructureUtils; -import org.matsim.core.utils.misc.OptionalTime; -import org.matsim.pt.routes.DefaultTransitPassengerRoute; -import org.matsim.pt.routes.TransitPassengerRoute; - -public class AbstractTransitRouter { - - private TransitRouterConfig trConfig; - private TransitTravelDisutility travelDisutility; - - protected AbstractTransitRouter (TransitRouterConfig transitRouterConfig){ - this.trConfig = transitRouterConfig; - } - - protected AbstractTransitRouter(TransitRouterConfig config, TransitTravelDisutility transitTravelDisutility){ - this.trConfig = config; - this.travelDisutility = transitTravelDisutility; - } - - // a setter is required for default PT router, I dont see any other way to make AbstractTransitRouter 'general purpose'. - protected void setTransitTravelDisutility(TransitTravelDisutility transitTravelDisutility){ - this.travelDisutility = transitTravelDisutility; - } - - // methods - protected final double getWalkTime(Person person, Coord coord, Coord toCoord) { - return getTravelDisutility().getWalkTravelTime(person, coord, toCoord); - } - - protected final double getTransferTime(Person person, Coord coord, Coord toCoord) { - return getTravelDisutility().getWalkTravelTime(person, coord, toCoord) + this.getConfig().getAdditionalTransferTime(); - } - - /** - * TODO: Replace by FallbackRoutingModule?! - gl-nov'19 - */ - @Deprecated - protected final List createDirectWalkLegList(Person person, Coord fromCoord, Coord toCoord) { - List legs = new ArrayList<>(); - Leg leg = PopulationUtils.createLeg(TransportMode.walk); - double walkTime = getWalkTime(person, fromCoord, toCoord); - leg.setTravelTime(walkTime); - TripStructureUtils.setRoutingMode(leg, TransportMode.pt); - Route walkRoute = RouteUtils.createGenericRouteImpl(null, null); - walkRoute.setTravelTime(walkTime); - leg.setRoute(walkRoute); - legs.add(leg); - return legs; - } - - private Leg createAccessTransitWalkLeg(Coord fromCoord, RouteSegment routeSegement) { - Leg leg = this.createTransitWalkLeg(fromCoord, routeSegement.fromStop.getCoord()); - Route walkRoute = RouteUtils.createGenericRouteImpl(null, routeSegement.fromStop.getLinkId()); - walkRoute.setTravelTime(leg.getTravelTime().seconds()); - walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(fromCoord, routeSegement.fromStop.getCoord())); - leg.setRoute(walkRoute); - return leg; - } - - private Leg createEgressTransitWalkLeg(RouteSegment routeSegement, Coord toCoord) { - Leg leg = this.createTransitWalkLeg(routeSegement.toStop.getCoord(), toCoord); - Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.toStop.getLinkId(), null); - walkRoute.setTravelTime(leg.getTravelTime().seconds()); - walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.toStop.getCoord(), toCoord)); - leg.setRoute(walkRoute); - return leg; - } - - private Leg createTransferTransitWalkLeg(RouteSegment routeSegement) { - Leg leg = this.createTransitWalkLeg(routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()); - Route walkRoute = RouteUtils.createGenericRouteImpl(routeSegement.getFromStop().getLinkId(), routeSegement.getToStop().getLinkId()); -// walkRoute.setTravelTime(leg.getTravelTime() ); - // transit walk leg should include additional transfer time; Amit, Aug'17 - leg.setTravelTime( getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); - walkRoute.setTravelTime(getTransferTime(null, routeSegement.getFromStop().getCoord(), routeSegement.getToStop().getCoord()) ); - walkRoute.setDistance(trConfig.getBeelineDistanceFactor() * NetworkUtils.getEuclideanDistance(routeSegement.fromStop.getCoord(), routeSegement.toStop.getCoord())); - leg.setRoute(walkRoute); - - return leg; - } - - protected List convertPassengerRouteToLegList(double departureTime, InternalTransitPassengerRoute p, Coord fromCoord, Coord toCoord, Person person) { - // convert the route into a sequence of legs - List legs = new ArrayList<>(); - - // access leg - Leg accessLeg; - // check if first leg extends walking distance - if (p.getRoute().get(0).getRouteTaken() == null) { - // route starts with transfer - extend initial walk to that stop - //TODO: what if first leg extends the walking distance to more than first routeSegment i.e., (accessLeg, transfer, transfer ...). Amit Jan'18 -// accessLeg = createTransitWalkLeg(fromCoord, p.getRoute().get(0).getToStop().getCoord()); - accessLeg = createAccessTransitWalkLeg(fromCoord, p.getRoute().get(0)); - p.getRoute().remove(0); - } else { - // do not extend it - add a regular walk leg - // -// accessLeg = createTransitWalkLeg(fromCoord, p.getRoute().get(0).getFromStop().getCoord()); - accessLeg = createAccessTransitWalkLeg(fromCoord, p.getRoute().get(0)); - } - - // egress leg - Leg egressLeg; - // check if first leg extends walking distance - if (p.getRoute().get(p.getRoute().size() - 1).getRouteTaken() == null) { - // route starts with transfer - extend initial walk to that stop -// egressLeg = createTransitWalkLeg(p.getRoute().get(p.getRoute().size() - 1).getFromStop().getCoord(), toCoord); - egressLeg = createEgressTransitWalkLeg(p.getRoute().get(p.getRoute().size() - 1), toCoord); - p.getRoute().remove(p.getRoute().size() - 1); - } else { - // do not extend it - add a regular walk leg - // access leg -// egressLeg = createTransitWalkLeg(p.getRoute().get(p.getRoute().size() - 1).getToStop().getCoord(), toCoord); - egressLeg = createEgressTransitWalkLeg(p.getRoute().get(p.getRoute().size() - 1), toCoord); - } - - - // add very first leg - legs.add(accessLeg); - - // route segments are now in pt-walk-pt sequence - for (RouteSegment routeSegement : p.getRoute()) { - if (routeSegement.getRouteTaken() == null) {// transfer - if (!routeSegement.fromStop.equals(routeSegement.toStop)) { // same to/from stop => no transfer. Amit Feb'18 - legs.add(createTransferTransitWalkLeg(routeSegement)); - } - } else { - // pt leg - legs.add(createTransitLeg(routeSegement)); - } - } - - // add last leg - legs.add(egressLeg); - - return legs; - } - - private Leg createTransitLeg(RouteSegment routeSegment) { - Leg leg = PopulationUtils.createLeg(TransportMode.pt); - - TransitPassengerRoute ptRoute = new DefaultTransitPassengerRoute( // - routeSegment.getFromStop().getLinkId(), routeSegment.getToStop().getLinkId(), // - routeSegment.getFromStop().getId(), routeSegment.getToStop().getId(), // - routeSegment.getLineTaken(), routeSegment.getRouteTaken() - ); - - ptRoute.setTravelTime(routeSegment.travelTime); - leg.setRoute(ptRoute); - - leg.setTravelTime(routeSegment.getTravelTime()); - return leg; - } - - private Leg createTransitWalkLeg(Coord fromCoord, Coord toCoord) { - Leg leg = PopulationUtils.createLeg(TransportMode.walk); - double walkTime = getWalkTime(null, fromCoord, toCoord); - leg.setTravelTime(walkTime); - return leg; - } - - protected final TransitRouterConfig getConfig() { - return trConfig; - } - - protected final double getWalkDisutility(Person person, Coord coord, Coord toCoord) { - return getTravelDisutility().getWalkTravelDisutility(person, coord, toCoord); - } - - protected final TransitTravelDisutility getTravelDisutility() { - return travelDisutility; - } - -} \ No newline at end of file diff --git a/matsim/src/main/java/org/matsim/pt/router/CustomDataManager.java b/matsim/src/main/java/org/matsim/pt/router/CustomDataManager.java deleted file mode 100644 index 52ced005624..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/CustomDataManager.java +++ /dev/null @@ -1,73 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 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.pt.router; - -import java.util.HashMap; - -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Node; - -/** - * A helper class to store custom data for {@link TransitTravelDisutility} which can be used - * to e.g. keep track of paid fares during the routing process. - * The stored data will be invalidated for each new routing request. - * - * @author mrieser / senozon - */ -public class CustomDataManager { - - private final HashMap data = new HashMap(); - private Node fromNode = null; - private Node toNode = null; - - private Object tmpToNodeData = null; - - public void setToNodeCustomData(final Object data) { - this.tmpToNodeData = data; - } - - /** - * @param node - * @return the stored data for the given node, or null if there is no data stored yet. - */ - public Object getFromNodeCustomData() { - return this.data.get(this.fromNode); - } - - public void initForLink(final Link link) { - this.fromNode = link.getFromNode(); - this.toNode = link.getToNode(); - this.tmpToNodeData = null; - } - - public void storeTmpData() { - if (this.tmpToNodeData != null) { - this.data.put(this.toNode, this.tmpToNodeData); - } - } - - public void reset() { - this.data.clear(); - this.fromNode = null; - this.toNode = null; - this.tmpToNodeData = null; - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/router/FakeFacility.java b/matsim/src/main/java/org/matsim/pt/router/FakeFacility.java deleted file mode 100644 index 00c2edade64..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/FakeFacility.java +++ /dev/null @@ -1,47 +0,0 @@ - -/* *********************************************************************** * - * project: org.matsim.* - * FakeFacility.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2019 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.pt.router; - -import java.util.Map; - -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.facilities.Facility; - -public final class FakeFacility implements Facility { - private Coord coord; - public FakeFacility( Coord coord ) { this.coord = coord ; } - @Override public Coord getCoord() { - return this.coord ; - } - - @Override - public Map getCustomAttributes() { - throw new RuntimeException("not implemented") ; - } - - @Override - public Id getLinkId() { - throw new RuntimeException("not implemented") ; - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/router/InternalTransitPassengerRoute.java b/matsim/src/main/java/org/matsim/pt/router/InternalTransitPassengerRoute.java deleted file mode 100644 index 61f04a3f20a..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/InternalTransitPassengerRoute.java +++ /dev/null @@ -1,52 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2015 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.pt.router; - -import java.util.List; - -/** - * - * @author aneumann - * - */ -public class InternalTransitPassengerRoute { - - private final double cost; - private final List route; - - public InternalTransitPassengerRoute(double cost, List leastCostRoute) { - this.cost = cost; - this.route = leastCostRoute; - - } - - public double getTravelCost() { - return this.cost; - } - - public List getRoute() { - return this.route; - } - - @Override - public String toString() { - return "Cost: " + this.cost + " via " + this.route; - } -} diff --git a/matsim/src/main/java/org/matsim/pt/router/PreparedTransitSchedule.java b/matsim/src/main/java/org/matsim/pt/router/PreparedTransitSchedule.java index 0de8829631f..35a9c3c4131 100644 --- a/matsim/src/main/java/org/matsim/pt/router/PreparedTransitSchedule.java +++ b/matsim/src/main/java/org/matsim/pt/router/PreparedTransitSchedule.java @@ -29,19 +29,21 @@ import org.matsim.pt.transitSchedule.api.TransitSchedule; /** - * + * * Allows fast queries of a TransitSchedule for the next departure of a given route at a given stop, from a given point * in time. If you need further queries of a TransitSchedule, put them here! - * + * * (I renamed this class and put the TransitSchedule in the constructor to make the purpose clear. michaz '13) - * + * * Thread-safe. - * + * * @author mrieser * */ public class PreparedTransitSchedule { - + + final static double MIDNIGHT = 24.0*3600; + /* * This needs to be a ConcurrentHashMap since multiple threads might add * data concurrently. Alternatively, the map could be filled with data @@ -55,7 +57,7 @@ public class PreparedTransitSchedule { * Conceptually, an instance of this class wraps a TransitSchedule to optimize a function of it. */ public PreparedTransitSchedule(TransitSchedule schedule) { - + } @Deprecated @@ -65,20 +67,20 @@ public PreparedTransitSchedule(TransitSchedule schedule) { public PreparedTransitSchedule() { } - + public double getNextDepartureTime(final TransitRoute route, final TransitRouteStop stop, final double depTime) { - + double earliestDepartureTimeAtTerminus = depTime - stop.getDepartureOffset().seconds(); // This shifts my time back to the terminus. - - if (earliestDepartureTimeAtTerminus >= TransitRouterNetworkTravelTimeAndDisutility.MIDNIGHT) { - earliestDepartureTimeAtTerminus = earliestDepartureTimeAtTerminus % TransitRouterNetworkTravelTimeAndDisutility.MIDNIGHT; + + if (earliestDepartureTimeAtTerminus >= MIDNIGHT) { + earliestDepartureTimeAtTerminus = earliestDepartureTimeAtTerminus % MIDNIGHT; } if (earliestDepartureTimeAtTerminus < 0) { // this may happen when depTime < departureOffset, e.g. I want to start at 24:03, but the bus departs at 23:55 at terminus - earliestDepartureTimeAtTerminus += TransitRouterNetworkTravelTimeAndDisutility.MIDNIGHT; + earliestDepartureTimeAtTerminus += MIDNIGHT; } - + // this will search for the terminus departure that corresponds to my departure at the stop: double[] cache = sortedDepartureCache.get(route); if (cache == null) { @@ -102,14 +104,14 @@ public double getNextDepartureTime(final TransitRoute route, final TransitRouteS } double bestDepartureTime = cache[pos]; // (departure time at terminus) - + bestDepartureTime += stop.getDepartureOffset().seconds(); // (resulting departure time at stop) - + while (bestDepartureTime < depTime) { - bestDepartureTime += TransitRouterNetworkTravelTimeAndDisutility.MIDNIGHT; + bestDepartureTime += MIDNIGHT; // (add enough "MIDNIGHT"s until we are _after_ the desired departure time) } return bestDepartureTime; } -} \ No newline at end of file +} diff --git a/matsim/src/main/java/org/matsim/pt/router/RouteSegment.java b/matsim/src/main/java/org/matsim/pt/router/RouteSegment.java deleted file mode 100644 index f3a9199504c..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/RouteSegment.java +++ /dev/null @@ -1,73 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2015 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.pt.router; - -import org.matsim.api.core.v01.Id; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitRoute; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; - -/** - * - * @author aneumann - * - */ -public class RouteSegment { - - final TransitStopFacility fromStop; - final TransitStopFacility toStop; - final double travelTime; - final Id lineTaken; - final Id routeTaken; - - public RouteSegment(TransitStopFacility fromStop, TransitStopFacility toStop, double travelTime, Id lineTaken, Id routeTaken) { - this.fromStop = fromStop; - this.toStop = toStop; - this.travelTime = travelTime; - this.lineTaken = lineTaken; - this.routeTaken = routeTaken; - } - - @Override - public String toString() { - return "From: " + fromStop.getId() + " to " + toStop.getId() + " in " + travelTime + "s via " + routeTaken; - } - - public double getTravelTime() { - return travelTime; - } - - public TransitStopFacility getFromStop() { - return fromStop; - } - - public TransitStopFacility getToStop() { - return toStop; - } - - public Id getLineTaken() { - return lineTaken; - } - - public Id getRouteTaken() { - return routeTaken; - } -} - diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java b/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java deleted file mode 100644 index 92a8f0202e2..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java +++ /dev/null @@ -1,534 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitDijkstra.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.Node; -import org.matsim.api.core.v01.population.Person; -import org.matsim.core.router.InitialNode; -import org.matsim.core.router.util.DijkstraNodeData; -import org.matsim.core.router.util.LeastCostPathCalculator.Path; -import org.matsim.core.router.util.TravelTime; -import org.matsim.core.utils.collections.PseudoRemovePriorityQueue; -import org.matsim.core.utils.collections.RouterPriorityQueue; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkNode; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitRoute; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.vehicles.Vehicle; - -/** - * This class is based on and similar to org.matsim.pt.router.MultiNodeDijkstra - * - * In contrast to org.matsim.pt.router.MultiNodeDijkstra, however, it stores the last - * LeastCostPathTree. It is, therefore, much faster than it, in cases where many routes - * starting with the same fromNode are calculated subsequently as every route from that - * fromCoord can be retrieved now without having to compute the tree again. - * - * Call createLeastCostPathTree(fromNodes, person, fromCoord) in order to create and cache the - * LeastCostPathTree. Every following call of getPath(toNodes) will return the leastCostPath - * from the fromNodes to the toNodes. - * - * The fromCoord you passed in createLeastCostPathTree operates as a primary key to determine - * if you are working with the LeastCostPathTree you think you are. You can just pass the - * original requested origin here. - * - * Please keep in mind, that you are responsible to order all queries in a way such that all - * those originating in the same fromCoord are done subsequently. Otherwise, the mentioned - * efficiency gain with not take effect. - * - * @author gthunig - */ -public class TransitLeastCostPathTree { - - /** - * The network on which we find routes. - */ - protected Network network; - - /** - * The cost calculator. Provides the cost for each link and time step. - */ - private final TransitTravelDisutility costFunction; - - /** - * The travel time calculator. Provides the travel time for each link and time step. - */ - private final TravelTime timeFunction; - - private final HashMap, DijkstraNodeData> nodeData; - private Person person = null; - private Vehicle vehicle = null; - private CustomDataManager customDataManager = new CustomDataManager(); - private Map fromNodes = null; - - private RouterPriorityQueue pendingNodes; - - public TransitLeastCostPathTree(final Network network, final TransitTravelDisutility costFunction, - final TravelTime timeFunction, - final Map fromNodes, final Person person) { - this.network = network; - this.costFunction = costFunction; - this.timeFunction = timeFunction; - - this.nodeData = new HashMap<>((int)(network.getNodes().size() * 1.1), 0.95f); - - //create tree - this.resetNetworkVisited(); - this.person = person; - this.customDataManager.reset(); - this.fromNodes = fromNodes; - - pendingNodes = (RouterPriorityQueue) createRouterPriorityQueue(); - for (Map.Entry entry : fromNodes.entrySet()) { - DijkstraNodeData data = getData(entry.getKey()); - visitNode(entry.getKey(), data, pendingNodes, entry.getValue().initialTime, entry.getValue().initialCost, null); - } - - // do the real work - while (pendingNodes.size() > 0) { - Node outNode = pendingNodes.poll(); - relaxNode(outNode, pendingNodes); - } - } - - public TransitLeastCostPathTree(final Network network, final TransitTravelDisutility costFunction, - final TravelTime timeFunction, - final Map fromNodes, final Map toNodes, - final Person person) { - this.network = network; - this.costFunction = costFunction; - this.timeFunction = timeFunction; - - this.nodeData = new HashMap<>((int)(network.getNodes().size() * 1.1), 0.95f); - - //create tree - this.resetNetworkVisited(); - this.person = person; - this.customDataManager.reset(); - this.fromNodes = fromNodes; - - pendingNodes = (RouterPriorityQueue) createRouterPriorityQueue(); - for (Map.Entry entry : fromNodes.entrySet()) { - DijkstraNodeData data = getData(entry.getKey()); - visitNode(entry.getKey(), data, pendingNodes, entry.getValue().initialTime, entry.getValue().initialCost, null); - } - - expandNodeData(toNodes); - } - - private int getIterationId() { -// TODO could delete all the now unnecessary occurrences of the IterationID especially in DijkstraNodeData and -// TODO replace it with a flag visited but that would interfere the useage of the MultiNodeDijkstra - return 0; - } - - /** - * Resets all nodes in the network as if they have not been visited yet. - */ - private void resetNetworkVisited() { - for (Node node : this.network.getNodes().values()) { - DijkstraNodeData data = getData(node); - data.resetVisited(); - } - } - - private void expandNodeData(final Map toNodes) { - Set endNodes = new HashSet<>(toNodes.keySet()); - double minCost = Double.POSITIVE_INFINITY; - - // do the real work - while (endNodes.size() > 0) { - Node outNode = pendingNodes.poll(); - - if (outNode == null) { - // seems we have no more nodes left, but not yet reached all endNodes... - endNodes.clear(); - } else { - DijkstraNodeData data = getData(outNode); - boolean isEndNode = endNodes.remove(outNode); - if (isEndNode) { - InitialNode initData = toNodes.get(outNode); - double cost = data.getCost() + initData.initialCost; - if (cost < minCost) { - minCost = cost; - } - } - if (data.getCost() > minCost) { - endNodes.clear(); // we can't get any better now - } else { - relaxNode(outNode, pendingNodes); - } - } - } - } - - /** - * Method to request the passenger route from the (cached) fromNodes to the passed toNodes. - * Should only be requested after calling createTransitLeastCostPathTree(). - * - * @param toNodes - * The nodes that are the next stops to the toCoord and you like to route to. - * - * @return - * the transitPassengerRoute between the fromNode and the toNode. - * Will be null if the route could not be found. - */ - public InternalTransitPassengerRoute getTransitPassengerRoute(final Map toNodes) { - //find the best node - double minCost = Double.POSITIVE_INFINITY; - Node minCostNode = null; - for (Map.Entry e : toNodes.entrySet()) { - Node currentNode = e.getKey(); - DijkstraNodeData r = this.nodeData.get(currentNode.getId()); - if (r == null) { - expandNodeData(toNodes); - } - DijkstraNodeData data = getData(currentNode); - InitialNode initData = e.getValue(); - double cost = data.getCost() + initData.initialCost; - if (data.getCost() != 0.0 || fromNodes.containsKey(currentNode)) { - if (cost < minCost) { - minCost = cost; - minCostNode = currentNode; - } - } - } - - if (minCostNode == null) { - return null; - } - - // now construct route segments, which are required for TransitPassengerRoute - List routeSegments = new ArrayList<>(); - - TransitRouterNetworkLink link = (TransitRouterNetworkLink) getData(minCostNode).getPrevLink(); - TransitRouterNetworkLink downstreamLink = null; - Node previousFromNode = minCostNode; - double transferCost = 0.; - - while (link != null) { - TransitRouterNetworkNode fromNode = link.fromNode; - TransitRouterNetworkNode toNode = link.toNode; - - double travelTime = getData(toNode).getTime() - getData(fromNode).getTime(); - Id transitLineId = null; - Id routeId = null; - - boolean isTransferLeg = false; - if (link.line==null) isTransferLeg = true; - else { - transitLineId = link.line.getId(); - routeId = link.route.getId(); - } - - if (downstreamLink==null && isTransferLeg) { - // continuous transfers: see TransitRouterImplTest.testDoubleWalk. - // Another possibility is that trip start with transfer itself, see TransitRouterImplTest.testDoubleWalkOnly. - double tempTravelTime = 0.; - TransitStopFacility toStop = null; - - if (routeSegments.size()==0) { // very first leg starts with transfer - toStop = toNode.stop.getStopFacility(); - } else { - RouteSegment routeSegment = routeSegments.remove(0); - travelTime = routeSegment.travelTime; - toStop = routeSegment.toStop; - } - - routeSegments.add(0, - new RouteSegment(fromNode.stop.getStopFacility(), - toStop, - tempTravelTime+travelTime, - transitLineId, - routeId)); - //not sure, if transferCost will be included for every transfer or not. Currently, transfer cost will be accumulated for every transfer. Amit Sep'17 - } else if (downstreamLink == null // very first pt leg or first pt leg after transfer - || isTransferLeg ) { - routeSegments.add(0, new RouteSegment( fromNode.stop.getStopFacility(), - toNode.stop.getStopFacility(), - travelTime, - transitLineId, - routeId - )); - } else if (downstreamLink.line.getId() == link.line.getId() && downstreamLink.route.getId() == link.route.getId() ){ - //same route --> update the top routeSegment - RouteSegment routeSegment = routeSegments.remove(0); - routeSegments.add(0, new RouteSegment(fromNode.stop.getStopFacility(), - routeSegment.toStop, - routeSegment.travelTime+travelTime, - transitLineId, - routeId)); - } - - if (isTransferLeg) { - // transfer cost - if ( ! (this.costFunction instanceof TransitRouterNetworkTravelTimeAndDisutility) ) { - throw new RuntimeException("TransitTravelDisutility is not instance of "+TransitRouterNetworkTravelTimeAndDisutility.class.getSimpleName() - +". An acc "); - } - - transferCost += ((TransitRouterNetworkTravelTimeAndDisutility) this.costFunction).defaultTransferCost(link, - Double.NEGATIVE_INFINITY,null,null); - - downstreamLink = null; - } else { - downstreamLink = link; - } - - previousFromNode = fromNode; - link = (TransitRouterNetworkLink) getData(fromNode).getPrevLink(); - } - - DijkstraNodeData startNodeData = getData(previousFromNode); - DijkstraNodeData toNodeData = getData(minCostNode); - - double cost = toNodeData.getCost() - startNodeData.getCost() - + this.fromNodes.get(previousFromNode).initialCost - + toNodes.get(minCostNode).initialCost - + transferCost; - - // if there is no connection found, getPath(...) return a path with nothing in it, however, I (and AN) think that it should throw null. Amit Sep'17 - if (routeSegments.size()==0) return null; - else return new InternalTransitPassengerRoute(cost, routeSegments); - } - - /** - * Method to request the path from the (cached) fromNodes to the passed toNodes. - * Should only be requested after calling createTransitLeastCostPathTree(). - * - * @param toNodes - * The nodes that are the next stops to the toCoord and you like to route to. - * - * @return - * the leastCostPath between the fromNode and the toNode. - * Will be null if the path could not be found. - */ - public Path getPath(final Map toNodes) { - - //find the best node - double minCost = Double.POSITIVE_INFINITY; - Node minCostNode = null; - for (Map.Entry e : toNodes.entrySet()) { - Node currentNode = e.getKey(); - DijkstraNodeData r = this.nodeData.get(currentNode.getId()); - if (r == null) { - expandNodeData(toNodes); - } - DijkstraNodeData data = getData(currentNode); - InitialNode initData = e.getValue(); - double cost = data.getCost() + initData.initialCost; - if (data.getCost() != 0.0 || fromNodes.containsKey(currentNode)) { - if (cost < minCost) { - minCost = cost; - minCostNode = currentNode; - } - } - } - - if (minCostNode == null) { - return null; - } - - // now construct the path - List nodes = new LinkedList<>(); - List links = new LinkedList<>(); - - nodes.add(0, minCostNode); - Link tmpLink = getData(minCostNode).getPrevLink(); - while (tmpLink != null) { - links.add(0, tmpLink); - nodes.add(0, tmpLink.getFromNode()); - tmpLink = getData(tmpLink.getFromNode()).getPrevLink(); - } - - DijkstraNodeData startNodeData = getData(nodes.get(0)); - DijkstraNodeData toNodeData = getData(minCostNode); - - return new Path(nodes, links, toNodeData.getTime() - startNodeData.getTime(), - toNodeData.getCost() - startNodeData.getCost()); - } - - /** - * Allow replacing the RouterPriorityQueue. - */ - @SuppressWarnings("static-method") - /*package*/ RouterPriorityQueue createRouterPriorityQueue() { - return new PseudoRemovePriorityQueue<>(500); - } - - /** - * Inserts the given Node n into the pendingNodes queue and updates its time - * and cost information. - * - * @param n - * The Node that is revisited. - * @param data - * The data for n. - * @param pendingNodes - * The nodes visited and not processed yet. - * @param time - * The time of the visit of n. - * @param cost - * The accumulated cost at the time of the visit of n. - * @param outLink - * The node from which we came visiting n. - */ - protected void visitNode(final Node n, final DijkstraNodeData data, - final RouterPriorityQueue pendingNodes, final double time, final double cost, - final Link outLink) { - data.visit(outLink, cost, time, getIterationId()); - pendingNodes.add(n, getPriority(data)); - } - - /** - * Expands the given Node in the routing algorithm; may be overridden in - * sub-classes. - * - * @param outNode - * The Node to be expanded. - * @param pendingNodes - * The set of pending nodes so far. - */ - protected void relaxNode(final Node outNode, final RouterPriorityQueue pendingNodes) { - - DijkstraNodeData outData = getData(outNode); - double currTime = outData.getTime(); - double currCost = outData.getCost(); - for (Link l : outNode.getOutLinks().values()) { - relaxNodeLogic(l, pendingNodes, currTime, currCost); - } - } - - /** - * Logic that was previously located in the relaxNode(...) method. - * By doing so, the FastDijkstra can overwrite relaxNode without copying the logic. - */ - /*package*/ void relaxNodeLogic(final Link l, final RouterPriorityQueue pendingNodes, - final double currTime, final double currCost) { - addToPendingNodes(l, l.getToNode(), pendingNodes, currTime, currCost); - } - - /** - * Adds some parameters to the given Node then adds it to the set of pending - * nodes. - * - * @param l - * The link from which we came to this Node. - * @param n - * The Node to add to the pending nodes. - * @param pendingNodes - * The set of pending nodes. - * @param currTime - * The time at which we started to traverse l. - * @param currCost - * The cost at the time we started to traverse l. - * @return true if the node was added to the pending nodes, false otherwise - * (e.g. when the same node already has an earlier visiting time). - */ - protected boolean addToPendingNodes(final Link l, final Node n, - final RouterPriorityQueue pendingNodes, final double currTime, - final double currCost) { - - this.customDataManager.initForLink(l); - double travelTime = this.timeFunction.getLinkTravelTime(l, currTime, this.person, this.vehicle); - double travelCost = this.costFunction.getLinkTravelDisutility(l, currTime, this.person, this.vehicle, this.customDataManager); - DijkstraNodeData data = getData(n); - double nCost = data.getCost(); - if (!data.isVisited(getIterationId())) { - visitNode(n, data, pendingNodes, currTime + travelTime, currCost + travelCost, l); - this.customDataManager.storeTmpData(); - return true; - } - double totalCost = currCost + travelCost; - if (totalCost < nCost) { - revisitNode(n, data, pendingNodes, currTime + travelTime, totalCost, l); - this.customDataManager.storeTmpData(); - return true; - } - - return false; - } - - /** - * Changes the position of the given Node n in the pendingNodes queue and - * updates its time and cost information. - * - * @param n - * The Node that is revisited. - * @param data - * The data for n. - * @param pendingNodes - * The nodes visited and not processed yet. - * @param time - * The time of the visit of n. - * @param cost - * The accumulated cost at the time of the visit of n. - * @param outLink - * The link from which we came visiting n. - */ - void revisitNode(final Node n, final DijkstraNodeData data, - final RouterPriorityQueue pendingNodes, final double time, final double cost, - final Link outLink) { - pendingNodes.remove(n); - - data.visit(outLink, cost, time, getIterationId()); - pendingNodes.add(n, getPriority(data)); - } - - /** - * The value used to sort the pending nodes during routing. - * This implementation compares the total effective travel cost - * to sort the nodes in the pending nodes queue during routing. - */ - private double getPriority(final DijkstraNodeData data) { - return data.getCost(); - } - - /** - * Returns the data for the given node. Creates a new NodeData if none exists - * yet. - * - * @param n - * The Node for which to return the data. - * @return The data for the given Node - */ - protected DijkstraNodeData getData(final Node n) { - DijkstraNodeData r = this.nodeData.get(n.getId()); - if (null == r) { - r = new DijkstraNodeData(); - this.nodeData.put(n.getId(), r); - } - return r; - } - -} \ No newline at end of file diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouter.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouter.java index 7fbe8110802..a2318e18052 100644 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouter.java +++ b/matsim/src/main/java/org/matsim/pt/router/TransitRouter.java @@ -29,6 +29,6 @@ */ public interface TransitRouter { - public abstract List calcRoute(RoutingRequest request); + List calcRoute(RoutingRequest request); } diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterImpl.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterImpl.java deleted file mode 100644 index 716490a972f..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterImpl.java +++ /dev/null @@ -1,188 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TranitRouter.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.network.Node; -import org.matsim.api.core.v01.population.Leg; -import org.matsim.api.core.v01.population.Person; -import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.core.router.InitialNode; -import org.matsim.core.router.RoutingRequest; -import org.matsim.core.router.util.TravelTime; -import org.matsim.core.utils.geometry.CoordUtils; -import org.matsim.facilities.Facility; -import org.matsim.pt.transitSchedule.api.TransitSchedule; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * Not thread-safe because MultiNodeDijkstra is not. Does not expect the TransitSchedule to change once constructed! michaz '13 - * - * @author mrieser - */ -public class TransitRouterImpl extends AbstractTransitRouter implements TransitRouter { - - private final TransitRouterNetwork transitNetwork; - private final TravelTime travelTime; - private final TransitTravelDisutility travelDisutility; - private final PreparedTransitSchedule preparedTransitSchedule; - - private boolean cacheTree; - private TransitLeastCostPathTree tree; - private Facility previousFromFacility; - private double previousDepartureTime; - - public TransitRouterImpl(final TransitRouterConfig trConfig, final TransitSchedule schedule) { - super(trConfig); - this.transitNetwork = TransitRouterNetwork.createFromSchedule(schedule, - trConfig.getBeelineWalkConnectionDistance()); - this.preparedTransitSchedule = new PreparedTransitSchedule(schedule); - TransitRouterNetworkTravelTimeAndDisutility transitRouterNetworkTravelTimeAndDisutility = new TransitRouterNetworkTravelTimeAndDisutility( - trConfig, - new PreparedTransitSchedule(schedule)); - this.travelDisutility = transitRouterNetworkTravelTimeAndDisutility; - this.travelTime = transitRouterNetworkTravelTimeAndDisutility; - setTransitTravelDisutility(this.travelDisutility); - - this.cacheTree = trConfig.isCacheTree(); - } - - public TransitRouterImpl( - final TransitRouterConfig trConfig, - final PreparedTransitSchedule preparedTransitSchedule, - final TransitRouterNetwork routerNetwork, - final TravelTime travelTime, - final TransitTravelDisutility travelDisutility) { - - super(trConfig, travelDisutility); - - this.transitNetwork = routerNetwork; - this.preparedTransitSchedule = preparedTransitSchedule; - this.travelDisutility = travelDisutility; - this.travelTime = travelTime; - - this.cacheTree = trConfig.isCacheTree(); - } - - private Map locateWrappedNearestTransitNodes(Person person, Coord coord, double departureTime) { - Collection nearestNodes = getTransitRouterNetwork().getNearestNodes( - coord, - this.getConfig().getSearchRadius()); - if (nearestNodes.size() < 2) { - // also enlarge search area if only one stop found, maybe a second one is near the border of the search area - TransitRouterNetwork.TransitRouterNetworkNode nearestNode = this.getTransitRouterNetwork() - .getNearestNode(coord); - if (nearestNode != null) { // transit schedule might be completely empty! - double distance = CoordUtils.calcEuclideanDistance(coord, - nearestNode.stop.getStopFacility().getCoord()); - nearestNodes = this.getTransitRouterNetwork() - .getNearestNodes(coord, distance + this.getConfig().getExtensionRadius()); - } - } - Map wrappedNearestNodes = new LinkedHashMap<>(); - for (TransitRouterNetwork.TransitRouterNetworkNode node : nearestNodes) { - Coord toCoord = node.stop.getStopFacility().getCoord(); - double initialTime = getWalkTime(person, coord, toCoord); - double initialCost = getWalkDisutility(person, coord, toCoord); - wrappedNearestNodes.put(node, new InitialNode(initialCost, initialTime + departureTime)); - } - return wrappedNearestNodes; - } - - @Override - public List calcRoute( final RoutingRequest request ) { - final Facility fromFacility = request.getFromFacility(); - final Facility toFacility = request.getToFacility(); - final double departureTime = request.getDepartureTime(); - final Person person = request.getPerson(); - - // find possible start stops - Map wrappedFromNodes = this.locateWrappedNearestTransitNodes(person, - fromFacility.getCoord(), - departureTime); - - - // find possible end stops - Map wrappedToNodes = this.locateWrappedNearestTransitNodes(person, - toFacility.getCoord(), - departureTime); - - InternalTransitPassengerRoute transitPassengerRoute = null; - - if (cacheTree) { - if ((fromFacility != previousFromFacility) && (departureTime != previousDepartureTime)) { // Compute tree only if fromFacility and departure time are different from previous request. - tree = new TransitLeastCostPathTree(getTransitRouterNetwork(), - getTravelDisutility(), - getTravelTime(), - wrappedFromNodes, - person); - } - } else { // Compute new tree for every routing request - tree = new TransitLeastCostPathTree(getTransitRouterNetwork(), - getTravelDisutility(), - getTravelTime(), - wrappedFromNodes, - wrappedToNodes, - person); - // yyyyyy This sounds like it is doing the full tree. But I think it is not. Kai, nov'16 - // Yes, only if you leave out the wrappedToNodes from the argument list, it does compute the full tree. See the new case above. dz, june'18 - } - - // find routes between start and end stop - transitPassengerRoute = tree.getTransitPassengerRoute(wrappedToNodes); - - if (transitPassengerRoute == null) { - return null; // TripRouter / FallbackRoutingModule will create a direct walk leg - } - double pathCost = transitPassengerRoute.getTravelCost(); - - double directWalkCost = getWalkDisutility(person, fromFacility.getCoord(), toFacility.getCoord()); - - if (directWalkCost * getConfig().getDirectWalkFactor() < pathCost) { - return null; // TripRouter / FallbackRoutingModule will create a direct walk leg - } - - previousFromFacility = fromFacility; - previousDepartureTime = departureTime; - - return convertPassengerRouteToLegList(departureTime, - transitPassengerRoute, - fromFacility.getCoord(), - toFacility.getCoord(), - person); - } - - public TransitRouterNetwork getTransitRouterNetwork() { - return transitNetwork; - } - - TravelTime getTravelTime() { - return travelTime; - } - - PreparedTransitSchedule getPreparedTransitSchedule() { - return preparedTransitSchedule; - } -} diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java deleted file mode 100644 index d72c3ce1f54..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterImplFactory.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 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.pt.router; - -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.pt.transitSchedule.api.TransitSchedule; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; -import jakarta.inject.Singleton; - -/** - * @author mrieser - */ -@Singleton -public class TransitRouterImplFactory implements Provider { - - private final TransitRouterConfig config; - private final TransitSchedule transitSchedule; - private TransitRouterNetwork routerNetwork; - private PreparedTransitSchedule preparedTransitSchedule; - - @Inject - TransitRouterImplFactory(final TransitSchedule schedule, final EventsManager events, final Config config) { - this(schedule, new TransitRouterConfig( - config.scoring(), - config.routing(), - config.transitRouter(), - config.vspExperimental())); - events.addHandler((TransitScheduleChangedEventHandler) event -> { - routerNetwork = null; - preparedTransitSchedule = null; - }); - } - - public TransitRouterImplFactory(final TransitSchedule schedule, final TransitRouterConfig config) { - this.config = config; - this.transitSchedule = schedule; - } - - @Override - public TransitRouter get() { - if (this.routerNetwork == null) { - this.routerNetwork = TransitRouterNetwork.createFromSchedule(transitSchedule, this.config.getBeelineWalkConnectionDistance()); - } - if (this.preparedTransitSchedule == null) { - this.preparedTransitSchedule = new PreparedTransitSchedule(transitSchedule); - } - - TransitRouterNetworkTravelTimeAndDisutility ttCalculator = new TransitRouterNetworkTravelTimeAndDisutility(this.config, this.preparedTransitSchedule); - return new TransitRouterImpl(this.config, this.preparedTransitSchedule, this.routerNetwork, ttCalculator, ttCalculator); - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java index ea6102825c8..95b724568f6 100644 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java +++ b/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java @@ -32,8 +32,7 @@ public void install() { if (getConfig().transit().isUseTransit()) { switch (getConfig().transit().getRoutingAlgorithmType()) { case DijkstraBased: - bind(TransitRouter.class).toProvider(TransitRouterImplFactory.class); - break; + throw new RuntimeException("'DijkstraBased' is no longer supported as a transit routing algorithm. Use 'SwissRailRaptor' instead."); case SwissRailRaptor: install(new SwissRailRaptorModule()); break; diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterNetwork.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterNetwork.java deleted file mode 100644 index 3ecc02f77dd..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterNetwork.java +++ /dev/null @@ -1,488 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterNetwork.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -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.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.NetworkFactory; -import org.matsim.api.core.v01.network.Node; -import org.matsim.core.utils.collections.IdentifiableArrayMap; -import org.matsim.core.utils.collections.QuadTree; -import org.matsim.core.utils.collections.Tuple; -import org.matsim.core.utils.geometry.CoordUtils; -import org.matsim.core.utils.misc.Counter; -import org.matsim.core.utils.misc.Time; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitRoute; -import org.matsim.pt.transitSchedule.api.TransitRouteStop; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.utils.objectattributes.attributable.Attributes; - -/** - * Converting the TransitRouterNetwork into a {@link org.matsim.core.router.util.RoutingNetwork} might - * speed up the routing and additionally reduce the memory consumption (e.g. by using array for a nodes - * in- and outgoing links). cdobler, nov'12 - * - * @author mrieser - * @author nagel - */ -public final class TransitRouterNetwork implements Network { - - private final static Logger log = LogManager.getLogger(TransitRouterNetwork.class); - - private final Map, TransitRouterNetworkLink> links = new LinkedHashMap<>(); - private final Map, TransitRouterNetworkNode> nodes = new LinkedHashMap<>(); - private QuadTree qtNodes = null; - - private long nextNodeId = 0; - private long nextLinkId = 0; - - - public static final class TransitRouterNetworkNode implements Node { - - public final TransitRouteStop stop; - public final TransitRoute route; - public final TransitLine line; - final Id id; - final Map, TransitRouterNetworkLink> ingoingLinks = new IdentifiableArrayMap<>(); - final Map, TransitRouterNetworkLink> outgoingLinks = new IdentifiableArrayMap<>(); - - public TransitRouterNetworkNode(final Id id, final TransitRouteStop stop, final TransitRoute route, final TransitLine line) { - this.id = id; - this.stop = stop; - this.route = route; - this.line = line; - } - - @Override - public Map, ? extends Link> getInLinks() { - return this.ingoingLinks; - } - - @Override - public Map, ? extends Link> getOutLinks() { - return this.outgoingLinks; - } - - @Override - public boolean addInLink(final Link link) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean addOutLink(final Link link) { - throw new UnsupportedOperationException(); - } - - @Override - public Coord getCoord() { - return this.stop.getStopFacility().getCoord(); - } - - @Override - public Id getId() { - return this.id; - } - - public TransitRouteStop getStop() { - return stop; - } - - public TransitRoute getRoute() { - return route; - } - - public TransitLine getLine() { - return line; - } - - @Override - public String toString() { - return this.id.toString(); - } - - @Override - public Link removeInLink(Id linkId) { - throw new RuntimeException("not implemented") ; - } - - @Override - public Link removeOutLink(Id outLinkId) { - throw new RuntimeException("not implemented") ; - } - - @Override - public void setCoord(Coord coord) { - throw new RuntimeException("not implemented") ; - } - - @Override - public Attributes getAttributes() { - throw new UnsupportedOperationException(); - } - } - - /** - * Looks to me like an implementation of the Link interface, with get(Transit)Route and get(Transit)Line on top. - * To recall: TransitLine is something like M44. But it can have more than one route, e.g. going north, going south, - * long route, short route. That is, presumably we have one such TransitRouterNetworkLink per TransitRoute. kai/manuel, feb'12 - */ - public static final class TransitRouterNetworkLink implements Link { - - public final TransitRouterNetworkNode fromNode; - public final TransitRouterNetworkNode toNode; - final TransitRoute route; - final TransitLine line; - final Id id; - private final double length; - - public TransitRouterNetworkLink(final Id id, final TransitRouterNetworkNode fromNode, final TransitRouterNetworkNode toNode, final TransitRoute route, final TransitLine line, double length) { - this.id = id; - this.fromNode = fromNode; - this.toNode = toNode; - this.route = route; - this.line = line; - this.length = length; - } - - public TransitRouterNetworkLink(final Id id, final TransitRouterNetworkNode fromNode, final TransitRouterNetworkNode toNode, final TransitRoute route, final TransitLine line) { - this(id, fromNode, toNode, route, line, CoordUtils.calcEuclideanDistance(toNode.stop.getStopFacility().getCoord(), fromNode.stop.getStopFacility().getCoord())); - } - - @Override - public TransitRouterNetworkNode getFromNode() { - return this.fromNode; - } - - @Override - public TransitRouterNetworkNode getToNode() { - return this.toNode; - } - - @Override - public double getCapacity() { - return 9999; - } - - @Override - public double getCapacity(final double time) { - return getCapacity(); - } - - @Override - public double getFreespeed() { - return 10; - } - - @Override - public double getFreespeed(final double time) { - return getFreespeed(); - } - - @Override - public Id getId() { - return this.id; - } - - @Override - public double getNumberOfLanes() { - return 1; - } - - @Override - public double getNumberOfLanes(final double time) { - return getNumberOfLanes(); - } - - @Override - public double getLength() { - return this.length; - } - - @Override - public void setCapacity(final double capacity) { - throw new UnsupportedOperationException(); - } - - @Override - public void setFreespeed(final double freespeed) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean setFromNode(final Node node) { - throw new UnsupportedOperationException(); - } - - @Override - public void setNumberOfLanes(final double lanes) { - throw new UnsupportedOperationException(); - } - - @Override - public void setLength(final double length) { - throw new UnsupportedOperationException(); - } - - @Override - public boolean setToNode(final Node node) { - throw new UnsupportedOperationException(); - } - - @Override - public Coord getCoord() { - throw new UnsupportedOperationException(); - } - - @Override - public Set getAllowedModes() { - return null; - } - - @Override - public void setAllowedModes(final Set modes) { - throw new UnsupportedOperationException(); - } - - public TransitRoute getRoute() { - return route; - } - - public TransitLine getLine() { - return line; - } - - @Override - public String toString() { - return "[" + this.id.toString() + " (" + this.getFromNode().id + " > " + this.getToNode().id + ")]"; - } - - @Override - public double getCapacityPeriod() { - throw new UnsupportedOperationException(); - } - - @Override - public Attributes getAttributes() { - throw new UnsupportedOperationException(); - } - } - - public TransitRouterNetworkNode createNode(final TransitRouteStop stop, final TransitRoute route, final TransitLine line) { - final TransitRouterNetworkNode node = new TransitRouterNetworkNode(Id.create(this.nextNodeId++, Node.class), stop, route, line); - this.nodes.put(node.getId(), node); - return node; - } - - public TransitRouterNetworkLink createLink(final TransitRouterNetworkNode fromNode, final TransitRouterNetworkNode toNode, final TransitRoute route, final TransitLine line) { - final TransitRouterNetworkLink link = new TransitRouterNetworkLink(Id.create(this.nextLinkId++, Link.class), fromNode, toNode, route, line); - this.links.put(link.getId(), link); - fromNode.outgoingLinks.put(link.getId(), link); - toNode.ingoingLinks.put(link.getId(), link); - return link; - } - - @Override - public Map, ? extends TransitRouterNetworkNode> getNodes() { - return this.nodes; - } - - @Override - public Map, ? extends TransitRouterNetworkLink> getLinks() { - return this.links; - } - - public void finishInit() { - double minX = Double.POSITIVE_INFINITY; - double minY = Double.POSITIVE_INFINITY; - double maxX = Double.NEGATIVE_INFINITY; - double maxY = Double.NEGATIVE_INFINITY; - - for (TransitRouterNetworkNode node : this.nodes.values()) { - Coord c = node.stop.getStopFacility().getCoord(); - if (c.getX() < minX) { - minX = c.getX(); - } - if (c.getY() < minY) { - minY = c.getY(); - } - if (c.getX() > maxX) { - maxX = c.getX(); - } - if (c.getY() > maxY) { - maxY = c.getY(); - } - } - - QuadTree quadTree = new QuadTree(minX, minY, maxX, maxY); - for (TransitRouterNetworkNode node : this.nodes.values()) { - Coord c = node.stop.getStopFacility().getCoord(); - quadTree.put(c.getX(), c.getY(), node); - } - this.qtNodes = quadTree; - } - - public Collection getNearestNodes(final Coord coord, final double distance) { - return this.qtNodes.getDisk(coord.getX(), coord.getY(), distance); - } - - public TransitRouterNetworkNode getNearestNode(final Coord coord) { - return this.qtNodes.getClosest(coord.getX(), coord.getY()); - } - - @Override - public double getCapacityPeriod() { - return 3600.0; - } - - @Override - public NetworkFactory getFactory() { - return null; - } - - @Override - public double getEffectiveLaneWidth() { - return 3; - } - - @Override - public void addNode(Node nn) { - throw new UnsupportedOperationException(); - } - - @Override - public void addLink(Link ll) { - throw new UnsupportedOperationException(); - } - - @Override - public Link removeLink(Id linkId) { - throw new UnsupportedOperationException(); - } - - @Override - public Node removeNode(Id nodeId) { - throw new UnsupportedOperationException(); - } - - public static TransitRouterNetwork createFromSchedule(final TransitSchedule schedule, final double maxBeelineWalkConnectionDistance) { - log.info("start creating transit network"); - final TransitRouterNetwork network = new TransitRouterNetwork(); - final Counter linkCounter = new Counter(" link #"); - final Counter nodeCounter = new Counter(" node #"); - // build nodes and links connecting the nodes according to the transit routes - for (TransitLine line : schedule.getTransitLines().values()) { - for (TransitRoute route : line.getRoutes().values()) { - TransitRouterNetworkNode prevNode = null; - for (TransitRouteStop stop : route.getStops()) { - TransitRouterNetworkNode node = network.createNode(stop, route, line); - nodeCounter.incCounter(); - if (prevNode != null) { - network.createLink(prevNode, node, route, line); - linkCounter.incCounter(); - } - prevNode = node; - } - } - } - network.finishInit(); // not nice to call "finishInit" here before we added all links... - // in my view, it would be possible to completely do without finishInit: do the - // additions to the central data structures as items come in, not near the end. I would - // prefer that because nobody could forget the "finishInit". kai, apr'10 - // well, not really. finishInit creates the quadtree, for this, the extent must be known, - // which is not at the very start, so the quadtree data structure cannot be updated as - // links come in. mrieser, dec'10 - log.info("add transfer links"); - - List> toBeAdded = new LinkedList>(); - // connect all stops with walking links if they're located less than beelineWalkConnectionDistance from each other - for (TransitRouterNetworkNode node : network.getNodes().values()) { - if (node.getInLinks().size() > 0) { // only add links from this node to other nodes if agents actually can arrive here - for (TransitRouterNetworkNode node2 : network.getNearestNodes(node.stop.getStopFacility().getCoord(), maxBeelineWalkConnectionDistance)) { - if ((node != node2) && (node2.getOutLinks().size() > 0)) { // only add links to other nodes when agents can depart there - if ((node.line != node2.line) || (node.stop.getStopFacility() != node2.stop.getStopFacility())) { - // do not yet add them to the network, as this would change in/out-links - toBeAdded.add(new Tuple(node, node2)); - } - } - } - } - } - log.info(toBeAdded.size() + " transfer links to be added."); - for (Tuple tuple : toBeAdded) { - network.createLink(tuple.getFirst(), tuple.getSecond(), null, null); - linkCounter.incCounter(); - } - - log.info("transit router network statistics:"); - log.info(" # nodes: " + network.getNodes().size()); - log.info(" # links total: " + network.getLinks().size()); - log.info(" # transfer links: " + toBeAdded.size()); - - return network; - } - - @Override - public void setCapacityPeriod(double capPeriod) { - throw new RuntimeException("not implemented") ; - } - - @Override - public void setEffectiveCellSize(double effectiveCellSize) { - throw new RuntimeException("not implemented") ; - } - - @Override - public void setEffectiveLaneWidth(double effectiveLaneWidth) { - throw new RuntimeException("not implemented") ; - } - - @Override - public void setName(String name) { - throw new RuntimeException("not implemented") ; - } - - @Override - public String getName() { - throw new RuntimeException("not implemented") ; - } - - @Override - public double getEffectiveCellSize() { - throw new RuntimeException("not implemented") ; - } - - @Override - public Attributes getAttributes() { - throw new UnsupportedOperationException(); - } -} diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeAndDisutility.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeAndDisutility.java deleted file mode 100644 index 79de4237b65..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeAndDisutility.java +++ /dev/null @@ -1,219 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterNetworkCost.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.population.Person; -import org.matsim.core.router.util.TravelTime; -import org.matsim.core.utils.geometry.CoordUtils; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink; -import org.matsim.pt.transitSchedule.api.TransitRouteStop; -import org.matsim.vehicles.Vehicle; - -/** - * TravelTime and TravelCost calculator to be used with the transit network used for transit routing. - * - * This class is NOT thread-safe! - * - * @author mrieser - */ -public class TransitRouterNetworkTravelTimeAndDisutility implements TravelTime, TransitTravelDisutility { - - final static double MIDNIGHT = 24.0*3600; - - protected final TransitRouterConfig config; - private Link previousLink = null; - private double previousTime = Double.NaN; - private double cachedTravelTime = Double.NaN; - - private final PreparedTransitSchedule preparedTransitSchedule; - - /* - * If this constructor is used, every instance use its own PreparedTransitSchedule which might - * consume a lot of memory. - * - * cdobler, nov'12 - */ - @Deprecated - public TransitRouterNetworkTravelTimeAndDisutility(final TransitRouterConfig config) { - this(config, new PreparedTransitSchedule()); - } - - public TransitRouterNetworkTravelTimeAndDisutility(final TransitRouterConfig config, PreparedTransitSchedule preparedTransitSchedule) { - this.config = config; - this.preparedTransitSchedule = preparedTransitSchedule; - } - - @Override - public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager) { - double cost; - if (((TransitRouterNetworkLink) link).getRoute() == null) { - // "route" here means "pt route". If no pt route is attached, it means that it is a transfer link. - - cost = defaultTransferCost(link, time, person, vehicle); - - } else { - double offVehWaitTime = offVehicleWaitTime(link, time); - double inVehTime = getLinkTravelTime(link,time, person, vehicle) - offVehWaitTime; - cost = - inVehTime * this.config.getMarginalUtilityOfTravelTimePt_utl_s() - -offVehWaitTime * this.config.getMarginalUtilityOfWaitingPt_utl_s() - -link.getLength() * this.config.getMarginalUtilityOfTravelDistancePt_utl_m(); - - } - return cost; - } - - /** - * method to allow inclusion of offVehicleWaitTime without code replication. kai, oct'12 - * - * @param link - * @param time - * @return - */ - protected double offVehicleWaitTime(final Link link, final double time) { - double offVehWaitTime=0; - double nextVehArrivalTime = getVehArrivalTime(link, time); - if (time < nextVehArrivalTime){ // it means the agent waits outside the veh - offVehWaitTime = nextVehArrivalTime-time; - } - return offVehWaitTime; - - } - - /** - * convenience method for derived classes in order to bring Manuel's version closer to this one here. - * kai, oct'12 - */ - protected final double defaultTransferCost(final Link link, final double time, - final Person person, final Vehicle vehicle) { - double cost; - double transfertime = getLinkTravelTime(link, time, person, vehicle); - double waittime = this.config.getAdditionalTransferTime(); - - // say that the effective walk time is the transfer time minus some "buffer" - double walktime = transfertime - waittime; - // (this looks like walktime might become negative. But at least in the default version, the additional transfer time is always - // _added_ to the walk time (see getLinkTravelTime below) so at least in that case this cannot happen. kai, triggered by cd, may'16) - if ( walktime < 0. ) { - throw new RuntimeException( "negative walk time; should not happen; needs to be repaired" ) ; - } - - double walkDistance = link.getLength(); - - // weigh this "buffer" not with the walk time disutility, but with the wait time disutility: - // (note that this is the same "additional disutl of wait" as in the scoring function. Its default is zero. - // only if you are "including the opportunity cost of time into the router", then the disutility of waiting will - // be the same as the marginal opprotunity cost of time). kai, nov'11 - cost = - walktime * this.config.getMarginalUtilityOfTravelTimeWalk_utl_s() - - walkDistance * this.config.getMarginalUtilityOfTravelDistanceWalk_utl_m() - - waittime * this.config.getMarginalUtilityOfWaitingPt_utl_s() - - this.config.getUtilityOfLineSwitch_utl(); - return cost; - } - - @Override - public double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle) { - if ((link == this.previousLink) && (time == this.previousTime)) { - return this.cachedTravelTime; - } - this.previousLink = link; - this.previousTime = time; - - TransitRouterNetworkLink wrapped = (TransitRouterNetworkLink) link; - TransitRouteStop fromStop = wrapped.fromNode.stop; - TransitRouteStop toStop = wrapped.toNode.stop; - if (wrapped.route != null) { - // (agent stays on the same route, so use transit line travel time) - - // get the next departure time: - double bestDepartureTime = preparedTransitSchedule.getNextDepartureTime(wrapped.route, fromStop, time); - - // the travel time on the link is - // the time until the departure (``dpTime - now'') - // + the travel time on the link (there.arrivalTime - here.departureTime) - // But quite often, we only have the departure time at the next stop. Then we use that: - double arrivalOffset = toStop.getArrivalOffset().or(toStop::getDepartureOffset).seconds(); - double time2 = (bestDepartureTime - time) + (arrivalOffset - fromStop.getDepartureOffset().seconds()); - if (time2 < 0) { - // ( this can only happen, I think, when ``bestDepartureTime'' is after midnight but ``time'' was before ) - time2 += MIDNIGHT; - } - this.cachedTravelTime = time2; - return time2; - } - // different transit routes, so it must be a line switch - double distance = wrapped.getLength(); - double time2 = distance / this.config.getBeelineWalkSpeed() + this.config.getAdditionalTransferTime(); - this.cachedTravelTime = time2; - return time2; - } - - //variables for caching offVehWaitTime - Link previousWaitLink; - double previousWaitTime; - double cachedVehArrivalTime; - - public double getVehArrivalTime(final Link link, final double now){ - if ((link == this.previousWaitLink) && (now == this.previousWaitTime)) { - return this.cachedVehArrivalTime; - } - this.previousWaitLink = link; - this.previousWaitTime = now; - - //first find out vehicle arrival time to fromStop according to transit schedule - TransitRouterNetworkLink wrapped = (TransitRouterNetworkLink) link; - if (wrapped.getRoute() == null) { - throw new RuntimeException("should not happen") ; - } - TransitRouteStop fromStop = wrapped.fromNode.stop; - - double nextDepartureTime = preparedTransitSchedule.getNextDepartureTime(wrapped.getRoute(), fromStop, now); - - double fromStopDepartureOffset = fromStop.getDepartureOffset().seconds(); - double fromStopArrivalOffset = fromStop.getArrivalOffset().orElse(fromStopDepartureOffset); - double vehWaitAtStopTime = fromStopDepartureOffset - fromStopArrivalOffset; //time in which the veh stops at station - double vehArrivalTime = nextDepartureTime - vehWaitAtStopTime; - cachedVehArrivalTime = vehArrivalTime ; - return vehArrivalTime ; - } - - @Override - public double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord) { - // getMarginalUtilityOfTravelTimeWalk INCLUDES the opportunity cost of time. kai, dec'12 - double timeCost = - getWalkTravelTime(person, coord, toCoord) * config.getMarginalUtilityOfTravelTimeWalk_utl_s() ; - // (sign: margUtl is negative; overall it should be positive because it is a cost.) - - double distanceCost = - CoordUtils.calcEuclideanDistance(coord,toCoord) * - config.getBeelineDistanceFactor() * config.getMarginalUtilityOfTravelDistanceWalk_utl_m(); - // (sign: same as above) - - return timeCost + distanceCost ; - } - - @Override - public double getWalkTravelTime(Person person, Coord coord, Coord toCoord) { - double distance = CoordUtils.calcEuclideanDistance(coord, toCoord); - double initialTime = distance / config.getBeelineWalkSpeed(); - return initialTime; - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitTravelDisutility.java b/matsim/src/main/java/org/matsim/pt/router/TransitTravelDisutility.java deleted file mode 100644 index e069df124b4..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitTravelDisutility.java +++ /dev/null @@ -1,54 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2012 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.pt.router; - -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.population.Person; -import org.matsim.vehicles.Vehicle; - -/** - * @author mrieser / senozon - */ -public interface TransitTravelDisutility { - - /** - * Returns the disutility to travel on the specified link at the specified time. - * - * @param link The link for which the travel disutility is calculated. - * @param time The departure time (in seconds since 00:00) at the beginning of the link for which the disutility is calculated. - * @param person The person that wants to travel along the link. Note that this parameter can be null! - * @param vehicle The vehicle with which the person wants to travel along the link. Note that this parameter can be null! - * @param dataManager A helper class to enable the cost calculator store arbitrary data during one routing request. - * @return The disutility to travel over the link link, departing at time time. - */ - public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager); - - /** - * This is used for walking to and from the nearest transit stop from the start and end location, - * as well as for the "direct" walk from start to finish without using a pt line at all. - * It is not used for transfer links (these are handled by the transitTravelDisutility). - */ - double getWalkTravelTime(Person person, Coord coord, Coord toCoord); - - double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord); - - -} diff --git a/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java b/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java index c1c442de687..3789e469a25 100644 --- a/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java +++ b/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java @@ -17,9 +17,6 @@ * * * *********************************************************************** */ -/** - * - */ package org.matsim.examples.simple; import java.util.List; @@ -61,7 +58,7 @@ public class PtScoringTest { @Parameterized.Parameters public static Object[] testParameters() { - return new Object[] {TypicalDurationScoreComputation.relative,TypicalDurationScoreComputation.uniform}; + return new Object[] {TypicalDurationScoreComputation.relative, TypicalDurationScoreComputation.uniform}; } @Rule public MatsimTestUtils utils = new MatsimTestUtils(); @@ -69,7 +66,6 @@ public static Object[] testParameters() { @Test public void test_PtScoringLineswitch() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple-lineswitch"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); ScoringConfigGroup pcs = config.scoring() ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ @@ -210,10 +206,10 @@ public void test_PtScoringLineswitch() { System.out.println(" score: " + pp.getSelectedPlan().getScore() ) ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ - Assert.assertEquals(-21.28929580072052, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(-21.280962467387187, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(27.46011565686209, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(27.468448990195423, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } } @@ -222,7 +218,6 @@ public void test_PtScoringLineswitch() { @Test public void test_PtScoringLineswitchAndPtConstant() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple-lineswitch"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); ScoringConfigGroup pcs = config.scoring() ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)) @@ -366,10 +361,10 @@ public void test_PtScoringLineswitchAndPtConstant() { if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ // Assert.assertEquals(89.14608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; - Assert.assertEquals(-19.28929580072052, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(-19.280962467387187, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(29.46011565686209, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(29.468448990195423, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } } @@ -378,8 +373,7 @@ public void test_PtScoringLineswitchAndPtConstant() { @Test public void test_PtScoring_Wait() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); - ScoringConfigGroup pcs = config.scoring() ; + ScoringConfigGroup pcs = config.scoring(); if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ for(ActivityParams params : pcs.getActivityParams()){ @@ -453,10 +447,10 @@ public void test_PtScoring_Wait() { System.out.println("agent score: " + pp.getSelectedPlan().getScore() ) ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ - Assert.assertEquals(89.14608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(89.13108279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(137.14608279715043, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(137.1310827971504, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } } @@ -465,7 +459,6 @@ public void test_PtScoring_Wait() { @Test public void test_PtScoring() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); ScoringConfigGroup pcs = config.scoring() ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)) @@ -536,10 +529,10 @@ public void test_PtScoring() { System.out.println(" score: " + pp.getSelectedPlan().getScore() ) ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ - Assert.assertEquals(89.85608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(89.87441613048377, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(137.85608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(137.87441613048375, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } diff --git a/matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java b/matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java deleted file mode 100644 index abaf360b0e7..00000000000 --- a/matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterNetworkTravelTimeCostTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink; -import org.matsim.testcases.MatsimTestUtils; - -/** - * Tests that specifically look at the computation of the out-of-vehicle wait time. There is overlap with the original tests; it is most - * probably possible to combine/condense them. - *

- * Comments:
    - *
  • As far as I can tell, it is not tested if other utility values for the out-of-vehicle wait times influences the results. - * This should/could be done in org.matsim.examples.simple.PtScoringTest . - * - * @author manuel after mrieser - */ - -public class AdaptedTransitRouterNetworkTravelTimeCostTest { - - @Test public void testTravelTime() { - //create the scenario test - Fixture f = new Fixture(); - f.init(); - - //create the adapted router - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule) ; - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - - // find the link connecting C and G on the red line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == f.redLine) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("G"))) { - testLink = link; - } - } - //at 6:00 the link travel time = 540 - assertEquals(9.0*60, tc.getLinkTravelTime(testLink, 6.0*3600, null, null), MatsimTestUtils.EPSILON); - } - - @Test public void testVehArrivalTime() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule) ; - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == f.blueLine) && (link.fromNode.stop.getStopFacility().getName().equals("C")) - && (link.toNode.stop.getStopFacility().getName().equals("D"))) { - testLink = link; - } - } - - //original MATSim. same as before - assertEquals(9.0*60 , tc.getLinkTravelTime(testLink, 6.0*3600, null, null) , MatsimTestUtils.EPSILON); - assertEquals(9.0*60+1 , tc.getLinkTravelTime(testLink, 6.0*3600-1, null, null) , MatsimTestUtils.EPSILON); - - /* - //if the agents arrives to stop (in or outside the veh) before 06:02, his/her "arrrival veh time" is 05:58 - //veh arrival time to stop= 05:58 - //veh departure from stop = 06:02 - //System.out.println("veh arr: " + timecost.getVehArrivalTime(testLink , (6.0*3600) + (1*60))); - //System.out.println("next departure: " + timecost.getNextDepartureTime(testLink.getRoute(), testLink.getFromNode().getStop(), (6.0*3600) + 60)); - */ - - //this arrival would be for waiting outside the vehicle at the stop - assertEquals((5.0*3600) + (58*60) , tc.getVehArrivalTime(testLink, (5.0*3600) + (56*60)), MatsimTestUtils.EPSILON); - assertEquals((5.0*3600) + (58*60) , tc.getVehArrivalTime(testLink, (5.0*3600) + (57*60)), MatsimTestUtils.EPSILON); - - //this arrival would be for waiting inside the vehicle - assertEquals((5.0*3600) + (58*60) , tc.getVehArrivalTime(testLink, (5.0*3600) + (58*60)), MatsimTestUtils.EPSILON); - assertEquals((5.0*3600) + (58*60) , tc.getVehArrivalTime(testLink, (5.0*3600) + (59*60)), MatsimTestUtils.EPSILON); - assertEquals((5.0*3600) + (58*60) , tc.getVehArrivalTime(testLink, (6.0*3600) + (1*60)), MatsimTestUtils.EPSILON); - assertEquals((5.0*3600) + (58*60) , tc.getVehArrivalTime(testLink, (6.0*3600) + (2*60)), MatsimTestUtils.EPSILON); - - //if the agents arrives after to stop after 06:02, his/her "arrrival veh time" is displaced to 06:18 - assertEquals((6.0*3600) + (18*60) , tc.getVehArrivalTime(testLink, (6.0*3600) + (3*60)), MatsimTestUtils.EPSILON); - } - - @Test public void testTravelTimeAfterMidnight() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule) ; - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == f.blueLine) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("D"))) { - testLink = link; - } - } - - //original - // planned departure at 25:00, has to wait until 05:22 = 29:22 - assertEquals(22.0*60 + 4.0*3600 + 7.0*60, tc.getLinkTravelTime(testLink, 25.0*3600, null, null ), MatsimTestUtils.EPSILON); - //after adaption : next veh arrival is in 29:18 - assertEquals((29.0*3600) + (18*60.0) , tc.getVehArrivalTime(testLink, 25.0*3600), MatsimTestUtils.EPSILON); - - //original - // planned departure at 47:00, has to wait until 05:22 = 53:22 - assertEquals(22.0*60 + 6.0*3600 + 7.0*60, tc.getLinkTravelTime(testLink, 47.0*3600, null, null), MatsimTestUtils.EPSILON); - //after adaption : next veh arrival is in 53:18 - assertEquals((53.0*3600) + (18*60.0), tc.getVehArrivalTime(testLink, 47.0*3600), MatsimTestUtils.EPSILON); - - //original - // planned departure at 49:00, has to wait until 05:22 = 53:22, tests explicitly > 2*MIDNIGHT - assertEquals(22.0*60 + 4.0*3600 + 7.0*60, tc.getLinkTravelTime(testLink, 49.0*3600, null, null), MatsimTestUtils.EPSILON); - //after adaption : next veh arrival is in 53:18 - assertEquals((53.0*3600) + (18*60.0), tc.getVehArrivalTime(testLink, 49.0*3600), MatsimTestUtils.EPSILON); - } - - @Test public void testTravelCostLineSwitch() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule) ; - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == null) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("C"))) { - testLink = link; - } - } - - double oldCost = - conf.getUtilityOfLineSwitch_utl(); - double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); - conf.setUtilityOfLineSwitch_utl(0.0); - double cost2 = tc.getLinkTravelDisutility(testLink, 6.0*3600, null, null, null); // use different time because of internal caching effects - assertEquals(oldCost, cost1 - cost2, MatsimTestUtils.EPSILON); - conf.setUtilityOfLineSwitch_utl(-40.125); - double cost3 = tc.getLinkTravelDisutility(testLink, 5.0*3600, null, null, null); - assertEquals(40.125, cost3 - cost2, MatsimTestUtils.EPSILON); - } - - - @Test public void testTravelCostLineSwitch_AdditionalTransferTime() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule) ; - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == null) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("C"))) { - testLink = link; - } - } - - double oldCost = - conf.getUtilityOfLineSwitch_utl(); - double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); - conf.setUtilityOfLineSwitch_utl(0.0); - double cost2 = tc.getLinkTravelDisutility(testLink, 6.0*3600, null, null, null); // use different time because of internal caching effects - assertEquals(oldCost, cost1 - cost2, MatsimTestUtils.EPSILON); - conf.setAdditionalTransferTime(120.0); - double cost3 = tc.getLinkTravelDisutility(testLink, 5.0*3600, null, null, null); - assertEquals(-120.0 * conf.getMarginalUtilityOfWaitingPt_utl_s(), cost3 - cost2, MatsimTestUtils.EPSILON); - // test with custom value for utility of waiting, just in case too many of the default marginal utilities are 0.0 - conf.setMarginalUtilityOfWaitingPt_utl_s(-12.0 / 3600.0); - double cost4 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); - assertEquals(120.0 * 12.0 / 3600.0, cost4 - cost2, MatsimTestUtils.EPSILON); - } - - -} diff --git a/matsim/src/test/java/org/matsim/pt/router/TransitLeastCostPathTreeTest.java b/matsim/src/test/java/org/matsim/pt/router/TransitLeastCostPathTreeTest.java deleted file mode 100644 index b168007ee70..00000000000 --- a/matsim/src/test/java/org/matsim/pt/router/TransitLeastCostPathTreeTest.java +++ /dev/null @@ -1,239 +0,0 @@ - -/* *********************************************************************** * - * project: org.matsim.* - * TransitLeastCostPathTreeTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2019 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.pt.router; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.assertj.core.api.Assertions; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.Node; -import org.matsim.api.core.v01.population.Person; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.network.NetworkUtils; -import org.matsim.core.router.InitialNode; -import org.matsim.core.router.util.LeastCostPathCalculator.Path; -import org.matsim.core.router.util.TravelTime; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.pt.transitSchedule.api.TransitScheduleReader; -import org.matsim.testcases.MatsimTestUtils; -import org.matsim.vehicles.Vehicle; - -/** - * Junit Test for the TransitLeastCostPathTree. - * - * @author gabriel.thunig on 23.05.2016. - */ -public class TransitLeastCostPathTreeTest { - - private TransitRouterNetwork network; - private TransitRouterNetworkTravelTimeAndDisutility travelDisutility; - - /** - * Instantiates a new TransitLeastCostPathTree object with a sample transitSchedule and default configuration. - */ - public void instantiateNetworkAndTravelDisutility() { - String transitScheduleFile = "test/scenarios/pt-tutorial/transitschedule.xml"; - - Config config = ConfigUtils.createConfig(); - Scenario scenario = ScenarioUtils.loadScenario(config); - scenario.getConfig().transit().setUseTransit(true); - TransitScheduleReader reader = new TransitScheduleReader(scenario); - TransitRouterConfig transitRouterConfig = new TransitRouterConfig(scenario.getConfig()); - reader.readFile(transitScheduleFile); - TransitSchedule transitSchedule = scenario.getTransitSchedule(); - network = TransitRouterNetwork.createFromSchedule(transitSchedule, transitRouterConfig.getBeelineWalkConnectionDistance()); - - PreparedTransitSchedule preparedTransitSchedule = new PreparedTransitSchedule(transitSchedule); - travelDisutility = new TransitRouterNetworkTravelTimeAndDisutility(transitRouterConfig, preparedTransitSchedule); - } - - /** - * Check whether the @Before-instantiation is instantiating a network and a travelDisutility. - */ - @Test - public void TestNetworkAndTravelDisutilityInstantiated() { - instantiateNetworkAndTravelDisutility(); - Assert.assertNotNull(network); - Assert.assertNotNull(travelDisutility); - } - - /** - * Get the very next transitNode. - * @param person Which person we are routing for. For default leave null. - * @param coord The origin of the tree. - * @param departureTime The time the person departures at the origin. - * @return the next transitNode. - */ - private Map locateWrappedNearestTransitNode(Person person, Coord coord, double departureTime) { - TransitRouterNetwork.TransitRouterNetworkNode nearestNode = network.getNearestNode(coord); - Map wrappedNearestNodes = new LinkedHashMap<>(); - Coord toCoord = nearestNode.stop.getStopFacility().getCoord(); - double initialTime = travelDisutility.getWalkTravelTime(person, coord, toCoord); - double initialCost = travelDisutility.getWalkTravelDisutility(person, coord, toCoord); - wrappedNearestNodes.put(nearestNode, new InitialNode(initialCost, initialTime + departureTime)); - return wrappedNearestNodes; - } - - /** - * Try to route a standard connection. - */ - @Test - public void TestValidRouting() { - instantiateNetworkAndTravelDisutility(); - Coord fromCoord = new Coord(1050d, 1050d); - Map wrappedFromNodes = this.locateWrappedNearestTransitNode(null, fromCoord, 28800); - TransitLeastCostPathTree tree = new TransitLeastCostPathTree(network, travelDisutility, travelDisutility, wrappedFromNodes, null); - Coord toCoord = new Coord(3950d, 1050d); - Map wrappedToNodes = this.locateWrappedNearestTransitNode(null, toCoord, 28800); - Path path = tree.getPath(wrappedToNodes); - Assert.assertNotNull(path); - double pathCost = path.travelCost; - Assert.assertEquals(1.8d, pathCost, MatsimTestUtils.EPSILON); - double pathTime = path.travelTime; - Assert.assertEquals(540d, pathTime, MatsimTestUtils.EPSILON); - } - - /** - * Try to route a connection with interchange. - */ - @Test - public void TestValidRoutingWithInterchange() { - instantiateNetworkAndTravelDisutility(); - Coord fromCoord = new Coord(1050d, 1050d); - Map wrappedFromNodes = this.locateWrappedNearestTransitNode(null, fromCoord, 28800); - TransitLeastCostPathTree tree = new TransitLeastCostPathTree(network, travelDisutility, travelDisutility, wrappedFromNodes, null); - Coord toCoord = new Coord(2050d, 2960d); - Map wrappedToNodes = this.locateWrappedNearestTransitNode(null, toCoord, 28800); - Path path = tree.getPath(wrappedToNodes); - Assert.assertNotNull(path); - double pathCost = path.travelCost; - Assert.assertEquals(1.7706666666666668d, pathCost, MatsimTestUtils.EPSILON); - double pathTime = path.travelTime; - Assert.assertEquals(231.20000000000073d, pathTime, MatsimTestUtils.EPSILON); - } - - @Ignore - @Test - public void TestSpeedImprovementOnStopCriterion() { - Fixture f = new Fixture(); - TestTimeCost tc = new TestTimeCost(); - for (int i = 0; i < f.count-1; i++) { - tc.setData(Id.create(i, Link.class), 1.0, 1.0); - } - Map fromNodes = new HashMap<>(); - fromNodes.put(f.network.getNodes().get(Id.create(0, Node.class)), new InitialNode(0.0, 0.0)); - Map toNodes = new HashMap<>(); - toNodes.put(f.network.getNodes().get(Id.create(1, Node.class)), new InitialNode(0.0, 0.0)); - for (Node node : fromNodes.keySet()) { - System.out.println("From Node = " + node.getCoord()); - } - for (Node node : toNodes.keySet()) { - System.out.println("To Node = " + node.getCoord()); - } - long startTime = System.currentTimeMillis(); - new TransitLeastCostPathTree(f.network, tc, tc, fromNodes, null); - long endTime = System.currentTimeMillis(); - long elapsedTimeWithoutStopCreterion = (endTime - startTime); - startTime = System.currentTimeMillis(); - new TransitLeastCostPathTree(f.network, tc, tc, fromNodes, toNodes, null); - endTime = System.currentTimeMillis(); - long elapsedTimeWithStopCreterion = (endTime - startTime); - Double bareRatio = (double)elapsedTimeWithoutStopCreterion / (double)elapsedTimeWithStopCreterion; - System.out.println("bareRatio = " + bareRatio); - int ratio = (int) ((bareRatio) * 10); - System.out.println("Time without stop criterion = " + elapsedTimeWithoutStopCreterion); - System.out.println("Time with stop criterion = " + elapsedTimeWithStopCreterion); - System.out.println("ratio = " + ratio); - Assertions.assertThat(ratio).isGreaterThan(15); - } - - /** - * Creates a simple network to be used in TestSpeedImprovementOnStopCriterion. - * - *
    -     *   (0)--(1)--(2)--...--(9997)--(9998)--(9999)
    -     * 
    - * - * @author gthunig - */ - /*package*/ static class Fixture { - /*package*/ Network network; - - int count = 10000; - - public Fixture() { - this.network = NetworkUtils.createNetwork(); - Node linkStartNode = NetworkUtils.createAndAddNode(this.network, Id.create(0, Node.class), new Coord((double) 0, (double) 0)); - for (int i = 1; i < count; i++) { - Node linkEndNode = NetworkUtils.createAndAddNode(this.network, Id.create(i, Node.class), new Coord((double) i, (double) 0)); - final Node fromNode = linkStartNode; - final Node toNode = linkEndNode; - NetworkUtils.createAndAddLink(this.network,Id.create(i-1, Link.class), fromNode, toNode, 1000.0, 10.0, 2000.0, (double) 1 ); - linkStartNode = linkEndNode; - } - - } - } - - /*package*/ static class TestTimeCost implements TravelTime, TransitTravelDisutility { - - private final Map, Double> travelTimes = new HashMap<>(); - private final Map, Double> travelCosts = new HashMap<>(); - - public void setData(final Id id, final double travelTime, final double travelCost) { - this.travelTimes.put(id, travelTime); - this.travelCosts.put(id, travelCost); - } - - @Override - public double getLinkTravelTime(final Link link, final double time, Person person, Vehicle vehicle) { - return this.travelTimes.get(link.getId()); - } - - @Override - public double getLinkTravelDisutility(final Link link, final double time, final Person person, final Vehicle vehicle, final CustomDataManager dataManager) { - return this.travelCosts.get(link.getId()); - } - - @Override - public double getWalkTravelTime(Person person, Coord coord, Coord toCoord) { - return 0; - } - - @Override - public double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord) { - return 0; - } - - } -} diff --git a/matsim/src/test/java/org/matsim/pt/router/TransitRouterCustomDataTest.java b/matsim/src/test/java/org/matsim/pt/router/TransitRouterCustomDataTest.java deleted file mode 100644 index da34930a8be..00000000000 --- a/matsim/src/test/java/org/matsim/pt/router/TransitRouterCustomDataTest.java +++ /dev/null @@ -1,208 +0,0 @@ - -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterCustomDataTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2019 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.pt.router; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.population.Person; -import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.router.DefaultRoutingRequest; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkNode; -import org.matsim.pt.transitSchedule.api.Departure; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitRoute; -import org.matsim.pt.transitSchedule.api.TransitRouteStop; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.pt.transitSchedule.api.TransitScheduleFactory; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.vehicles.Vehicle; - -/** - * @author mrieser / senozon - */ -public class TransitRouterCustomDataTest { - @Test - public void testCustomDataIntegration() { - Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); - scenario.getConfig().transit().setUseTransit(true); - createTestSchedule(scenario); - - TransitRouterConfig trConfig = new TransitRouterConfig(scenario.getConfig().scoring(), - scenario.getConfig().routing(), scenario.getConfig().transitRouter(), - scenario.getConfig().vspExperimental()); - trConfig.setBeelineWalkSpeed(0.1); // something very slow, so the agent does not walk over night - trConfig.setSearchRadius(200); - - TransitRouterNetworkTravelTimeAndDisutility transitRouterNetworkTravelTimeAndDisutility = new TransitRouterNetworkTravelTimeAndDisutility(trConfig); - - MockingTransitTravelDisutility disutility = new MockingTransitTravelDisutility(transitRouterNetworkTravelTimeAndDisutility); - - TransitRouterNetwork transitNetwork = TransitRouterNetwork.createFromSchedule(scenario.getTransitSchedule(), trConfig.getBeelineWalkConnectionDistance()); - - TransitRouterImpl router = new TransitRouterImpl(trConfig, new PreparedTransitSchedule(scenario.getTransitSchedule()), transitNetwork, transitRouterNetworkTravelTimeAndDisutility, disutility); - - double x = -100; - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility( new Coord(x, (double) 0)), new FakeFacility( new Coord((double) 3100, (double) 0)), 5.9*3600, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", legs); - - /* the following is not really nice as a test, but I had to somehow - * keep track of the internal state and have to replay this now - * to ensure everything works as expected... - */ - Assert.assertEquals(8, disutility.states.size()); - Assert.assertEquals("[[1>2 @ 22240.0]]", disutility.states.get(0)); // first link to be expanded: from stop 1 to stop 2, line 1 - Assert.assertEquals("[[1>3 @ 22240.0]]", disutility.states.get(1)); // now from stop 1 to stop 3, line 2 - Assert.assertEquals("[[1>2 @ 22240.0], [2>3 @ 108300.0]]", disutility.states.get(2)); // from stop 2 to stop 3, coming from stop 1 before, line 1 - Assert.assertEquals("[[1>2 @ 22240.0], [2>3 @ 108300.0], [3>4 @ 108600.0]]", disutility.states.get(3)); // continuing on line 1 - Assert.assertEquals("[[1>2 @ 22240.0], [2>3 @ 108300.0], [3>3 @ 108600.0]]", disutility.states.get(4)); // transfer at stop 3, coming from line 1, to line 2 - Assert.assertEquals("[[1>3 @ 22240.0], [3>5 @ 108690.0]]", disutility.states.get(5)); // continue on line 2 - Assert.assertEquals("[[1>3 @ 22240.0], [3>3 @ 108690.0]]", disutility.states.get(6)); // transfer at stop 3, coming from line 2, should be a dead end - Assert.assertEquals("[[1>2 @ 22240.0], [2>3 @ 108300.0], [3>4 @ 108600.0], [4>5 @ 108900.0]]", disutility.states.get(7)); // continue on line 1 - - /* important to notice: - * state[4] should be ignored, as it is a worse result than previously found solutions. - * The ignoring of the state can be seen e.g. in state[5] which continues on line 2 state[4] switched to, - * but using the original travel sequence. - */ - } - - private static class MockingTransitTravelDisutility implements TransitTravelDisutility { - - private final TransitRouterNetworkTravelTimeAndDisutility routerDisutility; - private ArrayList states = new ArrayList<>(); - - public MockingTransitTravelDisutility(final TransitRouterNetworkTravelTimeAndDisutility routerDisutility) { - this.routerDisutility = routerDisutility; - } - - @Override - public double getLinkTravelDisutility(Link link, double time, - Person person, Vehicle vehicle, CustomDataManager dataManager) { - double val = this.routerDisutility.getLinkTravelDisutility(link, time, person, vehicle, dataManager); - - System.out.print("handling link " + ((TransitRouterNetworkNode) link.getFromNode()).getStop().getStopFacility().getId() - + ">" + ((TransitRouterNetworkNode) link.getToNode()).getStop().getStopFacility().getId()); - ArrayList links = new ArrayList<>(); - Object o = dataManager.getFromNodeCustomData(); - if (o instanceof ArrayList) { - links.addAll((Collection) o); - } - links.add(new LoggerData(link, time)); - String newState = Arrays.toString(links.toArray(new LoggerData[links.size()])); - System.out.println(" : " + newState); - this.states.add(newState); - dataManager.setToNodeCustomData(links); - - return val; - } - - @Override - public double getWalkTravelDisutility(Person person, Coord coord, Coord toCoord) { - return routerDisutility.getWalkTravelDisutility(person, coord, toCoord); - } - - @Override - public double getWalkTravelTime(Person person, Coord coord, Coord toCoord) { - return routerDisutility.getWalkTravelTime(person, coord, toCoord); - } - - } - - private static class LoggerData { - private final Link link; - private final double time; - public LoggerData(final Link link, final double time) { - this.link = link; - this.time = time; - } - @Override - public String toString() { - return "[" + ((TransitRouterNetworkNode) link.getFromNode()).getStop().getStopFacility().getId() - + ">" + ((TransitRouterNetworkNode) link.getToNode()).getStop().getStopFacility().getId() - + " @ " + time + "]"; - } - } - - /** - * Creates the following test schedule: - * - * - * (2) (4) - * / \ / \ - * / \ / \ - * / \ / \ - * (1)-------(3)-------(5) - * - * line 1 traveling from 1 to 2 to 3 to 4 to 5 - * line 2 traveling from 1 to 3 to 5, slower from 1 to 3 than line 1, faster from 3 to 5 and from 5 to 7 - * - */ - private final void createTestSchedule(final Scenario scenario) { - TransitSchedule schedule = scenario.getTransitSchedule(); - TransitScheduleFactory f = schedule.getFactory(); - - TransitStopFacility f1 = f.createTransitStopFacility(Id.create("1", TransitStopFacility.class), new Coord((double) 0, (double) 0), false); - TransitStopFacility f2 = f.createTransitStopFacility(Id.create("2", TransitStopFacility.class), new Coord((double) 500, (double) 500), false); - TransitStopFacility f3 = f.createTransitStopFacility(Id.create("3", TransitStopFacility.class), new Coord((double) 1000, (double) 0), false); - TransitStopFacility f4 = f.createTransitStopFacility(Id.create("4", TransitStopFacility.class), new Coord((double) 1500, (double) 500), false); - TransitStopFacility f5 = f.createTransitStopFacility(Id.create("5", TransitStopFacility.class), new Coord((double) 2000, (double) 0), false); - - schedule.addStopFacility(f1); - schedule.addStopFacility(f2); - schedule.addStopFacility(f3); - schedule.addStopFacility(f4); - schedule.addStopFacility(f5); - - TransitLine line1 = f.createTransitLine(Id.create("1", TransitLine.class)); - List stops = new ArrayList<>(); - stops.add(f.createTransitRouteStopBuilder(f1).departureOffset(0.0).build()); - stops.add(f.createTransitRouteStopBuilder(f2).departureOffset(300.0).build()); - stops.add(f.createTransitRouteStopBuilder(f3).departureOffset(600.0).build()); - stops.add(f.createTransitRouteStopBuilder(f4).departureOffset(900.0).build()); - stops.add(f.createTransitRouteStopBuilder(f5).arrivalOffset(1200.0).build()); - TransitRoute route1 = f.createTransitRoute(Id.create("1", TransitRoute.class), null, stops, "pt"); - line1.addRoute(route1); - schedule.addTransitLine(line1); - route1.addDeparture(f.createDeparture(Id.create("1", Departure.class), 6.0*3600)); - - TransitLine line2 = f.createTransitLine(Id.create("2", TransitLine.class)); - List stops2 = new ArrayList<>(); - stops2.add(f.createTransitRouteStopBuilder(f1).departureOffset(0.0).build()); - stops2.add(f.createTransitRouteStopBuilder(f3).departureOffset(750.0).build()); - stops2.add(f.createTransitRouteStopBuilder(f5).arrivalOffset(1100.0).build()); - TransitRoute route2 = f.createTransitRoute(Id.create("2", TransitRoute.class), null, stops2, "pt"); - line2.addRoute(route2); - schedule.addTransitLine(line2); - route2.addDeparture(f.createDeparture(Id.create("2", Departure.class), 6.0*3600 - 60)); - } -} diff --git a/matsim/src/test/java/org/matsim/pt/router/TransitRouterImplTest.java b/matsim/src/test/java/org/matsim/pt/router/TransitRouterImplTest.java deleted file mode 100644 index ad312f938b2..00000000000 --- a/matsim/src/test/java/org/matsim/pt/router/TransitRouterImplTest.java +++ /dev/null @@ -1,869 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * NewTransitRouteTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.api.core.v01.network.Node; -import org.matsim.api.core.v01.population.Activity; -import org.matsim.api.core.v01.population.Leg; -import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigUtils; -import org.matsim.core.population.routes.NetworkRoute; -import org.matsim.core.population.routes.RouteUtils; -import org.matsim.core.router.DefaultRoutingModules; -import org.matsim.core.router.DefaultRoutingRequest; -import org.matsim.core.router.RoutingModule; -import org.matsim.core.router.TransitRouterWrapper; -import org.matsim.core.scenario.MutableScenario; -import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.utils.geometry.CoordUtils; -import org.matsim.facilities.ActivityFacilities; -import org.matsim.facilities.ActivityFacility; -import org.matsim.pt.routes.TransitPassengerRoute; -import org.matsim.pt.transitSchedule.api.Departure; -import org.matsim.pt.transitSchedule.api.TransitLine; -import org.matsim.pt.transitSchedule.api.TransitRoute; -import org.matsim.pt.transitSchedule.api.TransitRouteStop; -import org.matsim.pt.transitSchedule.api.TransitSchedule; -import org.matsim.pt.transitSchedule.api.TransitScheduleFactory; -import org.matsim.pt.transitSchedule.api.TransitStopFacility; -import org.matsim.testcases.MatsimTestUtils; - -/** - * @author mrieser - */ -@RunWith(Parameterized.class) -public class TransitRouterImplTest { - private static final Logger log = LogManager.getLogger(TransitRouterImplTest.class) ; - - private String routerType ; - - @Parameters(name = "{index}: TransitRouter == {0}") - public static Collection createRouterTypes() { - Object[] router = new Object [] { - "standard" -// ,TransitRouterType.raptor - }; - return Arrays.asList(router); - } - - public TransitRouterImplTest( String routerType ) { - log.warn( "using router=" + routerType ) ; - this.routerType = routerType; - } - - @Test - public void testSingleLine() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig()); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord fromCoord = new Coord(3800, 5100); - Coord toCoord = new Coord(16100, 5050); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 5.0*3600, null)); - assertEquals(3, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(1)).getRoute() instanceof TransitPassengerRoute); - TransitPassengerRoute ptRoute = (TransitPassengerRoute) ((Leg)legs.get(1)).getRoute(); - assertEquals(Id.create("0", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("6", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.blueLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("blue A > I", TransitRoute.class), ptRoute.getRouteId()); - double actualTravelTime = 0.0; - for (PlanElement leg : legs) { - actualTravelTime += ((Leg)leg).getTravelTime().seconds(); - } - double expectedTravelTime = 29.0 * 60 + // agent takes the *:06 course, arriving in D at *:29 - CoordUtils.calcEuclideanDistance(f.schedule.getFacilities().get(Id.create("6", TransitStopFacility.class)).getCoord(), toCoord) / trConfig.getBeelineWalkSpeed(); - assertEquals(expectedTravelTime, actualTravelTime, MatsimTestUtils.EPSILON); - } - - protected TransitRouter createTransitRouter(TransitSchedule schedule, TransitRouterConfig trConfig, String routerType) { - TransitRouter router = null ; - switch( routerType ) { -// case raptor: -// double costPerMeterTraveled = 0. ; -// double costPerBoarding = 0. ; -// RaptorDisutility raptorDisutility = new RaptorDisutility(trConfig, costPerBoarding, costPerMeterTraveled); -// TransitRouterQuadTree transitRouterQuadTree = new TransitRouterQuadTree(raptorDisutility); -// transitRouterQuadTree.initializeFromSchedule(schedule, trConfig.getBeelineWalkConnectionDistance()); -// router = new Raptor(transitRouterQuadTree, raptorDisutility, trConfig) ; -// break; - case "standard": - router = new TransitRouterImpl(trConfig, schedule); - break; - default: - break; - } - return router; - } - - @Test - public void testFromToSameStop() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig()); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord fromCoord = new Coord((double) 3800, (double) 5100); - Coord toCoord = new Coord((double) 4100, (double) 5050); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 5.0*3600, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", legs); - } - - @Test - public void testDirectWalkCheaper() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord fromCoord = new Coord((double) 4000, (double) 3000); - Coord toCoord = new Coord((double) 8000, (double) 3000); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 5.0*3600, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", legs); - } - - @Test - public void testSingleLine_DifferentWaitingTime() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord fromCoord = new Coord((double) 4000, (double) 5002); - Coord toCoord = new Coord((double) 8000, (double) 5002); - - double inVehicleTime = 7.0*60; // travel time from A to B - for (int min = 0; min < 30; min += 3) { - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 5.0*3600 + min*60, null)); - assertEquals(3, legs.size()); // walk-pt-walk - double actualTravelTime = 0.0; - for (PlanElement leg : legs) { - actualTravelTime += ((Leg)leg).getTravelTime().seconds(); - } - double waitingTime = ((46 - min) % 20) * 60; // departures at *:06 and *:26 and *:46 - assertEquals("expected different waiting time at 05:"+min, waitingTime, actualTravelTime - inVehicleTime, MatsimTestUtils.EPSILON); - } - } - - @Test - public void testLineChange() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord toCoord = new Coord((double) 16100, (double) 10050); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord((double) 3800, (double) 5100)), new FakeFacility(toCoord), 6.0*3600, null)); - assertEquals(5, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(3)).getMode()); - assertEquals(TransportMode.walk, ((Leg)legs.get(4)).getMode()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(1)).getRoute() instanceof TransitPassengerRoute); - TransitPassengerRoute ptRoute = (TransitPassengerRoute) ((Leg)legs.get(1)).getRoute(); - assertEquals(Id.create("0", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("4", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.blueLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("blue A > I", TransitRoute.class), ptRoute.getRouteId()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(3)).getRoute() instanceof TransitPassengerRoute); - ptRoute = (TransitPassengerRoute) ((Leg)legs.get(3)).getRoute(); - assertEquals(Id.create("18", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("19", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.greenLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("green clockwise", TransitRoute.class), ptRoute.getRouteId()); - double actualTravelTime = 0.0; - for (PlanElement leg : legs) { - actualTravelTime += ((Leg)leg).getTravelTime().seconds(); - } - double expectedTravelTime = 31.0 * 60 + // agent takes the *:06 course, arriving in C at *:18, departing at *:21, arriving in K at*:31 - CoordUtils.calcEuclideanDistance(f.schedule.getFacilities().get(Id.create("19", TransitStopFacility.class)).getCoord(), toCoord) / trConfig.getBeelineWalkSpeed(); - assertEquals(expectedTravelTime, actualTravelTime, MatsimTestUtils.EPSILON); - } - - @Test - public void testTransferWalkDistance(){ - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig config = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouter router = createTransitRouter(f.schedule, config, routerType); - Coord fromCoord = new Coord((double) 3800, (double) 5100); - Coord toCoord = new Coord((double) 16100, (double) 10050); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 6.0*3600, null)); - Leg leg1 = (Leg) legs.get(1); - TransitPassengerRoute route1 = (TransitPassengerRoute) leg1.getRoute(); - Coord coord1 = f.schedule.getFacilities().get(route1.getEgressStopId()).getCoord(); - Leg leg3 = (Leg) legs.get(3); - TransitPassengerRoute route3 = (TransitPassengerRoute) leg3.getRoute(); - Coord coord3 = f.schedule.getFacilities().get(route3.getAccessStopId()).getCoord(); - double beelineFactor = f.scenario.getConfig().routing().getModeRoutingParams().get(TransportMode.walk).getBeelineDistanceFactor(); - assertEquals(CoordUtils.calcEuclideanDistance(coord1, coord3) * beelineFactor, - ((Leg)legs.get(2)).getRoute().getDistance(), MatsimTestUtils.EPSILON); - } - - @Test - public void testFasterAlternative() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord toCoord = new Coord((double) 28100, (double) 4950); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility( new Coord((double) 3800, (double) 5100)), new FakeFacility(toCoord), 5.0*3600 + 40.0*60, null)); - assertEquals(4, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(2)).getMode()); - assertEquals(TransportMode.walk, ((Leg)legs.get(3)).getMode()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(1)).getRoute() instanceof TransitPassengerRoute); - TransitPassengerRoute ptRoute = (TransitPassengerRoute) ((Leg)legs.get(1)).getRoute(); - assertEquals(Id.create("0", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("4", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.blueLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("blue A > I", TransitRoute.class), ptRoute.getRouteId()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(2)).getRoute() instanceof TransitPassengerRoute); - ptRoute = (TransitPassengerRoute) ((Leg)legs.get(2)).getRoute(); - assertEquals(Id.create("4", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("12", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.redLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("red C > G", TransitRoute.class), ptRoute.getRouteId()); - double actualTravelTime = 0.0; - for (PlanElement leg : legs) { - actualTravelTime += ((Leg)leg).getTravelTime().seconds(); - } - double expectedTravelTime = 29.0 * 60 + // agent takes the *:46 course, arriving in C at *:58, departing at *:00, arriving in G at*:09 - CoordUtils.calcEuclideanDistance(f.schedule.getFacilities().get(Id.create("12", TransitStopFacility.class)).getCoord(), toCoord) / trConfig.getBeelineWalkSpeed(); - assertEquals(expectedTravelTime, actualTravelTime, MatsimTestUtils.EPSILON); - } - - @Test - public void testTransferWeights() { - /* idea: travel from C to F - * If starting at the right time, one could take the red line to G and travel back with blue to F. - * If one doesn't want to switch lines, one could take the blue line from C to F directly. - * Using the red line (dep *:00, change at G *:09/*:12) results in an arrival time of *:19, - * using the blue line only (dep *:02) results in an arrival time of *:23. So the line switch - * cost must be larger than 4 minutes to have an effect. - */ - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - trConfig.setUtilityOfLineSwitch_utl(0); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null)); - assertEquals(5, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(f.redLine.getId(), ((TransitPassengerRoute) ((Leg)legs.get(1)).getRoute()).getLineId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(3)).getMode()); - assertEquals(f.blueLine.getId(), ((TransitPassengerRoute) ((Leg)legs.get(3)).getRoute()).getLineId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(4)).getMode()); - - trConfig.setUtilityOfLineSwitch_utl(300.0 * trConfig.getMarginalUtilityOfTravelTimePt_utl_s()); // corresponds to 5 minutes transit travel time - legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null)); - assertEquals(3, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(f.blueLine.getId(), ((TransitPassengerRoute) ((Leg)legs.get(1)).getRoute()).getLineId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - } - - @Test - public void testTransferTime() { - /* idea: travel from C to F - * If starting at the right time, one could take the red line to G and travel back with blue to F. - * If one doesn't want to switch lines, one could take the blue line from C to F directly. - * Using the red line (dep *:00, change at G *:09/*:12) results in an arrival time of *:19, - * using the blue line only (dep *:02) results in an arrival time of *:23. - * For the line switch at G, 3 minutes are available. If the additional "savety" time is larger than - * that, the direct connection should be taken. - */ - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - trConfig.setUtilityOfLineSwitch_utl(0); - assertEquals(0, trConfig.getAdditionalTransferTime(), 1e-8); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null)); - assertEquals(5, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(f.redLine.getId(), ((TransitPassengerRoute) ((Leg)legs.get(1)).getRoute()).getLineId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(3)).getMode()); - assertEquals(f.blueLine.getId(), ((TransitPassengerRoute) ((Leg)legs.get(3)).getRoute()).getLineId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(4)).getMode()); - - trConfig.setAdditionalTransferTime(3.0*60); // 3 mins already enough, as there is a small distance to walk anyway which adds some time - router = createTransitRouter(f.schedule, trConfig, routerType); // this is necessary to update the router for any change in config. At least raptor transit router fails without this. Amit Sep'17. - legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord((double) 11900, (double) 5100)), new FakeFacility(new Coord((double) 24100, (double) 4950)), 6.0*3600 - 5.0*60, null)); - assertEquals(3, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(f.blueLine.getId(), ((TransitPassengerRoute) ((Leg)legs.get(1)).getRoute()).getLineId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - } - - @Test - public void testAfterMidnight() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - trConfig.setBeelineWalkSpeed(0.1); // something very slow, so the agent does not walk over night - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - Coord toCoord = new Coord((double) 16100, (double) 5050); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord((double) 3800, (double) 5100)), new FakeFacility(toCoord), 25.0*3600, null)); - assertEquals(3, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(1)).getRoute() instanceof TransitPassengerRoute); - TransitPassengerRoute ptRoute = (TransitPassengerRoute) ((Leg)legs.get(1)).getRoute(); - assertEquals(Id.create("0", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("6", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.blueLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("blue A > I", TransitRoute.class), ptRoute.getRouteId()); - double actualTravelTime = 0.0; - for (PlanElement leg : legs) { - actualTravelTime += ((Leg)leg).getTravelTime().seconds(); - } - double expectedTravelTime = 4*3600 + 29.0 * 60 + // arrival at 05:29 at D - CoordUtils.calcEuclideanDistance(f.schedule.getFacilities().get(Id.create("6", TransitStopFacility.class)).getCoord(), toCoord) / trConfig.getBeelineWalkSpeed(); - assertEquals(expectedTravelTime, actualTravelTime, MatsimTestUtils.EPSILON); - } - - @Test - public void testCoordFarAway() { - Fixture f = new Fixture(); - f.init(); - final TransitRouterConfig trConfig = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental() ); - TransitRouter router = createTransitRouter(f.schedule, trConfig, routerType); - double x = +42000; - double x1 = -2000; - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(new Coord(x1, (double) 0)), new FakeFacility(new Coord(x, (double) 0)), 5.5*3600, null)); // should map to stops A and I - assertEquals(3, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertTrue("expected TransitRoute in leg.", ((Leg)legs.get(1)).getRoute() instanceof TransitPassengerRoute); - TransitPassengerRoute ptRoute = (TransitPassengerRoute) ((Leg)legs.get(1)).getRoute(); - assertEquals(Id.create("0", TransitStopFacility.class), ptRoute.getAccessStopId()); - assertEquals(Id.create("16", TransitStopFacility.class), ptRoute.getEgressStopId()); - assertEquals(f.blueLine.getId(), ptRoute.getLineId()); - assertEquals(Id.create("blue A > I", TransitRoute.class), ptRoute.getRouteId()); - } - - /** - * In rare cases, Dijkstra may choose to go along two walk links to get from one location to another. - * Test, that still only one walk leg with the correct start and end points/links is returned. - */ - @Test - public void testDoubleWalk() { - WalkFixture f = new WalkFixture(); - f.routerConfig.setMarginalUtilityOfTravelTimePt_utl_s(-1.0 / 3600.0 - 6.0/3600.0); - f.routerConfig.setUtilityOfLineSwitch_utl(0.2); // must be relatively low in this example, otherwise it's cheaper to walk the whole distance... - TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(f.coord1), new FakeFacility(f.coord7), 990, null)); - assertEquals(5, legs.size()); - assertEquals(TransportMode.walk, ((Leg)legs.get(0)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(1)).getMode()); - assertEquals(f.stop1.getId(), ((TransitPassengerRoute) ((Leg)legs.get(1)).getRoute()).getAccessStopId()); - assertEquals(f.stop2.getId(), ((TransitPassengerRoute) ((Leg)legs.get(1)).getRoute()).getEgressStopId()); - assertEquals(f.stop1.getLinkId(), ((Leg)legs.get(1)).getRoute().getStartLinkId()); - assertEquals(f.stop2.getLinkId(), ((Leg)legs.get(1)).getRoute().getEndLinkId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(2)).getMode()); - assertEquals(TransportMode.pt, ((Leg)legs.get(3)).getMode()); - assertEquals(f.stop2.getLinkId(), ((Leg)legs.get(2)).getRoute().getStartLinkId()); - assertEquals(f.stop6.getLinkId(), ((Leg)legs.get(2)).getRoute().getEndLinkId()); - assertEquals(f.stop6.getId(), ((TransitPassengerRoute) ((Leg)legs.get(3)).getRoute()).getAccessStopId()); - assertEquals(f.stop7.getId(), ((TransitPassengerRoute) ((Leg)legs.get(3)).getRoute()).getEgressStopId()); - assertEquals(f.stop6.getLinkId(), ((Leg)legs.get(3)).getRoute().getStartLinkId()); - assertEquals(f.stop7.getLinkId(), ((Leg)legs.get(3)).getRoute().getEndLinkId()); - assertEquals(TransportMode.walk, ((Leg)legs.get(4)).getMode()); - } - - /** - * Tests that if only a single transfer-/walk-link is found, the router correctly only returns - * on walk leg from start to end. - */ - @Test - public void testSingleWalkOnly() { - WalkFixture f = new WalkFixture(); - f.routerConfig.setSearchRadius(0.8 * CoordUtils.calcEuclideanDistance(f.coord2, f.coord4)); - f.routerConfig.setExtensionRadius(0.0); - - TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(f.coord2), new FakeFacility(f.coord4), 990, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", legs); - } - - /** - * Tests that if only exactly two transfer-/walk-link are found, the router correctly only returns - * on walk leg from start to end. Differs from {@link #testSingleWalkOnly()} in that it tests for - * the correct internal working when more than one walk links are returned. - */ - @Test - public void testDoubleWalkOnly() { - WalkFixture f = new WalkFixture(); - f.routerConfig.setSearchRadius(0.8 * CoordUtils.calcEuclideanDistance(f.coord2, f.coord4)); - f.routerConfig.setExtensionRadius(0.0); - - TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(f.coord2), new FakeFacility(f.coord6), 990, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", legs); - } - - @SuppressWarnings("unchecked") - @Test - public void testLongTransferTime() { - // 5 minutes additional transfer time - { - TransferFixture f = new TransferFixture(5 * 60.0); - TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); - Coord fromCoord = f.fromFacility.getCoord(); - Coord toCoord = f.toFacility.getCoord(); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 7.0*3600 + 50*60, null)); - double legDuration = calcTripDuration(new ArrayList<>(legs)); - Assert.assertEquals(5, legs.size()); - Assert.assertEquals(100, ((Leg)legs.get(0)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s; arrival at 07:51:40 - Assert.assertEquals(800, ((Leg)legs.get(1)).getTravelTime().seconds(), 0.0); // 8m 20s waiting for pt departure and 5m pt travel time -> 500s + 300s = 800s; arrival at 08:05:00 - Assert.assertEquals(304, ((Leg)legs.get(2)).getTravelTime().seconds(), 0.0); // 0.004km with 1m/s walk speed and additional waiting time -> 4s + 300s = 304s; arrival at 08:10:04 - Assert.assertEquals(596, ((Leg)legs.get(3)).getTravelTime().seconds(), 0.0); // 4m 56s waiting for pt departure and 5m pt travel time -> 296s + 300s = 596s; arrival at 08:15:00 - Assert.assertEquals(100, ((Leg)legs.get(4)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s - Assert.assertEquals(1900.0, legDuration, 0.0); - - RoutingModule walkRoutingModule = DefaultRoutingModules.createTeleportationRouter(TransportMode.walk, f.scenario, - f.config.routing().getModeRoutingParams().get(TransportMode.walk)); - - TransitRouterWrapper wrapper = new TransitRouterWrapper( - router, - f.schedule, - f.scenario.getNetwork(), // use a walk router in case no PT path is found - walkRoutingModule); - - List planElements = (List) wrapper.calcRoute(DefaultRoutingRequest.withoutAttributes(f.fromFacility, f.toFacility, 7.0*3600 + 50*60, null)); - double tripDuration = calcTripDuration(planElements); - Assert.assertEquals(9, planElements.size()); - Assert.assertEquals(100, ((Leg)planElements.get(0)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s; arrival at 07:51:40 - Assert.assertEquals(800, ((Leg)planElements.get(2)).getTravelTime().seconds(), 0.0); // 8m 20s waiting for pt departure and 5m pt travel time -> 500s + 300s = 800s; arrival at 08:05:00 - Assert.assertEquals(304, ((Leg)planElements.get(4)).getTravelTime().seconds(), 0.0); // 0.004km with 1m/s walk speed and additional waiting time -> 4s + 300s = 304s; arrival at 08:10:04 - Assert.assertEquals(596, ((Leg)planElements.get(6)).getTravelTime().seconds(), 0.0); // 4m 56s waiting for pt departure and 5m pt travel time -> 296s + 300s = 596s; arrival at 08:15:00 - Assert.assertEquals(100, ((Leg)planElements.get(8)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s - Assert.assertEquals(1900.0, tripDuration, 0.0); - } - - // 65 minutes additional transfer time - miss one departure - { - TransferFixture f = new TransferFixture(65 * 60.0); - TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); - Coord fromCoord = f.fromFacility.getCoord(); - Coord toCoord = f.toFacility.getCoord(); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 7.0*3600 + 50*60, null)); - double legDuration = calcTripDuration(new ArrayList<>(legs)); - Assert.assertEquals(5, legs.size()); - Assert.assertEquals(100, ((Leg)legs.get(0)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s; arrival at 07:51:40 - Assert.assertEquals(800, ((Leg)legs.get(1)).getTravelTime().seconds(), 0.0); // 8m 20s waiting for pt departure and 5m pt travel time -> 500s + 300s = 800s; arrival at 08:05:00 - Assert.assertEquals(3904, ((Leg)legs.get(2)).getTravelTime().seconds(), 0.0); // 0.004km with 1m/s walk speed and additional waiting time -> 4s + 3900s = 3904s; arrival at 09:10:04 - Assert.assertEquals(596, ((Leg)legs.get(3)).getTravelTime().seconds(), 0.0); // 4m 56s waiting for pt departure and 5m pt travel time -> 296s + 300s = 596s; arrival at 09:15:00 - Assert.assertEquals(100, ((Leg)legs.get(4)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s - Assert.assertEquals(5500.0, legDuration, 0.0); - - RoutingModule walkRoutingModule = DefaultRoutingModules.createTeleportationRouter(TransportMode.walk, f.scenario, - f.config.routing().getModeRoutingParams().get(TransportMode.walk)); - - TransitRouterWrapper wrapper = new TransitRouterWrapper( - router, - f.schedule, - f.scenario.getNetwork(), // use a walk router in case no PT path is found - walkRoutingModule); - - List planElements = (List) wrapper.calcRoute(DefaultRoutingRequest.withoutAttributes(f.fromFacility, f.toFacility, 7.0*3600 + 50*60, null)); - double tripDuration = calcTripDuration(planElements); - Assert.assertEquals(9, planElements.size()); - Assert.assertEquals(100, ((Leg)planElements.get(0)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s; arrival at 07:51:40 - Assert.assertEquals(800, ((Leg)planElements.get(2)).getTravelTime().seconds(), 0.0); // 8m 20s waiting for pt departure and 5m pt travel time -> 500s + 300s = 800s; arrival at 08:05:00 - Assert.assertEquals(3904, ((Leg)planElements.get(4)).getTravelTime().seconds(), 0.0); // 0.004km with 1m/s walk speed and additional waiting time -> 4s + 3900s = 3904s; arrival at 09:10:04 - Assert.assertEquals(596, ((Leg)planElements.get(6)).getTravelTime().seconds(), 0.0); // 4m 56s waiting for pt departure and 5m pt travel time -> 296s + 300s = 596s; arrival at 09:15:00 - Assert.assertEquals(100, ((Leg)planElements.get(8)).getTravelTime().seconds(), 0.0); // 0.1km with 1m/s walk speed -> 100s - Assert.assertEquals(5500.0, tripDuration, 0.0); - } - - // 600 minutes additional transfer time - miss all departures - { - TransferFixture f = new TransferFixture(600 * 60.0); - TransitRouter router = createTransitRouter(f.schedule, f.routerConfig, routerType); - Coord fromCoord = f.fromFacility.getCoord(); - Coord toCoord = f.toFacility.getCoord(); - List legs = router.calcRoute(DefaultRoutingRequest.withoutAttributes(new FakeFacility(fromCoord), new FakeFacility(toCoord), 7.0*3600 + 50*60, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", legs); - - RoutingModule walkRoutingModule = DefaultRoutingModules.createTeleportationRouter(TransportMode.walk, f.scenario, - f.config.routing().getModeRoutingParams().get(TransportMode.walk)); - - TransitRouterWrapper wrapper = new TransitRouterWrapper( - router, - f.schedule, - f.scenario.getNetwork(), // use a walk router in case no PT path is found - walkRoutingModule); - - List planElements = (List) wrapper.calcRoute(DefaultRoutingRequest.withoutAttributes(f.fromFacility, f.toFacility, 7.0*3600 + 50*60, null)); - Assert.assertNull("The router should not find a route and return null, but did return something else.", planElements); - } - } - - private static double calcTripDuration(List planElements) { - double duration = 0.0; - for (PlanElement pe : planElements) { - if (pe instanceof Activity) { - Activity act = (Activity) pe; - if (act.getStartTime().isDefined() && act.getEndTime().isDefined()) { - double startTime = act.getStartTime().seconds(); - double endTime = act.getEndTime().seconds(); - duration += (endTime - startTime); - } - } else if (pe instanceof Leg) { - Leg leg = (Leg) pe; - duration += leg.getTravelTime().seconds(); - } - } - return duration; - } - - /** - * Generates the following network for testing: - *
    -	 *                (5)
    -	 *                 |
    -	 *                 3
    -	 *                 |
    -	 * (1)---1---(2)  (4)  (6)---4---(7)
    -	 *                 |
    -	 *                 2
    -	 *                 |
    -	 *                (3)
    -	 * 
    - * Each link represents a transit line. Between the stops (2) and (4) and also - * between (4) and (6) agents must walk. - * - * @author mrieser - */ - private static class WalkFixture { - - /*package*/ final MutableScenario scenario; - /*package*/ final TransitSchedule schedule; - /*package*/ final TransitRouterConfig routerConfig; - - final Coord coord1; - final Coord coord2; - final Coord coord3; - final Coord coord4; - final Coord coord5; - final Coord coord6; - final Coord coord7; - - final TransitStopFacility stop1; - final TransitStopFacility stop2; - final TransitStopFacility stop3; - final TransitStopFacility stop4; - final TransitStopFacility stop5; - final TransitStopFacility stop6; - final TransitStopFacility stop7; - - /*package*/ WalkFixture() { - this.scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); - this.scenario.getConfig().transit().setUseTransit(true); - this.routerConfig = new TransitRouterConfig(this.scenario.getConfig().scoring(), - this.scenario.getConfig().routing(), this.scenario.getConfig().transitRouter(), - this.scenario.getConfig().vspExperimental()); - this.routerConfig.setSearchRadius(500.0); - this.routerConfig.setBeelineWalkConnectionDistance(100.0); - this.routerConfig.setBeelineWalkSpeed(10.0); // so the agents can walk the distance in 10 seconds - - double x = 0; - this.coord1 = new Coord(x, (double) 0); - x += 1000; - this.coord2 = new Coord(x, (double) 0); - x += (this.routerConfig.getBeelineWalkConnectionDistance() * 0.75); - double y = -1000; - this.coord3 = new Coord(x, y); - this.coord4 = new Coord(x, (double) 0); - this.coord5 = new Coord(x, (double) 1000); - x += (this.routerConfig.getBeelineWalkConnectionDistance() * 0.75); - this.coord6 = new Coord(x, (double) 0); - x += 1000; - this.coord7 = new Coord(x, (double) 0); - - // network - Network network = this.scenario.getNetwork(); - Node node1 = network.getFactory().createNode(Id.create("1", Node.class), this.coord1); - Node node2 = network.getFactory().createNode(Id.create("2", Node.class), this.coord2); - Node node3 = network.getFactory().createNode(Id.create("3", Node.class), this.coord3); - Node node4 = network.getFactory().createNode(Id.create("4", Node.class), this.coord4); - Node node5 = network.getFactory().createNode(Id.create("5", Node.class), this.coord5); - Node node6 = network.getFactory().createNode(Id.create("6", Node.class), this.coord6); - Node node7 = network.getFactory().createNode(Id.create("7", Node.class), this.coord7); - network.addNode(node1); - network.addNode(node2); - network.addNode(node3); - network.addNode(node4); - network.addNode(node5); - network.addNode(node6); - network.addNode(node7); - Link link1 = network.getFactory().createLink(Id.create("1", Link.class), node1, node2); - Link link2 = network.getFactory().createLink(Id.create("2", Link.class), node3, node4); - Link link3 = network.getFactory().createLink(Id.create("3", Link.class), node4, node5); - Link link4 = network.getFactory().createLink(Id.create("4", Link.class), node6, node7); - network.addLink(link1); - network.addLink(link2); - network.addLink(link3); - network.addLink(link4); - - // schedule - this.schedule = this.scenario.getTransitSchedule(); - TransitScheduleFactory sb = this.schedule.getFactory(); - - this.stop1 = sb.createTransitStopFacility(Id.create("1", TransitStopFacility.class), this.coord1, false); - this.stop2 = sb.createTransitStopFacility(Id.create("2", TransitStopFacility.class), this.coord2, false); - this.stop3 = sb.createTransitStopFacility(Id.create("3", TransitStopFacility.class), this.coord3, false); - this.stop4 = sb.createTransitStopFacility(Id.create("4", TransitStopFacility.class), this.coord4, false); - this.stop5 = sb.createTransitStopFacility(Id.create("5", TransitStopFacility.class), this.coord5, false); - this.stop6 = sb.createTransitStopFacility(Id.create("6", TransitStopFacility.class), this.coord6, false); - this.stop7 = sb.createTransitStopFacility(Id.create("7", TransitStopFacility.class), this.coord7, false); - this.stop1.setLinkId(link1.getId()); - this.stop2.setLinkId(link1.getId()); - this.stop3.setLinkId(link2.getId()); - this.stop4.setLinkId(link2.getId()); - this.stop5.setLinkId(link3.getId()); - this.stop6.setLinkId(link4.getId()); - this.stop7.setLinkId(link4.getId()); - - { // line 1 - TransitLine tLine = sb.createTransitLine(Id.create("1", TransitLine.class)); - { - NetworkRoute netRoute = RouteUtils.createLinkNetworkRouteImpl(link1.getId(), link1.getId()); - List stops = new ArrayList<>(2); - stops.add(sb.createTransitRouteStop(this.stop1, 0, 0)); - stops.add(sb.createTransitRouteStop(this.stop2, 50, 50)); - TransitRoute tRoute = sb.createTransitRoute(Id.create("1a", TransitRoute.class), netRoute, stops, "bus"); - tRoute.addDeparture(sb.createDeparture(Id.create("1a1", Departure.class), 1000)); - tLine.addRoute(tRoute); - } - this.schedule.addTransitLine(tLine); - } - - { // line 2 - TransitLine tLine = sb.createTransitLine(Id.create("2", TransitLine.class)); - { - NetworkRoute netRoute = RouteUtils.createLinkNetworkRouteImpl(link2.getId(), link3.getId()); - List stops = new ArrayList<>(3); - stops.add(sb.createTransitRouteStop(this.stop3, 0, 0)); - stops.add(sb.createTransitRouteStop(this.stop4, 50, 50)); - stops.add(sb.createTransitRouteStop(this.stop5, 100, 100)); - TransitRoute tRoute = sb.createTransitRoute(Id.create("2a", TransitRoute.class), netRoute, stops, "bus"); - tRoute.addDeparture(sb.createDeparture(Id.create("2a1", Departure.class), 1000)); - tLine.addRoute(tRoute); - } - this.schedule.addTransitLine(tLine); - } - - { // line 3 - TransitLine tLine = sb.createTransitLine(Id.create("3", TransitLine.class)); - { - NetworkRoute netRoute = RouteUtils.createLinkNetworkRouteImpl(link4.getId(), link4.getId()); - List stops = new ArrayList<>(2); - stops.add(sb.createTransitRouteStop(this.stop6, 0, 0)); - stops.add(sb.createTransitRouteStop(this.stop7, 50, 50)); - TransitRoute tRoute = sb.createTransitRoute(Id.create("3a", TransitRoute.class), netRoute, stops, "train"); - tRoute.addDeparture(sb.createDeparture(Id.create("3a1", Departure.class), 1070)); - tLine.addRoute(tRoute); - } - this.schedule.addTransitLine(tLine); - } - } - - } - - /** - * Generates the following network for testing: - *
    -	 *  (n) node
    -	 *  [s] stop facilities
    -	 *   l  link
    -	 *
    -	 *  [0]       [1]
    -	 *  (0)---0---(1)---1---(2)
    -	 *            [2]       [3]
    -	 *
    -	 * 
    - * - * Simple setup with one line from 0 to 1 and one from 2 to 3. - * - * Departures are every 5 minutes. PT travel time from (1) to (2) and from (2) to (1) is one hour. - * A short cut is realized via an entry in the transfer matrix (5 minutes). - * - * @author cdobler - */ - private static class TransferFixture { - - /*package*/ final Config config; - /*package*/ final Scenario scenario; - /*package*/ final TransitSchedule schedule; - /*package*/ final TransitRouterConfig routerConfig; - - final TransitStopFacility stop0; - final TransitStopFacility stop1; - final TransitStopFacility stop2; - final TransitStopFacility stop3; - - final ActivityFacility fromFacility; - final ActivityFacility toFacility; - - /*package*/ TransferFixture(double additionalTransferTime) { - this.config = ConfigUtils.createConfig(); - this.config.transitRouter().setAdditionalTransferTime(additionalTransferTime); - this.scenario = ScenarioUtils.createScenario(this.config); - this.scenario.getConfig().transit().setUseTransit(true); - this.routerConfig = new TransitRouterConfig(this.scenario.getConfig().scoring(), this.scenario.getConfig().routing(), this.scenario.getConfig().transitRouter(), this.scenario.getConfig().vspExperimental()); - this.routerConfig.setSearchRadius(500.0); - this.routerConfig.setBeelineWalkConnectionDistance(100.0); - this.routerConfig.setBeelineWalkSpeed(1.0); // so the agents can walk the distance in 100 seconds - - // network - Network network = this.scenario.getNetwork(); - - Node node0 = network.getFactory().createNode(Id.create("0", Node.class), new Coord(0, 1000)); - Node node1 = network.getFactory().createNode(Id.create("1", Node.class), new Coord(25000, 1000)); - Node node2 = network.getFactory().createNode(Id.create("2", Node.class), new Coord(50000, 1000)); - network.addNode(node0); - network.addNode(node1); - network.addNode(node2); - - Link link0 = network.getFactory().createLink(Id.create("0", Link.class), node0, node1); - Link link1 = network.getFactory().createLink(Id.create("1", Link.class), node1, node2); - network.addLink(link0); - network.addLink(link1); - - // facilities - ActivityFacilities facilities = this.scenario.getActivityFacilities(); - - this.fromFacility = facilities.getFactory().createActivityFacility(Id.create("fromFacility", ActivityFacility.class), new Coord(0, 1102)); - this.toFacility = facilities.getFactory().createActivityFacility(Id.create("toFacility", ActivityFacility.class), new Coord(50000, 898)); - facilities.addActivityFacility(this.fromFacility); - facilities.addActivityFacility(this.toFacility); - - // schedule - this.schedule = this.scenario.getTransitSchedule(); - TransitScheduleFactory sb = this.schedule.getFactory(); - - this.stop0 = sb.createTransitStopFacility(Id.create("0", TransitStopFacility.class), new Coord(0, 1002), false); - this.stop1 = sb.createTransitStopFacility(Id.create("1", TransitStopFacility.class), new Coord(25000, 1002), false); - this.stop2 = sb.createTransitStopFacility(Id.create("2", TransitStopFacility.class), new Coord(25000, 998), false); - this.stop3 = sb.createTransitStopFacility(Id.create("3", TransitStopFacility.class), new Coord(50000, 998), false); - this.schedule.addStopFacility(this.stop0); - this.schedule.addStopFacility(this.stop1); - this.schedule.addStopFacility(this.stop2); - this.schedule.addStopFacility(this.stop3); - this.stop0.setLinkId(link0.getId()); - this.stop1.setLinkId(link0.getId()); - this.stop2.setLinkId(link1.getId()); - this.stop3.setLinkId(link1.getId()); - - // route from 0 to 1 - { - TransitLine line0to1 = sb.createTransitLine(Id.create("0to1", TransitLine.class)); - this.schedule.addTransitLine(line0to1); - NetworkRoute netRoute = RouteUtils.createLinkNetworkRouteImpl(link0.getId(), link0.getId()); - List> routeLinks = new ArrayList<>(); - netRoute.setLinkIds(link0.getId(), routeLinks, link0.getId()); - List stops = new ArrayList<>(); - stops.add(sb.createTransitRouteStopBuilder(this.stop0).departureOffset(0.0).build()); - stops.add(sb.createTransitRouteStopBuilder(this.stop1).arrivalOffset(5*60.0).build()); - TransitRoute route = sb.createTransitRoute(Id.create("0to1", TransitRoute.class), netRoute, stops, "train"); - line0to1.addRoute(route); - - route.addDeparture(sb.createDeparture(Id.create("l0to1 d0", Departure.class), 8.0*3600)); - route.addDeparture(sb.createDeparture(Id.create("l0to1 d1", Departure.class), 9.0*3600)); - route.addDeparture(sb.createDeparture(Id.create("l0to1 d2", Departure.class), 10.0*3600)); - route.addDeparture(sb.createDeparture(Id.create("l0to1 d3", Departure.class), 11.0*3600)); - route.addDeparture(sb.createDeparture(Id.create("l0to1 d4", Departure.class), 12.0*3600)); - } - - // route from 2 to 3 - { - TransitLine line2to3 = sb.createTransitLine(Id.create("2to3", TransitLine.class)); - this.schedule.addTransitLine(line2to3); - NetworkRoute netRoute = RouteUtils.createLinkNetworkRouteImpl(link1.getId(), link1.getId()); - List> routeLinks = new ArrayList<>(); - netRoute.setLinkIds(link1.getId(), routeLinks, link1.getId()); - List stops = new ArrayList<>(); - stops.add(sb.createTransitRouteStopBuilder(this.stop2).departureOffset(0.0).build()); - stops.add(sb.createTransitRouteStopBuilder(this.stop3).arrivalOffset(5*60.0).build()); - TransitRoute route = sb.createTransitRoute(Id.create("2to3", TransitRoute.class), netRoute, stops, "train"); - line2to3.addRoute(route); - - route.addDeparture(sb.createDeparture(Id.create("l2to3 d0", Departure.class), 8.0*3600 + 15 * 60)); - route.addDeparture(sb.createDeparture(Id.create("l2to3 d1", Departure.class), 9.0*3600 + 15 * 60)); - route.addDeparture(sb.createDeparture(Id.create("l2to3 d2", Departure.class), 10.0*3600 + 15 * 60)); - route.addDeparture(sb.createDeparture(Id.create("l2to3 d3", Departure.class), 11.0*3600 + 15 * 60)); - route.addDeparture(sb.createDeparture(Id.create("l2to3 d4", Departure.class), 12.0*3600 + 15 * 60)); - } - } - } -} diff --git a/matsim/src/test/java/org/matsim/pt/router/TransitRouterModuleTest.java b/matsim/src/test/java/org/matsim/pt/router/TransitRouterModuleTest.java index 3eb275ea9f6..196ff84dc0c 100644 --- a/matsim/src/test/java/org/matsim/pt/router/TransitRouterModuleTest.java +++ b/matsim/src/test/java/org/matsim/pt/router/TransitRouterModuleTest.java @@ -18,28 +18,6 @@ public class TransitRouterModuleTest { @Rule public MatsimTestUtils utils = new MatsimTestUtils(); - @Test - public void testTransitRoutingAlgorithm_DependencyInjection_Dijkstra() { - Fixture f = new Fixture(); - f.config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); - f.config.controller().setOutputDirectory(this.utils.getOutputDirectory()); - f.config.controller().setLastIteration(0); - f.config.controller().setDumpDataAtEnd(false); - - Controler controler = new Controler(f.scenario); - controler.addOverridingModule(new AbstractModule() { - @Override - public void install() { - bindMobsim().to(DummyMobsim.class); - } - }); - controler.run(); - Injector injector = controler.getInjector(); - - TransitRouter router = injector.getInstance(TransitRouter.class); - Assert.assertEquals(TransitRouterImpl.class, router.getClass()); - } - @Test public void testTransitRoutingAlgorithm_DependencyInjection_Raptor() { Fixture f = new Fixture(); diff --git a/matsim/src/test/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeCostTest.java b/matsim/src/test/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeCostTest.java deleted file mode 100644 index 5e2afb97a50..00000000000 --- a/matsim/src/test/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeCostTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterNetworkTravelTimeCostTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink; -import org.matsim.testcases.MatsimTestUtils; - -/** - * @author mrieser - */ -public class TransitRouterNetworkTravelTimeCostTest { - - @Test public void testTravelTime() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule); - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - // find the link connecting C and G on the red line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == f.redLine) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("G"))) { - testLink = link; - } - } - assertEquals(9.0*60, tc.getLinkTravelTime(testLink, 6.0*3600, null, null), MatsimTestUtils.EPSILON); - } - - @Test public void testWaitingTime() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule); - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == f.blueLine) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("D"))) { - testLink = link; - } - } - assertEquals(2.0*60 + 7.0*60, tc.getLinkTravelTime(testLink, 6.0*3600, null, null), MatsimTestUtils.EPSILON); - assertEquals(1.0*60 + 7.0*60, tc.getLinkTravelTime(testLink, 6.0*3600 + 60, null, null), MatsimTestUtils.EPSILON); - assertEquals(0.0*60 + 7.0*60, tc.getLinkTravelTime(testLink, 6.0*3600 + 120, null, null), MatsimTestUtils.EPSILON); - assertEquals(20.0*60 -1 + 7.0*60, tc.getLinkTravelTime(testLink, 6.0*3600 + 121, null, null), MatsimTestUtils.EPSILON); - } - - @Test public void testTravelTimeAfterMidnight() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule); - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == f.blueLine) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("D"))) { - testLink = link; - } - } - // planned departure at 25:00, has to wait until 05:22 = 29:22 - assertEquals(22.0*60 + 4.0*3600 + 7.0*60, tc.getLinkTravelTime(testLink, 25.0*3600, null, null), MatsimTestUtils.EPSILON); - // planned departure at 47:00, has to wait until 05:22 = 53:22 - assertEquals(22.0*60 + 6.0*3600 + 7.0*60, tc.getLinkTravelTime(testLink, 47.0*3600, null, null), MatsimTestUtils.EPSILON); - // planned departure at 49:00, has to wait until 05:22 = 53:22, tests explicitly > 2*MIDNIGHT - assertEquals(22.0*60 + 4.0*3600 + 7.0*60, tc.getLinkTravelTime(testLink, 49.0*3600, null, null), MatsimTestUtils.EPSILON); - } - - @Test public void testTravelCostLineSwitch() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule); - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == null) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("C"))) { - testLink = link; - } - } - - double oldCost = - conf.getUtilityOfLineSwitch_utl(); - double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); - conf.setUtilityOfLineSwitch_utl(0.0); - double cost2 = tc.getLinkTravelDisutility(testLink, 6.0*3600, null, null, null); // use different time because of internal caching effects - assertEquals(oldCost, cost1 - cost2, MatsimTestUtils.EPSILON); - conf.setUtilityOfLineSwitch_utl(-40.125); - double cost3 = tc.getLinkTravelDisutility(testLink, 5.0*3600, null, null, null); - assertEquals(40.125, cost3 - cost2, MatsimTestUtils.EPSILON); - } - - @Test public void testTravelCostLineSwitch_AdditionalTransferTime() { - Fixture f = new Fixture(); - f.init(); - TransitRouterConfig conf = new TransitRouterConfig(f.scenario.getConfig().scoring(), - f.scenario.getConfig().routing(), f.scenario.getConfig().transitRouter(), - f.scenario.getConfig().vspExperimental()); - TransitRouterNetworkTravelTimeAndDisutility tc = new TransitRouterNetworkTravelTimeAndDisutility(conf); - TransitRouterImpl router = new TransitRouterImpl(conf, f.schedule); - TransitRouterNetwork routerNet = router.getTransitRouterNetwork(); - // find the link connecting C and D on the blue line - TransitRouterNetworkLink testLink = null; - for (TransitRouterNetworkLink link : routerNet.getLinks().values()) { - if ((link.getLine() == null) && - (link.fromNode.stop.getStopFacility().getName().equals("C")) && - (link.toNode.stop.getStopFacility().getName().equals("C"))) { - testLink = link; - } - } - - double oldCost = - conf.getUtilityOfLineSwitch_utl(); - double cost1 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); - conf.setUtilityOfLineSwitch_utl(0.0); - double cost2 = tc.getLinkTravelDisutility(testLink, 6.0*3600, null, null, null); // use different time because of internal caching effects - assertEquals(oldCost, cost1 - cost2, MatsimTestUtils.EPSILON); - conf.setAdditionalTransferTime(120.0); - double cost3 = tc.getLinkTravelDisutility(testLink, 5.0*3600, null, null, null); - assertEquals(-120.0 * conf.getMarginalUtilityOfWaitingPt_utl_s(), cost3 - cost2, MatsimTestUtils.EPSILON); - // test with custom value for utility of waiting, just in case too many of the default marginal utilities are 0.0 - conf.setMarginalUtilityOfWaitingPt_utl_s(-12.0 / 3600.0); - double cost4 = tc.getLinkTravelDisutility(testLink, 7.0*3600, null, null, null); - assertEquals(120.0 * 12.0 / 3600.0, cost4 - cost2, MatsimTestUtils.EPSILON); - } - -} diff --git a/matsim/src/test/java/org/matsim/pt/transitSchedule/TransitScheduleReprojectionIOTest.java b/matsim/src/test/java/org/matsim/pt/transitSchedule/TransitScheduleReprojectionIOTest.java index 1ba6c69e18a..526fefcb1d2 100644 --- a/matsim/src/test/java/org/matsim/pt/transitSchedule/TransitScheduleReprojectionIOTest.java +++ b/matsim/src/test/java/org/matsim/pt/transitSchedule/TransitScheduleReprojectionIOTest.java @@ -108,13 +108,13 @@ public void testWithControlerAndConfigParameters() { Scenario scenario ; { final Config config = ConfigUtils.createConfig( ExamplesUtils.getTestScenarioURL( "pt-tutorial" ) ); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); config.transit().setTransitScheduleFile( "transitschedule.xml" ); config.transit().setUseTransit( true ); config.transit().setInputScheduleCRS( INITIAL_CRS ); config.global().setCoordinateSystem( TARGET_CRS ); config.controller().setLastIteration( -1 ); config.controller().setOutputDirectory( outputDirectory ); + config.network().setInputFile("multimodalnetwork.xml"); scenario = ScenarioUtils.loadScenario( config ); } @@ -174,10 +174,10 @@ public void testWithControlerAndAttributes() { new TransitScheduleWriter( originalScenario.getTransitSchedule() ).writeFile( withAttributes ); final Config config = ConfigUtils.createConfig( ExamplesUtils.getTestScenarioURL( "pt-tutorial" ) ); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); config.transit().setTransitScheduleFile( withAttributes ); config.transit().setUseTransit( true ); config.transit().setInputScheduleCRS( INITIAL_CRS ); + config.network().setInputFile("multimodalnetwork.xml"); // yyyyyy Is it so plausible that this is given here when the test is about having this in the file? kai, sep'18 config.global().setCoordinateSystem( TARGET_CRS ); config.controller().setLastIteration( -1 );