MATSIM
FastAStarEuclideanFactory.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * FastAStarEuclideanFactory.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 
36 
41 
43  private final Map<Network, RoutingNetwork> routingNetworks = new HashMap<>();
44  private final Map<Network, PreProcessEuclidean> preProcessData = new HashMap<>();
45  private final double overdoFactor;
46 
48  this(1);
49  }
50 
51  public FastAStarEuclideanFactory(double overdoFactor) {
53  }
54 
55  private FastAStarEuclideanFactory(final FastRouterType fastRouterType, double overdoFactor) {
56  this.overdoFactor = overdoFactor;
57  switch (fastRouterType) {
58  case ARRAY:
59  this.routingNetworkFactory = new ArrayRoutingNetworkFactory();
60  break;
61  case POINTER:
62  throw new RuntimeException(
63  "PointerRoutingNetworks are no longer supported. Use ArrayRoutingNetworks instead. Aborting!");
64  default:
65  throw new RuntimeException("Undefined FastRouterType: " + fastRouterType);
66  }
67  }
68 
69  @Override
70  public synchronized LeastCostPathCalculator createPathCalculator(final Network network,
71  final TravelDisutility travelCosts, final TravelTime travelTimes) {
72  RoutingNetwork routingNetwork = this.routingNetworks.get(network);
73  PreProcessEuclidean preProcessEuclidean = this.preProcessData.get(network);
74 
75  if (routingNetwork == null) {
76  routingNetwork = this.routingNetworkFactory.createRoutingNetwork(network);
77 
78  preProcessEuclidean = new PreProcessEuclidean(travelCosts);
79  preProcessEuclidean.run(network);
80  this.preProcessData.put(network, preProcessEuclidean);
81 
82  for (RoutingNetworkNode node : routingNetwork.getNodes().values()) {
83  node.setDeadEndData(preProcessEuclidean.getNodeData(node.getNode()));
84  }
85 
86  this.routingNetworks.put(network, routingNetwork);
87  }
89 
90  return new FastAStarEuclidean(routingNetwork, preProcessEuclidean, travelCosts, travelTimes, overdoFactor,
91  fastRouterFactory);
92  }
93 }
synchronized LeastCostPathCalculator createPathCalculator(final Network network, final TravelDisutility travelCosts, final TravelTime travelTimes)
final Map< Network, PreProcessEuclidean > preProcessData
Map< Id< Node >, RoutingNetworkNode > getNodes()
FastAStarEuclideanFactory(final FastRouterType fastRouterType, double overdoFactor)
RoutingNetwork createRoutingNetwork(final Network network)