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

JDK1.0.2 simulations (1996-2001) => kinematics => Topic started by: Fu-Kwun Hwang on January 29, 2004, 09:48:02 am



Title: Traffic Light System
Post by: Fu-Kwun Hwang on January 29, 2004, 09:48:02 am
Traffic light control:  **** click the following tabs for more information
[page title=Simulation]
Would you like to engineer the traffic light system for a one-way street that consists of several lanes along which rush-hour traffic flows?
How would you time the onset of green lights at the various intersection?
How to promote the traffic flow? This java applet let you play with it.

Due to java version changes, this simulation become very slow.
Please check out Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)


Due to so many requests from the users, source code for this applet is distributed with the ZIP files you will receive if you click get file for offline use button. It is also available as attached file. Please do not ask me to send you the source code again, help yourself-- it is just a click away!





You are welcomed to check out Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0),too.
[page title=How to play it]
  1. The traffic lights at interactions are for cars moving from left to right. The traffic on the perpendicular streets can only move when light is RED.

  2. You can change the period of each light

    1. clicking the traffic light at the top-left cornor
    2. the number near each color is the period for that particular light (second)
    3. left/right mouse click will decrease/increase one second
    4. ( for MAC user, click between light and number to the right to increase the length of time)

  3. parameter controls
    each click to the arrow at left/right of the number will decrease/increase
    the parameter by 1 unit.

    1. delay time
      control near the traffic light controls the delay of the onset of green light at the interaction relative to that at prevous ntersection.
    2. max Velocity control represents the speed limit¡]Vmin=5, Vmax= 50¡^
    3. acceleration control represents the acceleration for the car when it speeds up.¡]Amin=1 , Amax=20¡^

  4. TextField values

    1. T¡Gtime in second after pressing the start button
    2. N1/N2/flow rate¡G total number of cars passes intersection (N1:left-right/N2:up-down)
      flow rate=(N1+N2/3.)/T
    3. n1/n2/flow rate¡G number of cars passes intersection during last minute.
      flow rate=(n1+n2/3.)/60


  5. Color code for car
    1. yellow: accelerating (A>0.)
    2. green: moving with constant speed (include stopped) A=0.
    3. red: stopping (A<0.)


  6. Velocity of each car is represented by a blue dot.

  7. A new function has been added to help you determine the delay time between traffic lights.
    Click the right mouse button to suspend (the animation).
    The time intervals (for the first car ) during which the signals are green/yellow/red
    1. are represented by thin (colored)lines at one side of the road.

    A blue curve represent x-t (displacement verse time) for the first car is shown.
    Use that curve with those color intervals to adjust the delay time between
    traffic lights. Click the right mouse button again to resume.

[page title=Observation]
  1. Suppose a platoon is stopped at interaction. When the green light comes on, there is a "start-up wave" travels from the leader along the length of the platoon at a speed vs.
  2. How to adjust parameters to increase the traffic flow?
    1. adjust timing of each light
    2. adjust delay time control
    3. adjust Vmax
    4. adjust A(acceleration)

Think of it! Play with it! I hope you do learn some physics from this applet.

If you click the right mouse button in the simulation, you will see a curve similar to the following figure (Hints to adjust the traffic flow) (http://www.phy.ntnu.edu.tw/ntnujava/pics/trafficControl.png)
[endpage]
Applet latest updated: 2009/12/25

I have created another version of traffic light control applet with EJS (http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?p=1614) and you can view how it was implemented with EJS(You can find the code).

Please download the last trafficControl.java if you want latest version code (2009 Dec. 25).


Title: Reading Calipers.
Post by: on July 07, 2004, 08:09:16 pm
Hello all,

I am on here wondering if anyone reading this know where I can find a website that will teach me how to read a caliper. I need to learn this for a job I am applying for.

Sincerely

Robert


Title: about how to read a cliper
Post by: Fu-Kwun Hwang on April 17, 2005, 01:18:06 pm
If you want to know how to read a cliper.
Please check out the following URL
http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?t=69


Title: topic139
Post by: xingweiping on May 04, 2005, 12:30:35 pm
Thanks so much for sharing the source code with us. actually we currently have a group project which is very similar to this, but we just totaly have no idea about it. until I found your site via google. what a day! your applet is very inspirational and we are so enlighted! :D  :idea:


Title: query
Post by: karthik_kotee on September 15, 2005, 11:58:01 pm
sir could i get the source code(.java file) for the traffic system


Title: topic139
Post by: vipin_ajmera on September 20, 2005, 04:54:53 pm
plz can u give me source code of traffic light system


Title: topic139
Post by: Fu-Kwun Hwang on September 21, 2005, 07:19:27 am
Both of you you have received the source code in your email account.


Title: request for source code
Post by: lopa on September 25, 2005, 06:45:00 pm
Sir/mam,
plz give me the source code of this applet,using this topics,traffic light system.
ok, thanks,


Title: Great Simulation
Post by: primanox on September 27, 2005, 09:47:17 am
I love this simulation. You did an excellent job! Could you please send me the source code? I would really like to see how you accomplished this. Thank you!


Title: request
Post by: hadi_telkom on September 30, 2005, 10:58:46 am
your traffic simulatioin is very good
may I get it, please.............


Title: topic139
Post by: wurakeem on October 01, 2005, 06:34:22 am
I like your simulation.
is it possible to have the source code?

thanks.


Title: topic139
Post by: joe on October 08, 2005, 12:07:08 am
This is a very good simulation.
I like it very much.
May I take the source code please?


Title: topic139
Post by: Fu-Kwun Hwang on October 18, 2005, 08:58:13 am
Source code has been sent.


Title: regarding traffic simulator
Post by: lifeline on October 20, 2005, 05:42:08 am
hi,
it was gud to see ur traffic simulator . I would like to learn how u did it . Could u plz mail me the code .

Thanks.


Title: topic139
Post by: avir on October 21, 2005, 06:04:19 am
I also would like to get a copy of the source.


Title: topic139
Post by: eniss on November 02, 2005, 11:44:55 pm
Dear Sir,

we are a group of 3 studens, having a project at university, similar to this one. could you please send us source code for learing purposes. if possible. if no, thanks anyway for a great site


Title: I want the source code of this applet
Post by: Mohamed shahab PK on November 03, 2005, 07:30:03 am
Hello I also need a source code of this applet


Title: urgent
Post by: jmiyasato on November 08, 2005, 08:28:06 am
could i have the code for the traffic simulation plz===????? javiermiy@gmail.com thx!!!!!!


Title: Great Simulation, source code?
Post by: v_lotay on November 11, 2005, 06:17:14 am
Your simulation is great, I was wondering if it would be possible to get the source code,

v_lotay@hotmail.com


Title: topic139
Post by: Fu-Kwun Hwang on November 11, 2005, 10:19:05 am
You should have received source code in your email account.


Title: Haven't received the source code
Post by: v_lotay on November 12, 2005, 01:16:49 am
I'm sorry I haven't received the source code, could you please send it to me again.  My e-mail address again is v_lotay@hotmail.com, infact try sending it to vaneet.lotay@gmail.com as well just in case the first one doesn't work.

Thank you, I appreciate it, sorry for the inconvenience.


Title: topic139
Post by: Fu-Kwun Hwang on November 12, 2005, 10:27:28 am
I sent the files to the above two email accounts again.


Title: Thanks I got the files
Post by: v_lotay on November 13, 2005, 05:16:40 am
Thanks I received files in both e-mail accounts.


Title: good work!
Post by: brixchin21 on November 13, 2005, 02:12:57 pm
please send me also the source code. plz! thanks anyway!

cloysterspam@yahoo.com


Title: topic139
Post by: beachlinum on November 14, 2005, 01:13:12 am
hey thats acool work, i love it, can i have the source code? and i was wondering if u can help me in doing somtin smillar to this work,  by doing high way with cars genarating by poisson distrubution to make the cars genaration more relaistic> can u help me on that please???
my email is musiclinum@hotmail.com plus the one regitered in my profile


Title: topic139
Post by: Fu-Kwun Hwang on November 14, 2005, 09:46:58 am
You can d it by yourself with the source code I sent you!


Title: May i get the code for reference
Post by: suszyh on November 14, 2005, 03:58:36 pm
It is nice simulation demo. May i know what kind of message passin machenism u use in this simulation? Do u have conceptual model for it?


I will appreciate your help if u could send the code and conceptual model to me. suszyh@hotmail.com since i I haven't received the source code.

thanks


Title: topic139
Post by: ajay arora on November 14, 2005, 09:22:14 pm
Hi ...plz include me also for sending the source code asap !! plzz
thanx


Title: simulation Traffic light
Post by: Kwanda on November 14, 2005, 11:30:35 pm
I love this simulation.excellent job! Could you please send me the source code? I would really like to see how you accomplished this. Thank you! rui.jesus@gapi.co.mz


Title: Hello
Post by: gigispeed1332 on November 15, 2005, 09:04:55 pm
I really liked this program u made is their anyway i can get the source code, we are working on a project in class similar to this simulating the movement of a line in a bank. I was wondering if I could see how you accomplished this. Thanx a bunch.

email = gigispeed1332@yahoo.ca/handyk13@hotmail.com


Title: topic139
Post by: Fu-Kwun Hwang on November 16, 2005, 08:39:34 am
Because too many persons interested in the source code for this applet,
I have added it to the ZIP files you will receive when you click "GET APPLET FILES" button.
It was written 8 years ago with JDK1.0.2

The physics behind the code is very simple.
Just car with constant acceleration (a) when car is accelerated.
When the car reach maximum velocity, it will move with the same velocoty (acceleration a=0 ).

There is a minimum distance between any two cars to avoid collision between two cars.

When there is a red light or if the distance between two cars is less than minimum distance,
the car will slow down (another constant acceleration: -a).

I hope the above information is helpful for those who want to do more work on the code.
I am sorry that I did not add enough comment in the code.

Fu-Kwun  :-)


Title: Request for Source code
Post by: neetamalik2 on November 16, 2005, 12:04:32 pm
Hi,
Sir , could u plz send me the source code for this simulation (traffic light one)
My id is neetamalik2@gmail.com
Thanks
Neeta


Title: topic139
Post by: Fu-Kwun Hwang on November 16, 2005, 12:17:05 pm
The source code is inlcuded in the ZIP file you would receive when you click the GET APPLET BUTTON at the first posted message.


Title: topic139
Post by: cemagalhaes on November 23, 2005, 02:30:05 am
How can I get the applet?
What is the first posted message? Is this one????
Thank you


