MATSIM
PreProcessEuclidean.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * PreProcessEuclidean.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 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.util;
22 
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
28 
38 
39  private static final Logger log = LogManager.getLogger(PreProcessEuclidean.class);
40 
41  // Must be initialized to MAX_VALUE, otherwise updateMaxFreeSpeed(...) does
42  // not change minTravelCostPerLength
43  private double minTravelCostPerLength = Double.POSITIVE_INFINITY;
44 
46 
51  public PreProcessEuclidean(final TravelDisutility costFunction) {
52  this.costFunction = costFunction;
53  }
54 
55  @Override
56  public void run(final Network network) {
57  super.run(network);
58 
59  if (!checkLinkLengths(network)) {
60  log.warn("There are links with stored length smaller than their Euclidean distance in this network. Thus, A* cannot guarantee to calculate the least-cost paths between two nodes.");
61  }
62 
64  }
65 
66  private void updateMinTravelCostPerLength(final Network network) {
67  for (Link link : network.getLinks().values()) {
68  double minCost = this.costFunction.getLinkMinimumTravelDisutility(link) / link.getLength();
69  if (getMinTravelCostPerLength() > minCost) {
70  setMinTravelCostPerLength(minCost);
71  }
72  }
73  }
74 
75  private boolean checkLinkLengths(final Network network) {
76  for (Link link : network.getLinks().values()) {
77  double linkLength = link.getLength();
78  double eucDist = CoordUtils.calcEuclideanDistance(link.getFromNode().getCoord(), link.getToNode().getCoord());
79  if (linkLength < eucDist) {
80  if (log.isDebugEnabled()) {
81  log.debug("link " + link.getId() + " has length " + linkLength + " which is smaller than the euclidean distance " + eucDist);
82  }
83  return false;
84  }
85  }
86  return true;
87  }
88 
89  void setMinTravelCostPerLength(final double maxFreeSpeed) {
90  this.minTravelCostPerLength = maxFreeSpeed;
91  }
92 
97  public double getMinTravelCostPerLength() {
98  return this.minTravelCostPerLength;
99  }
100 
106  return this.costFunction;
107  }
108 }
PreProcessEuclidean(final TravelDisutility costFunction)
static double calcEuclideanDistance(Coord coord, Coord other)
Map< Id< Link >, ? extends Link > getLinks()
double getLinkMinimumTravelDisutility(final Link link)