Lane Class Reference

A class representing a lane in a road. More...

#include <Lane.h>

Collaboration diagram for Lane:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void setOutputDetector (Detector *out)
 Sets the output detector for the direction.
 Lane ()
 Default constructor.
 Lane (int length, std::vector< Detector * > detectors, bool DirPos, bool AllowLaneChange)
 Main constructor.
virtual ~Lane ()
 Default destructor.
bool update (double step)
 Updates the positions of all Vehicles in the Lane.
int getIndex ()
 Gets the index of the lane.
double getLastPos ()
 Gets the position of the last vehicle in the lane.
int getNoVeh ()
 Gets the number of vehicles in the lane.
double getLength ()
 Gets the length of the Lane.
void insert (int i, Vehicle *pVeh)
 Inserts a Vehicle into the Lane.
bool ChangeLanes (Vehicle *pVeh)
 Changes a Vehicle's Lane if advantageous and possible.
void setRightLane (Lane *right)
 Sets a pointer to the Lane to the right of the current Lane.
void setLeftLane (Lane *left)
 Sets a pointer to the Lane to the left of the current Lane.
std::vector< Vehicle * > getPos ()
 Gets all the Vehicles currently in the Lane.

Private Member Functions

VehicleFinadAdjacentVehicle (Lane *AdjacentLane, double location, bool front, int *iAdjacentLane=NULL)
 Finds a vehicle in the adjacent lane.
void ImplementLaneChange (Vehicle *pVeh, int LaneChangeID, int iVehLeftLane, int iVehRightLane)
 Changes a vehicle to another lane.
void AddVehicleToDetector (double prevPosition, double curPosition, Vehicle *pVeh)
 Adds a vehicle to the detectors list of vehicles for that step.

Private Attributes

std::vector< Vehicle * > m_pVehicles
std::vector< Detector * > m_vDetectors
int m_Dir
int m_iLane
double m_Flow
double m_RoadLength
int m_NoVeh
double m_PrevVehiclePosition
bool m_AllowLaneChanging
bool m_DirPos
Lanem_LeftLane
Lanem_RightLane
Detectorm_OutputDetector

Static Private Attributes

static int m_index = 0


Detailed Description

A class representing a lane in a road.

Constructor & Destructor Documentation

Lane::Lane (  ) 

Default constructor.

Lane::Lane ( int  RoadLength,
std::vector< Detector * >  detectors,
bool  DirPos,
bool  AllowLaneChange 
)

Main constructor.

The main constructor used for creating a Lane object.

Parameters:
RoadLength The length of the Road
detectors The detectors to be used in the lane
DirPos Whether the lane is in the positive direction or not
AllowLaneChange Whether lane changing is allowed

Lane::~Lane (  )  [virtual]

Default destructor.


Member Function Documentation

void Lane::setOutputDetector ( Detector out  ) 

Sets the output detector for the direction.

Parameters:
out The output detector

bool Lane::update ( double  step  ) 

Updates the positions of all Vehicles in the Lane.

This function is called for each iteration of the simulation, and handles the updating of the positions of Vehicles, and the removal of Vehicles which are no longer on the Road. If there are any Vehicles on the Road, the Vehicle at the head of the Lane is updated with respect to the clear Road ahead of it. Following this, all Vehicles following the Vehicle at the head of the Road are updated with respect to the preceding Vehicle. These Vehicles are also checked to see if it is time to determine if changing to another Lane would be advantageous. After all Vehicles have been updated, it is checked to see whether the Vehicle at the head of the Lane has yet passed the end of the Road. If it has, it is removed from the Lane and the simulation. Vehicles are also checked to see if they have passed a detector during the update

Parameters:
step The timestep
Returns:
Whether the lane is empty or not
See also:
changeLanes()

int Lane::getIndex (  ) 

Gets the index of the lane.

Returns:
The index of the lane

double Lane::getLastPos (  ) 

Gets the position of the last vehicle in the lane.

Returns:
The position of the last vehicle in the lane

int Lane::getNoVeh (  ) 

Gets the number of vehicles in the lane.

Returns:
The number of vehicles in the lane

double Lane::getLength (  ) 

Gets the length of the Lane.

Returns:
The length of the Lane

void Lane::insert ( int  i,
Vehicle pVeh 
)

Inserts a Vehicle into the Lane.

This function inserts a given Vehicle into a particular position in a Lane

Parameters:
i The position to insert the Vehicle into
pVeh The Vehicle to insert

bool Lane::ChangeLanes ( Vehicle pVeh  ) 

Changes a Vehicle's Lane if advantageous and possible.

Parameters:
pVeh The vehicle changing lanes
Returns:
Whether or not the vehicle has changed lane
This function is called whenever it is time for a Vehicle to check whether or not it would be advantageous to move to another Lane. The vehicle finds its neighbours in the left and right lanes, and then decides whether to change lane, or which lane to change to, based on their properties.

void Lane::setRightLane ( Lane right  ) 

Sets a pointer to the Lane to the right of the current Lane.

Parameters:
right The Lane to point to

void Lane::setLeftLane ( Lane left  ) 

Sets a pointer to the Lane to the left of the current Lane.

Parameters:
left The Lane to point to

std::vector< Vehicle * > Lane::getPos (  ) 

Gets all the Vehicles currently in the Lane.

This function returns the vector which contains pointers to all Vehicles which are currently in the Lane

Returns:
All of the Vehicles in the Lane

Vehicle * Lane::FinadAdjacentVehicle ( Lane AdjacentLane,
double  location,
bool  front,
int *  iAdjacentLane = NULL 
) [private]

Finds a vehicle in the adjacent lane.

Parameters:
AdjacentLane The lane at which we are looking
location The location of the vehicle wishing to change
front Whether or not we are looking for the vehicle in front of the current vehicle's position
iAdjacentLane The index to switch into in the adjacent lane
Returns:
The vehicle desired
This function looks for either the vehicle that would be in front of the current vehicle if it were in the same lane, or the vehicle that would be behind if it were in the same lane. It returns the appropriate vehicle, and sets the iAdjacentIndex to the index into which the current vehicle should change if it changes lane

void Lane::ImplementLaneChange ( Vehicle pVeh,
int  LaneChangeID,
int  iVehLeftLane,
int  iVehRightLane 
) [private]

Changes a vehicle to another lane.

Parameters:
pVeh The vehicle changing lane
LaneChangeID The lane to change to
iVehLeftLane The index of the vehicle if moving to the left lane
iVehRightLane The index of the vehicle if moving to the right lane
This function inserts the vehicle that is changing lane into the appropriate lane

void Lane::AddVehicleToDetector ( double  prevPosition,
double  curPosition,
Vehicle pVeh 
) [private]

Adds a vehicle to the detectors list of vehicles for that step.

Parameters:
prevPosition The vehicle's previous position
curPosition The vehicle's current position
pVeh The vehicle passing the detector


Member Data Documentation

std::vector<Vehicle*> Lane::m_pVehicles [private]

std::vector<Detector*> Lane::m_vDetectors [private]

int Lane::m_Dir [private]

int Lane::m_index = 0 [static, private]

int Lane::m_iLane [private]

double Lane::m_Flow [private]

double Lane::m_RoadLength [private]

int Lane::m_NoVeh [private]

double Lane::m_PrevVehiclePosition [private]

bool Lane::m_AllowLaneChanging [private]

bool Lane::m_DirPos [private]

Lane* Lane::m_LeftLane [private]

Lane* Lane::m_RightLane [private]


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

Generated on Fri Jul 25 16:11:19 2008 for EvolveTraffic by  doxygen 1.5.6