00001 // Parameter.cpp : implementation file 00002 // 00003 00004 #include "stdafx.h" 00005 #include "EvolveTraffic.h" 00006 #include "Parameter.h" 00007 00008 #ifdef _DEBUG 00009 #define new DEBUG_NEW 00010 #undef THIS_FILE 00011 static char THIS_FILE[] = __FILE__; 00012 #endif 00013 00015 // CParameter 00016 00017 IMPLEMENT_SERIAL(CParameter, CObject, VERSION_NUMBER) 00018 00019 CParameter::CParameter() 00020 { 00021 00022 } 00023 00024 CParameter::~CParameter() 00025 { 00026 00027 } 00028 00029 CParameter::CParameter(const CParameter& param) 00030 { 00031 this->m_Distribution = param.m_Distribution; 00032 this->m_ID = param.getID(); 00033 } 00034 00036 // CParameter diagnostics 00037 00038 #ifdef _DEBUG 00039 void CParameter::AssertValid() const 00040 { 00041 CObject::AssertValid(); 00042 } 00043 00044 void CParameter::Dump(CDumpContext& dc) const 00045 { 00046 CObject::Dump(dc); 00047 } 00048 #endif //_DEBUG 00049 00051 // CParameter serialization 00052 00053 void CParameter::Serialize(CArchive& ar) 00054 { 00055 m_Distribution.Serialize(ar); 00056 if (ar.IsStoring()) 00057 ar << m_ID; 00058 else 00059 ar >> m_ID; 00060 } 00061 00063 // CParameter message handlers 00064 00065 void CParameter::SetDefaultParams() 00066 { 00067 // Here we set the default IDM properties based on ID 00068 // No set shapes since default distribvution is DIST_NORMAL 00069 switch(m_ID) 00070 { 00071 case IDM_PARAM_T: 00072 { 00073 m_Distribution.setLocation(1.2); 00074 m_Distribution.setScale(0.05); 00075 } 00076 break; 00077 case IDM_PARAM_A: 00078 { 00079 m_Distribution.setLocation(1.0); 00080 m_Distribution.setScale(0.05); 00081 } 00082 break; 00083 case IDM_PARAM_B: 00084 { 00085 m_Distribution.setLocation(2.0); 00086 m_Distribution.setScale(0.1); 00087 } 00088 break; 00089 case IDM_PARAM_S0: 00090 { 00091 m_Distribution.setLocation(1.0); 00092 m_Distribution.setScale(0.05); 00093 } 00094 break; 00095 case IDM_PARAM_S1: 00096 { 00097 m_Distribution.setLocation(10.0); 00098 m_Distribution.setScale(0.7); 00099 } 00100 break; 00101 case IDM_PARAM_V0: 00102 { // Defined as km/h 00103 m_Distribution.setLocation(80); 00104 m_Distribution.setScale(3.0); 00105 } 00106 break; 00107 case IDM_PARAM_DELTA: 00108 { // Leave as a constant 00109 m_Distribution.setDistributionID(DIST_CONST); 00110 m_Distribution.setLocation(4); 00111 } 00112 break; 00113 case IDM_PARAM_POLITE: 00114 { // Leave as a constant 00115 m_Distribution.setDistributionID(DIST_CONST); 00116 m_Distribution.setLocation(0.0); 00117 } 00118 break; 00119 case IDM_PARAM_BIAS: 00120 { // Leave as a constant 00121 m_Distribution.setDistributionID(DIST_CONST); 00122 m_Distribution.setLocation(0.1); 00123 } 00124 break; 00125 case IDM_PARAM_DELTAATH: 00126 { // Leave as a constant 00127 m_Distribution.setDistributionID(DIST_CONST); 00128 m_Distribution.setLocation(0.3); 00129 } 00130 break; 00131 default: // IDM_PARAM_V0: 00132 { // Defined as km/h 00133 m_Distribution.setLocation(80); 00134 m_Distribution.setScale(3.0); 00135 } 00136 break; 00137 } 00138 } 00139 00140 CParameter& CParameter::operator=(const CParameter ¶m) 00141 { 00142 this->m_Distribution = param.m_Distribution; 00143 this->m_ID = param.getID(); 00144 00145 return *this; 00146 } 00147 00148 CDistribution* CParameter::getDistribution() 00149 { 00150 return &m_Distribution; 00151 } 00152 00153 void CParameter::setDistribution(CDistribution* dist) 00154 { 00155 m_Distribution = *dist; 00156 } 00157 00158 WORD CParameter::getID() const 00159 { 00160 return m_ID; 00161 } 00162 00163 void CParameter::setID(WORD id) 00164 { 00165 m_ID = id; 00166 SetDefaultParams(); 00167 } 00168 00169 // This function returns generated value for the parameter 00170 double CParameter::Generate() 00171 { 00172 return m_Distribution.Generate(); 00173 } 00174 00175 double CParameter::GenKeepingCoV(double newLocation) 00176 { 00177 return m_Distribution.GenKeepingCoV(newLocation); 00178 } 00179