Title: how to
Post by: Laurain on November 24, 2005, 11:56:42 am
[b:4b0398b3bc]hi just want to ask wh :o  :?  :wink:  :P  :roll:  :wink: ere can i get a source code or a website about intersection traffic light system.this is for our project.tnx :)  :D [color=blue:4b0398b3bc][/color:4b0398b3bc][size=9:4b0398b3bc][/size:4b0398b3bc][size=12:4b0398b3bc][/size:4b0398b3bc][/b:4b0398b3bc]


Title: copy of the source code
Post by: brian316 on December 06, 2005, 08:12:18 pm
can i get a copy of that traffic simulation source code :?:


Title: topic139
Post by: Fu-Kwun Hwang on December 07, 2005, 05:10:23 pm
If you read the above message carefully, I already post message indicated that

[b:b31713a190]The source code is inlcuded in the ZIP file you would receive when you click the GET APPLET BUTTON at the first posted message[/b:b31713a190]


Title: topic139
Post by: Aisha on December 18, 2005, 12:23:27 pm
i'm very intersting in your project sir, could you plz send me the source


Title: topic139
Post by: Fu-Kwun Hwang on December 22, 2005, 03:17:42 pm
Could you please look at the above messgae.
It is included in the ZIP file you will recieved in you email account if you click the "GET APPLET FILE" button! :-)


Title: code
Post by: chae on January 25, 2006, 12:46:18 pm
hope you can give the code too...cha_ez@hotmail.com


Title: what type sensor
Post by: faizal on February 14, 2006, 08:58:57 pm
i have problem with my project,
i do not know what type sensor i want use to make the traffic light system "reduce traffic jam". if prof know what type of suitable sensor please email at ecal_83@yahoo.com.my


Title: I am Calistes
Post by: adlcalistes on February 15, 2006, 02:32:38 pm
Dear sir,
I dont have to say any thing about your excellent work on physics, you know I am as a physics teacher, enjoying your hard work with appreciation. The time you devote for this job is so expensive. For us its very simple to enjoy it you know. But I know that with our satisfaction , you are satisfied.
Not only me , my students are also highly appreciating your excellent task. I want you to continue with this to help the teacher as well as the student, as they are in need of it.
Behalf of my students highly I appreciate your devotion ,sharing of knowledge, with the idea of helping the others.
Again I highly apprecite your task, and pray for you to develope new ideas.
Thank you sir.
Take care
Calistes.


Title: topic139
Post by: Fu-Kwun Hwang on February 16, 2006, 07:01:48 am
I hope you, and best of all, your students can enjoy the fun of physics as I do.
 If you can think of any topic which simulations can help student learn better, please let me know. Tell me what kind of simulation you want.  And I will try to create one for you and other teachers to use it in the classroom!   :D


Title: topic139
Post by: adlcalistes on February 16, 2006, 08:25:02 am
Thank you sir,
If you dont mind trying to make the simulation, for the Millikan oil drop expt, and the Photo electic effect, I highly would appreciate it.
Thank you.
Calistes.


Title: another traffic simulation
Post by: rhazoel on February 23, 2006, 10:27:36 am
helllo. the traffic simulation is really great. but, doe anyone here also knows how to make a traffic simulation in a round or rotonda road (roundabout). im pretty much interested in this kind of study. please do help me. thanks..


Title: Traffic Light Simullation
Post by: ISUJ on February 24, 2006, 04:02:05 pm
I hope You can send me a source :o . Thank You vladimir.josifoski@gmail.com


Title: topic139
Post by: kernel on February 24, 2006, 09:15:50 pm
I'll like to receive the source too if it's possible basbaum@gmail.com  :D


Title: topic139
Post by: Fu-Kwun Hwang on February 25, 2006, 04:09:16 pm
I already post the same message before. I will post it here again!

[b:41fb3e999d]The source code for this applet is included in the ZIP files you will received after you click "GET APPLET FILES" button![/b:41fb3e999d]


Title: topic139
Post by: malikguna on March 02, 2006, 08:46:41 pm
i too would like to explore my knowledge in traffic controller program. please send me a soruce code this project.

 guna_it183@yahoo.com

have a nice day..
guna.


Title: REGARDING TRAFFIC CONTROL
Post by: neeraj4ever on March 07, 2006, 05:02:45 pm
CAN YOU SEND ME THE SOUCRE CODE OF THIS PLZ


Title: Hi
Post by: Aseel on March 12, 2006, 09:28:56 pm
The simulation u made is really wonderful!!!
I am coding something similar but I am facing some real difficulties, so can I get the source code please??
This will help me a lot.
Thank you


Title: topic139
Post by: Aseel on March 12, 2006, 09:46:36 pm
Sorry I just notice the button!!
I got the source code
thank you :)


Title: Wrong message
Post by: asahan on April 17, 2006, 12:42:46 am
Sorry, I sent a message in a wrong way a few minutes ago. Could you also send me source file link to my mail address?

ahmets_a@yahoo.com


Title: Sorry
Post by: asahan on April 17, 2006, 12:45:40 am
I got it :oops:


Title: Regarding Source Code For This Simulation
Post by: phoenix7 on May 01, 2006, 07:00:46 pm
Is it still possible to get the source code for this simulation? If so, what do I need to do to receive it?

Thank you,
phoenix7


Title: topic139
Post by: Fu-Kwun Hwang on May 02, 2006, 02:20:01 pm
The source code is included in the ZIP file you should have received (if you clicked GET APPLET FILE button).


Title: topic139
Post by: phoenix7 on May 02, 2006, 11:02:36 pm
Hi,

Thank you very much for your quick response to my post!

I checked my email (phoecago@hotmail.com) and I did not received the zip file. Is this where you sent it? Or am I looking in the wrong place?

phoenix7


Title: topic139
Post by: Fu-Kwun Hwang on May 03, 2006, 09:49:25 am
You need to click GET APPLET FILE button under the simulation (near the end of the first message which contain the simuation).
I check the database , you did not click the button yet.


Title: Confirmed
Post by: rhipple on May 04, 2006, 04:08:17 am
For your information, I just confirmed that the "source code mailer" is working correctly.


Title: topic139
Post by: fatimamadni on May 04, 2006, 11:17:48 am
your simulation is really cool, can i get the code please.


Title: re- traffic light system
Post by: biodun1 on May 15, 2006, 10:26:11 pm
Hi,
this is a job well done. Is really very interesting. Keep it up.
I have a prob. I try to view this simulation offline but it would not display on my laptop. I have installed the jre and the update but is still not viewable offline.

pls can somebody help me...


Title: topic139
Post by: Fu-Kwun Hwang on May 16, 2006, 10:14:53 am
If you view it with the browser. Please open java console and find out the error message.
Post the error message, otherwiser, it is not easy to identify the real problem.


Title: topic139
Post by: karimmakki on November 08, 2006, 01:22:30 am

if someone can help me, i need a simulation for the road light control but using the assembly language or the c language,

if anyone could help, i nned it urgent



Title: topic139
Post by: trn_udhaya on December 11, 2006, 12:15:12 am
This was a really well constructed simulation of a traffic light controller system.I had a project on hand to do a similar kind of simulation and was clearly having difficulty on how to proceed. Thanks to your excellent post I have got some help on hand. I just downloaded it and want to convey my sincere thanks for providing an opportunity to download the source code.


Title: request for source code
Post by: leeks1030 on December 15, 2006, 01:12:27 pm
Hi,
Sir , could u plz send me the source code for this simulation (traffic light one)
My email is leeks1030@yahoo.com


Title: topic139
Post by: anathema17 on December 31, 2006, 10:20:48 am

elo sir,,

sir can i have the source code plz,, thank u very much i nid it b4 jan 4 07 thx,,



Title: Request to Source Code (HELP!!)
Post by: xmx23 on January 18, 2007, 03:48:35 pm
wow this simulation is suited for my project.. im curretly working a project similar to this which is to be implemented in matlab.. sir, can you email me this source code (.java file)??? email: kurt_cs2040@yahoo.com


Title: topic139
Post by: Fu-Kwun Hwang on January 18, 2007, 04:29:13 pm
If you are a registered user and login to the system. You should find the download button at the top the this web page. Click that button.
The source code for this applet and all other related files will be sent to you email acount automatically.




Title: Re: Traffic Light System
Post by: RysinToRize on February 20, 2007, 10:26:33 am
This is very good.. Is there any way for me to actually recieve the source code for this?? I would really appreciate it. Thanks.


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on February 20, 2007, 11:07:33 pm
I have post the same response several times. Because so many users ask for source code for this applet.
So it is included in the ZIP file you have received if you click "GET APPLET FILES FOZ OFFLINE USE" Button.

I hope the same question would not be posted again!


Title: Re: Traffic Light System
Post by: sarit on March 03, 2007, 12:10:01 am
Some of link I use to seminar about traffic jam problem

www.helbing.org


Title: Re: Traffic Light System
Post by: PTL on March 08, 2007, 10:20:54 pm
hi DR!
This is my first time get to know java ... I just wondering how to write simulation without using applet  :)

Regards PTL


Title: Re: Traffic Light System
Post by: nasser on March 13, 2007, 01:23:23 am
عمل رائع

شكرا جزيلا



Title: Re: Traffic Light System (asking code)
Post by: at_keren on April 20, 2007, 12:50:48 pm
your simulation is so astonished me,,,
I'm so inspired by your design...
I am a college student, and having a project about traffic light...
and I'm so desperately need your help..
can you send me the source code..
my email : ast_atine@yahoo.com


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 21, 2007, 08:31:34 am
Source code for this applet is included in the ZIP file you would have received if you clicked "GET APPLET FILES FOZ OFFLINE USE" Button.


Title: Re: Traffic Light System
Post by: jimma on April 24, 2007, 10:03:43 am
I would be grateful to view the source code.
Thank you


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 28, 2007, 04:27:48 pm
As indicated in the previous messages for several times.
The source code is in the ZIP files you received if you have clicked "GET APPLET FILES FOR OFFLINE USE" buttons. It looks like some users did not read message carefully in the forum.


Title: Re: Traffic Light System
Post by: larienciel on May 15, 2007, 09:24:49 am
hello dear, i am a uni student that's having the same project too... but i realised that it's jdk1.0.2 simulations ... so will this work on the jdk1.6.1.0 ?? i am sorry i need to master java and complete this task in 3 month's time with some background programming skills of C,C++ and others but not java... so is this task possible for me ? and da i would really wish to have a copy of the source code... how do i run it ? just copy the code and paste it in NEtbean 5.5 ? then build and run ? will that work ? sorry i am really just a novice in JAVa.... cheers mate


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 15, 2007, 09:43:32 pm
The code was written many years ago with JDK1.0.2.
You need to modify a few line to make it work.
But I would suggest you look at another version created by EJS (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0). (You can find out the java source code,too. But it will be much easier to work directly with EJS.)


