Go Back   DriverHeaven.net > Forums > Software / Tools > Programming, Coding, (Web)Design

Notices

Reply
 
LinkBack Thread Tools Display Modes
Old Nov 7, 2004, 05:45 PM   #1 (permalink)
lime
DriverHeaven Newbie
 
Join Date: Oct 2004
Posts: 8
lime is on a distinguished road

java question

i'm working on a simulator project and i'm having trouble in one area....

i run a simulation of planes landing and taking off on one runway, the user inputs the minutes to run the sim, the prob of a plane landing and taking off, the minutes it takes to land and to take off....the constructor and everything is fine but i'm having trouble in this one method

the method runs the actual simulation ... it generates random doubles to check if a plane wants to land and if a plane wants to take off, if so it adds them to the appropriate queue. the part i'm having trouble with is getting the average wait time in the queue and the number of planes left in each queue....here's the code i have for this method so far, any ideas ????

Code:
public void runSim() {
 		rnd = new Random();
 		while(interval <= minutes){
 			temp = rnd.nextDouble();
 			if(temp < probLand){
 				landingQ.add(new airplane(interval));
 			}
 			temp = rnd.nextDouble();
 			if(temp < probTake){
 				takeOffQ.add(new airplane(interval));
 			}
 			if(landingQ.size() > maxLand)
 				maxLand++;
 			if(takeOffQ.size() > maxTake)
 			    maxTake++;		    
 			if(!landingQ.isEmpty()){
 				landed++;
 			    landSum += interval - ((airplane)landingQ.front()).getStart();
 				landingQ.remove();
 				interval += minToLand;
 			}
 			else if((landingQ.isEmpty()) && (!takeOffQ.isEmpty())){
 				tookOff++;
 			    takeSum += interval - ((airplane)takeOffQ.front()).getStart();
 				takeOffQ.remove();
 				interval += minToTake;
 			}
 			else if((landingQ.isEmpty()) && (takeOffQ.isEmpty())){
 				interval++;
 		    }			
 		} // end while
 		leftLand = landingQ.size();
 		leftTake = takeOffQ.size();
 		if(landed == 0)
 			avgLand = 0;
 		else
 			avgLand = landSum/landed;
 		if(tookOff == 0)
 			avgTake = 0;
 		else
 			avgTake = takeSum/tookOff;
 	} // end method runSim()

Last edited by lime; Nov 7, 2004 at 05:52 PM.
lime is offline   Reply With Quote
Old Nov 8, 2004, 03:18 AM   #2 (permalink)
pr0digal jenius
Delete Me
 
Join Date: Mar 2004
Posts: 15,115
pr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to all

i'll look at it tomorrow when I'm more awake, just thought I'd let you knwo now so you wouldn't think you'd been abandoned
pr0digal jenius is offline   Reply With Quote
Old Nov 9, 2004, 04:26 PM   #3 (permalink)
pr0digal jenius
Delete Me
 
Join Date: Mar 2004
Posts: 15,115
pr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to allpr0digal jenius is a name known to all

hrmm..I dunno...that's a really round about way to do the program.....what all is in your landingQ class?
pr0digal jenius is offline   Reply With Quote
Old Nov 9, 2004, 05:42 PM   #4 (permalink)
lime
DriverHeaven Newbie
 
Join Date: Oct 2004
Posts: 8
lime is on a distinguished road

the landingQ is just an UnboundedQueue....it's fine...i just need help on how to check if the runway is free, if so and the landingQ isn't empty, then allow a plane to land, so the runway is not free for minToLand minutes....then go from there... i'm having trouble with that part
lime is offline   Reply With Quote
Old Nov 9, 2004, 06:08 PM   #5 (permalink)
bug77
DriverHeaven Senior Member
 
Join Date: Oct 2003
Location: around
Posts: 792
bug77 is on a distinguished road

My guess is landSum, landed, takeSum, tookOff are of an integral type. In this case, you need to convert at least one of the operands to a float.
E.g.: avgLand = (float)landSum/landed;

On the other hand, double type is a performance killer on 32 bit platforms, so you'd be better off with float. Or if that is not a concern, just use
if(Math.random()<whatever){
}


I hope that solves your problem. If not get back to me.
bug77 is offline   Reply With Quote
Old Nov 9, 2004, 06:14 PM   #6 (permalink)
germanjulian
Back in London
 
germanjulian's Avatar
 
Join Date: Jul 2003
Location: London
Posts: 1,794
germanjulian is on a distinguished road

why dont you go to a developer forum where you will get loads more help.
devshed.com for example

not saying the people here dont know cause some of them do but on developer forums its all about develoing
__________________
/|\ Asus P5W DH Deluxe, Intel C2D E6600, 2GB Corsair XMS2-6400C4 DDR2, E-VGA GeForce 7800 GT, Creative X-Fi Extreme Music, 500GB Seagate 7200.10 SATA, Lian Li PC-V1100 Aluminum Case Black, etc. http://germanjulian.com /|\
germanjulian is offline   Reply With Quote
Old Nov 9, 2004, 09:44 PM   #7 (permalink)
bug77
DriverHeaven Senior Member
 
Join Date: Oct 2003
Location: around
Posts: 792
bug77 is on a distinguished road

Quote:
Originally Posted by lime
the landingQ is just an UnboundedQueue....it's fine...i just need help on how to check if the runway is free, if so and the landingQ isn't empty, then allow a plane to land, so the runway is not free for minToLand minutes....then go from there... i'm having trouble with that part
Have a boolean value tell if the runway is free. Whenever it is in use for a period of time, set the value to indicate that and have a thread sleep for that amount of time and reset the value afterwards.
bug77 is offline   Reply With Quote
Old Nov 10, 2004, 08:41 PM   #8 (permalink)
lime
DriverHeaven Newbie
 
Join Date: Oct 2004
Posts: 8
lime is on a distinguished road

well we had a lab exam with a similar problem and i figured out how to do that in the exam....so know my program works...i did use a boolean for runwayFree and it works better now....thanks for your help
lime is offline   Reply With Quote
Old Nov 21, 2004, 06:47 PM   #9 (permalink)
slinkydink
DriverHeaven Newbie
 
Join Date: May 2003
Posts: 10
slinkydink is on a distinguished road

code looks good, although I would use math.random instead
slinkydink is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump




 

 
Powered by: vBulletin
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Artwork by Allan 'Zardon' Campbell, vBulletin implementation by Craig '5320' Humphreys based on original artwork by Ratchet.

All times are GMT -5. The time now is 08:54 AM. Copyright ©2008 DriverHeaven.net