private LeastCostPathCalculator createLeastCostPathCalculator(){ LeastCostPathCalculator router = routerCache.get(Thread.currentThread().getId()); if(router == null){ LeastCostPathCalculator newRouter = leastCostPathCalculatorFactory.createPathCalculator(network, travelDisutility, travelTime); router = routerCache.putIfAbsent(Thread.currentThread().getId(), newRouter); if(router == null){ router = newRouter; } } return router; }
@Override public final PlanAlgorithm getPlanAlgoInstance() { ReplanningContext replanningContext = this.getReplanningContext(); MultiNodeDijkstra forwardMultiNodeDijkstra = (MultiNodeDijkstra) this.forwardMultiNodeDijsktaFactory.createPathCalculator(this.scenario.getNetwork(), travelDisutilities.get(TransportMode.car).createTravelDisutility(travelTimes.get(TransportMode.car)), travelTimes.get(TransportMode.car)); BackwardFastMultiNodeDijkstra backwardMultiNodeDijkstra = (BackwardFastMultiNodeDijkstra) this.backwardMultiNodeDijsktaFactory.createPathCalculator( this.scenario.getNetwork(), travelDisutilities.get(TransportMode.car).createTravelDisutility(travelTimes.get(TransportMode.car)), travelTimes.get(TransportMode.car)); // this one corresponds to the "frozen epsilon" paper(s) // the random number generators are re-seeded anyway in the dc module. So we do not need a MatsimRandom instance here TripRouter tripRouter = tripRouterProvider.get(); int iteration = replanningContext.getIteration(); return new BestResponseLocationMutator(this.quadTreesOfType, this.facilitiesOfType, this.personsMaxEpsUnscaled, this.lcContext, this.sampler, tripRouter, forwardMultiNodeDijkstra, backwardMultiNodeDijkstra, scoringFunctionFactory, iteration, this.nearestLinks); } }
leastCostPathCalculatorFactory.createPathCalculator( filteredNetwork, travelDisutilityFactory.createTravelDisutility(travelTime),
@Override public RoutingModule get() { if (filteredNetwork == null){ TransportModeNetworkFilter filter = new TransportModeNetworkFilter(network); Set<String> modes = new HashSet<>(); modes.add(TransportMode.car); filteredNetwork = NetworkUtils.createNetwork(); filter.filter(filteredNetwork, modes); } TravelDisutilityFactory travelDisutilityFactory = this.travelDisutilityFactory.get(PlansCalcRouteWithTollOrNot.CAR_WITH_PAYED_AREA_TOLL); TravelTime travelTime = travelTimes.get(TransportMode.car); LeastCostPathCalculator routeAlgo = leastCostPathCalculatorFactory.createPathCalculator( filteredNetwork, travelDisutilityFactory.createTravelDisutility(travelTime), travelTime); if ( plansCalcRouteConfigGroup.isInsertingAccessEgressWalk() ) { return DefaultRoutingModules.createAccessEgressNetworkRouter(TransportMode.car, populationFactory, filteredNetwork, routeAlgo, plansCalcRouteConfigGroup); } else { return DefaultRoutingModules.createPureNetworkRouter(TransportMode.car, populationFactory, filteredNetwork, routeAlgo); } // yyyyyy not so great that this differentiation is here; need to push it down a bit (again). kai, feb'2016 } }
@Override public RoutingModule get() { // FreespeedTravelTimeAndDisutility ptTimeCostCalc = new FreespeedTravelTimeAndDisutility(-1.0, 0.0, 0.0); // I wanted to introduce the freespeed limit. Decided to locally re-implement rather than making the FreespeedTravelTimeAndDisutility // class longer. kai, nov'16 // yyyy the following might be improved by including additional disutility parameters. But the original one I found was also // just doing fastest time (see commented out version above). kai, nov'16 final TravelTime travelTime = new TravelTime(){ @Override public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) { return link.getLength() / Math.min( link.getFreespeed(time) , params.getTeleportedModeFreespeedLimit() ) ; } } ; TravelDisutility travelDisutility = new TravelDisutility(){ @Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { return travelTime.getLinkTravelTime(link, time, person, vehicle) ; } @Override public double getLinkMinimumTravelDisutility(Link link) { return link.getLength() / Math.min( link.getFreespeed() , params.getTeleportedModeFreespeedLimit() ) ; } } ; Gbl.assertNotNull(leastCostPathCalculatorFactory); LeastCostPathCalculator routeAlgoPtFreeFlow = leastCostPathCalculatorFactory.createPathCalculator( network, travelDisutility, travelTime); return DefaultRoutingModules.createPseudoTransitRouter(params.getMode(), populationFactory, network, routeAlgoPtFreeFlow, params); } }
LinkToLinkRoutingModule(final String mode, final PopulationFactory populationFactory, Network network, LeastCostPathCalculatorFactory leastCostPathCalcFactory, TravelDisutilityFactory travelCostCalculatorFactory, LinkToLinkTravelTime l2ltravelTimes, NetworkTurnInfoBuilderI turnInfoBuilder) { this.network = network; this.populationFactory = populationFactory; this.mode = mode; invertedNetwork = new NetworkInverter(network, turnInfoBuilder.createAllowedTurnInfos()).getInvertedNetwork(); // convert l2ltravelTimes into something that can be used by the inverted network router: TravelTimesInvertedNetworkProxy invertedTravelTimes = new TravelTimesInvertedNetworkProxy(network, l2ltravelTimes); // (method that takes a getLinkTravelTime( link , ...) with a link from the inverted network, converts it into links on the // original network, and looks up the link2link tttime in the l2ltravelTimes data structure) TravelDisutility travelCost = travelCostCalculatorFactory.createTravelDisutility(invertedTravelTimes); leastCostPathCalculator = leastCostPathCalcFactory.createPathCalculator(invertedNetwork, travelCost, invertedTravelTimes); }
@Deprecated // use TripRouter instead. kai, dec'13 public PlanRouterAdapter( final MatsimServices controler) { this.planRouter = new PlanRouter( controler.getTripRouterProvider().get(), controler.getScenario().getActivityFacilities() ); TravelTime time = controler.getLinkTravelTimes(); TravelDisutility disutility = controler.getTravelDisutilityFactory().createTravelDisutility( time); LeastCostPathCalculatorFactory factory = controler.getLeastCostPathCalculatorFactory(); Network network = controler.getScenario().getNetwork(); this.routeAlgo = factory.createPathCalculator(network, disutility, time); PopulationFactory populationFactory = controler.getScenario().getPopulation().getFactory(); this.routeFactory = ((PopulationFactory) populationFactory).getRouteFactories(); }
@Override public GenericStrategyManager<CarrierPlan, Carrier> createStrategyManager() { TravelDisutility travelDisutility = TravelDisutilities.createBaseDisutility(types, modeTravelTimes.get(TransportMode.car)); final LeastCostPathCalculator router = leastCostPathCalculatorFactory.createPathCalculator(network, travelDisutility, modeTravelTimes.get(TransportMode.car));
@Test public void testPersonAvailableForDisutility_AStarLandmarks() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastAStarEuclideanFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Test public void testPersonAvailableForDisutility_FastDijkstra() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastDijkstraFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
@Test public void testPersonAvailableForDisutility_FastAStarLandmarks() { Fixture f = new Fixture(); LeastCostPathCalculatorFactory routerFactory = new FastAStarLandmarksFactory(); LeastCostPathCalculator router = routerFactory.createPathCalculator(f.network, f.costFunction, new FreeSpeedTravelTime()); router.calcLeastCostPath( f.network.getNodes().get(Id.create("2", Node.class)), f.network.getNodes().get(Id.create("1", Node.class)), 07*3600, f.person, f.vehicle); // hopefully there was no Exception until here... Assert.assertEquals(22, f.costFunction.cnt); // make sure the costFunction was actually used }
TravelDisutility travelDisutility = travelDisutilityFactory.createTravelDisutility(travelTime ) ; LeastCostPathCalculator pathCalculator = pathCalculatorFactory.createPathCalculator(network, travelDisutility, travelTime ) ;
@Test public void testRouterCreation() { for (ControlerConfigGroup.RoutingAlgorithmType routingAlgorithmType : ControlerConfigGroup.RoutingAlgorithmType.values()) { Config config = ConfigUtils.createConfig(); config.controler().setRoutingAlgorithmType(routingAlgorithmType); Scenario scenario = ScenarioUtils.createScenario(config); LeastCostPathCalculatorFactory defaultLeastCostPathCalculatorFactory = TripRouterFactoryBuilderWithDefaults.createDefaultLeastCostPathCalculatorFactory(scenario); LeastCostPathCalculator pathCalculator = defaultLeastCostPathCalculatorFactory.createPathCalculator( scenario.getNetwork(), ControlerDefaults.createDefaultTravelDisutilityFactory(scenario).createTravelDisutility(new FreeSpeedTravelTime()), new FreeSpeedTravelTime()); Assert.assertNotNull(pathCalculator); } }