Download Visual Traffic Simulation
Transcript
47 4.4. COMPONENT DESIGN cars new location and in the SimPanels tick() method, all the cars are drawn to a backbuffer. The last action of a tick is that the backbuffer is labeled with the current frame number and is swapped onto the screen. This design combines a back-buffering approach to animation with the necessesity of clearly presenting the time dimension to the user. The timer runs in its own thread and sleeps by x milliseconds in between each tick. The user has direct control of the speed of the timer by controlling x through a slider. The simulation can also be paused by suppressing the timers ability to tick. The vehicle movement model The simplest mathematical car-following model is linear. This means that as long as there’s no obstruction (another car or a red light) in front of a vehicle, it will travel at the speed limit of k kilometres per hour. If a car gets within a distance of L metres from an obstruction, it will reduce its speed proportionally to that distance. If a car gets within a distance of l metres from an obstruction, it will stop altogether. Let x denote the distance in metres between two cars (measured from the front of one to the back of another, or between the front of one car and a red light ahead). The speed v of the car is: k, if x >= L between0andk, if l < x < L v= 0 if x <= l In the second case, l < x < L, we’re assuming the car changes speed proportionally to changes in distance, so that v is given by a “linear” function of x (the graph of v as a function of x is a straight line). This means that v = mx + c for two constants m and c. These constants can be determined from the two conditions: 1. v=0 when x=l 2. v=k when x=L;