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