Title: java code of traffic light system
Post by: hifijava on May 16, 2007, 10:45:42 pm

plz can u give me source code of traffic light system


Title: Re: Traffic Light System
Post by: hifijava on May 18, 2007, 09:17:32 pm
could you please send me the source code.java  for traffic light system. I would be very happy.

thanks
email; hasan727@hotmail.com


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 18, 2007, 09:31:34 pm
I have posted the same reply many times. The source code for this applet is included in the ZIP file you received, if you have click "GET APPELT FILE for offline use" button. Please read the posted messages before you ask! ???


Title: Re: Traffic Light System
Post by: guateweb on June 19, 2007, 08:58:35 am
The traffic light where I live have no system to sincronize them or faisl to do it right, I see no one cares about here, I will like to get as much knolegde as possible to learn whow to move from total caos to something more easy to the flow without much technology, what you will recommend to use? in terms of what are the best tips to make the traffic flow for 2 or 3 lane one way streets with intersections every 100 mts. Do you know of any low cost device that can be used to sincronize the traffic lights? Thanks. Rene


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on June 20, 2007, 11:54:52 am
If it is a one way street, then you can control the delay between street light to control the traffic flow and the best speed.
If the timing is right, then all the car only have to stop at most once, and if s/he follow the suggested(designed) speed, s/he will never have to stop.
Because all the light will be green when s/he arrive at the intersection.
If the driver drive too fast or too slow, s/he will have to hit the break more often.

However, if there too many cars. It will fail due to accumulated reaction time from many drivers.

If the distance between intersections is 100 m, and the suggested driving speed is 20m/s (72km/hr), then you should keep about 5 seconds delay (for those car already drive steady with v=20 m/s) between traffic lights to have maximum traffic flow . For car stopped at the traffic light, it will take more time to reach another traffic light. So if there are heavy traffic, the delay time need to be increased and car need to be stopped more times.


Title: Re: Traffic Light System
Post by: Sivasayanth on July 14, 2007, 11:02:22 am
Very wondering simulation. i really appreciate your great work


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on July 14, 2007, 03:33:24 pm
The source code is included in the ZIP file you should have received (if you have click "get files for offline use" button).
There is another version of this applet created with EJS.
Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)

If you look into the forum, click load applet as signed applet. And you will be able to find out the model for that simulation. (Actually, it works for all the EJS  simulations posted in this forum).


Title: Re: Traffic Light System
Post by: uleng_ong on August 09, 2007, 02:44:19 am
hello!Sir!
First of all,thank you very much for your kindness to share the traffic system source code.
My lecturer require me to pass him a traffic system program with more than 12 streets.I had no idea to implement it.Can you give me some clues?And,i had compile the soource code you sent to my mail,but,i seem like cannot debugging since the error "error...exception in main thread..." keep on appearing on my screen.What should i do with it?
Thanks again for your kindness!!! :-*


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on August 09, 2007, 07:53:59 am
The code was written 10 years ago with JDK1.0.2. You might need to change some of the code for current JDK.
But you can look at how the program was written.
There is another Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0) which you can modify/download it and generate new simulation.
I would suggest you work with that one.
Basically, you just need formula for constant acceleration.
For many streets, you just need to replicate it many time.


Title: Re: Traffic Light System
Post by: theking_invincible on August 14, 2007, 12:58:03 am
hey that was a 1 nice idea
can i also get the code of the system
thanx in advance


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on August 14, 2007, 01:11:03 pm
hey that was a 1 nice idea
can i also get the code of the system
thanx in advance
Would you please read the posted messages, you will find out how to get the source code.
(I have answered it so many times). ;)


Title: Re: Traffic Light System
Post by: leoietec on August 21, 2007, 12:12:39 am
Could you send me the source code?

Thanks


Title: Re: Traffic Light System
Post by: sudhan on August 26, 2007, 03:04:57 pm
the simulation was very good. can i get the source code plz


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on August 26, 2007, 10:55:52 pm
Please READ the posted messages  and you will know how to get the source code.


Title: Re: Traffic Light System
Post by: jafar-_jmj on September 10, 2007, 02:38:05 pm

sir kindly send me a source code for the traffic light system we will need this for our project and this will be of great help in our group thank


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on September 10, 2007, 11:51:53 pm
If you have read the posted message. You should know you will get source code when you click "GET files for offline use" button. The source code for this applet is included in the ZIP files you would have received in your email.
I do not know why so many users just want to ask for the source code, and do not even want to read the above posted message. (Including this one).

I hope no more users, post similar message again!


Title: Re: Traffic Light System
Post by: AntonAZ on September 21, 2007, 04:20:49 am
Sorry, but I have a problem. I installed latest JAVA RunTime but the simulation execute very slowly that its impossible to play.
The traffic light control applet with EJS works correct but I'd like to try JDK version.

OS: WinXP
Browser: IE6.

Thank You.


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on September 21, 2007, 04:42:58 pm
The JDK102 version is smaller than EJS version.
May be you did not have enough RAM installed or you are running too many program at the same time.
Next time, try to access this applet before you access EJS version.


Title: Re: Traffic Light System
Post by: gon on October 12, 2007, 11:35:07 am
Your Java applet was very good. Please!!! Can you email me the source code for the traffic light system. Our group in Government Development Authority needed it very much. It can help our community development especially the increasing value/prices of car accessories and increasing number of accidents in our place due to traffic light malfunctioning. Please!!!


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on October 12, 2007, 07:56:34 pm
If you have read the posted messages, you should know the source code for this applet is included in the file you will receive if you have clicked the "Get file for offline use" button.


Title: Re: Traffic Light System
Post by: youngscientist on October 22, 2007, 08:49:01 am
Please send me the source code to bwradford@cox.net


Title: Re: Traffic Light System
Post by: omeng on October 24, 2007, 04:10:21 pm
hi..
can you send me the code to my email add??tnx
i just want to know more about this system, so can you please give me some tutorials or information on how to develop this system?.
THANK YOU VERY MUCH..


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on October 24, 2007, 04:14:32 pm
Please check out Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0),
You will be able to see all the code in the EJS and it is much easier to create java applet with EJS.


Title: Re: Traffic Light System
Post by: omeng on October 25, 2007, 02:25:32 pm
tnx


Title: Re: Hello
Post by: serkan3123 on November 11, 2007, 06:08:21 pm
thnk you


Title: Re: Traffic Light System
Post by: cmeonnow1 on December 01, 2007, 12:42:47 pm
sir,,we were asked these questions in our presentation..
we r making pc based traffic control management system,,

q,1.why r u making pc based system not microcontroller based,,,wht r the advantages of pc based?

q.2. wht sensors u can use to control the flow of traffic management under fluctuating traffic flow?

q.2 we said tht sensors r instaled which increase the time of the clock for light change,,,
the ask details of sensors which we wil use?


plz sir answer me these question,,,,,,,,,,,mail me at cme_on_now@yahoo.com

as sooon as possible,....plz


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on December 01, 2007, 05:03:04 pm
The traffic light system was designed to show how to apply basic physics principle into real life situation.
I upload it on the web so that everyone can learn it.
But it only answer why I did it.
Your question was why you use pc based system? You should ask yourself.

The traffic flow can be monitored by many ways:
use light sensor  or even use camera image and count with program.


Title: Re: Traffic Light System
Post by: cmeonnow1 on December 03, 2007, 12:47:32 am
ok sir,,,,,,,,thx fr rplying,,,,

i wil ask the concern topic question ,,,,

hope u wil be rplying be as u did this time,,,,,,

thx


Title: Re: Traffic Light System
Post by: ddyson on January 04, 2008, 03:56:01 am
I'm interested in calculating the total times for acceleration, cruising, idle (stopped) and deceleration. I would like to use those times to calculate estimates for pollution emissions. Is there a way to add this to your code? Either in the ejs version or your old version.

Thanks,
Mike


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on January 04, 2008, 09:09:22 am
For constant acceleration a:
 V(t)=V(0)+a*t
 X(t)=X(0)+V(0)*t+(1/2)*a*t*t

The above equations can be found in high school physics textbook.
You can download ejs source code and modify what you want!
But you need to understand the physics first to make sure you did something correct.


Title: Re: Traffic Light System
Post by: kherfan on January 04, 2008, 11:23:14 pm
Sir..
i just wanted to thanks on you on this excellent example


Title: Re: Traffic Light System
Post by: mgchibike on February 05, 2008, 12:55:16 am
hi, i love it, can i have the source code? and i was wondering if u can help me in doing some soular work> can u help me on that please???
my email is mgchibike@yahoo.com.tanx


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on February 05, 2008, 02:03:24 pm
You did not read the posted message carefully. Otherwise, you should know how to get the source.
We also have simulations related to solar system. Please check out those simulations first, or, write down in more detail what you really want.


Title: Re: Traffic Light System
Post by: kingek on April 14, 2008, 11:30:29 pm
I also would like to get a copy of the source.
Thanks


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 15, 2008, 08:07:25 pm
You will find the source code for this applet when you download this applet.


Title: gagus
Post by: dirgajuli on April 16, 2008, 04:09:15 pm
plese help me about triple pendulum in ejs


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 20, 2008, 08:25:08 am
Do you have problem in physics about triple pendulums or you just need help in java coding?
For triple pendulum, you need to derive formulas first (to get equations for motion).

Please check out Double pendulum (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=195.0)  and post your related question there. This subject for this topic is traffic light system.


Title: Re: Traffic Light System
Post by: angeleyes on May 28, 2008, 05:12:05 am
hi its nice to be here as its my first time
what you did is so nice .


Title: Re: Traffic Light System
Post by: dorin on June 09, 2008, 09:48:40 pm
Hello. I have messaged you earlyer totay, about a simulation of a street intersection. Nothing much, just something to make my presentation about graphs a little more dinamic and visual.
Please, if you wouldn't mind helping me with this task, i don't know much about programing, but i see u know a lot. Can u make a simulation of an intersection of two streets with two lanes each, and a traffic light for each lane, the exterior lane going straight ahead and the interior lane makeing a turn to the left (trough the midle of the intersection) and some cars going on the coresponding lanes and some buttons for each light so i can increase/decrease the time that each light stayes green/red? If you want i could send you a picture of the intersection and how i would like the interface to look like. If you could please help me, i would be greatefull.
Thank you in advance,
Maxim Dorin.
max_piro@yahoo.com

