The intersections will be represented by two queues the two


In a city there is an intersection where two (single lane) one-way streets cross each other. Write a C or C++ program that simulates the situation at this intersection and measures how long each queue gets during a 2 hour period. Adjust the phasing of the traffic lights to minimise the two queues that form at the intersection.

A sample program is available as a starting point for the assignment. It is able to receive two command line arguments, phase for Q1 and phase for Q2 (the equivalent of adjusting the phasing of the traffic lights for each intersection). During testing you can change the command line arguments approach, but for the final submission make sure that your code is working with it (open a cmd window and test it).

The intersections will be represented by two queues. The two queues need to be implemented using a dynamic data-structure, as the number of cars in each queue are unknown before the runtime.

Notes:

1. The program must contain two queues, each one based on a linked-list.

2. Write a new method (or function) to return the number of items (length) of the queue.

3. Each car is represented by an ID number - hence you need two queues of integers.

4. You need an integer counter (clock) to count the seconds from 0 to 7200 (2 hours), which is already implemented in the example.

5. This is an event driven program - the main program is a loop that increments the clock each time it executes.

6. Every 18 seconds a car joins queue 1 and every 22 seconds a car joins queue 2. This is fixed and should not be changed (in the example, represented by variables Q1arrive and Q2arrive).

7. Every 10 seconds a car leaves a queue and crosses the intersection (depending on which queue has the green light). This is also fixed, and is represented by variable leave_rate.

8. Phasing is the number of seconds that the light is green. Start your program with a phasing of 40 seconds for queue 1 and a phasing of 30 seconds for queue 2. For "technical reasons", phasing can never be set to less than 30 seconds. Again, in the example the variables are Q1phase and Q2phase.

9. Adjust the phasing to minimise the length of the queues. The current length of the queues are printed out for every second of the runtime. During the runtime, a queue of less than 5 cars is ideal but a queue of less than 9 cars is already acceptable. Try different phasing until you get acceptable queue sizes for both Q1 and Q2 (that's when arguments from command lines are useful).

10. After trying different phasing, write down as a comment on the top of the source code what was the best combination (phasing queue 1 = __ , phasing queue 2 = __).

Solution Preview :

Prepared by a verified Expert
Other Subject: The intersections will be represented by two queues the two
Reference No:- TGS0665630

Now Priced at $40 (50% Discount)

Recommended (98%)

Rated (4.3/5)