Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is going to be written in C++ and it is a car simulation with street lights. 1. A traffic light exists which permits

This program is going to be written in C++ and it is a car simulation with street lights.

1. A traffic light exists which permits precisely one car out from each street at a time (yes, this is not a normal intersection). The green light is active in a counter-clockwise pattern around the intersection, starting at the top. The intersection looks like the figure below. When one light is green, all of the other streets lights are red.

2. It takes precisely two seconds for each car to drive from any street to any other street through the intersection. Cars begin driving immediately when the light changes green and there is a sign at each street instructing drivers one car per green light.

3. It takes three seconds for the light to change from green to red.

4. Each time the light changes, there is a 25% chance that a new car will show up at the intersection on each street. Meaning, theres a 25% chance a new car will show up at the top street, another 25% chance that a car will show up at the left street, and so on every time the light changes.

5. If there are no cars waiting at a particular street entering the intersection, the traffic light still waits for a car to proceed. (Theres no sensors or fancy equipment advising the traffic light to skip an empty street).

6. At any one time, only one car may be in the intersection.

7. A car cannot enter the road and cross the intersection both on the same green light (they must come to a complete stop even if theres no car in front of them). That is to say, if a new car arrives and theres no car in front it, the new car cannot proceed through the intersection until the next time that the light turns green.

8. You will need to track how much virtual time has passed. This is much easier than it sounds. You simply need to have a variable to which you add a number of seconds for each event that occurs. You may need to make multiple virtual clocks to measure both elapsed time and time that the intersection has a car in it. You also need to be careful about ensuring that you dont double-count time. (e.g. a green light lasts three seconds and the car takes 2 seconds to go through the intersection only three seconds have elapsed).

This is the first implementation of four and each one needs to be in its own c++ file.

1. You should create a class to represent the roads and instances of the roads. Create other classes and instances as necessary. You may wish to consider using an array to represent the four in-bound roads as it will ultimately make it easy to manage your code. (file: sim-1.cpp)

2. You should run your simulation for 1 million simulated seconds and report the following statistics:

a. The average number of cars waiting to enter the intersection from each road. (The average to be calculate by measuring once per cycle the number of cars waiting to enter the intersection and then dividing the sum of all of the measurements by the number of cycles.)

b. The average utilization of the intersection (what percent of the time is there a car in the intersection?)

Second implementation:

1. The traffic light is made more intelligent by the introduction of sensors such that the light will only turn green if there is a car waiting at the road (it skips roads with no waiting cars). (file: sim-2.cpp)

2. You should run your simulation for 1 million simulated seconds and report the following statistics:

a. The average number of cars waiting to enter the intersection.

b. The average utilization of the intersection (what percent of the time is there a car in the intersection?)

Third implentation:

a. If the probability of a car arriving increases from 25% to 50%, how is traffic affected?

Fourth implementation:

b. Given the (a) above, if the amount of time between lights is decreased from 3 seconds to 2.5 seconds, how is traffic affected?

This part is for the third and fouth implementaions:

For each of the two above scenarios, you should run your simulation for 1 million simulated seconds and report the following statistics:

a. The average number of cars waiting to enter the intersection.

b. The average utilization of the intersection (what percent of the time is there a car in the intersection?)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions