MATSIM
DijkstraFactory.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * DijkstraFactory.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2008 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.core.router;
22 
23 import java.util.HashMap;
24 import java.util.Map;
25 
26 import jakarta.inject.Inject;
27 import jakarta.inject.Singleton;
28 
35 
36 @Singleton
38 
39  private final boolean usePreProcessData;
40  private final Map<Network, PreProcessDijkstra> preProcessData = new HashMap<>();
41 
42  @Inject
43  public DijkstraFactory() {
44  this.usePreProcessData = false;
45  }
46 
47  public DijkstraFactory(final boolean usePreProcessData) {
48  this.usePreProcessData = usePreProcessData;
49  }
50 
51  // yy there is no guarantee that "createPathCalculator" is called with the same network as the one that was used for "preProcessData".
52  // This can happen for example when LinkToLink routing is switched on. kai & theresa, feb'15
53  // To fix this, we create the PreProcessData when the first LeastCostPathCalculator object is created and store it in a map using
54  // the network as key. For the PreProcessDijkstra data this is fine, since it does not take travel times and disutilities into account.
55  // For the AStarLandmarks data, we would have to include the other two arguments into the lookup value as well... cdobler, sep'17
56  @Override
57  public synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes) {
58  if (this.usePreProcessData) {
59  PreProcessDijkstra preProcessDijkstra = this.preProcessData.get(network);
60  if (preProcessDijkstra == null) {
61  preProcessDijkstra = new PreProcessDijkstra();
62  preProcessDijkstra.run(network);
63  this.preProcessData.put(network, preProcessDijkstra);
64  }
65  return new Dijkstra(network, travelCosts, travelTimes, preProcessDijkstra);
66  }
67  return new Dijkstra(network, travelCosts, travelTimes);
68  }
69 }
DijkstraFactory(final boolean usePreProcessData)
final Map< Network, PreProcessDijkstra > preProcessData
synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes)