MATSIM
CalcAverageTripLength.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * CalcAverageTripLength.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.analysis;
22 
33 
43 @Deprecated
45 
46  private double sumLength = 0.0;
47  private int cntTrips = 0;
48  private final Network network;
49 
50  public CalcAverageTripLength(final Network network) {
51  this.network = network;
52  }
53 
54  @Override
55  public void run(final Person person) {
56  this.run(person.getSelectedPlan());
57  }
58 
59  @Override
60  public void run(final Plan plan) {
61  for (PlanElement pe : plan.getPlanElements()) {
62  if (pe instanceof Leg) {
63  Leg leg = (Leg) pe;
64  Route route = leg.getRoute();
65  if (route != null) {
66  // does not work for Routes which are not a NetworkRoute, e.g. DrtRoute
67  double dist = RouteUtils.calcDistanceExcludingStartEndLink((NetworkRoute) route, this.network);
68  if (route.getEndLinkId() != null && route.getStartLinkId() != route.getEndLinkId()) {
69  dist += this.network.getLinks().get(route.getEndLinkId()).getLength();
70  }
71  this.sumLength += dist;
72  this.cntTrips++;
73  }
74  }
75  }
76  }
77 
78  public double getAverageTripLength() {
79  if (this.cntTrips == 0) {
80  return 0;
81  }
82  return (this.sumLength / this.cntTrips);
83  }
84 }
List< PlanElement > getPlanElements()
Map< Id< Link >, ? extends Link > getLinks()
static double calcDistanceExcludingStartEndLink(final NetworkRoute route, final Network network)