#include <LaneChangeDetector.h>
Public Member Functions | |
LaneChangeDetector (std::string dir, double dt, double dx, int roadLen, bool DirPos, WORD VehType) | |
Constructor. | |
virtual | ~LaneChangeDetector () |
Destructor. | |
virtual void | EndOutput () |
Cleans up end of file output. | |
void | addEvent (LaneChangeEvent *lce) |
Adds an event to the detector. | |
Private Member Functions | |
virtual void | InitOutputFiles () |
Initialises the output files. | |
virtual void | doIntervalOutput () |
Processes output. | |
virtual void | ReInit () |
Re-initialises the detector after output. | |
void | InitVerboseFile () |
Initialises the verbose file for output. | |
void | InitCompositionFile () |
Initialises the composition file for output. | |
void | InitSpaceTimeFile () |
Initialises the space-time file for output. | |
void | InitRateFile () |
Initialises the rate file for output. | |
void | doVerboseOutput () |
Processes verbose output. | |
void | doCompositionOutput () |
Processes composition output. | |
void | doSpaceTimeOutput () |
Processes space-time output. | |
void | doRateOutput () |
Processes rate output. | |
void | AddCurrentEvent (LaneChangeEvent *lce) |
Private Attributes | |
std::vector< LaneChangeEvent * > | m_vChangeEvents |
std::ofstream | m_OutFile_Verbose |
std::ofstream | m_OutFile_Composition |
std::ofstream | m_OutFile_SpaceTime |
std::ofstream | m_OutFile_Rate |
int | m_NoLaneChangeEvents |
int | m_DistanceInterval |
int | m_NoDistIntervals |
std::vector< int > | m_vDistanceIntervals |
std::vector< int > | m_vDistInt_LCECount |
std::string | m_MetricsDir2 |
Definition at line 18 of file LaneChangeDetector.h.
LaneChangeDetector::LaneChangeDetector | ( | std::string | dir, | |
double | dt, | |||
double | dx, | |||
int | roadLen, | |||
bool | DirPos, | |||
WORD | VehType | |||
) |
Constructor.
dir | The detector output directory | |
dt | The time interval to use | |
dx | The distance interval to use | |
roadLen | The length of the road | |
DirPos | Whether the detector is in the positive direction | |
VehType | The type of vehicles to track |
Definition at line 27 of file LaneChangeDetector.cpp.
References InitOutputFiles(), Detector::m_DetectorType, Detector::m_DirPos, m_DistanceInterval, Detector::m_MetricsDir, m_NoDistIntervals, m_NoLaneChangeEvents, Detector::m_RoadLength, Detector::m_TimeInterval, m_vDistanceIntervals, m_vDistInt_LCECount, Detector::m_VehicleType, and METRICS_TYPE_LANE_CHANGE.
00029 { 00030 m_MetricsDir = dir; 00031 m_TimeInterval = dt; 00032 m_DistanceInterval = dx; 00033 m_RoadLength = roadLen; 00034 m_DirPos = DirPos; 00035 m_VehicleType = VehType; 00036 00037 m_NoLaneChangeEvents = 0; 00038 m_DetectorType = METRICS_TYPE_LANE_CHANGE; 00039 00040 int curPos = 0; 00041 while(curPos < m_RoadLength) 00042 { 00043 m_vDistanceIntervals.push_back(curPos); 00044 curPos += m_DistanceInterval; 00045 } 00046 m_vDistanceIntervals.push_back(m_RoadLength); // enclose the last interval 00047 m_NoDistIntervals = m_vDistanceIntervals.size(); 00048 m_vDistInt_LCECount.assign(m_NoDistIntervals, 0); 00049 00050 InitOutputFiles(); 00051 }
LaneChangeDetector::~LaneChangeDetector | ( | ) | [virtual] |
void LaneChangeDetector::EndOutput | ( | ) | [virtual] |
Cleans up end of file output.
Reimplemented from Detector.
Definition at line 129 of file LaneChangeDetector.cpp.
References m_OutFile_Composition, m_OutFile_Rate, m_OutFile_SpaceTime, m_OutFile_Verbose, Detector::m_VehicleType, and METRICS_VEH_ALL.
00130 { 00131 if(m_VehicleType == METRICS_VEH_ALL) 00132 m_OutFile_Composition.close(); 00133 00134 m_OutFile_Verbose.close(); 00135 m_OutFile_SpaceTime.close(); 00136 m_OutFile_Rate.close(); 00137 }
void LaneChangeDetector::addEvent | ( | LaneChangeEvent * | pLCE | ) |
Adds an event to the detector.
pLCE | The event to add |
Definition at line 77 of file LaneChangeDetector.cpp.
References AddCurrentEvent(), LaneChangeEvent::getVehicleType(), Detector::m_VehicleType, METRICS_VEH_ALL, METRICS_VEH_CAR, METRICS_VEH_CRANE, METRICS_VEH_LARGETRUCK, METRICS_VEH_LOWLOADER, METRICS_VEH_SMALLTRUCK, VEH_ID_CAR, VEH_ID_CRANE, VEH_ID_LARGETRUCK, VEH_ID_LOWLOADER, and VEH_ID_SMALLTRUCK.
Referenced by Lane::ImplementLaneChange().
00078 { 00079 WORD vehID = pLCE->getVehicleType(); 00080 00081 switch(m_VehicleType) 00082 { 00083 case METRICS_VEH_ALL: 00084 AddCurrentEvent(pLCE); 00085 break; 00086 case METRICS_VEH_CAR: 00087 if(vehID == VEH_ID_CAR) 00088 AddCurrentEvent(pLCE); 00089 break; 00090 case METRICS_VEH_SMALLTRUCK: 00091 if(vehID == VEH_ID_SMALLTRUCK) 00092 AddCurrentEvent(pLCE); 00093 break; 00094 case METRICS_VEH_LARGETRUCK: 00095 if(vehID == VEH_ID_LARGETRUCK) 00096 AddCurrentEvent(pLCE); 00097 break; 00098 case METRICS_VEH_CRANE: 00099 if(vehID == VEH_ID_CRANE) 00100 AddCurrentEvent(pLCE); 00101 break; 00102 case METRICS_VEH_LOWLOADER: 00103 if(vehID == VEH_ID_LOWLOADER) 00104 AddCurrentEvent(pLCE); 00105 break; 00106 default: 00107 AddCurrentEvent(pLCE); 00108 } 00109 }
void LaneChangeDetector::InitOutputFiles | ( | ) | [private, virtual] |
Initialises the output files.
Reimplemented from Detector.
Definition at line 60 of file LaneChangeDetector.cpp.
References InitCompositionFile(), InitRateFile(), InitSpaceTimeFile(), InitVerboseFile(), Detector::m_VehicleType, and METRICS_VEH_ALL.
Referenced by LaneChangeDetector().
00061 { 00062 if(m_VehicleType == METRICS_VEH_ALL) 00063 InitCompositionFile(); // only makes sense for all vehicles 00064 00065 InitVerboseFile(); 00066 InitSpaceTimeFile(); 00067 InitRateFile(); 00068 }
void LaneChangeDetector::doIntervalOutput | ( | ) | [private, virtual] |
Processes output.
Reimplemented from Detector.
Definition at line 118 of file LaneChangeDetector.cpp.
References doCompositionOutput(), doRateOutput(), doSpaceTimeOutput(), doVerboseOutput(), and ReInit().
00119 { 00120 doVerboseOutput(); 00121 doCompositionOutput(); 00122 doSpaceTimeOutput(); 00123 doRateOutput(); 00124 00125 ReInit(); 00126 }
void LaneChangeDetector::ReInit | ( | ) | [private, virtual] |
Re-initialises the detector after output.
Reimplemented from Detector.
Definition at line 140 of file LaneChangeDetector.cpp.
References m_NoDistIntervals, m_NoLaneChangeEvents, m_vChangeEvents, and m_vDistInt_LCECount.
Referenced by doIntervalOutput().
00141 { 00142 m_NoLaneChangeEvents = 0; 00143 00144 m_vDistInt_LCECount.clear(); 00145 m_vDistInt_LCECount.assign(m_NoDistIntervals, 0); 00146 00147 for(int i = 0; i < m_vChangeEvents.size(); i++) 00148 delete m_vChangeEvents.at(i); 00149 m_vChangeEvents.clear(); 00150 00151 }
void LaneChangeDetector::InitVerboseFile | ( | ) | [private] |
Initialises the verbose file for output.
Definition at line 154 of file LaneChangeDetector.cpp.
References Detector::m_DirPos, Detector::m_MetricsDir, m_OutFile_Verbose, Detector::m_VehicleType, Detector::MapDetVehTypeToString(), and Detector::MapDirToString().
Referenced by InitOutputFiles().
00155 { 00156 std::string file; 00157 file = m_MetricsDir; 00158 file += "LC_All_" + MapDetVehTypeToString(m_VehicleType) + "_" 00159 + MapDirToString(m_DirPos) + ".csv"; 00160 00161 m_OutFile_Verbose.open(file.c_str(), std::ios::out); 00162 00163 m_OutFile_Verbose << "LANE CHANGE - VERBOSE OUTPUT OF EVENTS" << '\n'; 00164 m_OutFile_Verbose << "Time,"; 00165 m_OutFile_Verbose << "Position,"; 00166 m_OutFile_Verbose << "From Lane,"; 00167 m_OutFile_Verbose << "To Lane,"; 00168 m_OutFile_Verbose << "Right/Left,"; 00169 m_OutFile_Verbose << "Type" << '\n'; 00170 m_OutFile_Verbose << std::endl; 00171 }
void LaneChangeDetector::InitCompositionFile | ( | ) | [private] |
Initialises the composition file for output.
Definition at line 174 of file LaneChangeDetector.cpp.
References Detector::m_DirPos, Detector::m_MetricsDir, m_OutFile_Composition, Detector::m_VehicleType, Detector::MapDetVehTypeToString(), and Detector::MapDirToString().
Referenced by InitOutputFiles().
00175 { 00176 std::string file; 00177 file = m_MetricsDir; 00178 file += "LC_Comp_" + MapDetVehTypeToString(m_VehicleType) + "_" 00179 + MapDirToString(m_DirPos) + ".csv"; 00180 00181 m_OutFile_Composition.open(file.c_str(), std::ios::out); 00182 00183 m_OutFile_Composition << "LANE CHANGE - COMPOSITION OF EVENTS" << "\n"; 00184 m_OutFile_Composition << "Time Interval" << ","; 00185 m_OutFile_Composition << "Car Changes" << ","; 00186 m_OutFile_Composition << "SmallTr Changes" << ","; 00187 m_OutFile_Composition << "LargeTr Changes" << ","; 00188 m_OutFile_Composition << "Crane Changes" << ","; 00189 m_OutFile_Composition << "LowLoad Changes" << '\n'; 00190 00191 }
void LaneChangeDetector::InitSpaceTimeFile | ( | ) | [private] |
Initialises the space-time file for output.
Definition at line 194 of file LaneChangeDetector.cpp.
References Detector::m_DirPos, Detector::m_MetricsDir, m_OutFile_SpaceTime, Detector::m_VehicleType, Detector::MapDetVehTypeToString(), and Detector::MapDirToString().
Referenced by InitOutputFiles().
00195 { 00196 std::string file; 00197 file = m_MetricsDir; 00198 file += "LC_ST_" + MapDetVehTypeToString(m_VehicleType) + "_" 00199 + MapDirToString(m_DirPos) + ".csv"; 00200 00201 m_OutFile_SpaceTime.open(file.c_str(), std::ios::out); 00202 00203 m_OutFile_SpaceTime << "LANE CHANGE - SPACE TIME OF EVENTS" << '\n'; 00204 m_OutFile_SpaceTime << "Left To Right," << ',' << "Right To Left" << '\n'; 00205 m_OutFile_SpaceTime << "Time (s),Location (m),Time (s),Location (m)" << '\n'; 00206 }
void LaneChangeDetector::InitRateFile | ( | ) | [private] |
Initialises the rate file for output.
Definition at line 209 of file LaneChangeDetector.cpp.
References Detector::m_DirPos, Detector::m_MetricsDir, m_NoDistIntervals, m_OutFile_Rate, m_vDistanceIntervals, Detector::m_VehicleType, Detector::MapDetVehTypeToString(), and Detector::MapDirToString().
Referenced by InitOutputFiles().
00210 { 00211 std::string file; 00212 file = m_MetricsDir; 00213 file += "LC_Rate_" + MapDetVehTypeToString(m_VehicleType) + "_" 00214 + MapDirToString(m_DirPos) + ".csv"; 00215 00216 m_OutFile_Rate.open(file.c_str(), std::ios::out); 00217 00218 m_OutFile_Rate << "LANE CHANGE - RATES BY LOCATION AND TIME" << '\n'; 00219 m_OutFile_Rate << "Time (s),Location (m)" << '\n'; 00220 m_OutFile_Rate << ","; 00221 for(int i = 0; i < m_NoDistIntervals; i++) 00222 m_OutFile_Rate << m_vDistanceIntervals[i] << ","; 00223 m_OutFile_Rate << '\n'; 00224 }
void LaneChangeDetector::doVerboseOutput | ( | ) | [private] |
Processes verbose output.
Definition at line 227 of file LaneChangeDetector.cpp.
References LaneChangeEvent::getChangeLeft(), LaneChangeEvent::getDestinationLane(), LaneChangeEvent::getDirPos(), LaneChangeEvent::getOriginLane(), LaneChangeEvent::getPosition(), LaneChangeEvent::getTime(), LaneChangeEvent::getVehicleType(), m_NoLaneChangeEvents, m_OutFile_Verbose, m_vChangeEvents, VEH_ID_CAR, VEH_ID_CRANE, VEH_ID_LARGETRUCK, VEH_ID_LOWLOADER, and VEH_ID_SMALLTRUCK.
Referenced by doIntervalOutput().
00228 { 00229 for(int i = 0; i < m_NoLaneChangeEvents; i++) 00230 { 00231 LaneChangeEvent* curEvent = m_vChangeEvents.at(i); 00232 00233 std::string change = (curEvent->getChangeLeft()) ? "Left" : "Right"; 00234 std::string dir = (curEvent->getDirPos()) ? "Pos" : "Neg"; 00235 00236 std::string type; 00237 00238 switch(curEvent->getVehicleType()) 00239 { 00240 case VEH_ID_CAR: type = "Car"; break; 00241 case VEH_ID_SMALLTRUCK: type = "SmallTr"; break; 00242 case VEH_ID_LARGETRUCK: type = "LargeTr"; break; 00243 case VEH_ID_CRANE: type = "Crane"; break; 00244 case VEH_ID_LOWLOADER: type = "Lowload"; break; 00245 } 00246 00247 m_OutFile_Verbose << curEvent->getTime() << " ," 00248 << curEvent->getPosition() << " ," 00249 << curEvent->getOriginLane() << " ," 00250 << curEvent->getDestinationLane() << " ," 00251 << change << " ," 00252 << type << '\n'; 00253 } 00254 }
void LaneChangeDetector::doCompositionOutput | ( | ) | [private] |
Processes composition output.
Definition at line 257 of file LaneChangeDetector.cpp.
References m_NoLaneChangeEvents, m_OutFile_Composition, Detector::m_TotalTime, m_vChangeEvents, VEH_ID_CAR, VEH_ID_CRANE, VEH_ID_LARGETRUCK, VEH_ID_LOWLOADER, and VEH_ID_SMALLTRUCK.
Referenced by doIntervalOutput().
00258 { 00259 int nCar = 0; 00260 int nSmallTruck = 0; 00261 int nLargeTruck = 0; 00262 int nCrane = 0; 00263 int nLowLoader = 0; 00264 00265 for(int i = 0; i < m_NoLaneChangeEvents; i++) 00266 { 00267 WORD VehType = m_vChangeEvents.at(i)->getVehicleType(); 00268 00269 switch(VehType) 00270 { 00271 case VEH_ID_CAR: nCar++; break; 00272 case VEH_ID_SMALLTRUCK: nSmallTruck++; break; 00273 case VEH_ID_LARGETRUCK: nLargeTruck++; break; 00274 case VEH_ID_CRANE: nCrane++; break; 00275 case VEH_ID_LOWLOADER: nLowLoader++; break; 00276 default: nCar++; 00277 } 00278 } 00279 00280 m_OutFile_Composition << m_TotalTime << ","; 00281 m_OutFile_Composition << nCar << ","; 00282 m_OutFile_Composition << nSmallTruck << ","; 00283 m_OutFile_Composition << nLargeTruck << ","; 00284 m_OutFile_Composition << nCrane << ","; 00285 m_OutFile_Composition << nLowLoader << '\n'; 00286 }
void LaneChangeDetector::doSpaceTimeOutput | ( | ) | [private] |
Processes space-time output.
Definition at line 289 of file LaneChangeDetector.cpp.
References LaneChangeEvent::getChangeLeft(), LaneChangeEvent::getPosition(), LaneChangeEvent::getTime(), m_NoLaneChangeEvents, m_OutFile_SpaceTime, and m_vChangeEvents.
Referenced by doIntervalOutput().
00290 { 00291 for(int i = 0; i < m_NoLaneChangeEvents; i++) 00292 { 00293 LaneChangeEvent* pLCE = m_vChangeEvents.at(i); 00294 double time = pLCE->getTime(); 00295 double position = pLCE->getPosition(); 00296 bool bChangeToLeft = pLCE->getChangeLeft(); 00297 00298 if(bChangeToLeft) // send to right hand column 00299 m_OutFile_SpaceTime << ",,"; 00300 00301 m_OutFile_SpaceTime << time << ',' << position << '\n'; 00302 } 00303 }
void LaneChangeDetector::doRateOutput | ( | ) | [private] |
Processes rate output.
Definition at line 306 of file LaneChangeDetector.cpp.
References m_DistanceInterval, m_NoDistIntervals, m_NoLaneChangeEvents, m_OutFile_Rate, Detector::m_TimeInterval, Detector::m_TotalTime, m_vChangeEvents, m_vDistanceIntervals, m_vDistInt_LCECount, and SECS_PER_HOUR.
Referenced by doIntervalOutput().
00307 { 00308 for(int i = 0; i < m_NoLaneChangeEvents; i++) 00309 { 00310 double position = m_vChangeEvents.at(i)->getPosition(); 00311 int iDistInterval = 0; 00312 // find the interval to be incremented 00313 while( !(position < m_vDistanceIntervals[iDistInterval]) ) 00314 iDistInterval++; 00315 00316 m_vDistInt_LCECount[iDistInterval]++; // count it 00317 } 00318 00319 double deltaX = (double)m_DistanceInterval/1000; // change to km 00320 double deltaT = (double)m_TimeInterval/SECS_PER_HOUR; // change to hour 00321 00322 m_OutFile_Rate << m_TotalTime; 00323 for(i = 0; i < m_NoDistIntervals; i++) 00324 { 00325 double n = m_vDistInt_LCECount[i]; 00326 double rate = n/(deltaX*deltaT); 00327 m_OutFile_Rate << ',' << rate; 00328 } 00329 m_OutFile_Rate << '\n'; 00330 }
void LaneChangeDetector::AddCurrentEvent | ( | LaneChangeEvent * | lce | ) | [private] |
Definition at line 111 of file LaneChangeDetector.cpp.
References m_NoLaneChangeEvents, and m_vChangeEvents.
Referenced by addEvent().
00112 { 00113 m_vChangeEvents.push_back(lce); 00114 m_NoLaneChangeEvents++; 00115 }
std::vector<LaneChangeEvent*> LaneChangeDetector::m_vChangeEvents [private] |
Definition at line 46 of file LaneChangeDetector.h.
Referenced by AddCurrentEvent(), doCompositionOutput(), doRateOutput(), doSpaceTimeOutput(), doVerboseOutput(), and ReInit().
std::ofstream LaneChangeDetector::m_OutFile_Verbose [private] |
Definition at line 48 of file LaneChangeDetector.h.
Referenced by doVerboseOutput(), EndOutput(), and InitVerboseFile().
std::ofstream LaneChangeDetector::m_OutFile_Composition [private] |
Definition at line 49 of file LaneChangeDetector.h.
Referenced by doCompositionOutput(), EndOutput(), and InitCompositionFile().
std::ofstream LaneChangeDetector::m_OutFile_SpaceTime [private] |
Definition at line 50 of file LaneChangeDetector.h.
Referenced by doSpaceTimeOutput(), EndOutput(), and InitSpaceTimeFile().
std::ofstream LaneChangeDetector::m_OutFile_Rate [private] |
Definition at line 51 of file LaneChangeDetector.h.
Referenced by doRateOutput(), EndOutput(), and InitRateFile().
int LaneChangeDetector::m_NoLaneChangeEvents [private] |
Definition at line 53 of file LaneChangeDetector.h.
Referenced by AddCurrentEvent(), doCompositionOutput(), doRateOutput(), doSpaceTimeOutput(), doVerboseOutput(), LaneChangeDetector(), and ReInit().
int LaneChangeDetector::m_DistanceInterval [private] |
Definition at line 54 of file LaneChangeDetector.h.
Referenced by doRateOutput(), and LaneChangeDetector().
int LaneChangeDetector::m_NoDistIntervals [private] |
Definition at line 55 of file LaneChangeDetector.h.
Referenced by doRateOutput(), InitRateFile(), LaneChangeDetector(), and ReInit().
std::vector<int> LaneChangeDetector::m_vDistanceIntervals [private] |
Definition at line 56 of file LaneChangeDetector.h.
Referenced by doRateOutput(), InitRateFile(), and LaneChangeDetector().
std::vector<int> LaneChangeDetector::m_vDistInt_LCECount [private] |
Definition at line 57 of file LaneChangeDetector.h.
Referenced by doRateOutput(), LaneChangeDetector(), and ReInit().
std::string LaneChangeDetector::m_MetricsDir2 [private] |
Definition at line 59 of file LaneChangeDetector.h.