p.s. also, if anyone else on the forum can help me he is welcomed.


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on June 09, 2008, 11:49:57 pm
The purpose of the simulation is to help user understand related physics.
The source code for this one and the EJS version are available.  You can try to do it and I will try to help.


Title: Re: Traffic Light System
Post by: trailmix on June 11, 2008, 10:38:51 am
Can you please tell me how to not read your multiple, incredibly straightforward instructions on getting the source code?  I feel that as a new member must not show up your other members, who must have some real amazing programming skills in spite of not being able to read instruction number 1. 

thanks for the simulation - its great to see a clear demo of the time/distance physics, and good luck with the rubes.
 


Title: Re: Traffic Light System
Post by: listza on August 23, 2008, 03:39:51 pm
Mr. Fu Kwun Hwang

Would you send me the source code of the traffic light system simulation?....
I also have a project about Object Oriented Simulation of Traffic Light System for my college task

Thank you very much...

-*-


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on August 23, 2008, 08:32:04 pm
Please read the first message more carefully and you will know how to find/get the source code.


Title: Re: Traffic Light System
Post by: karmentr on October 08, 2008, 02:44:11 am
Thank-*-You by Fu/Kwun Hwang  ;)


Title: Re: Traffic Light System
Post by: rEd1 on November 13, 2008, 10:06:01 am
sir can you send me the source code... plzzz???? thank you


Title: Re: Traffic Light System
Post by: hidayat89 on December 17, 2008, 03:01:36 pm

   

hey thats a cool work, i love it, can i have the source code? and i was wondering if u can help me in doing somtin smillar to this work.  can u help me on that please???
my email is -*-   ;) :)


Title: Re: Traffic Light System
Post by: LANO-85 on January 29, 2009, 12:46:33 am
hi all please i want some one to help me in running the system without using html , i want to run it by using .java how i will do it ?? plz answer me

 note ( i dawnlouded the classes ) but they not run!!!!!!!!! ???


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on January 29, 2009, 10:41:13 am
You can get the source code (.java) to do what you want. (It is included in the ZIP file if you clicked "get file for offline use" button.)
But you did not read the first message carefully ???  ???  so you do not know where to find the source code.  ::)


Title: Re: Traffic Light System
Post by: LANO-85 on January 29, 2009, 06:32:38 pm
ya i read it and i dawnloud the zip file , but ( implementation of methods is not available  ) so how can i run them ?? its run as html and i want to run them as java or as an applet . do you have any way to help me in this point ( i want to run them using java)
thanks very much


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on January 29, 2009, 08:19:19 pm
The files you have download include java source code and java generated byte code.
It was running as an applet when you view it in html. (The java was running.)
You can also use appletviewer to view the class file.
You can modify the source code by yourself if you want to run it as an java application.


Title: Re: Traffic Light System
Post by: coolvaneegurl on March 03, 2009, 01:12:38 pm
Hello sir. Sir, I really liked your simulation. I was wondering if the simulation could be changed into a multi lane traffic to adopt the lane changing behavior easily or would it require a lot of work. Also can I have one control on each traffic light? Does it require a lot of work? I need this for my Course project. I would really appreciate it if you would show me how to do it, or tell me what to do as I am totally lost and I am just a beginner in Java. Your help will be very much appreciated. Thank you sir.


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 03, 2009, 04:12:53 pm
If you have checked out the link provide just below the simulation at the first post. i.e.
 Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)
That is a two lanes traffic control. May be that is what you want.
You can download it and modified it (Right click to open the source in EJS if you have installed EJS4) to suit what ever need you might have.


Title: Re: Traffic Light System
Post by: coolvaneegurl on March 04, 2009, 01:08:07 pm
Oh ok sir. About th EJS version of simulation, I have checked it out and it is not what i want. What i really need is for one lane to be divided into 2 lanes. Means one strecth of road that has two lanes. I am quite lost in EJS. I have never had any experince in EJS and finding it difficult to get any help on how to use it. Any suggestions sir. Thank you very much for your help sir. 


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 04, 2009, 04:01:21 pm
If car in each land never switch land, then it will be similar to Time duration for the yellow traffic light (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=712.0) (this one has more than 2 lanes).

About help in EJS. Have you check out EJS's original web site and information at this web site.
There are many videos and flv files at this web site which show you examples (how to create simulation with EJS).
Please check them out.


Title: Re: Traffic Light System
Post by: yeek01 on March 18, 2009, 04:50:58 am
sir, can u help me  to modify the source code so that i can play it using java?

and Wat is EJS4 stand for? Easy Java Simulation? How to get this?

I'm interest to change this simulation into 2 lands.

-*- thanks 1st...

And there are some errors when i using java to compile it. The following are the errors:

--------------------Configuration: --------------------
Note: C:\Documents and Settings\Administrator\Desktop\trafficControl\trafficControl.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Documents and Settings\Administrator\Desktop\trafficControl\trafficControl.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Process completed.


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 18, 2009, 06:41:03 am
1. You should be able to find information about Easy Java Simulation Easily at this forum home page.
Please check out those information and download latest EJS from EJS's web site.
2. The JDK102 version was created with JDK1.0.2 more than 12 years ago.
You need to modify some code if you want to compile with current version directly.


Title: Re: Traffic Light System
Post by: coolvaneegurl on March 24, 2009, 05:19:06 pm
Sir, can you please tell me how to have individual control for each traffic light? In your simulation only the green light can be controlled. So i have split it into two where the first is tlight and the second is tlight2. I have deleted all the other lights and also i have deleted the cars in lane 2. So i have only one lane of cars. But the car only responds to tlight and not tlight2. Why is that so? I do not understand...how do I make my cars respond to both tlight1 and tlight2? Please help me...thank you



Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 24, 2009, 05:29:19 pm
Quote
In your simulation only the green light can be controlled. 
The period for all three lights can be controlled in my simulation.
Just right/left click in one of the light.

The first delay time control time delay between the left most one and the center one.
The second delay control control time delay between center light and the right most one.

I do not know what do you mean by lane 1 or lane2? Do you mean vertical lanes?
There is no way I can help because I do not know what you did.

I do not have any information about your background knowledge in traffic control/java programming and physics involved.
It is very difficult to help if I do not have  enough information.


Title: Re: Traffic Light System
Post by: coolvaneegurl on March 24, 2009, 05:43:38 pm
Oh..ooopsss.....sowry sir. What I mean is in your simulation using EJS. Can i send you what i did so far so can have a look? Please  ;D


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 24, 2009, 09:14:03 pm
Please post your question at the same post related to your question.

I will try to find time to have a look if you can write down in detail what you did with the download code/ why you did that , what is the purpose for the changes .. etc.


Title: Re: Traffic Light System
Post by: rahulshhh on April 10, 2009, 08:12:13 am
plz send me the source code to "rahulshhh@yahoo.co.in"
thanxxxx


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 10, 2009, 08:47:32 am
You did not read the posted message carefully.
Please help yourself to download it -- just a click away. ;)


Title: Re: Traffic Light System
Post by: rflaviu on May 17, 2009, 10:17:59 pm
Hello,
I  just downloaded the source code. I am using Java JDK 6 update 10.
The problem I have is that when I run it, the traffic light control overwrites with the road and the intersections are very small.
Can u make a suggestion?Where can I change or what can I change to do it work properly?


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 17, 2009, 11:26:35 pm
This version was created more than 10 years ago with JDK1.0.2
There must be some modification in new version which cause the problem you have described.
I have created another version of traffic light control applet with EJS  (http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?p=1614).
I will be able to help if you have question/problem with the new EJS version.(I am more familiar with EJS, and I did not study later JDK for a long time--- since 2001.)
I can show you where to download JDK1.0.2 if you need it , but I am not able to give you suggestion for the latest JDK. Sorry!


Title: Re: Traffic Light System
Post by: dannydesiliva on September 22, 2009, 12:37:59 pm
Hey all,
Couple of years ago,when i was an engineering student I tried to develop an intelligent traffic control light system.
Back then I observed a lot of pollution at the traffic lights and the wastage of the energy resource gasoline.Green light was on even though there were no vehicles in that direction.This made me think and the result Intelligent traffic control system(Not completed).
My design outlook was something like this,
A Microcontroller which will use the input from the pressure sensors on the road some 100 to 500 mts away from the traffic light.Microcontroller will calculate the number of vehicles,load of vehicles and depending on that time for a particular direction is calculated as against the traditional fixed time control systems.everything was fine but i was unable to create usable pressure sensor.Readymade sensors were very costly.My question is any one has any idea for an alternative for the sensor or changes to the design outlook .

thanks
Bobby


Title: Re: Traffic Light System
Post by: muharam on October 18, 2009, 01:10:06 am
hy any one hlep me in my project my project about designing a Traffic Light controller using MC68000 assembley language and simulate it using IDE68K and EASY68K


  can i get the source code, we are working on a project
 Thanx a bunch
can any one hv it .please send to my email
akram_muharam@yahoo.com


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on October 18, 2009, 10:06:54 am
The source code is available as attachement file at the first message.
Please download it by yourself. ;D


Title: Re: Traffic Light System
Post by: Joshtaylor on October 26, 2009, 09:10:23 pm
Very helpful post.. Thank you for the information...


Title: Re: Traffic Light System
Post by: Coffee makers on December 17, 2009, 02:57:14 pm
Nice post thanks-*-


Title: Re: Traffic Light System
Post by: ikuraru on January 19, 2010, 09:48:17 am
wow, I like it :)


Title: Re: Traffic Light System
Post by: moltak on March 16, 2010, 11:05:58 pm
hey.. can anyone pls tell me what algorithm is being used in this traffic light system? i need it for my case study. pls answer it asap. thank you very much!


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 16, 2010, 11:24:55 pm
1.  Car will accelerate (a=gu) until it reach maximum speed under the following condition:
  there is no car in front and it can pass the next street light before light turn red.
2. Car will de-accelerate(a=-gu) until it reach zero velocity if it is too close to the car just in front of it.
  The minimum distance is related to reaction time, dmin= V * treaction.
3. Car will keep at the same speed if it reach maximum speed.
  
  


Title: Re: Traffic Light System
Post by: mchetou82007 on April 22, 2010, 11:51:11 pm
send me sourrce code
thanx


