MATSIM
AbstractTravelTimeAggregator.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * AbstractTravelTimeAggregator.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.trafficmonitoring;
22 
23  abstract class AbstractTravelTimeAggregator {
24 
25  private final int travelTimeBinSize;
26  private final int numSlots;
27  private TravelTimeGetter travelTimeGetter;
28 
29  AbstractTravelTimeAggregator(final int numSlots, final int travelTimeBinSize) {
30  this.numSlots = numSlots;
31  this.travelTimeBinSize = travelTimeBinSize;
32 
33  this.connectTravelTimeGetter(new AveragingTravelTimeGetter()); // by default
34  }
35 
39  void connectTravelTimeGetter(final TravelTimeGetter travelTimeGetter) {
40  this.travelTimeGetter = travelTimeGetter;
41  travelTimeGetter.setTravelTimeAggregator(this);
42  }
43 
44  int getTimeSlotIndex(final double time) {
45  return TimeBinUtils.getTimeBinIndex(time, travelTimeBinSize, numSlots);
46  }
47 
48  abstract void addTravelTime(TravelTimeData travelTimeRole, double enterTime,
49  double leaveTime);
50 
51  void addStuckEventTravelTime(final TravelTimeData travelTimeRole,
52  final double enterTime, final double stuckEventTime) {
53  //here is the right place to handle StuckEvents (just overwrite this method)
54  }
55 
56  double getTravelTime(final TravelTimeData travelTimeRole, final double time) {
57  return this.travelTimeGetter.getTravelTime(travelTimeRole, time);
58  }
59 
60  /*package*/ TravelTimeGetter getTravelTimeGetter() { // for tests
61  return this.travelTimeGetter;
62  }
63 
64 }
static int getTimeBinIndex(double time, int travelTimeBinSize, int travelTimeBinCount)