MATSIM
LinkToLinkRouting.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *
4  * *********************************************************************** *
5  * *
6  * copyright : (C) 2017 by the members listed in the COPYING, *
7  * LICENSE and WARRANTY file. *
8  * email : info at matsim dot org *
9  * *
10  * *********************************************************************** *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * See also COPYING, LICENSE and WARRANTY file *
17  * *
18  * *********************************************************************** */
19 
20 package org.matsim.core.router;
21 
22 import java.util.HashSet;
23 import java.util.Map;
24 import java.util.Set;
25 
26 import jakarta.inject.*;
27 
28 import com.google.inject.name.Named;
29 import org.matsim.api.core.v01.Scenario;
39 import org.matsim.core.router.util.*;
41 
42 public class LinkToLinkRouting
43  implements Provider<RoutingModule> {
44  private final String mode;
45 
46  @Inject
47  PopulationFactory populationFactory;
48 
49  @Inject
50  SingleModeNetworksCache singleModeNetworksCache;
51 
52  @Inject
53  RoutingConfigGroup routingConfigGroup;
54 
55  @Inject
56  LeastCostPathCalculatorFactory leastCostPathCalcFactory;
57 
58  @Inject
59  Scenario scenario;
60 
61  @Inject
62  Map<String, TravelDisutilityFactory> travelDisutilities;
63 
64  @Inject
65  Network network;
66 
67  @Inject
68  LinkToLinkTravelTime travelTimes;
69 
70  @Inject
71  NetworkTurnInfoBuilderI networkTurnInfoBuilder;
72 
73  @Inject
74  TimeInterpretation timeInterpretation;
75 
76  @Inject
77  @Named(TransportMode.walk)
79 
80  @Inject
82 
83  public LinkToLinkRouting(String mode) {
84  this.mode = mode;
85  }
86 
87 
92  @Override
93  public RoutingModule get() {
94 
95  // the network refers to the (transport)mode:
96  Network filteredNetwork = null;
97  Network invertedNetwork = null;
98 
99  // Ensure this is not performed concurrently by multiple threads!
100  synchronized (this.singleModeNetworksCache.getSingleModeNetworksCache()) {
101  filteredNetwork = this.singleModeNetworksCache.getSingleModeNetworksCache().get(mode);
102  invertedNetwork = this.singleModeNetworksCache.getSingleModeNetworksCache().get(mode + "-inv");
103  if (filteredNetwork == null) {
105  Set<String> modes = new HashSet<>();
106  modes.add(mode);
107  filteredNetwork = NetworkUtils.createNetwork(scenario.getConfig().network());
108  filter.filter(filteredNetwork, modes);
109 
110  invertedNetwork = new NetworkInverter(filteredNetwork, networkTurnInfoBuilder.createAllowedTurnInfos()).getInvertedNetwork();
111 
112  this.singleModeNetworksCache.getSingleModeNetworksCache().put(mode, filteredNetwork);
113  this.singleModeNetworksCache.getSingleModeNetworksCache().put(mode + "-inv", invertedNetwork);
114  }
115  }
116 
117  InvertedLeastPathCalculator leastCostPathCalculator = InvertedLeastPathCalculator.create(
118  leastCostPathCalcFactory, travelDisutilities.get(mode),
119  filteredNetwork, invertedNetwork, travelTimes
120  );
121 
122  // see NetworkRoutingProvider for some notes
123  if (!routingConfigGroup.getAccessEgressType().equals(RoutingConfigGroup.AccessEgressType.none)) {
124  if (mode.equals(TransportMode.walk)) {
125  return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, leastCostPathCalculator, scenario,
126  filteredNetwork, invertedNetwork, null,null, timeInterpretation, multimodalLinkChooser);
127  } else {
128  return DefaultRoutingModules.createAccessEgressNetworkRouter(mode, leastCostPathCalculator, scenario,
129  filteredNetwork, invertedNetwork, walkRouter, walkRouter, timeInterpretation, multimodalLinkChooser);
130  }
131 
132  } else {
133  // pure inverted router
134  return new LinkToLinkRoutingModule(mode, populationFactory, filteredNetwork, invertedNetwork, leastCostPathCalculator);
135  }
136  }
137 }
void filter(final Network subNetwork, final Set< String > extractModes)
static RoutingModule createAccessEgressNetworkRouter(String mode, final LeastCostPathCalculator routeAlgo, Scenario scenario, Network filteredNetwork, RoutingModule accessEgressToNetworkRouter, TimeInterpretation timeInterpretation, MultimodalLinkChooser multimodalLinkChooser)