00001 00002 #include "stdafx.h" 00003 #include "Sim.h" 00004 00006 Sim::Sim() 00007 { 00008 m_CurrentSimTime = 0.0; 00009 } 00010 00012 Sim::~Sim() 00013 { 00014 00015 } 00016 00022 void Sim::init() 00023 { 00024 m_Road.setNoDirections(m_NoDirections); 00025 m_Road.setNoLanes(m_NoLanes); 00026 m_Road.setNoLanesDirPos(m_NoLanesDirPos); 00027 m_Road.setNoLanesDirNeg(m_NoLanesDirNeg); 00028 m_Road.setRoadLength(m_RoadLength); 00029 00030 m_Road.initTruckGroup(m_FileIn, m_FileOut, m_FileType); 00031 m_CurrentSimTime = m_Road.init(); 00032 } 00033 00045 M2D Sim::doOneTimeStep(bool* pInSimulation) 00046 { 00047 m_Road.populate(m_SimTimeStep,m_CurrentSimTime); 00048 00049 bool SimOver = m_Road.update(m_SimTimeStep, m_CurrentSimTime); 00050 if(SimOver) 00051 (*pInSimulation) = false; // we're no longer in a simulation 00052 00053 m_vVehicles = m_Road.getVehicles(); 00054 m_CurrentSimTime += m_SimTimeStep; 00055 m_PercentComplete = m_Road.getPercentComplete(); 00056 00057 return m_vVehicles; 00058 } 00059 00064 bool Sim::doFullSimulation() 00065 { 00066 bool InSim = true; 00067 while(InSim) 00068 doOneTimeStep(&InSim); // InSim becomes false when sim is over 00069 00070 return false; // so we know when it's finished 00071 } 00072 00077 M2D Sim::getPositions() 00078 { 00079 return m_vVehicles; 00080 } 00081 00082 int Sim::getPercentComplete() 00083 { 00084 return m_PercentComplete; 00085 } 00086 00091 double Sim::getRoadLength() 00092 { 00093 return m_Road.getLength(); 00094 } 00095 00096 00097 // Set functions for the initialization 00098 00103 void Sim::setFileIn(string file) 00104 { 00105 m_FileIn = file; 00106 } 00107 00112 void Sim::setFileOut(string file) 00113 { 00114 m_FileOut = file; 00115 } 00116 00121 void Sim::setFileType(WORD fileType) 00122 { 00123 m_FileType = fileType; 00124 } 00125 00130 void Sim::setNoLanesDirPos(int nlpos) 00131 { 00132 m_NoLanesDirPos = nlpos; 00133 } 00134 00139 void Sim::setNoLanesDirNeg(int nlneg) 00140 { 00141 m_NoLanesDirNeg = nlneg; 00142 } 00143 00148 void Sim::setSimTimeStep(double ts) 00149 { 00150 m_SimTimeStep = ts; 00151 } 00152 00157 void Sim::setNoDirections(int nd) 00158 { 00159 m_NoDirections = nd; 00160 } 00161 00166 void Sim::setNoLanes(int nl) 00167 { 00168 m_NoLanes = nl; 00169 } 00170 00175 void Sim::setRoadLength(int L) 00176 { 00177 m_RoadLength = L; 00178 m_Road.setRoadLength(L); 00179 } 00180 00185 double Sim::getCurrentSimTime() 00186 { 00187 return m_CurrentSimTime; 00188 } 00189 00194 Road* Sim::getRoad() 00195 { 00196 return &m_Road; 00197 } 00198 00204 void Sim::clear() 00205 { 00206 m_CurrentSimTime = 0.0; 00207 m_Road.clear(); 00208 }