Traffic Simulator Applet(交通模拟器小程序)
Traffic Simulator Applet(交通模擬器小程序)
原文
I wrote this traffic simulation, following the article "Und nun die Stauvorhersage" of the German Magazine?Die Zeit, 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:
- A freeway is modeled as a sequence of grid points.
- Every car occupies one grid point. Each grid point occupies at most one car.
- A car can have a speed of 0 - 5 grid points per time interval.
- A car with speed of less than 5 increases its speed by one unit in each time interval, until it reaches the maximum speed.
- If a car's distance to the car in front is?d?grid points, its speed is reduced to?d-1 if necessary to avoid crashing into it.
- With a certain probability, in each time interval some cars slow down one unit for no good reason whatsoever.
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.
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.
Now increase the probability that some cars slow down. Note how traffic jams occur almost immediately.
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.
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.)
?
For more information about applets, graphics programming and multithreading in Java, see?Core Java.
譯文
我是根據1996年6月7日德國《時代周刊》上的“ Und nun die Stauvorhersage”一文編寫此交通模擬的。這篇文章描述了杜伊斯堡大學Michael Schreckenberger教授和科隆大學的匿名合作者的工作。洛斯阿拉莫斯國家實驗室。這些研究人員根據簡單的規則對流量進行建模,例如:
- 高速公路被建模為一系列網格點。
- 每輛車占據一個網格點。每個網格點最多占用一輛車。
- 汽車在每個時間間隔內的速度為0-5格點。
- 速度低于5的汽車在每個時間間隔內將速度提高一個單位,直到達到最大速度。
- 如果汽車到前方汽車的距離是d格點,則在必要時將其速度降低到d-1,以避免撞向它。
- 很有可能,在每個時間間隔中,有些汽車毫無緣由地減速一個單元。
此小程序為這些規則建模。每條線均顯示同一條道路的圖像。每個正方形代表一輛汽車。第一個滾動條可讓您調整某些汽車減??速的可能性。如果滑塊一直向左移動,則沒有汽車減速。如果一直正確,那么每輛車都會減速一個單位。典型的設置是10%-20%的汽車減速。第二個滑塊控制汽車的到達速度。一直到左側時,沒有新車進入高速公路。如果一直都在右邊,只要高速公路入口不被阻塞,則每個時間間隔都會有一輛新車進入高速公路。
嘗試以下實驗。將減速的可能性降低到0。將到達率提高到1。這意味著,每單位時間,就有一輛新車駛入道路。注意道路如何承受此負荷。
現在增加某些汽車減??速的可能性。請注意,交通堵塞幾乎是立即發生的。
道德是:如果不是橡膠領子,手機用戶和化妝師不能保持恒定的速度,我們所有人都可以更快地工作。
請注意,即使個別汽車仍在行駛,交通擁堵如何保持靜止甚至向后移動。實際上,導致卡紙的第一輛汽車在卡紙變壞時早已離開現場。 (為使跟蹤車輛更容易,每十分之一的車輛都被涂成紅色。)
有關Java中的applet,圖形編程和多線程的更多信息,請參見Core Java。
?
總結
以上是生活随笔為你收集整理的Traffic Simulator Applet(交通模拟器小程序)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA四大名著
- 下一篇: Windows——在当前目录打开 Pow