Title: Re: Traffic Light System
Post by: nitang on April 29, 2010, 11:43:29 pm
Sir,
I really liked your simulation.Even i am trying to simulate a traffic signal.But i am facing a problem in generating the random cars from all sides towards the junction and the repaint is confusing me a lot.Can you please help me out in my problem??


Title: Re: Traffic Light System
Post by: kidashley25 on June 08, 2010, 09:56:11 am
hello does anybody here, know about -*-Turn Signal Switch? I really need some help.


Title: Re: Traffic Light System
Post by: wafiy on October 13, 2010, 01:59:53 am
can you please send me the code to my email address,-*-
i really2 do need that program for my project now,thanks ;)


Title: Re: Traffic Light System source code
Post by: Fu-Kwun Hwang on October 13, 2010, 08:29:49 am
The source code is available as attachment. You can download it by yourself if you really need it.
Please read the first message (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=139.msg636#msg636) under this topic carefully and you will find out how to download it.


Title: Re: Traffic Light System
Post by: hanukaran on January 27, 2011, 12:08:46 am
thank you for the idea sir.i have the file now.but the problem is im begginer.How to open this .php file.Which hav to use to open this file


Title: Re: Traffic Light System
Post by: ahmedelshfie on January 27, 2011, 01:06:13 am
To you access the applet you need to unzip the file that you download before, will find a web page name is trafficControl.html hit click using mouse,
You will be able to watch applet in your PC.


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on January 27, 2011, 09:18:35 am
If you just need to view it offline. Click get file for offline use and you should get .zip file.
Unzip it and open html file with your browser. (the instruction is available as email message  if you decided to received it via email.)

You can download the java source code,too!
The file you have download should be trafficControl.java instead of php file.
The file can be open with any text editor, it can be compiled into java class code.


Title: Re: Traffic Light System
Post by: ibpro on February 17, 2011, 12:31:35 am
Thanks for the Traffic Control System.  It's beautiful.  I need to adjust the code to accommodate emergency vehicles.  I need your help on this.  Thanks


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on February 17, 2011, 10:22:18 am
Please describe in detail what kind of help you need. You are welcomed to check out High way traffic simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=2092). Car can change lane when it is blocked.


Title: Re: Traffic Light System
Post by: dev_cool21 on March 02, 2011, 06:11:34 am
hey can any one help me in modifying the code , my professor has asked me to change some of the options in traffic light. i.e each trafiic light timings for red ,green and yellow should be customisable.. can some one help me out in couple of days?..


Title: Re: Modidy code for Traffic Light System
Post by: Fu-Kwun Hwang on March 02, 2011, 07:05:31 am
1. The code at this topic was created more than 10 years ago with JDK1.0.2
You might want to check out Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0) and working with EJS (http://fem.um.es/EjsWiki/index.php).

2. Please write down what you have done (or what you know about java or programming)?
The timing for red,green,blue light are the same for those three traffic lights (and it can be changed with mouse click--left click to decrease or right click to increase).
You need to define a new GUI to change one of the traffic light, and modify the value for them it the code.
It seems to be an exercise for you. I will try to help but I should not do the job for you.


Title: Re: Traffic Light System
Post by: Leutz on April 11, 2011, 07:10:36 pm
Hi.

I just registered on the forum, being interested in the traffic applications. I found this topic and tried to see how the application work, but I was unable to access it.
When I access the first page of the topic the browser crashes. It works on the other pages of the topic though. I tried with several browsers, and also with different internet providers (home, school ... etc.). It's the same - the first page is somehow broken.
Same thing happens with the link you provided about the newer EJS version.

So in the end, I was unable to see the application running, or at least get the files and make it work by myself somehow. Could you help me with this?

Thank you.

Best wishes,
Leutz


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 11, 2011, 09:54:54 pm
I just viewed it with my firefox without any problem.  ??? I do not why you can not view it. sorry!

You might want to check out another version:  Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)


Title: Re: Traffic Light System
Post by: yurci on May 06, 2011, 05:50:02 am
Hello; i am new to java. How am i gonna compile the source code? i am useing net beans and it is saying main class notexisit. And if i run the trafficcontrol.java applet appers but say not initilized? what should i do?

THANKS


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 06, 2011, 01:14:48 pm
main class is for java application. The code is for creating java applet.
I am not familiar with NET BEANS , however, I think you need to change your selection from application to applet.


Title: Re: Traffic Light System
Post by: ahmedelshfie on May 06, 2011, 05:05:01 pm
Try use DJ Java Decompiler (http://members.fortunecity.com/neshkov/dj.html) is more simple than net beans and i believe you will not meet any probelm to compile the source code Just need to already install  java sdk.
good luck!


Title: Re: Traffic Light System
Post by: fari on June 21, 2011, 03:53:19 pm
sir! the code that u e-mail me showing no output n have these errors................
java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.



so plzzz relpy me faaaaaaaaaaast plzzzzzzzzzzzzzzzzzzzzzzzzzz..................


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on June 22, 2011, 04:20:35 pm
It was written as an applet (more than 10 years ago) instead of an application (so there is no main in the code).

You can use appletviewer to view it. (need an html page with applet tag)

Please check out sun's web site and find out more information.


You can check out traffic light control applet with EJS (http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?p=1614). You can download jar file version which can be run as an application. (just double click the downloaded ajr file).
And you can modify it with EJS and create new version,too!


Title: Re: Traffic Light System
Post by: wendels on August 18, 2011, 01:33:01 pm
I just viewed it with my firefox without any problem.  ??? I do not why you can not view it. sorry!

You might want to check out another version:  Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)

sir pls! send me the source code of traffic light intersection,,thnx!
 


Title: Re: Traffic Light System
Post by: ahmedelshfie on August 18, 2011, 05:13:01 pm
You can download the source code by yourself, down the applet choose download File and later click Get files for offline use and source code will be already in your PC as attachment file unzip and enjoy.


Title: Re: Traffic Light System
Post by: jonnyryan on September 08, 2011, 10:44:27 pm
Hi there, I'm having difficulty locating the source code. Where exactly is it located? Thanks.


Title: Re: Traffic Light System
Post by: ahmedelshfie on September 09, 2011, 02:32:59 am
Your post at page 6 you should first back to page number1 and you will find download source code as attachment zip file, take a look to image that i attach.


Title: Re: Traffic Light System
Post by: mwinganiza on March 01, 2012, 01:03:08 pm

Hi,Is it possible to run the code as an application but not an applet?


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 01, 2012, 08:37:09 pm
You are welcomed to check out EJS version of traffic light control (http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?p=1614).
Download the jar file and run it as an apllication with many options(screen shot/save as animated gif/...).


Title: Re: Traffic Light System
Post by: civosco on March 06, 2012, 02:21:15 am
please send me the source code at civosco@gmail.com
thanks in advance


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on March 06, 2012, 12:03:28 pm
The source code is available as attached file (under the first posted message).
Please download it by yourself if you really need it! :-)


Title: Re: Traffic Light System
Post by: mikemuri_05 on April 19, 2012, 08:35:37 pm
Hi Sir, Can I have a source code (java file) for the traffic light system. Thanks appreciate your help!


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on April 20, 2012, 07:46:14 am
The source code is available as attached file at the same post(first post of this topic) where you found simulation.
Please download it by yourself if you really need it.


Title: Re: Traffic Light System
Post by: wyatt on June 29, 2012, 11:21:27 pm
i need source code


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on June 30, 2012, 11:13:30 am
It is available as attachment under the first posted message. Please download it by yourself if you need it.
It is just a click away. :-)


Title: Re: Traffic Light System
Post by: ericsson on December 17, 2012, 05:21:37 pm
can help me in my source coding with Assembly Code for microP 68000 that use output LED & 7 segments. its for traffic light system???


Title: Re: Reading Calipers.
Post by: mazen on May 14, 2013, 04:03:21 pm
Dear Sir,
it's wonderfull simulation,i like it, could you please send me the source code for traffic control.

To: soso_ali994@hotmmail.com
Or : hardzep11@hotmail.com

Thanks & regards


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 14, 2013, 11:31:25 pm
The source code is available as attached file at the first message (where you find the simulation).
Please download it by yourself if you really need it!


Title: Re: Traffic Light System
Post by: mazen on May 15, 2013, 02:15:38 am
Thank You..


Title: Re: Traffic Light System
Post by: laramsf on May 15, 2013, 02:58:54 am
I'm having trouble little ..How do I get a Java program ...Because the version that I do not work well incomplete .. and it bad version
Can you send a Java program in email or give me a site.
(Sorry for the inconvenience)


Title: Re: Traffic Light System
Post by: laramsf on May 15, 2013, 03:10:03 am
plz can u give me source code of traffic light system


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 15, 2013, 09:03:11 am
As I have replied, the source code is available for download.
This version was created more than 17 years ago with JDK1.0.2
I just compiled with JDK1.0.2 and it is working fine.
You might be able to modified some of the code if you are familiar with java. 
The source code is listed again.


Quote
import java.awt.*;
import java.util.*;

public class trafficControl extends java.applet.Applet implements Runnable{
   Dimension offDimension;
   Image bgImage,fgImage;
   Light L;
   Traffic T;
   TextField countText,scoreText,XYpos;
   int numLight=3,numSection=numLight+1;
   String rts,STR[]={"Reset","Start","Time","maxVelocity","Acceleration","delayTime","lighttime"};
   Color bgColor=new Color(0xE0,0xE0,0xE0);//new Color(0xC8,0xDF,0xD0);
   public void init(){
      setBackground(bgColor);
      for(int i=0;i         if((rts=getParameter(STR))!=null)
            STR=new String(rts);
      }
      Panel p=new Panel();
      p.add(new Label("N1/N2"));
      p.add(countText=new TextField("0/0/0.00",12));
      countText.setEditable(false);
//      p.add(new Label("T="));
//      p.add(timeText=new TextField("0",3));
//      timeText.setEditable(false);
      p.add(new Label("n1/n2"));
      p.add(scoreText=new TextField("0/0/0.00",9));
      scoreText.setEditable(false);
      p.add(new Button(STR[1]));
      p.add(new Button(STR[0]));
      add("North",p);
      L=new Light(numLight,STR);
      T=new Traffic(L);
      String str;
      if((str=getParameter("accelerationValue"))!=null)
         T.a=Double.valueOf(str).doubleValue();
      if((str=getParameter("vmax"))!=null)
         car.vmax=Double.valueOf(str).doubleValue();
      reset();
   }

