Outline
Classes used to build the scenery and infrastructure
Classes manipulated by the simulation run
Simulation
Overview from the top
Design of classes
Design alternatives and tradeoffs


Classes used to build the scenery and infrastructure:
 
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


Classes manipulated by the simulation run:
 
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


Simulation:

TLight.InitStatus( );
Timer Loop: {
    TLight.Update( );
    ForAll CQueue: {
        CQueue.Comit( );
        CQueue.Move( );
        CQueque.Insert(new car w. probability p)
    }
}
 
Top Previous Next


Overview from the top:

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



Design of classes:

Place
Car
Road
TrafficLight
CarQueue
 
 
Top Previous Next


Design alternatives and tradeoffs
 
 
Top Previous Next