MATSIM
Public Member Functions | Private Attributes | List of all members
org.matsim.analysis.CalcAverageTripLength Class Reference
Inheritance diagram for org.matsim.analysis.CalcAverageTripLength:
Inheritance graph
[legend]

Public Member Functions

 CalcAverageTripLength (final Network network)
 
void run (final Person person)
 
void run (final Plan plan)
 
double getAverageTripLength ()
 
final void run (final Population plans)
 

Private Attributes

double sumLength = 0.0
 
int cntTrips = 0
 
final Network network
 

Detailed Description

Calculates the average trip length of all routes in a plan. The trip length is the sum of the length of all links, including the route's end link, but not including the route's start link.

This class works only for NetworkRoutes and will likely fail for legs with other types of Routes.

Author
mrieser

Definition at line 44 of file CalcAverageTripLength.java.

Constructor & Destructor Documentation

◆ CalcAverageTripLength()

org.matsim.analysis.CalcAverageTripLength.CalcAverageTripLength ( final Network  network)

Member Function Documentation

◆ run() [1/3]

void org.matsim.analysis.CalcAverageTripLength.run ( final Person  person)

Implements org.matsim.core.population.algorithms.PersonAlgorithm.

Definition at line 55 of file CalcAverageTripLength.java.

References org.matsim.api.core.v01.population.HasPlansAndId< T extends BasicPlan, I >.getSelectedPlan().

55  {
56  this.run(person.getSelectedPlan());
57  }
Here is the call graph for this function:

◆ run() [2/3]

void org.matsim.analysis.CalcAverageTripLength.run ( final Plan  plan)

Implements org.matsim.core.population.algorithms.PlanAlgorithm.

Definition at line 60 of file CalcAverageTripLength.java.

References org.matsim.core.population.routes.RouteUtils.calcDistanceExcludingStartEndLink(), org.matsim.api.core.v01.population.Route.getEndLinkId(), org.matsim.api.core.v01.network.Network.getLinks(), org.matsim.api.core.v01.population.Plan.getPlanElements(), org.matsim.api.core.v01.population.Leg.getRoute(), and org.matsim.api.core.v01.population.Route.getStartLinkId().

60  {
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  }
Map< Id< Link >, ? extends Link > getLinks()
Here is the call graph for this function:

◆ getAverageTripLength()

double org.matsim.analysis.CalcAverageTripLength.getAverageTripLength ( )

Definition at line 78 of file CalcAverageTripLength.java.

78  {
79  if (this.cntTrips == 0) {
80  return 0;
81  }
82  return (this.sumLength / this.cntTrips);
83  }

◆ run() [3/3]

final void org.matsim.core.population.algorithms.AbstractPersonAlgorithm.run ( final Population  plans)
inherited

Definition at line 34 of file AbstractPersonAlgorithm.java.

References org.matsim.api.core.v01.population.Population.getPersons(), org.matsim.core.utils.misc.Counter.incCounter(), and org.matsim.core.utils.misc.Counter.printCounter().

34  {
35  log.info("running " + this.getClass().getName() + " algorithm...");
36  Counter counter = new Counter(" person # ");
37 
38  for (Person p : plans.getPersons().values()) {
39  counter.incCounter();
40  this.run(p);
41  }
42  counter.printCounter();
43  log.info("done running algorithm.");
44  }
Here is the call graph for this function:

Member Data Documentation

◆ sumLength

double org.matsim.analysis.CalcAverageTripLength.sumLength = 0.0
private

Definition at line 46 of file CalcAverageTripLength.java.

◆ cntTrips

int org.matsim.analysis.CalcAverageTripLength.cntTrips = 0
private

Definition at line 47 of file CalcAverageTripLength.java.

◆ network

final Network org.matsim.analysis.CalcAverageTripLength.network
private

The documentation for this class was generated from the following file: