MATSIM
FreespeedFactorRouting.java
Go to the documentation of this file.
1 
2 /* *********************************************************************** *
3  * project: org.matsim.*
4  * FreespeedFactorRouting.java
5  * *
6  * *********************************************************************** *
7  * *
8  * copyright : (C) 2019 by the members listed in the COPYING, *
9  * LICENSE and WARRANTY file. *
10  * email : info at matsim dot org *
11  * *
12  * *********************************************************************** *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * See also COPYING, LICENSE and WARRANTY file *
19  * *
20  * *********************************************************************** */
21 
22  package org.matsim.core.router;
23 
24 import jakarta.inject.Inject;
25 import jakarta.inject.Provider;
26 
32 import org.matsim.core.gbl.Gbl;
37 import org.matsim.vehicles.Vehicle;
38 
39 class FreespeedFactorRouting implements Provider<RoutingModule> {
40 
41  private final RoutingConfigGroup.TeleportedModeParams params;
42 
43  public FreespeedFactorRouting( RoutingConfigGroup.TeleportedModeParams params ) {
44  this.params = params;
45  }
46 
47  @Inject
48  private Network network;
49 
50  @Inject
51  private PopulationFactory populationFactory;
52 
53  @Inject
54  private LeastCostPathCalculatorFactory leastCostPathCalculatorFactory;
55 
56  @Override
57  public RoutingModule get() {
58 
59 // FreespeedTravelTimeAndDisutility ptTimeCostCalc = new FreespeedTravelTimeAndDisutility(-1.0, 0.0, 0.0);
60  // I wanted to introduce the freespeed limit. Decided to locally re-implement rather than making the FreespeedTravelTimeAndDisutility
61  // class longer. kai, nov'16
62 
63  // yyyy the following might be improved by including additional disutility parameters. But the original one I found was also
64  // just doing fastest time (see commented out version above). kai, nov'16
65  final TravelTime travelTime = new TravelTime(){
66  @Override public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) {
67  return link.getLength() / Math.min( link.getFreespeed(time) , params.getTeleportedModeFreespeedLimit() ) ;
68  }
69  } ;
70  TravelDisutility travelDisutility = new TravelDisutility(){
71  @Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
72  return travelTime.getLinkTravelTime(link, time, person, vehicle) ;
73  }
74  @Override public double getLinkMinimumTravelDisutility(Link link) {
75  return link.getLength() / Math.min( link.getFreespeed() , params.getTeleportedModeFreespeedLimit() ) ;
76  }
77  } ;
78  Gbl.assertNotNull(leastCostPathCalculatorFactory);
79  LeastCostPathCalculator routeAlgoPtFreeFlow = leastCostPathCalculatorFactory.createPathCalculator(
80  network, travelDisutility, travelTime);
81  return DefaultRoutingModules.createPseudoTransitRouter(params.getMode(), populationFactory,
82  network, routeAlgoPtFreeFlow, params);
83  }
84 }