# A First Course in Mathematical Modeling (4th Edition) View more editions Solutions for Chapter B1

• 472 step-by-step solutions
• Solved by professors & experts
• iOS, Android, & web
Chapter: Problem:

Consider an intersection of two one-way streets controlled by a traffic light. Assume that between 5 and 15 cars (varying probabilistically) arrive at the intersection every 10 sec in direction 1, and that between 6 and 24 cars arrive every 10 sec going in direction 2. Suppose that 36 cars per 10 sec can cross the intersection in direction 1 and that 20cars per 10 sec can cross the intersection in direction 2 if the traffic light is green. No turning is allowed. Initially, assume that the traffic light is green for 30 sec and red for 70 sec in direction 1. Write a simulation algorithm to answer the following questions for a 60-min time period:

a. How many cars pass through the intersection in direction 1 during the hour?

b. What is the average waiting time of a car stopped when the traffic signal is red in direction 1? The maximum waiting time?

c. What is the average length of the queue of cars stopped for a red light in direction 1? The maximum length?

d. What is the average number of cars passing through the intersection in direction 1 during the time when the traffic light is green? What is the maximum number?

e. Answer Problems (a)–(d) for direction 2. How would you use your simulation to determine the switching period for which the total waiting time in both directions is as small as possible? (You will have to modify it to account for the waiting times in direction 2.)

Sample Solution
Chapter: Problem:
• Step 1 of 7

Summary of Traffic Light Simulation Terms

 segmentSize length of a segment in seconds minArrival minimum number of cars arriving per segment maxArrival maximum number of cars arriving per segment throughput number of cars per segment that can cross when the traffic light is green redSegments size in segments when the signal is red greenSegments size in segments when the signal is green initialState initial state the traffic light is in totalSegments total amount of time, in segments, to simulate for arrivals number of cars arriving in a segments – a random number between minArrival and maxArrival state state the traffic light is in, red or green stateSegments number of segments remaining in the current state waitRed number of segments waited by the cars during a segment when the light is red waitingRed have cars been waiting at a red light? waitRedSegment segment from which cars have been waiting at a red traffic light numCross number of cars passing through the intersection during a green light queue length of the queue at the intersection numGreen number of times during which the traffic light was green numRed number of time the traffic light was red totalWait total waiting time for cars when the traffic light was red totalQueue total length of the queues formed when the traffic light was red SEGMENT current segment, starting at 0 NUMCARS total number of cars passing through the crossing during totalSegments time AVGWAITTIME average waiting time of cars when the light is red MAXWAITTIME maximum waiting time of cars when the light is red AVGQUEUE average length of queue of cars waiting when the light is red MAXQUEUE maximum length of queue of cars waiting when the light is red AVGNUMCARS average number of cars crossing when the light is green MAXNUMCARS maximum number of cars crossing when the light is green
• Step 2 of 7

Traffic Light Simulation Algorithm

 Input segmentSize, minArrival, maxArrival, throughput, redSegments, greenSegments, initialState and totalSegments Output NUMCARS, AVGWAITTIME, MAXWAITTIME, AVGQUEUE, MAXQUEUE, AVGNUMCARS and MAXNUMCARS

STEP 1 Initially set the following parameters to zero: queue, numGreen, numRed, NUMCARS, totalWait, MAXWAITTIME, totalQueue, MAXQUEUE and MAXNUMCARS.

STEP 2 Set state to initialState.

state = initialState

STEP 3 While totalSegments > 0; do Steps 4-26.

STEP 4 If the state is green, then increment numGreen by 1 and set numCross to zero. GOTO Step 7.

If state = green, then numGreen += 1, numCross = 0.

GOTO Step 7.

STEP 5 Increment numRed by 1 and set waitRed to zero.

numRed += 1.

waitRed = 0

STEP 6 If queue > 0, then set waitingRed to true and set waitRedSegment to SEGMENT, Else set waitingRed to false.

If queue > 0, then waitingRed = true,

waitRedSegment = SEGMENT;

Else waitingRed = false.

STEP 7 Set stateSegments to the segments for state.

If state = red, then stateSegments = redSegments;

Else state = green, then stateSegments = greenSegments.

STEP 8 Decrement totalSegments by 1.

totalSegments -= 1.

STEP 9 Add arrival to queue.

queue += arrival.

STEP 10 If state = green, then GOTO Step 13.

STEP 11 Update the amount of time that cars have been waiting in the queue by adding queue to waitRed.

waitRed += queue.

STEP 12 If waitingRed is false and the length of queue is not zero, then set waitingRed to true and set waitRedSegment to SEGMENT. GOTO Step 15.

If (waitingRed = false && queue > 0), then waitingRed = true,

waitRedSegment = SEGMENT.

STEP 13 If queue is less than throughput then add queue to numCross and set queue to zero. GOTO Step 15.

If (queue < throughput), then numCross += queue, queue = 0.

