MATSIM
NetworkAdaptLength.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * NetworkAdaptLength.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2009 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.network.algorithms;
22 
23 import org.apache.logging.log4j.LogManager;
24 import org.apache.logging.log4j.Logger;
29 
30 public final class NetworkAdaptLength implements NetworkRunnable {
31 
32  private static final double overLengthFactor = 1.001; // link length is at least 1 permil longer than euclidean distance
33 
34  private static final Logger log = LogManager.getLogger(NetworkAdaptLength.class);
35 
36  @Override
37  public void run(Network network) {
38  log.info("running " + this.getClass().getName() + " module...");
39  log.info(" adapting link length to at least 'overLengthFactor * euclidean distance' (works properly only for eucledian coord systems)");
40  log.info(" also ceil link length to meters");
41  log.info(" overLengthFactor: "+overLengthFactor);
42 
43  for (Link l : network.getLinks().values()) {
44  double dist = overLengthFactor*CoordUtils.calcEuclideanDistance(l.getFromNode().getCoord(),l.getToNode().getCoord());
45  if (dist > l.getLength()) { l.setLength(dist); }
46  double len = Math.ceil(l.getLength());
47  l.setLength(len);
48  }
49 
50  log.info("done.");
51  }
52 }
static double calcEuclideanDistance(Coord coord, Coord other)
Map< Id< Link >, ? extends Link > getLinks()