MATSIM
FastAStarEuclidean.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * FastAStarEuclidean.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 
37 import org.matsim.vehicles.Vehicle;
38 
49 public class FastAStarEuclidean extends AStarEuclidean {
50 
52  private final FastRouterDelegate fastRouter;
54  private int maxSize = -1;
55 
58  final FastRouterDelegateFactory fastRouterFactory) {
59  super(routingNetwork, preProcessData, costFunction, timeFunction, overdoFactor);
60 
61  this.routingNetwork = routingNetwork;
62  this.fastRouter = fastRouterFactory.createFastRouterDelegate(this, new AStarNodeDataFactory(), routingNetwork);
63 
64  this.nodeData.clear();
65  }
66 
67  /*
68  * Replace the references to the from and to nodes with their corresponding
69  * nodes in the routing network.
70  */
71  @Override
72  public Path calcLeastCostPath(final Node fromNode, final Node toNode, final double startTime, final Person person, final Vehicle vehicle) {
73 
74  this.fastRouter.initialize();
75  this.routingNetwork.initialize();
76 
77  RoutingNetworkNode routingNetworkFromNode = this.routingNetwork.getNodes().get(fromNode.getId());
78  RoutingNetworkNode routingNetworkToNode = this.routingNetwork.getNodes().get(toNode.getId());
79 
80  return super.calcLeastCostPath(routingNetworkFromNode, routingNetworkToNode, startTime, person, vehicle);
81  }
82 
83  @Override
84  /*package*/ RouterPriorityQueue<? extends Node> createRouterPriorityQueue() {
85  /*
86  * Re-use existing BinaryMinHeap instead of creating a new one. For large networks (> 10^6 nodes and links) this reduced
87  * the computation time by 40%! cdobler, oct'15
88  */
89  if (this.routingNetwork instanceof ArrayRoutingNetwork) {
90  int size = this.routingNetwork.getNodes().size();
91  if (this.heap == null || this.maxSize != size) {
92  this.maxSize = size;
93  this.heap = new BinaryMinHeap<>(maxSize);
94  return this.heap;
95  } else {
96  this.heap.reset();
97  return this.heap;
98  }
99 // int maxSize = this.routingNetwork.getNodes().size();
100 // return new BinaryMinHeap<ArrayRoutingNetworkNode>(maxSize);
101  } else {
102  return super.createRouterPriorityQueue();
103  }
104  }
105 
106  /*
107  * Constructs the path and replaces the nodes and links from the routing network
108  * with their corresponding nodes and links from the network.
109  */
110  @Override
111  protected Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime) {
112  return this.fastRouter.constructPath(fromNode, toNode, startTime, arrivalTime);
113  }
114 
115  /*
116  * For performance reasons the outgoing links of a node are stored in
117  * the routing network in an array instead of a map. Therefore we have
118  * to iterate over an array instead of over a map.
119  */
120  @Override
121  protected void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) {
122  this.fastRouter.relaxNode(outNode, toNode, pendingNodes);
123  }
124 
125  /*
126  * The DijkstraNodeData is taken from the RoutingNetworkNode and not from a map.
127  */
128  @Override
129  protected AStarNodeData getData(final Node n) {
130  return (AStarNodeData) this.fastRouter.getData(n);
131  }
132 
133  /*
134  * The DeadEndData is taken from the RoutingNetworkNode and not from a map.
135  */
136  @Override
138  return this.fastRouter.getPreProcessData(n);
139  }
140 }
Path calcLeastCostPath(final Node fromNode, final Node toNode, final double startTime, final Person person, final Vehicle vehicle)
Map< Id< Node >, RoutingNetworkNode > getNodes()
BinaryMinHeap< ArrayRoutingNetworkNode > heap
final PreProcessDijkstra preProcessData
Definition: Dijkstra.java:127
final TravelDisutility costFunction
Definition: Dijkstra.java:98
void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue< Node > pendingNodes)
final TravelTime timeFunction
Definition: Dijkstra.java:103
Path constructPath(Node fromNode, Node toNode, double startTime, double arrivalTime)
PreProcessDijkstra.DeadEndData getPreProcessData(final Node n)
FastRouterDelegate createFastRouterDelegate(Dijkstra dijkstra, NodeDataFactory nodeDataFactory, RoutingNetwork routingNetwork)