GOTO Step 15.

STEP 14 Reduce the value of queue by throughput and add throughput to numCross.

queue -= throughput,

numCross += throughput.

STEP 15 Decrement stateSegments by 1.

stateSegments -= 1.

STEP 16 If stateSegments > 0, then GOTO Step 8.

STEP 17 If state is green, then GOTO Step 23.

STEP 18 If queue is greater than MAXQUEUE, then set MAXQUEUE to queue.

if (queue > MAXQUEUE), then MAXQUEUE = queue.

STEP 19

• Step 3 of 7

totalQueue += queue.

STEP 20 Add waitRed to totalWait.

totalWait += waitRed.

STEP 21 If waitingRed is true, then set MAXWAITTIME to the difference of SEGMENT and waitRedSegment.

If (waitingRed = true), then MAXWAITTIME = SEGMENT – waitRedSegment.

STEP 22 GOTO Step 25.

STEP 23 If numCross if greater than MAXNUMCARS, then set MAXNUMCARS to numCross.

If (numCross > MAXNUMCARS), then MAXNUMCARS = numCross.

STEP 24 Add numCross to NUMCARS.

NUMCARS += numCross.

STEP 25 Switch state to other possible state.

If state = red, then state = green.

Else state = green, then state = red.

STEP 26 GOTO Step 4.

The Step 27 calculates output values for the traffic light simulation.

STEP 27 Output the following values:

NUMCARS, the number of cars that passed through the intersection

AVGWAITTIME = totalWait * segmentSize / totalQueue, the waiting time when the traffic light is red

MAXWAITTIME = MAXWAITTIME * segmentSize, the maximum waiting time during which the traffic light is red

AVGQUEUE = totalQueue / numRed, the average length of the queue when the traffic light is red

MAXQUEUE, the maximum length of the queue during which the traffic light is red

AVGNUMCARS = NUMCARS / numGreen, the average number of cars crossing the intersection when the traffic light is green

MAXNUMCARS, the maximum of cars going through the crossing when the traffic light is green

STOP

• Step 4 of 7

1. The results for cars crossing in direction 1 for 15 consecutive 60 minute intervals. These were calculated by running the algorithm with segmentSize, minArrival, maxArrival, throughput, redSegments, greenSegments, initialState and totalSegments set to 10, 5, 15, 36, 7, 3, green and 360.

 SimulationNumber Number of cars Average waiting time Maximum Waiting time Average length of queue Maximum length of queue Average number of cars Maximum number of cars 1 3512 40.29 70 70.97 95 94.92 108 2 3559 41.25 70 72.81 97 96.19 108 3 3503 40.58 70 70.69 89 94.68 108 4 3584 41.08 70 71.75 96 96.86 108 5 3463 40.35 70 69.83 87 93.59 108 6 3551 39.98 70 70.03 83 95.97 108 7 3584 40.18 70 68.83 80 96.86 108 8 3529 41.34 70 73.58 93 95.38 108 9 3521 40.47 70 70.72 93 95.16 108 10 3643 41.31 70 74.81 91 98.46 108 11 3581 40.36 70 74.22 94 96.78 108 12 3480 40.04 70 70.94 87 94.05 108 13 3627 42.52 70 78.03 107 98.03 108 14 3526 40.99 70 71.83 88 95.30 108 15 3519 39.91 70 69.78 88 95.11 108
• Step 5 of 7
• Step 6 of 7
The results for cars crossing in direction 2 for 15 consecutive 60 minute intervals. These were calculated by running the algorithm with segmentSize, minArrival, maxArrival, throughput, redSegments, greenSegments, initialState and totalSegments set to 10, 6, 24, 20, 3, 7, red and 360.  SimulationNumber Number of cars Average waiting time Maximum Waiting time Average length of queue Maximum length of queue Average number of cars Maximum number of cars 1 5040 27.64 30 170.43 315 140.00 140 2 4975 26.81 30 135.92 284 138.19 140 3 5038 26.84 30 137.35 297 139.94 140 4 4992 27.66 30 183.73 343 138.67 140 5 5032 27.54 30 178.97 316 139.78 140 6 5033 26.80 30 139.78 295 139.81 140 7 5013 27.84 30 219.38 476 139.25 140 8 5010 27.62 30 188.03 397 139.17 140 9 5034 27.49 30 182.22 298 139.83 140 10 5032 27.56 30 174.65 353 139.78 140 11 5021 28.53 30 287.03 452 139.47 140 12 5022 28.33 30 249.38 418 139.50 140 13 5030 27.87 30 212.89 373 139.72 140 14 5029 27.75 30 187.30 369 139.69 140 15 5027 27.58 30 174.51 343 139.64 140
• Step 7 of 7
Corresponding Textbook

A First Course in Mathematical Modeling | 4th Edition
9780495011590ISBN-13: 0495011592ISBN:
Alternate ISBN: 9780495561491, 9781111795665
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}