00001 // SpeedLimit.cpp: implementation of the SpeedLimit class. 00002 // 00004 00005 #include "stdafx.h" 00006 #include "SpeedLimit.h" 00007 00008 #ifdef _DEBUG 00009 #undef THIS_FILE 00010 static char THIS_FILE[]=__FILE__; 00011 #define new DEBUG_NEW 00012 #endif 00013 00015 // Construction/Destruction 00017 00019 SpeedLimit::SpeedLimit(int start, int end, double limit, bool DirPos) 00020 { 00021 m_Beginning = start; 00022 m_End = end; 00023 m_DirPos = DirPos; 00024 m_SpeedLimit = limit; 00025 } 00026 00028 SpeedLimit::~SpeedLimit() 00029 { 00030 00031 } 00032 00033 double SpeedLimit::getSpeedLimit() 00034 { 00035 return m_SpeedLimit; 00036 } 00037 00047 void SpeedLimit::addVehicle(Vehicle *pVeh) 00048 { 00049 double curV0 = pVeh->getDesiredVel(); 00050 double newV0 = curV0; // set limit to current V0 if curV0 < limit 00051 00052 // do we need to generate a new lower V0? 00053 if(curV0 > m_SpeedLimit) 00054 { 00055 WORD veh_id = pVeh->getID(); 00056 CIDMParameterSet* paramSet = getIDMParams(veh_id); 00057 CParameter V0 = (*paramSet->get_V0()); 00058 // Initial method - generate new V0 00059 //newV0 = V0.GenKeepingCoV(m_SpeedLimit)*KM_PER_H_TO_M_PER_S; 00060 // revised method - keep ratio of v0/location constant 00061 double meanV0 = (V0.getDistribution()->getLocation()*KM_PER_H_TO_M_PER_S); 00062 double v0ratio = curV0/meanV0; 00063 newV0 = v0ratio * m_SpeedLimit; 00064 //TRACE("***Speed limit - m_SpeedLimit: %f\tcurV0: %f\tmeanV0: %f\tv0ratio: %f\tnewV0: %f\n",m_SpeedLimit, curV0, meanV0, v0ratio, newV0); 00065 } 00066 // this method allows for other driver models 00067 DriverModel* driver = pVeh->getDriver(); 00068 driver->SetSpeedLimit(newV0); // always call this function, even if not changing V0 00069 } 00070 00075 void SpeedLimit::removeVehicle(Vehicle *pVeh) 00076 { 00077 DriverModel* driver = pVeh->getDriver(); 00078 driver->ClearSpeedLimit(); 00079 }