   public boolean action(Event ev, Object arg) {
      String label = (String)arg;
      if (ev.target instanceof Button) {
         if(label.equals(STR[1])){
            start();
         }else if(label.equals(STR[0])){
            reset();
         }
         return true;
      }
      return false;
   }

   Graphics g,g0,gb;
   Dimension area;
   void reset(){
      //stop();
      area=size();
      if ( (g == null) ){
//            || (area.width != bgDimension.width)
//            || (area.height != bgDimension.height) ) {
//         bgDimension = area;
         bgImage = createImage(area.width, area.height);
         fgImage = createImage(area.width, area.height);
         g = bgImage.getGraphics();
         g0=fgImage.getGraphics();//getGraphics();
      }
      runTime=0;
      lastTime = System.currentTimeMillis();
      g.setColor(bgColor);
      g.fillRect(0,0,area.width,area.height);
      g.setColor(Color.black);
      drawRoad(area);
      gb=this.getGraphics();
   }
   numberInput maxV,acceleration;
   void drawRoad(Dimension area){
      L.init(g,area);
      T.init(g0,L.X[0],L.y-5,area.width);
      maxV=new numberInput(g,5,L.y,STR[3]);
      maxV.setValue((int)car.vmax,5,50);
      acceleration=new numberInput(g,10,L.y+L.lSize.height,STR[4]);
      acceleration.setValue((int)T.a,1,20);
      repaint();
   }
   static boolean running,rightClick,changed=false;
   public boolean mouseDown(Event e, int x, int y){
      if(e.modifiers==Event.META_MASK)//"Right Click, ";
         rightClick=true;
      else rightClick=false;
      int w=L.lSize.width;
      if(L.mouseDown(e,x,y)){
         repaint();
         return true;
      }else if(x< 2*w && y<3*w){
         int sign=0;
         if(e.modifiers==Event.META_MASK || x>w)sign=1;//right click
         else if((L.greenTime>1)&&
                  (L.yellowTime-L.greenTime)>1 &&
                  (L.redTime-L.yellowTime)>1 )
                  sign=-1; // right click add 1, left click sub 1
      
         switch(y/w){
            case 0:L.greenTime+=sign;
            case 1:L.yellowTime+=sign;
            case 2:L.redTime+=sign;
         }
         L.setupLightTime(L.greenTime,L.yellowTime,L.redTime);
         repaint();
      }else if(maxV.mouseDown(e,x,y)){
         car.vmax=maxV.value();
         repaint();
      }else if(acceleration.mouseDown(e,x,y)){
         T.a=acceleration.value();
         repaint();
      }else{
         running=!running;
         changed=true;
         repaint();
      }
      return true;
   }
   //public boolean mouseDrag(Event e, int x, int y){
      //if(e.modifiers==Event.META_MASK)return true;
   //   return true;
   //}
   public boolean mouseUp(Event e, int x, int y){
      if(changed){
         if(!rightClick)running=!running;
         changed=false;
      }
      return true;
   }
   //public boolean mouseMove(Event e, int x, int y){
   //   XYpos.setText(String.valueOf(x)+","+String.valueOf(y));
   //   return true;
   //}
   public void paint(Graphics gs){
      if(g==null)reset();
      update(gs);
   }
   String d2String(double value){
      float f=(float)((int)(value*100.)/100.);
      String str=String.valueOf(f);
      if(str.indexOf(".")==-1)str+=".0";
      return str;
   }

   public void update(Graphics gs){

      g0.drawImage(bgImage, 0, 0, this);
      if(!running)L.drawTrace(g0,acceleration.value(),maxV.value());
      T.advanced(deltaT);
      T.drawVelocity(g0);
      g0.drawString(STR[2]+d2String(runTime)+" s",130,L.y-L.height);

      gs.drawImage(fgImage, 0, 0, this);
   }
   // animation code
   Thread animThread;
   long lastTime=0;
   double runTime;
   long delay=100,delta=100;
   //  This starts the threads.
   public void start(){
      //Start animating!
      if (animThread == null) {
         animThread = new Thread(this);
         animThread.start();
         //Remember the starting time. of thread
         lastTime = System.currentTimeMillis();
         runTime=0.;
      }
      running=true;
   }
    public void stop() {
      //Stop the animating thread.
      animThread = null;
   }
   int second=0;
   public void run() {
      //Just to be nice, lower this thread's priority
      Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
      //This is the animation loop.
      while (Thread.currentThread() == animThread) {
         //Advance the animation frame. with delta time
         delta=System.currentTimeMillis()-lastTime;
         lastTime+=delta;
         if(running)advanced(delta/1000.);
         try {
            animThread.sleep(Math.max(0,lastTime-System.currentTimeMillis()));
         } catch (InterruptedException e) {
            break;
         }
      }
   }
   int lastN1=0,lastN2=0,period=100;
   String str="(0/0)=>";
   void showResult(){
      countText.setText(String.valueOf(T.passed)+"/"+
            String.valueOf(T.passed2)+"/"+
            String.valueOf((int)(100.*(T.passed+T.passed/3.)/second)/50.));
      //period=3*(L.redTime);
      if(second%period==0){
      double score=(T.passed-lastN1+(T.passed2-lastN2)/3.)/period;
      scoreText.setText(String.valueOf(T.passed-lastN1)+"/"+
            String.valueOf(T.passed2-lastN2)+"/"+
            String.valueOf((int)(100.*score)/50.));
         lastN1=T.passed;
         lastN2=T.passed2;
      }
   }
   double deltaT;
   void advanced(double dt){
      runTime += dt;
      int t=(int)runTime;
      L.setStatus(t);
//      T.advanced(dt);
      deltaT=dt;
      if(t!=second){
         second=t;
         //timeText.setText(String.valueOf(second));
         showResult();
      }
/*
      g0.drawImage(bgImage, 0, 0, this);
      if(!running)L.drawTrace(g0,acceleration.value(),maxV.value());
      T.advanced(deltaT);
      T.drawVelocity(g0);
      g0.drawString(STR[2]+d2String(runTime)+" s",130,L.y-L.height);
      //g.drawImage(fgImage, 0, 0, this);

      repaint();
*/
      update(gb);
   }
}

class Light{// implements Runnable{
   static int green=0,yellow=1,red=2,count;
   Color color[]={Color.green,Color.yellow,Color.red};
   int X[],status[],y;
   static int height=70;
   int greenTime,yellowTime,redTime;
   int delayArray[];
   Dimension lSize=new Dimension(10,30);
   Graphics g;
   int dd=3;
   numberInput delayControl[];
   int init_delay=4;
   String STR[];
   Light(int n,String s[]){
      count=n;
      X=new int[n];
      status=new int[n];
      delayArray=new int[n];
      delayControl=new numberInput[n-1];
      STR=s;
   }
   int xx,yy,size,size2;
   int width,roadWidth;
   void init(Graphics gi,Dimension area){
      roadWidth=15;
      width=(area.width-count*roadWidth)/count;
      int x0=width/2,dx=width+roadWidth,y0=area.height;
      height=(area.height-3*lSize.height/2-roadWidth)/2;
      g=gi;
      y=y0-height;
      xx=lSize.width+dd;
      yy=y+dd;
      size=lSize.width/2;
      size2=2*size;
      drawRoad(width,roadWidth);// draw streets
      for(int i=0;i         X=x0+i*dx;
         status=red;
         delayArray=0;
         drawLight(i,0);
      }
      // draw Left top cornor light
      Color c=g.getColor();
      g.drawRect(0,0,lSize.width,lSize.height);
      for(int i=0;i<3;i++){// 3 lights
         g.setColor(color);
         g.fillOval(0,i*lSize.width,size2,size2);
         g.setColor(Color.black);
         g.drawOval(0,i*lSize.width,size2,size2);
      }
      g.setColor(c);
/*
   if(STR[6].length>0){
      String delimeter=",";
      String[] lv=STR[6].split(delimeter);
      setupLightTime(Integer.parseInt(lv[0]),Integer.parseInt(lv[1]),Integer.parseInt(lv[2]));
   }else    
*/
      setupLightTime(30,35,70);
      for(int i=1;i         delayControl[i-1]=new numberInput(g,X-lSize.width-5,yy,STR[5],true);
      }
   }
   void drawRoad(int width,int roadWidth){
      int x=0;
      int w,h=height,dh=h+roadWidth;
      //int dd=5;
      //int xx=lSize.width+dd,yy=dd;
      for(int i=0;i         if(i==count || i==0 )w=width/2;
         else w=width;
         g.drawRect(x,y,w,h-1); // lower part
         g.drawRect(x,y-dh,w,h); // upper part
         for(int j=y-dh+h;j>y-dh;j-=10)g.drawLine(x,j,x+5,j);
         for(int j=y-dh+h;j>y-dh;j-=20)g.drawLine(x+5,j,x+10,j);
         x=x+w+roadWidth;
      }
   }

   public boolean mouseDown(Event e, int x, int y){
      for(int i=1;i         if(delayControl[i-1].mouseDown(e,x,y)){
            setupDelay(i,delayControl[i-1].lastChange());
            return true;
         }
      }
      return false;
   }

