MATSIM
FastDijkstraFactory.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * FastDijkstraFactory.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2011 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 
39 
40 @Singleton
42 
43  private final boolean usePreProcessData;
45  private final Map<Network, RoutingNetwork> routingNetworks = new HashMap<>();
46  private final Map<Network, PreProcessDijkstra> preProcessData = new HashMap<>();
47 
48  @Inject
50  this(false, FastRouterType.ARRAY);
51  }
52 
53  public FastDijkstraFactory(final boolean usePreProcessData) {
55  }
56 
57  private FastDijkstraFactory(final boolean usePreProcessData, final FastRouterType fastRouterType) {
58  this.usePreProcessData = usePreProcessData;
59 
60  switch (fastRouterType) {
61  case ARRAY:
62  this.routingNetworkFactory = new ArrayRoutingNetworkFactory();
63  break;
64  case POINTER:
65  throw new RuntimeException("PointerRoutingNetworks are no longer supported. "
66  + "Use ArrayRoutingNetworks instead. Aborting!");
67  default:
68  throw new RuntimeException("Undefined FastRouterType: " + fastRouterType);
69  }
70  }
71 
72  @Override
73  public synchronized LeastCostPathCalculator createPathCalculator(final Network network,
74  final TravelDisutility travelCosts, final TravelTime travelTimes) {
75  RoutingNetwork routingNetwork = this.routingNetworks.get(network);
76  PreProcessDijkstra preProcessDijkstra = this.preProcessData.get(network);
77 
78  if (routingNetwork == null) {
79  routingNetwork = this.routingNetworkFactory.createRoutingNetwork(network);
80 
81  if (this.usePreProcessData) {
82  preProcessDijkstra = new PreProcessDijkstra();
83  preProcessDijkstra.run(network);
84  this.preProcessData.put(network, preProcessDijkstra);
85 
86  for (RoutingNetworkNode node : routingNetwork.getNodes().values()) {
87  node.setDeadEndData(preProcessDijkstra.getNodeData(node.getNode()));
88  }
89  }
90 
91  this.routingNetworks.put(network, routingNetwork);
92  }
94 
95  return new FastDijkstra(routingNetwork, travelCosts, travelTimes, preProcessDijkstra, fastRouterFactory);
96  }
97 }
FastDijkstraFactory(final boolean usePreProcessData)
Map< Id< Node >, RoutingNetworkNode > getNodes()
final RoutingNetworkFactory routingNetworkFactory
FastDijkstraFactory(final boolean usePreProcessData, final FastRouterType fastRouterType)
synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes)
RoutingNetwork createRoutingNetwork(final Network network)
final Map< Network, PreProcessDijkstra > preProcessData
final Map< Network, RoutingNetwork > routingNetworks