Intersection Problem Statement

 

You will be simulating automobile traffic flow/traffic signals at a typical intersection.  Traffic flows in both directions on each of the cross streets.  Cars form into eight different queues at the intersection:   

AbbreviationTraffic Flow

 

 

N

from the north, headed straight south

NL

from the north, headed east (left at intersection)

E

from the east, headed straight west

EL

from the east, headed south (left at intersection)

S

from the south, headed straight north

SL

from the south, headed west (left at intersection)

W

from the west, headed straight east

WL

from the west, headed north (left at intersection)

 

You must adhere to the following specifications.  

You will have an intersection class in intersection.h and intersection.cpp files.

Your testing files should, again, be called testing.cpp.  From our testing.cpp, we will #include intersection.h.  We will also create class instances in testing.cpp, using a lines such as:
              intersection mainStreet;
              intersection southState;

Your intersection class must have the following public functions:
void ChangeLight() which advances which queues get the green light according to the rules defined above.  For example, if E and W had the red light and ChangeLight() is executed, then NL and SL would get the red light.  It releases up to 5 cars from each queue, and prints out the car numbers that clears the queue.  For example:

            From East:  Clear 3, 4, 5, 9
            From West:  Clear 6, 7

          void EnterCar(string direction) which signifies that a car approaches the intersection from direction.  When a car enters the intersection, it is assigned a unique car number.  If it can, the car clears the intersection and prints out a message such as "Car 5 clears north."  Or else, the car is added to the direction queue and prints out a message such as "Car 5 added to NL queue."

          void CheckStatus(int& north, int& northLeft, int& east, int& eastLeft, int& south, int& southLeft, int& west, int& westLeft) returns via reference parameters the number of cars in each of the queues.

 

 

 

1 Flow of Events for the Clear Intersection Use Case

1.1 Preconditions 
The Initialize subflow of the Change Light use case, the Initialize subflow of the Light Status use case,  and Initialize subflow of the Car Queue use case must execute before the use case begins.

 

1.2 Main Flow

This use case begins when a car enters the intersection.   The car checks its status (S-1).  The use case ends when the car clears the intersection (S-4).

 

             

1.3 Subflows

            S-1 Check Status

Sends checks its status (S-2, S-3).  If the light is green and the queue is empty, the car clears the intersection (S-4).   Otherwise, it joins a queue (S-5).

 

            S-2 Check Light

Execute the Report Status subflow of the Light Status use case.  Send a message indicating if the light is green or red.

 

S-3 Check Queue

Execute the Report Status subflow of the Car Queue use case.  Send a message indicating if the queue is empty or not.

 

S-4 Go

The car clears the intersection and the use case ends.

 

S-5 Join a Queue

Send a message to the Add to Queue subflow of the Car Queue use case.

 

 

 

1.4  Alternative Flows
 



 

2 Flow of Events for the Change Light Use Case

2.1 Preconditions 
None.

 

2.2 Main Flow

 The Traffic lights are initialized (S-1).  The lights change (S-2) when the Traffic Light Controller advances the lights.

 

             

2.3 Subflows

            S-1 Initialize

The traffic lights are initialized with all lights red except NL and SL.  NL and SL are green.

 

S-2  Advance lights

Lights are advanced in the following order:

When the system is initiated, the traffic signal allows traffic to flow from NL and SL.  Next it allows traffic to flow from N and S.  Then, it allows traffic flow from EL and WL.  Lastly, it allows traffic to flow from E and W -- then starts again with NL and SL and so forth. 

 

When a light is changed (from green to red or from red to green), a message is sent to the Update Status subflow of the Light Status use case. 

 

2.4  Alternative Flows
 



3 Flow of Events for the Check Status Use Case

3.1 Preconditions 
None.

 

3.2 Main Flow

Status is obtained (S-1) and reported (S-2)

 

             

3.3 Subflows

            S-1 Obtain status

Send a message asking for the how many cars are in each queue via the Report Status subflow of the Car Queue use case.

 

S-2 Report status

Return a message indicating how many cars are in each queue

 

 

3.4  Alternative Flows
 



4 Flow of Events for the Light Status Use Case

4.1 Preconditions 
None.

 

4.2 Main Flow

Update (S-1) and report (S-2) the status of a traffic light color.

 

             

4.3 Subflows

            S-1 Update status

Change the color of the lights.  If a light is turned to green, send a message to the Release from Queue subflow of the Car Queue use case.

 

 

S-2 Report status

Send a message indicating the color of the traffic light

 

 

4.4   Alternative Flows

 

 

5 Flow of Events for the Car Queue Use Case

5.1 Preconditions 
None.

 

5.2 Main Flow

This use case begins by initializing the queue (S-1).  Cars may be added to the queue (S-2) or released from the queue (S-3).  Alternatively, the use case may report status (S-4) on how many cars are in the queue.

 

             

5.3 Subflows

            S-1 Initialize

The queue is initialized with zero cars.

 

S-2 Add to queue 

Receives a message from the Join a Queue subflow of the Clear Intersection use case.  Adds car to queue.

 

S-3 Release from queue

Release up to five cars from the queue.  Send a message to the Go subflow of the Clear Intersection use case.

 

S-4 Report status

Send a message indicating how many cars are in the queue.

 

5.4  Alternative Flows