   void drawLight(int n,int ts){
      // draw Light according to current status
      Color c=g.getColor();
      int x1=X[n]-xx;
      g.clearRect(x1,yy,lSize.width,lSize.height);
      g.drawRect(x1,yy,lSize.width,lSize.height);
      for(int i=0;i<3;i++)
         g.drawOval(x1,yy+i*lSize.width,size2,size2);

      g.setColor(Color.black);
      g.fillRect(x1-size,yy+5*lSize.width-12,16,14);
      g.setColor(color[status[n]]);
      g.fillOval(x1,yy+status[n]*lSize.width,size2,size2);
      g.drawString(String.valueOf(ts),x1-size,yy+5*lSize.width);
      g.setColor(c);
   }
   void setupLightTime(int tGreen,int tYellow, int tRed){
      greenTime=tGreen;
      yellowTime=tYellow;
      redTime=tRed;
      g.clearRect(2*size2,0,30,3*size2);
      Color c=g.getColor();
      g.setColor(Color.black);
      g.drawString(String.valueOf(greenTime),2*size2,size2);
      g.drawString(String.valueOf(yellowTime-greenTime),2*size2,2*size2);
      g.drawString(String.valueOf(redTime-yellowTime),2*size2,3*size2);
      //drawTiming(running);
      g.setColor(c);
   }
   void drawTrace(Graphics gp,double a,double maxV){
      int xi=width/2+1,xx=xi;
      int yi=y+height;
      double x=0.;//,vx=0.;
      double t,ta=maxV/a,ta2=ta*ta;
      a=a/2.;
      Color c=gp.getColor();
      drawTiming(gp);
      gp.setColor(Color.blue);
      for(t=0.;yi>y-height;t+=0.5){
         if(t         else gp.drawLine(xx,yi,xx=xi+(int)(a*ta2+maxV*(t-ta)),yi--);
         //if(t         //else gp.drawLine(xx=xi+(int)(a*ta2+maxV*(t-ta)),yi--,xx,yi);
      }
      gp.setColor(c);
   }
   void drawTiming(Graphics gp){
      //draw light timing info
      Color c=gp.getColor();
      int xi=width/2,yi;
      for(int i=0;i         gp.setColor(Color.white);
         gp.drawLine(xi,y+height,xi,y-height);
         //if(status){
         //   gp.setColor(Color.black);
         //   gp.drawLine(xi,y+height,xi,y);
         //   gp.drawLine(xi,y-roadWidth,xi,y-height);
         //}else{
            yi=y+height-2*delayArray;
            while(yi>y-height){
               gp.setColor(Color.green);
               gp.drawLine(xi,yi,xi,yi-=2*greenTime);
               gp.setColor(Color.yellow);
               gp.drawLine(xi,yi,xi,yi-=2*(yellowTime-greenTime));
               gp.setColor(Color.red);
               gp.drawLine(xi,yi,xi,yi-=2*(redTime-yellowTime));
            }
            yi=y+height-2*delayArray;
            while(yi               gp.setColor(Color.red);
               gp.drawLine(xi,yi,xi,yi+=2*(redTime-yellowTime));
               gp.setColor(Color.yellow);
               gp.drawLine(xi,yi,xi,yi+=2*(yellowTime-greenTime));
               gp.setColor(Color.green);
               gp.drawLine(xi,yi,xi,yi+=2*greenTime);
            }
         //}
         xi+=width+roadWidth;
      }
      gp.setColor(c);
   }
   
   void setupDelay(int id,int Time){
      for(int i=id;i+=Time;
      //drawTiming(running);
   }

   public int height(){ return height;}

   boolean setStatus(long t){
      boolean out=false;
      long dt;
      int s,ts;
      for(int i=0;i         s=status;
         dt=(t-delayArray) % redTime;
         if(dt<0)dt+=redTime;
         if(dt            status=green;
            ts=greenTime-(int)dt;
         }else if(dt            status=yellow;
            ts=yellowTime-(int)dt;
         }else{
            status=red;
            ts=redTime-(int)dt;
         }
         if(s!=status){
            out=true;
         }
            drawLight(i,ts);
      }
      return out;
   }
}

class numberInput {
   int width,height,xs,ys,x,y;
   String title;
   Graphics g;
   int value=0;
   double scale=1.;
   Rectangle add,sub;
   int change=0;
   boolean bounded=false;
   int min=0,max=100;
   int xwidth=60;
   numberInput(Graphics gs,int xi,int yi,String s,boolean rightAlign){
      g=gs;x=xi;y=yi;title=s;
      FontMetrics fm=g.getFontMetrics();
      if(rightAlign)x-=xwidth;//fm.stringWidth(title);
      init();
   }
   numberInput(Graphics gs,int xi,int yi,String s){
      g=gs;x=xi;y=yi;title=s;
      init();
   }
   void init(){
      FontMetrics fm=g.getFontMetrics();
      int h=fm.getHeight(),w=xwidth;//fm.stringWidth(title);
      int h2=h/2;
      width=w-h-2;
      height=h;
      int yy=y+h;
      g.drawString(title,x,yy);
      yy+=1;
      int xa[]={x,x+h2,x+h2},xb[]={x+w,x+w-h2,x+w-h2};
      int yab[]={yy+h2,yy,yy+h};
      xs=x+h2+3;
      ys=yy+h-2;
      g.drawRect(xs-2,ys-height+2,width-1,height);
      g.fillPolygon(xa,yab,3);
      g.fillPolygon(xb,yab,3);
      sub=new Rectangle(x,y+h+1,h2,h);
      add=new Rectangle(x+w-h2,y+h+1,h2,h);
      setValue(0);
   }
   void setValue(int i,int mi,int mx){
      setValue(i);
      bounded=true;
      min=mi;
      max=mx;
   }
   void setValue(int i,int s){
      scale=10^s;
      setValue(i);
   }
   
   void setValue(int i){
      value=i;
      g.clearRect(xs-2+1,ys-height+3,width-3,height-2);
      Color c=g.getColor();;
      g.setColor(Color.black);
      g.drawString(String.valueOf(i*scale),xs,ys);
      g.setColor(c);
   }
   boolean valueChange(int di){
      if(bounded &&( (value==min && di<0) || (value==max && di>0)))di=0;
      if(di==0)return false;
      value+=change;
      setValue(value);
      return true;
   }
   int lastChange(){ return change;}
   double value(){ return scale*value;}

   public boolean mouseDown(Event e, int x, int y){
      if(add.inside(x,y))change=1;
      else if(sub.inside(x,y))change=-1;
      else change=0;
      return valueChange(change);
   }
}

class Traffic {//implements Runnable{
   // traffic control center
   Vector v=new Vector(); // main traffic
   Vector v2[]; // other traffics
   car c;
   int w=10,h=5,y0,w2=w/2;
   Graphics g;
   static double a=10.;
   static private double a2=a/6.;
   int minDx=3,xMax,Dx,Dx2,minDx2;
   Light L;
   int passed=0,passed2=0;
   int ymax,ymin,y1;
   Traffic(Light Li){
      L=Li;
      v2=new Vector[L.count];
      for(int i=0;i=new Vector();
   }

   double roadWidth=15.;
   void init(Graphics gs,int x,int y,int xmax){
      passed=0;
      passed2=0;
      a2=a/6.;
      g=gs;
      xMax=xmax+w+minDx;
      y0=y;
      Dx=w+minDx;
      Dx2=Dx+minDx;
      minDx2=2*minDx;
      reset();
      v.removeAllElements();
      for(int i=0;x>0;i++,x-=Dx){
         c=new car((double)(x),0.,0.);
         if(i==0)c.setFront(true);
         else c.setFront(false);
         v.addElement(c);
         drawCar(c,false);
      }
      // for vertical cars
      ymax=y0+L.height();
      ymin=y0-(int)roadWidth-L.height();
      for(int i=0;i         v2.removeAllElements();
         int sign=1-2*(i%2);
         int n=L.height()/Dx;
         y1=y0-(int)roadWidth;
         for(int j=0;j            c=new car(y1-j*Dx,0.,0.);
            if(j==0)c.setFront(true);
               else c.setFront(false);
            v2.addElement(c);
            drawCar(c,L.X,sign,false);
         }
      }
      // draw car color code
      int xx=15,yy=ymin+15,xx2=xx+w+h;
      g.setColor(Color.black);
      g.drawRect(xx,yy,w,h);
      g.drawString("a>0.",xx2,yy+h);
      g.setColor(Color.yellow);
      g.fillRect(xx,yy,w,h);
      yy+=w;
      g.setColor(Color.black);
      g.drawRect(xx,yy,w,h);
      g.drawString("a=0.",xx2,yy+h);
      g.setColor(Color.green);
      g.fillRect(xx,yy,w,h);
      yy+=w;
      g.setColor(Color.black);
      g.drawRect(xx,yy,w,h);
      g.drawString("a<0.",xx2,yy+h);
      g.setColor(Color.red);
      g.fillRect(xx,yy,w,h);
      g.setColor(Color.black);
   }

   void reset(){
      g.clearRect(0,y0-h,xMax,h+1);
   }
   void drawCar(car c,int x,int sign,boolean erase){
         int xx=x+w2,yy=(int)c.y[0]-w2;
         if(sign==-1)yy=ymin+ymax-yy;
         if(erase)g.clearRect(xx,yy,h+1,w+1);
         else {
            g.drawRect(xx,yy,h,w);
            Color color=g.getColor();
            if(c.acceleration==0.)g.setColor(Color.green);
            else if(c.acceleration<0)g.setColor(Color.red);
            else g.setColor(Color.yellow);
            g.fillRect(xx,yy,h,w);
            g.setColor(color);
         }
   }

   void drawCar(car c,boolean erase){
         if(erase)g.clearRect((int)c.y[0]-w,y0-h,w+1,h+1);
         else {
            g.drawRect((int)c.y[0]-w,y0-h,w,h);
            Color color=g.getColor();
            if(c.acceleration==0.)g.setColor(Color.green);
            else if(c.acceleration<0)g.setColor(Color.red);
            else g.setColor(Color.yellow);
            g.fillRect((int)c.y[0]-w,y0-h,w,h);
            g.setColor(color);
         }
   }
   // traffic flow control
   car cs;
   boolean nextFront;
   void advanced(double dt){
      cs=null;
      c=(car)v.firstElement();
      c.setAcceleration(a);
      if(c.y[0]>xMax){// remove car outside boundary
         v.removeElement(c);
         passed+=1;
         drawCar(c,true);
         c=null;
      }
      nextFront=false;
      int count2=L.count;
      double aNeeded,tReact=1.;
      double minD=Dx*1.2,safeD=2.*Dx;
      for(Enumeration e=v.elements();e.hasMoreElements();){
         c=(car)e.nextElement();
         if(c.lightID            if(cs!=null){
               minD=cs.y[0]-c.y[0]-Dx;
               safeD=minD-c.y[1]*tReact;
               if(minD<0.)c.y[1]=cs.y[1];// too close
            }else{
               minD=Dx;
               safeD=2.*Dx;
            }
            if((cs!=null)&& safeD<0.){ // be safe
                     aNeeded=2.*(cs.y[1]*cs.y[1]-c.y[1]*c.y[1])/minD;//(cs.y[0]-c.y[0]-Dx);
                     //aNeeded=a;
                     c.setAcceleration(aNeeded);
            }else{
               switch(L.status[c.lightID]){
               case 0: // green light
                  if(cs!=null && minD>2.*minDx)c.setAcceleration(a);
               break;
               case 1: //yellow
                  if(L.X[c.lightID]-c.y[0] < c.y[1]*c.y[1]/(3.*Math.max(a,10.)))break;
               case 2:
                  if(c.isFront()){
                     if(L.X[c.lightID]-c.y[0] > 2.*Dx2)
                        c.setAcceleration(a);
                     else if(L.X[c.lightID]-c.y[0] < minDx){
                        c.y[1]=0.;
                        c.setAcceleration(0.);
                     }else {
                        aNeeded=c.y[1]*c.y[1]/(L.X[c.lightID]-c.y[0]);
                        c.setAcceleration(-aNeeded);
                     }
                  }else if(cs!=null){
                     if(safeD > Dx2)c.setAcceleration(a);
                     else if(cs.acceleration<0. && c.acceleration>0.){
                        aNeeded=(cs.y[1]*cs.y[1]-c.y[1]*c.y[1])/minDx;//(cs.y[0]-c.y[0]);
                        c.setAcceleration(aNeeded);
                     }else c.setAcceleration(0.);
                  }
                  break;
               }
            }
            if(c.y[0]>=L.X[c.lightID]){
               c.lightID+=1; //just pass one traffic light
               nextFront=true;
            }else if((c.y[0]                  c.setFront(true);
                  nextFront=false;
            }

         } else c.setAcceleration(a);

         // advanced one time step
         //drawCar(c,true);
         c.advanced(dt);
         drawCar(c,false);
         cs=c;
      }
      if((int)c.y[0]>Dx){
         v.addElement(new car(0.,0.,a));
         drawCar(c,false);
      }
      advanced2(dt);
   }

   void advanced2(double dt){
      // if passed lighID=1;
      int sign;
      for(int i=0;i         c=(car)v2.firstElement();
         cs=null;
         sign=1-2*(i%2);
         if(c.y[0]>ymax){
            v2.removeElement(c);
            passed2+=1;
            drawCar(c,L.X,sign,true);
            c=null;
         }
         nextFront=false;
         for(Enumeration e=v2.elements();e.hasMoreElements();){
            c=(car)e.nextElement();
            if(c.lightID==0){// not pass light yet
               if(c.y[0]<=y1){
                  if(nextFront){
                     c.setFront(true);
                     nextFront=false;
                  }
               }else{
                  c.lightID+=1; //just pass one traffic light
                  c.setAcceleration(a);// keep accelerating
                  nextFront=true;
                  if(cs!=null)c.setFront(false); // first car, always front
               }
               double aNeeded=a;
               if(L.status==2){ // red light, green for us
                  if(cs==null)c.setAcceleration(a);
                  else if((cs.y[0]-c.y[0]) > Dx2 )
                     c.setAcceleration(a);
               }else { // green or yellow light, red for us
                  if(c.isFront()){
                     if(y1-c.y[0] < minDx){
                        c.y[1]=0.;
                        c.setAcceleration(0);
                     }else{
                        aNeeded=c.y[1]*c.y[1]/(y1-c.y[0]);
                        c.setAcceleration(-aNeeded);
                     }
                  }else if(cs!=null){
                     if(cs.y[0]-c.y[0] > Dx2)
                        c.setAcceleration(a);
                     else if(cs.y[0]-c.y[0] < Dx){
                           c.y[1]=cs.y[1];
                           c.setAcceleration(0.);
                     }else if(cs.acceleration<=0.){
                        aNeeded=(cs.y[1]*cs.y[1]-c.y[1]*c.y[1])/(cs.y[0]-c.y[0]);
                        c.setAcceleration(aNeeded);
                     }
                  }
               }
               if( (cs!=null)   && (cs.y[0]-c.y[0] < Dx) ){
                  c.y[1]=0.;
               }
         }

            // advanced one time step
            //drawCar(c,L.X,sign,true);
            c.advanced(dt);
            drawCar(c,L.X,sign,false);
            cs=c;
         }
         if((int)c.y[0]>ymin+Dx){
            v2.addElement(new car(ymin,0.,a2));
            drawCar(c,L.X,sign,false);
         }
      }
   }
   void drawVelocity(Graphics g0){
      int size=2,size2=4;
      int xoffset=-w2-size,yoffset=y0-(int)roadWidth-size+h;
      g0.setColor(Color.blue);
      for(Enumeration e=v.elements();e.hasMoreElements();){
         c=(car)e.nextElement();
         g0.fillOval((int)c.y[0]+xoffset,yoffset-(int)(2.*c.y[1]),
            size2,size2);
      }
   }
}

class car extends rk4 {
   double acceleration=10.;
   static double vmax=30.,vmin=0.,vMove=3.;
   double xmax=100.;
   int lightID;
   boolean front=false;

   car(double xi,double vi,double ai){
      init(2,true);
      y[0]=xi;
      y[1]=vi;
      acceleration=ai;
      lightID=0;
   }

   void setAcceleration(double ai){
      acceleration=ai;
   }
   boolean isFront(){return front;}
   void setFront(boolean f){
      front=f;
   }
   void advanced(double dt){
      nextmove(dt);
      if(y[1]         acceleration=0.;
         y[1]=0.;
      }else if(y[1]>vmax){
         acceleration=0.;
         y[1]=vmax;
      }
   }
   public void derivs (double t,double y[],double dydx[]){
      dydx[0]=y[1]; // V_theta
      dydx[1]=acceleration; // alpha=-K theta
   }
}

// RK4
abstract class rk4 {
   int n;
   public double dydx[];
   public double y[],yout[];
   public void init(int dim,boolean self){
      n=dim;
      dydx=new double[n];
      yout=new double[n];
      if(self)y=yout;
         else   y=new double[n];
   }

    public abstract void derivs(double x,double y1[],double dydx[]);
   /*                                                                                                
   public void next(double x,double h){ // t & dt
      core(x,h);
   }
   public double[]  next(double h){ // dt
      core(0.,h);
      return yout;
   }*/
   public void nextmove(double h,double[] yin){
      y=yin;
      core(0.,h);
   }
   public void nextmove(double h){
      core(0.,h);
   }
   private void core(double x, double h){
   /* Runge-Kutta forth-order method */
      int i;
      double xh,hh,h6;
      double dym[]=new double[n];
      double dyt[]=new double[n];
      double yt[]=new double[n];
      hh=h*0.5;
      h6=h/6.0;
      xh=x+hh;
      derivs(xh,y,dydx);
      for (i=0;i=y+hh*dydx;
      derivs(xh,yt,dyt);
      for (i=0;i=y+hh*dyt;
      derivs(xh,yt,dym);
      for (i=0;i         yt=y+h*dym;
         dym += dyt;
      }
      derivs(x+h,yt,dyt);
      for (i=0;i         yout=y+h6*(dydx+dyt+2.0*dym);
   }
}


Title: Re: Traffic Light System
Post by: laramsf on May 16, 2013, 08:13:25 pm
Hello..
I know I am stupid Beginner in java, you can put more comments with the code?(Please)
To help me a lot to understand.

Thank you very much... :)



Title: Re: Traffic Light System
Post by: laramsf on May 18, 2013, 03:26:06 am
?


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 18, 2013, 09:19:22 am
The traffic control  code was created 17 years ago. I needed to draw all the view element with java code by myself.
I started to use EJS since 2001.  With EJS: I only need to define variables, provide initial value, relation between variables , set up properties for graphical user interface elements.  Then, EJS will generate java code and create the program.
e.g.     Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)
So I did not wrote java code for 12 years. 

It will take me a lot of time to write extended comments.
If you can indicate where you did not understand the code. I may be able to find time to check it out and figure out what the code is about.
Is it the physics you did not understand? Is it the numerical method you did not understand? Is it the view elements you did not understand?


Title: Re: Traffic Light System
Post by: mazen on May 23, 2013, 02:07:18 am
hi sir...
  I'm a college student, I have a graduation project, I loved this simulation, and I want to implement.
First:
- Install the Java JDK.
- Opened file TrafficControl with the textpad and saved the file to  TrafficControl.java
(But I can't find implementation"RUN"). Are my steps correct? What are the right steps?

Second:
How can I work extra opposite direction of the vector cars from left to right?
Please help.

Thank you


Title: Re: Traffic Light System
Post by: mazen on May 24, 2013, 03:51:42 am

hi sir...
  I'm a college student, I have a graduation project, I loved this simulation, and I want to implement.
First:

When i compile the source code gave me an error 100, mostly in the for loop?I did not know to deal with?
Can you solve this problem?

How can I work extra opposite direction of the vector cars from left to right?
Please help.

Thank you


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 25, 2013, 07:01:36 pm
The simulation at the top of this topic was created 17 years ago with JDK1.0.2

You might need to change some of the code for latest JDK.

However, you can compile it with JDK1.0.2 without error message.
JDK102.zip is added as attached file. You can download it and use it to compile the above code.


There is another  Ejs version of traffic control simulation (http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=365.0)
You can view how it was created and add new condition if you install EJS.
You can find ejs download link with google search:EJS download.

 


Title: Re: Traffic Light System
Post by: mazen on May 25, 2013, 08:03:34 pm
Sorry for the inconvenience sir, really.
How can i compile it with JDK1.0.2? i download it.
But
i think their error in my system because the winrar give me 3 error

secondly:
How do I use the ejs in thهis subject because I deal with it in the first time?


Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on May 26, 2013, 09:05:45 pm
Download jdk102.zip
unzip it to root

jdk102\bin\javac.exe your_java_code.java

Download EJS from the web site
unzip it
Click ejsConsole.jar to initial the preperties (only need to be done once).
Close it.

Download TrafficControl.jar from EJS version trafficControl web page
Double click it to run the jar file.
Click right mouse button in the java window. Select open EJS model,
And you will find all the code in the EJS environment.

You can learn more about EJS from EJS web site.



Title: Re: Traffic Light System
Post by: louse on June 04, 2013, 12:44:59 pm
your code for traffic signal light  is so great -*-


Title: Re: Traffic Light System
Post by: mazen on June 10, 2013, 03:32:05 am
Hello sir ..

I hope that you have the knowledge and the source code for the design of an compiler in C + +? With writing comments ..

Thank you


Title: Re: Traffic Light System
Post by: jimmyjjohn on July 23, 2013, 12:14:46 pm
Hello Dear!

I am on here wondering if anyone reading this know where I can find a website that will teach me how to read a caliper. I need to learn this for a job I am applying for.  :o :-*

Thanks-*-



Title: Re: Traffic Light System
Post by: Fu-Kwun Hwang on July 23, 2013, 03:39:51 pm
If you want to know how to read a cliper.
Please check out the following URL
http://www.phy.ntnu.edu.tw/ntnujava/viewtopic.php?t=69


Title: Re: Traffic Light System
Post by: Charli05 on September 30, 2016, 12:34:30 pm
The traffic light system contain have 3 light red yellow and green and these are the sign of your safety..