Class Place | Class Car | Class Road |
Constructor
SetLocation(row, col) GetLocation(row, col) |
Constructor
Reset(Car& c) |
Constructor
Destructor |
Block( )
Free( ) bool IsBlocked( ) bool IsFree( ) bool FreeToMove(dir) Move(dir) |
ComitToMove( )
MoveCar( ) bool Done( ) |
SetDirection(dir)
Insert(row, col) Link(Place*) |
Display( ) | DrawCar( )
EraseCar( ) |
Place* NextPlace(here)
Place* FindPlace(here) |
Top | Previous | Next |
Class TrafficLight | Class CarQueue |
Constructor -- physical location only | Constructor |
InitStatus(light cycle durations)
Update( ) |
Insert(Car)
Comit( ) Move( ) |
Display( ) | bool IsEmpty( )
bool IsFull( ) int Size( ) |
Top | Previous | Next |
TLight.InitStatus( );
Timer Loop: {
TLight.Update( );
ForAll CQueue: {
CQueue.Comit( );
CQueue.Move( );
CQueque.Insert(new car
w. probability p)
}
}
Top | Previous | Next |
The traffic light is initialized.
Simulation is controlled by the timer, the light and all cars advance
one 'unit' per timer cycle.
Light advances in its cycle.
Each car queue traverses all its cars to see if
they can move, then moves them ahead.
After the traversal, if a car has reached the end,
it is removed from the queue.
Finally, new car is generated with a given probability
(Reset the only Car object
defined for the simulation)
and if there is a free place
on the road, enter the car queue.
Top | Previous | Next |
Place
Car
Road
TrafficLight
CarQueue
Top | Previous | Next |
Top | Previous | Next |