MATSIM
NetworkFalsifier.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * NetworkFalsifier.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.network.algorithms;
22 
23 import org.matsim.api.core.v01.Coord;
30 
38 public final class NetworkFalsifier implements NetworkRunnable {
39 
40  private final double distance;
41 
42  public NetworkFalsifier(double distance) {
43  this.distance = distance;
44  }
45 
46  @Override
47  public void run(Network network) {
48  double maxDistance = this.distance * 2.0;
49  for (Node node : network.getNodes().values()) {
50  Coord coord = node.getCoord();
51  node.setCoord( new Coord(coord.getX() + (MatsimRandom.getRandom().nextDouble() - 0.5) * maxDistance,
52  coord.getY() + (MatsimRandom.getRandom().nextDouble() - 0.5) * maxDistance) ) ;
53  }
54 
55  for (Link link : network.getLinks().values()) {
56  Coord fromCoord = link.getFromNode().getCoord();
57  Coord toCoord = link.getToNode().getCoord();
58  link.setLength(CoordUtils.calcEuclideanDistance(fromCoord, toCoord));
59  }
60  }
61 
62 }
Map< Id< Node >, ? extends Node > getNodes()
static double calcEuclideanDistance(Coord coord, Coord other)
Map< Id< Link >, ? extends Link > getLinks()