Sim Class Reference

A class to represent the simulation handler. More...

#include <Sim.h>

Collaboration diagram for Sim:

Collaboration graph
[legend]

List of all members.

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 ()
RoadgetRoad ()
 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


Detailed Description

A class to represent the simulation handler.

Definition at line 18 of file Sim.h.


Constructor & Destructor Documentation

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]

Default Destructor.

Definition at line 12 of file Sim.cpp.

00013 {
00014         
00015 }


Member Function Documentation

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 }

Here is the call graph for this function:

bool Sim::doFullSimulation (  ) 

Does an entire simulation.

Returns:
Whether the sim has finished

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 }

Here is the call graph for this function:

void Sim::setFileIn ( string  file  ) 

Sets the file to read input from.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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 }

Here is the call graph for this function:

double Sim::getCurrentSimTime (  ) 

Gets the current time of the simulation.

Returns:
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.

Returns:
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 (  ) 

Gets the length of the road.

Returns:
The length of the road

Definition at line 91 of file Sim.cpp.

References Road::getLength(), and m_Road.

00092 {
00093         return m_Road.getLength();
00094 }

Here is the call graph for this function:

M2D Sim::getPositions (  ) 

Gets all the vehicles on the road.

Returns:
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.

Parameters:
pInSimulation Whether or not the simulation is still running
Returns:
All of the vehicles currently on the Road
This function is called while the simulation is running. It firstly populates the road each step, by calling Road.populate(), and then updates each vehicle on the road by calling Road.update(). In addition to this, the function return all of the vehicles currently on the road.

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 }

Here is the call graph for this function:

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().

Here is the call graph for this function:


Member Data Documentation

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]

Definition at line 48 of file Sim.h.

Referenced by doOneTimeStep(), and getPositions().

string Sim::m_FileIn [private]

Definition at line 49 of file Sim.h.

Referenced by init(), and setFileIn().

string Sim::m_FileOut [private]

Definition at line 50 of file Sim.h.

Referenced by init(), and setFileOut().

WORD Sim::m_FileType [private]

Definition at line 51 of file Sim.h.

Referenced by init(), and setFileType().

int Sim::m_NoLanesDirPos [private]

Definition at line 52 of file Sim.h.

Referenced by init(), and setNoLanesDirPos().

int Sim::m_NoLanesDirNeg [private]

Definition at line 53 of file Sim.h.

Referenced by init(), and setNoLanesDirNeg().

double Sim::m_SimTimeStep [private]

Definition at line 54 of file Sim.h.

Referenced by doOneTimeStep(), and setSimTimeStep().

int Sim::m_NoDirections [private]

Definition at line 55 of file Sim.h.

Referenced by init(), and setNoDirections().

int Sim::m_NoLanes [private]

Definition at line 56 of file Sim.h.

Referenced by init(), and setNoLanes().

int Sim::m_RoadLength [private]

Definition at line 57 of file Sim.h.

Referenced by init(), and setRoadLength().

int Sim::m_PercentComplete [private]

Definition at line 58 of file Sim.h.

Referenced by doOneTimeStep(), and getPercentComplete().


The documentation for this class was generated from the following files:

Generated on Wed Aug 20 00:48:50 2008 for EvolveTraffic by  doxygen 1.5.6