#include <Sim.h>
Public Member Functions | |
void | clear () |
Clears the sim so it can be used in another simulation. | |
bool | doFullSimulation () |
Does an entire simulation. | |
void | setFileIn (string file) |
Sets the file to read input from. | |
void | setFileOut (string file) |
Sets the file to write output to. | |
void | setFileType (WORD fileType) |
Sets the file type of the input. | |
void | setNoLanesDirPos (int nlpos) |
Sets the number of lanes in the positive direction. | |
void | setNoLanesDirNeg (int nlneg) |
Sets the number of lanes in the negative direction. | |
void | setSimTimeStep (double ts) |
Sets the size of the timestep. | |
void | setNoDirections (int nd) |
Sets the number of directions. | |
void | setNoLanes (int nl) |
Sets the number of lanes. | |
void | setRoadLength (int L) |
Sets the length of the road. | |
double | getCurrentSimTime () |
Gets the current time of the simulation. | |
int | getPercentComplete () |
Road * | getRoad () |
Gets the simulation's road object. | |
double | getRoadLength () |
Gets the length of the road. | |
M2D | getPositions () |
Gets all the vehicles on the road. | |
M2D | doOneTimeStep (bool *pInSimulation) |
Steps the simulation forward by one timestep. | |
void | init () |
Initialises the simulation. | |
Sim () | |
Default Constructor. | |
virtual | ~Sim () |
Default Destructor. | |
Private Attributes | |
double | m_CurrentSimTime |
Road | m_Road |
M2D | m_vVehicles |
string | m_FileIn |
string | m_FileOut |
WORD | m_FileType |
int | m_NoLanesDirPos |
int | m_NoLanesDirNeg |
double | m_SimTimeStep |
int | m_NoDirections |
int | m_NoLanes |
int | m_RoadLength |
int | m_PercentComplete |
Definition at line 18 of file Sim.h.
Sim::Sim | ( | ) |
Default Constructor.
Definition at line 6 of file Sim.cpp.
References m_CurrentSimTime.
00007 { 00008 m_CurrentSimTime = 0.0; 00009 }
Sim::~Sim | ( | ) | [virtual] |
void Sim::clear | ( | ) |
Clears the sim so it can be used in another simulation.
This function clears all of the sim's information so that it may be used in another simulation without re-instanciating.
Definition at line 204 of file Sim.cpp.
References Road::clear(), m_CurrentSimTime, and m_Road.
Referenced by CEvolveTrafficView::doSimFinished().
00205 { 00206 m_CurrentSimTime = 0.0; 00207 m_Road.clear(); 00208 }
bool Sim::doFullSimulation | ( | ) |
Does an entire simulation.
Definition at line 64 of file Sim.cpp.
References doOneTimeStep().
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 }
void Sim::setFileIn | ( | string | file | ) |
Sets the file to read input from.
file | The file to read input from |
Definition at line 103 of file Sim.cpp.
References m_FileIn.
Referenced by CEvolveTrafficDoc::initSim().
00104 { 00105 m_FileIn = file; 00106 }
void Sim::setFileOut | ( | string | file | ) |
Sets the file to write output to.
file | The file to write output to |
Definition at line 112 of file Sim.cpp.
References m_FileOut.
Referenced by CEvolveTrafficDoc::initSim().
00113 { 00114 m_FileOut = file; 00115 }
void Sim::setFileType | ( | WORD | fileType | ) |
Sets the file type of the input.
fileType | The file type of the input |
Definition at line 121 of file Sim.cpp.
References m_FileType.
Referenced by CEvolveTrafficDoc::initSim().
00122 { 00123 m_FileType = fileType; 00124 }
void Sim::setNoLanesDirPos | ( | int | nlpos | ) |
Sets the number of lanes in the positive direction.
nlpos | The number of lanes in the positive direction |
Definition at line 130 of file Sim.cpp.
References m_NoLanesDirPos.
Referenced by CEvolveTrafficDoc::initSim().
00131 { 00132 m_NoLanesDirPos = nlpos; 00133 }
void Sim::setNoLanesDirNeg | ( | int | nlneg | ) |
Sets the number of lanes in the negative direction.
nlneg | The number of lanes in the negative direction |
Definition at line 139 of file Sim.cpp.
References m_NoLanesDirNeg.
Referenced by CEvolveTrafficDoc::initSim().
00140 { 00141 m_NoLanesDirNeg = nlneg; 00142 }
void Sim::setSimTimeStep | ( | double | ts | ) |
Sets the size of the timestep.
ts | The size of the timestep |
Definition at line 148 of file Sim.cpp.
References m_SimTimeStep.
Referenced by CEvolveTrafficDoc::initSim().
00149 { 00150 m_SimTimeStep = ts; 00151 }
void Sim::setNoDirections | ( | int | nd | ) |
Sets the number of directions.
nd | The number of directions |
Definition at line 157 of file Sim.cpp.
References m_NoDirections.
Referenced by CEvolveTrafficDoc::initSim().
00158 { 00159 m_NoDirections = nd; 00160 }
void Sim::setNoLanes | ( | int | nl | ) |
Sets the number of lanes.
nl | The number of lanes |
Definition at line 166 of file Sim.cpp.
References m_NoLanes.
Referenced by CEvolveTrafficDoc::initSim().
00167 { 00168 m_NoLanes = nl; 00169 }
void Sim::setRoadLength | ( | int | L | ) |
Sets the length of the road.
L | The length of the road |
Definition at line 175 of file Sim.cpp.
References m_Road, m_RoadLength, and Road::setRoadLength().
Referenced by CEvolveTrafficDoc::initSim().
00176 { 00177 m_RoadLength = L; 00178 m_Road.setRoadLength(L); 00179 }
double Sim::getCurrentSimTime | ( | ) |
Gets the current time of the simulation.
Definition at line 185 of file Sim.cpp.
References m_CurrentSimTime.
Referenced by CEvolveTrafficView::DrawTimer(), and CEvolveTrafficView::OnRunInvisible().
00186 { 00187 return m_CurrentSimTime; 00188 }
int Sim::getPercentComplete | ( | ) |
Definition at line 82 of file Sim.cpp.
References m_PercentComplete.
Referenced by CEvolveTrafficView::UpdateProgressBar().
00083 { 00084 return m_PercentComplete; 00085 }
Road * Sim::getRoad | ( | ) |
Gets the simulation's road object.
Definition at line 194 of file Sim.cpp.
References m_Road.
Referenced by CEvolveTrafficDoc::initSim().
00195 { 00196 return &m_Road; 00197 }
double Sim::getRoadLength | ( | ) |
M2D Sim::getPositions | ( | ) |
Gets all the vehicles on the road.
Definition at line 77 of file Sim.cpp.
References m_vVehicles.
00078 { 00079 return m_vVehicles; 00080 }
M2D Sim::doOneTimeStep | ( | bool * | pInSimulation | ) |
Steps the simulation forward by one timestep.
pInSimulation | Whether or not the simulation is still running |
Definition at line 45 of file Sim.cpp.
References Road::getPercentComplete(), Road::getVehicles(), m_CurrentSimTime, m_PercentComplete, m_Road, m_SimTimeStep, m_vVehicles, Road::populate(), and Road::update().
Referenced by doFullSimulation(), CEvolveTrafficView::doLoop(), and CEvolveTrafficView::OnRunInvisible().
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 }
void Sim::init | ( | ) |
Initialises the simulation.
This function takes data which has been passed from the Graphical User Interface, and initialises the Road object with this data.
Definition at line 22 of file Sim.cpp.
References Road::init(), Road::initTruckGroup(), m_CurrentSimTime, m_FileIn, m_FileOut, m_FileType, m_NoDirections, m_NoLanes, m_NoLanesDirNeg, m_NoLanesDirPos, m_Road, m_RoadLength, Road::setNoDirections(), Road::setNoLanes(), Road::setNoLanesDirNeg(), Road::setNoLanesDirPos(), and Road::setRoadLength().
Referenced by CEvolveTrafficDoc::initSim().
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 }
double Sim::m_CurrentSimTime [private] |
Definition at line 46 of file Sim.h.
Referenced by clear(), doOneTimeStep(), getCurrentSimTime(), init(), and Sim().
Road Sim::m_Road [private] |
Definition at line 47 of file Sim.h.
Referenced by clear(), doOneTimeStep(), getRoad(), getRoadLength(), init(), and setRoadLength().
M2D Sim::m_vVehicles [private] |
string Sim::m_FileIn [private] |
string Sim::m_FileOut [private] |
WORD Sim::m_FileType [private] |
int Sim::m_NoLanesDirPos [private] |
int Sim::m_NoLanesDirNeg [private] |
double Sim::m_SimTimeStep [private] |
int Sim::m_NoDirections [private] |
int Sim::m_NoLanes [private] |
int Sim::m_RoadLength [private] |
int Sim::m_PercentComplete [private] |