NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/

Easy Java Simulations (2001- ) => Kinematics => Topic started by: Fu-Kwun Hwang on May 15, 2006, 04:27:10 pm



Title: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on May 15, 2006, 04:27:10 pm
This simulation is similar to the traffic light contril (http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?t=226) I have created many years ago.
But I rewrited it with ejs.

Each square represent a car. It could be painted with three different color depends on it's acceleration a.
1. a>0 (yellow): when there is no car in front of it or the car in front is far away (the distance is more than dmin) and the street light is not red.
2. a=0 (green): it will keep move with the same speed when it reach maximum speed.
3. a<0 (red): when the street light turn red or the car in front is too close (distance < dmin).

dmin= v* treaction time, where treaction time is the reaction time of the driver.

You can click the +/- sign to change the time delay between traffic lights.



acceleration=m/s2 (modify value and hit return to change acceleration)
reaction time=s


Title: topic365
Post by: chef on May 21, 2006, 04:45:33 am
cool you know a lot about java


Title: Re: Ejs version of traffic control simulation
Post by: combiz on March 09, 2007, 10:32:59 am
Could you please send me the source code for traffic control.
Thanks


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on March 09, 2007, 02:46:01 pm
If you click the button "load ejs as signed applet".
You can see the source code/modified it and save it to your disk. (EJS source is saved in XML format)
You will find variables defined, relations between variables ...
It is the same for all the simulations created with EJS shown in the web site.


Title: Re: Ejs version of traffic control simulation
Post by: bardha on April 18, 2007, 03:06:12 pm
Can this program be considered as a real-time system application program?

Please,if it's possible send me the documentation of this application,because i don't understand it very well.

Thank you.


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on April 19, 2007, 01:09:58 am
Yes. I believe many "one way traffic light system" did implement it to control the traffic in real life.

If you want to discuss about it, please write down what you know and what you think you do not understand.


Title: Re: Ejs version of traffic control simulation
Post by: revage06 on April 24, 2007, 08:03:13 pm
Dear Sir,
it's cool simulation, could you please send me the source code for traffic control.
Thanks & regards


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on April 28, 2007, 04:21:26 pm
The EJS will be installed into your browser if you clieck "load ejs as signed applets" for the first time. And the applets source will be loaded into ejs as well.
You can see all the source(variables,equations...), modify it or save it(click save button).
You can even generate new simulation after you modify the code.


Title: Re: Ejs version of traffic control simulation
Post by: crazyboyrs on May 31, 2007, 01:32:57 am
I've seen the previous version code.But i dun understand how to code the program in EJS.Is it simpler or more complicated?Got any sources?the EJS manual din help much


Title: hi mr Fu-Kwun Hwang
Post by: joel123 on July 25, 2007, 03:46:21 am
Mr Fu-Kwun Hwang i hope that you be fine, im from mexico and  im really interested in your simulation applet because im developing one simulator for my simultaion class and i think that your source code could help me to complete my project. please answer me to  my email as soon as posible thank you. ill be waiting for you answer bye


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on July 25, 2007, 08:45:19 am
The EJS will be loaded into your browser(with your permission) and you will be able to save/modify the ejs source code, if you clicked the above button (right under the simulation) labeled as "load ejs as signed applet".

Actually, it is the same for all the simulations created with EJS on our server.
So, please click the button. And you will find out how the ariables are defined, what are the relations used. You can save it if you click the save button in the EJS and you can even modify the code and generate new simulation (click green triangle).


Title: Re: Ejs version of traffic control simulation
Post by: serkan3123 on November 11, 2007, 04:14:35 am
Can you send me source code?

serkan3123@gmail.com


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on November 11, 2007, 10:04:35 am
You will get the EJS source code, if you clicked down ejs source link (just under the java simulation).
It is an xml file. You can open it if you install EJS or you can click load ejs as signed applet to load ejs into your browser(about 2M) and you can see the source automatically.


Title: Re: Ejs version of traffic control simulation
Post by: yeek01 on March 18, 2009, 05:48:29 am
Sir, i find error when i try to run it using EJS.

The following are the errors:

