00001 // Detector.cpp: implementation of the Detector class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "EvolveTraffic.h" 00007 #include "Detector.h" 00008 00009 #ifdef _DEBUG 00010 #undef THIS_FILE 00011 static char THIS_FILE[]=__FILE__; 00012 #define new DEBUG_NEW 00013 #endif 00014 00016 // Construction/Destruction 00018 00019 Detector::Detector() 00020 { 00021 m_TotalTime = 0.0; 00022 m_CurrentTime = 0.0; 00023 m_IntervalNo = 0; 00024 m_MetricsDir = "C:\\EvolveTraffic\\Metrics\\"; 00025 } 00026 00027 Detector::~Detector() 00028 { 00029 00030 } 00039 void Detector::CheckForOutputTime(double step) 00040 { 00041 m_TotalTime += step; 00042 m_CurrentTime += step; 00043 if(m_CurrentTime >= m_TimeInterval) 00044 { 00045 m_CurrentTime -= m_TimeInterval; // We reset the timer 00046 m_IntervalNo++; // increase the index 00047 doIntervalOutput(); // we call the virtual write function 00048 } 00049 } 00050 00051 std::string Detector::MapDetVehTypeToString(WORD DetVehType) 00052 { 00053 switch(DetVehType) 00054 { 00055 case METRICS_VEH_ALL: return "All"; 00056 case METRICS_VEH_CAR: return "Car"; 00057 case METRICS_VEH_SMALLTRUCK: return "ST"; 00058 case METRICS_VEH_LARGETRUCK: return "LT"; 00059 case METRICS_VEH_CRANE: return "Crane"; 00060 case METRICS_VEH_LOWLOADER: return "LL"; 00061 default: return "All"; 00062 } 00063 } 00064 00065 std::string Detector::MapDirToString(bool DirPos) 00066 { 00067 if(m_DirPos) 00068 return "Pos"; 00069 else 00070 return "Neg"; 00071 } 00072 00082 double Detector::FindDetectorArrivalTime(Vehicle *pVeh, const double curTime) 00083 { 00084 double distBeyondDetector = pVeh->getPos() - m_Location; 00085 double ArrivalTime = curTime - distBeyondDetector/pVeh->getVelocity(); 00086 00087 return ArrivalTime; 00088 } 00089 00090 int Detector::getLocation() 00091 { 00092 return m_Location; 00093 } 00094 00095 bool Detector::getDirPos() 00096 { 00097 return m_DirPos; 00098 } 00099 00100 WORD Detector::getDetectorType() 00101 { 00102 return m_DetectorType; 00103 }