MATSIM
NetworkSummary.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * NetworkSummary.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;
28 import org.matsim.core.utils.misc.Time;
29 
30 public final class NetworkSummary implements NetworkRunnable {
31 
32  private int network_capacity = 0;
33  private double minX = Double.POSITIVE_INFINITY;
34  private double maxX = Double.NEGATIVE_INFINITY;
35  private double minY = Double.POSITIVE_INFINITY;
36  private double maxY = Double.NEGATIVE_INFINITY;
37 
38  public NetworkSummary() {
39  super();
40  }
41 
42  @Override
43  public void run(final Network network) {
44  System.out.println(" running " + this.getClass().getName() + " algorithm...");
45 
46  int min_node_id = Integer.MAX_VALUE;
47  int max_node_id = Integer.MIN_VALUE;
48  int node_cnt = 0;
49  int min_link_id = Integer.MAX_VALUE;
50  int max_link_id = Integer.MIN_VALUE;
51  int link_cnt = 0;
52 
53  for (Node node : network.getNodes().values()) {
54  node_cnt++;
55  int node_getID = Integer.parseInt(node.getId().toString());
56  if (min_node_id > node_getID) { min_node_id = node_getID; }
57  if (max_node_id < node_getID) { max_node_id = node_getID; }
58  double x = node.getCoord().getX();
59  double y = node.getCoord().getY();
60  if (x > this.maxX) { this.maxX = x; }
61  if (x < this.minX) { this.minX = x; }
62  if (y > this.maxY) { this.maxY = y; }
63  if (y < this.minY) { this.minY = y; }
64  }
65 
66  double cellSize = network.getEffectiveCellSize();
67  for (Link link : network.getLinks().values()) {
68  link_cnt++;
69  int link_getID = Integer.parseInt(link.getId().toString());
70  if (min_link_id > link_getID) { min_link_id = link_getID; }
71  if (max_link_id < link_getID) { max_link_id = link_getID; }
72  this.network_capacity += Math.ceil(link.getLength()/cellSize);
73  }
74 
75  System.out.println(" network summary:");
76 // System.out.println(" name = " + network.getName());
77  System.out.println(" capperiod = " + Time.writeTime(network.getCapacityPeriod()));
78  System.out.println(" network_capacity = " + this.network_capacity + " cells");
79  System.out.println(" nodes summary:");
80  System.out.println(" number of nodes = " + node_cnt);
81  System.out.println(" min node id = " + min_node_id);
82  System.out.println(" max node id = " + max_node_id);
83  System.out.println(" links summary:");
84  System.out.println(" number of links = " + link_cnt);
85  System.out.println(" min link id = " + min_link_id);
86  System.out.println(" max link id = " + max_link_id);
87 
88  System.out.println(" done.");
89  }
90 
91  public final int getNetworkCapacity() {
92  return this.network_capacity;
93  }
94 
95  public final Coord getMinCoord() {
96  return new Coord(this.minX, this.minY);
97  }
98 
99  public final Coord getMaxCoord() {
100  return new Coord(this.maxX, this.maxY);
101  }
102 }
Map< Id< Node >, ? extends Node > getNodes()
static final String writeTime(final double seconds, final String timeformat)
Definition: Time.java:80
Map< Id< Link >, ? extends Link > getLinks()