Warning. Syntax error or custom page updatelight:
  Parse error at line 1, column 41.  Encountered: [
Warning. Syntax error or custom page updatecar:
  Parse error at line 1, column 42.  Encountered: [
File successfully read trafficcontrol.xml


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on March 18, 2009, 07:23:04 am
Please download it again. It should work fine now.
The following line has been changed from
public void updatelight (double tlight[],java.lang.Object clr[],String slight[]) {
to
public void updatelight (double[] tlight,java.lang.Object[] clr,String[] slight) {


Title: Re: Ejs version of traffic control simulation
Post by: arnanbd on August 16, 2009, 02:05:18 am
Dear Hwang

I have found your simulations very interesting. I was looking for such simulation because I had an argument with a friend regarding the optimal traffic light timing. You have some simulations but I was looking for a simulation with the following features:

One junction only.
Ability to control also the acceleration and delay time.
Ability to set a timer so that the simulation will take only the predefined timer.
Longer range for the lights durations.
Do you have such simulation?



Regards



Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on August 16, 2009, 07:45:27 am
There is a one junction simulation: Time duration for the yellow traffic light (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=712.0).

You can change the delay time, however, the maxmimum speed of each car is chosen  randomly.
Light duration for green and yellow light can be adjusted with slider.
You can download it and modify the code to fit with your need!


Title: Re: Ejs version of traffic control simulation
Post by: arnanbd on August 16, 2009, 02:44:22 pm
Thank you Hwang

This "yellow light simulation" is very nice, the only thing I miss is the car count and the ratio as you did in other simulations.
Unfortunatly I don't have the skils of dealing with Java codes.
By the way, are you familiar with this simulation: http://www.traffic-simulation.de/ ?


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on August 16, 2009, 10:32:49 pm
As I have mentioned at that post:
The maximum speed and maximum acceleration for each car is randomly selected in the simulation, so the number of cars passing the juntcton is not the same even with all the same parameters.

Please write down what is the problem you are working on and what is the purpose of your work.
May be there are better way to do it.

I did check out the simulation.
It is a nice simulation. I think it was designed for other purpose : what are the factors which will cause the traffic jam. 


Title: Re: Ejs version of traffic control simulation
Post by: arnanbd on August 17, 2009, 05:47:26 pm
The problem is to optimized trafic light timings.
There is a simulation made by you that does not run fast. http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=139
This one can help me. Can you transform it to EJS?


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on August 17, 2009, 09:54:55 pm
The simulation at the top of this topic (the first message) is the EJS version of that simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=139).


Title: Re: Ejs version of traffic control simulation
Post by: arnanbd on August 18, 2009, 04:18:15 pm
It's not the same. In the original there is an ability to control acceleration and delay.


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on August 18, 2009, 04:38:58 pm
You can change the delay by clicking the +/- sign in the simulation.
I will add the change of acceleration later.

I just added a text field for user to enter new maximum acceleration for the car.
You can enter new value and hit RETURN to change the maximum acceleration in the simulation.
However, it will be the same acceleration (but with minus sign) when the brake is applied to the car.


Title: Re: Ejs version of traffic control simulation
Post by: arnanbd on August 19, 2009, 05:49:58 am
Thank you very much Hwang.
Can you add also a delay for the cars i.e. the human response time to the green light or to the moving of the cars when the car in front of them started moving?
I know i'm asking a lot so I will understand what ever you will do.


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on August 19, 2009, 08:14:38 am
I just added another text field for you to change reaction time.

If you click the link VIEW (just below the simulation). Another web page will show up. And you will find an interface similar to EJS (the tool I used to create the simulation).
In the Model -> Variable tab: You will find all the variables defined in EJS.
For example: reaction time is defined in view sub-tab. the initial value is 0.5 (unit s).

What I just did was add another html command:

reaction time=<input type=text name=reactionTime value="0.5" onChange="document.trafficcontrol._model.reactionTime=parseFloat(this.value);" size=3>s


Title: Re: Ejs version of traffic control simulation
Post by: arnanbd on August 19, 2009, 04:25:02 pm
Thank you Hwang.
I have tried to change the acceleration and dealy parameters but it looks like it does not do anything.


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on August 19, 2009, 06:31:11 pm
You need to hit ENTER after you change your value.
For example: try acceleration =1.0 m/s2and reaction time=2.0 s


Title: Re: Ejs version of traffic control simulation
Post by: srinivas2828 on January 28, 2010, 08:20:10 pm
its awesome may i get a copy of source code if you dont mind  -*-


Title: Re: Ejs version of traffic control simulation
Post by: Fu-Kwun Hwang on January 28, 2010, 08:47:18 pm
The above simulation is created with EJS. You can download EJS xml source by click the link just below the simulation.
If you have download EJS and download the jar file. You can right click in the simulation and select open EJS model to view the source.