You are to use the queue data structure to design a traffic control system at an
ID: 3655116 • Letter: Y
Question
You are to use the queue data structure to design a traffic control system at an intersection to help ease congestion. To simplify the problem, there is only one land each way and no turn is permitted. For a bonus, you may add left and right turns. Use a random number generator to determine the arrival of a car to the intersection. The design must make the traffic flow without waiting or keep each car's waiting to the minimal (so there won't be congestion). The program must show in output (in real time) the cars in each lane and how long each car has waited. Use a GUI.Explanation / Answer
Random number generator cranks out values from 1-4 (or 0-3, if you prefer), pushes it to the corresponding queue. Once a certain lane reaches a set value (ie, 3 cars waiting in one lane), open that lane and empty it. If no lane has hit that value, open the one with the most data in the queue. I doubt they want you to thread this to keep up the addition of cars while you're checking and removing, so that should help. Keep each queue open for a set period of ticks. If a car is going to an open queue, simply don't add it as it would go right through the intersection. You could output data with each tick or output data whenever a lane is closed/opened.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.