Shaokang's Blog

My modified version is at https://shaokangjiang.github.io/traffic-simulation/. I just add an export function to export data for each car and measuring point to csv file. I will talk them in details at here and discuss my thought.

Modification

I just add an export function to get the data for each car and measuring point. You could see them in real time or download them.

View

To see them in real time. Visit: https://shaokangjiang.github.io/traffic-simulation/, you will be able to see a text field in the right bottom place. That is the data area. I set a limitation of a maximize of 500 rows because browser will be slow when there are too many rows as we need to append data in real time to those box. This limitation won’t limit content in the csv file you could get by pressing download button. Example image as shown below:

Download

It is also easy to download. Simply click the button below each box is enough. File will be saved as csv. File has a size limitation based on your browser, generally, 800 MB. Sample downloaded data:

Sample car data:

1
2
3
4
5
6
Time,rType,id,Speed,lane,u
0,MainRoad,200,58,0,660.09908
0,MainRoad,201,58,1,625.52486
0,MainRoad,202,58,2,590.95306
0,MainRoad,203,58,0,556.38140
0,MainRoad,204,58,1,521.80634

Sample statistic data:

1
2
3
4
5
6
7
Time,loc_x,loc_y,flow,Speed
0.2,613.894,182.693,0,--
0.2,175.208,429.275,0,--
0.2,613.894,489.337,0,--
10.2,613.894,182.693,3960,64
10.2,175.208,429.275,1800,64
10.2,613.894,489.337,1800,64

My Understanding

Based on my understanding, this simulation use the following system to monitor a car: Direction/position of vehicles <lane,u,rType> (One road only have one direction)

  • lane – which road this car is on
  • u – distance from start point
  • rType – type of road(main road or ramp or others)

I also have a plan to make another simulator in Java if I have time in the future, which has the same functionality as this one. Here is the detailed plan.

  1. Problem: A specific type of road, at least 3 main road and one ramp, will be provided. Number of road is able to change at the beginning of the program. The program will be given with the car density, car acceleration, Truck existence percentage and any rule regard to the road set up by the user by drag specific sign to specific position. Then, program needs to simulate the real time running situation and represent the real time graph on the left hand. User is able to change each criteria and graph left side should represent the change dynamically. After user stops, the program will be able to export data contains information about those cars and statistic data. During simulation, cars are able to change route and we assume that driver will choose to change the route if that route is faster.

  2. Graphical User interface:

    This is only a simple case, there could be other types of roads

    • An asking prompt to ask user for specific information

    • A major running part, left side is the real time running graph. Right hand contains bars to change different criteria, such as car density, car acceleration, Truck existence percentage.

    • When exit, prompt a save as prompts to ask user choose path to save. Or user could choose to ignore running data.

    • In the runtime, the center window is represented as the real time simulation result, like this:

  3. Data: The program might provide function to read configuration from files but it is not necessary.

Because those data are randomly chosen by user, there is no need to store them in a file before the program running. Initial configuration could be loaded from a configuration txt file. Content looks like this:

1
2
3
4
5
6
7
car_density: 0.5
car_acceleration: 1.2
trunk acceleration: 1.2
Truck existence percentage: 0.5
Maximize speed for trunk: 108
Maximize speed for car: 120
# of main road: 3
  • car density - double type \in (0,1), sample: 0.5 – means half road will get a car as an inflow in a second
  • car acceleration - double type \in (0,6), sample 1.2, unit m/s2m/s^2
  • trunk acceleration - double type \in (0,4), sample 1.2, unit m/s2m/s^2
  • Truck existence percentage - double type \in (0,1), sample: 0.5 – means half of inflow cars will be trunk.
  • Maximize speed for trunk - double type \in (0,120), sample 108, unit km/hkm/h
  • Maximize speed for car - double type \in (0,120), sample 108, unit km/hkm/h
  • # of main road - int type \in [2,5], sample 3.
  1. Class (Type) Summary: It is easy to see the program requires two type of cars, car and trunk. Actually, some values are shared. So, we could have an interface basiccar and an abstract class of them as well. Or other ways are also fine. Then, car and trunk class could implement them. We do also need some road classes, and a plot class to plot information provided by road class.
Class NameDescriptions
basicCar.javaSuper class of car and trunk, contains basic info to describe a car. See below for more information.
car.javaContain more info, such as maxmize speed for car, and personalized acceleration speed.
trunk.javaContain more info, such as maxmize speed for trunk, and personalized acceleration speed.
road.javaHandle restrictions user put and add cars to roads.
plot.javaThe most admin class that handle info between GUI and other class and plot on graph.

Credit:

Original simulator is at https://github.com/movsim/traffic-simulation-de. I forked from this repo and made those edition. Let me know if this is not appropriate.

 Comments