-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoadApplet.html
More file actions
79 lines (71 loc) · 3.12 KB
/
RoadApplet.html
File metadata and controls
79 lines (71 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html lang="" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>A Traffic Simulator Applet</title>
</head>
<body>
<h1>Traffic Simulator Applet</h1>
<p>
I wrote this traffic simulation, following the article "Und nun die
Stauvorhersage" of the German Magazine <i>Die Zeit</i>, June 7,
1996. The article describes the work of Professor Michael Schreckenberger
of the University of Duisburg and unnamed collaborators at the University
of Cologne and Los Alamos National Laboratory. These researchers model
traffic flow according to simple rules, such as the following:
</p>
<ul>
<li>A freeway is modeled as a sequence of grid points.</li>
<li>Every car occupies one grid point. Each grid point occupies at most
one car.
</li>
<li>A car can have a speed of 0 - 5 grid points per time interval.</li>
<li>A car with speed of less than 5 increases its speed by one unit in
each time interval, until it reaches the maximum speed.
</li>
<li>If a car's distance to the car in front is <i>d</i> grid points, its
speed is reduced to <i>d</i>-1 if necessary to avoid crashing into it.
</li>
<li>With a certain probability, in each time interval some cars slow down
one unit for no good reason whatsoever.
</li>
</ul>
<p>
This applet models these rules. Each line shows an image of the same
stretch of road. Each square denotes one car. The first scrollbar lets you
adjust the probability that some cars slow down. If the slider is all the
way to the left, no car slows down. If it is all the way to the right,
every car slows down one unit. A typical setting is that 10% - 20% of the
cars slow down. The second slider controls the arrival rate of the cars.
When it is all the way to the left, no new cars enter the freeway. If it
is all the way to the right, a new car enters the freeway every time
interval, provided the freeway entrance is not blocked. </p>
<p>
Try out the following experiments. Decrease the probability of slowdown
to 0. Crank up the arrival rate to 1. That means, every time unit, a new
car enters the road. Note how the road can carry this load.
</p>
<p>Now increase the probability that some cars slow down. Note how traffic
jams occur almost immediately.
</p>
<p>
The moral is: If it wasn't for the rubberneckers, the cellular phone
users, and the makeup-appliers who can't keep up a constant speed, we'd all
get to work more quickly.
</p>
<p>
Notice how the traffic jam is stationary or even moves backwards, even
though the individual cars are still moving. In fact, the first car
causing the jam has long left the scene by the time the jam gets bad.
(To make it easier to track cars, every tenth vehicle is colored red.)
</p>
<p>
<applet alt="Traffic jam visualization" archive="RoadApplet/RoadApplet.jar"
code="RoadApplet/RoadApplet.class" height="400" width="400">
</applet>
</p>
<p>
For more information about applets, graphics programming and
multithreading in Java, see
<a href="http://horstmann.com/corejava">Core Java</a>.
</p>
</body>
</html>