SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackerValueDesc.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Storage for a tracked value
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <vector>
34 #include <utils/common/RGBColor.h>
36 #include "TrackerValueDesc.h"
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 TrackerValueDesc::TrackerValueDesc(const std::string& name,
47  const RGBColor& col,
48  SUMOTime recordBegin)
49  : myName(name), myActiveCol(col), myInactiveCol(col),
50  myMin(0), myMax(0),
51  myAggregationInterval(TIME2STEPS(1) / DELTA_T), myInvalidValue(-1), myValidNo(0),
52  myRecordingBegin(recordBegin), myTmpLastAggValue(0) {}
53 
54 
56  // just to quit cleanly on a failure
57  if (myLock.locked()) {
58  myLock.unlock();
59  }
60 }
61 
62 
63 void
65  if (myValues.size() == 0) {
66  myMin = value;
67  myMax = value;
68  } else {
69  myMin = value < myMin ? value : myMin;
70  myMax = value > myMax ? value : myMax;
71  }
72  myLock.lock();
73  myValues.push_back(value);
74  if (value != myInvalidValue) {
75  myTmpLastAggValue += value;
76  myValidNo++;
77  }
78  const SUMOReal avg = myValidNo == 0 ? static_cast<SUMOReal>(0) : myTmpLastAggValue / static_cast<SUMOReal>(myValidNo);
79  if (myAggregationInterval == 1 || myValues.size() % myAggregationInterval == 1) {
80  myAggregatedValues.push_back(avg);
81  } else {
82  myAggregatedValues.back() = avg;
83  }
84  if (myValues.size() % myAggregationInterval == 0) {
86  myValidNo = 0;
87  }
88  myLock.unlock();
89 }
90 
91 
94  return myMax - myMin;
95 }
96 
97 
100  return myMin;
101 }
102 
103 
104 SUMOReal
106  return myMax;
107 }
108 
109 
110 SUMOReal
112  return (myMin + myMax) / 2.0f;
113 }
114 
115 
116 const RGBColor&
118  return myActiveCol;
119 }
120 
121 
122 const std::vector<SUMOReal> &
124  myLock.lock();
125  return myValues;
126 }
127 
128 
129 const std::vector<SUMOReal> &
131  myLock.lock();
132  return myAggregatedValues;
133 }
134 
135 
136 const std::string&
138  return myName;
139 }
140 
141 void
143  myLock.unlock();
144 }
145 
146 
147 void
149  myLock.lock();
150  if (myAggregationInterval != as / DELTA_T) {
152  // ok, the aggregation has changed,
153  // let's recompute the list of aggregated values
154  myAggregatedValues.clear();
155  std::vector<SUMOReal>::const_iterator i = myValues.begin();
156  while (i != myValues.end()) {
157  myTmpLastAggValue = 0;
158  myValidNo = 0;
159  for (int j = 0; j < myAggregationInterval && i != myValues.end(); j++, ++i) {
160  if ((*i) != myInvalidValue) {
161  myTmpLastAggValue += (*i);
162  myValidNo++;
163  }
164  }
165  if (myValidNo == 0) {
166  myAggregatedValues.push_back(0);
167  } else {
168  myAggregatedValues.push_back(myTmpLastAggValue / static_cast<SUMOReal>(myValidNo));
169  }
170  }
171  }
172  myLock.unlock();
173 }
174 
175 
176 SUMOTime
179 }
180 
181 
182 SUMOTime
184  return myRecordingBegin;
185 }
186 
187 
188 
189 /****************************************************************************/
190