|
| Notices |
Welcome to the DriverHeaven.net forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
 |
Nov 7, 2004, 05:45 PM
|
#1 (permalink)
|
|
DriverHeaven Newbie
Join Date: Oct 2004
Posts: 8
|
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.
|
|
|
Nov 8, 2004, 03:18 AM
|
#2 (permalink)
|
|
Delete Me
Join Date: Mar 2004
Posts: 15,115
|
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
|
|
|
Nov 9, 2004, 04:26 PM
|
#3 (permalink)
|
|
Delete Me
Join Date: Mar 2004
Posts: 15,115
|
hrmm..I dunno...that's a really round about way to do the program.....what all is in your landingQ class?
|
|
|
Nov 9, 2004, 05:42 PM
|
#4 (permalink)
|
|
DriverHeaven Newbie
Join Date: Oct 2004
Posts: 8
|
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
|
|
|
Nov 9, 2004, 06:08 PM
|
#5 (permalink)
|
|
DriverHeaven Senior Member
Join Date: Oct 2003
Location: around
Posts: 792
|
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.
|
|
|
Nov 9, 2004, 06:14 PM
|
#6 (permalink)
|
|
Back in London
Join Date: Jul 2003
Location: London
Posts: 1,794
|
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 /|\
|
|
|
Nov 9, 2004, 09:44 PM
|
#7 (permalink)
|
|
DriverHeaven Senior Member
Join Date: Oct 2003
Location: around
Posts: 792
|
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.
|
|
|
Nov 10, 2004, 08:41 PM
|
#8 (permalink)
|
|
DriverHeaven Newbie
Join Date: Oct 2004
Posts: 8
|
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
|
|
|
Nov 21, 2004, 06:47 PM
|
#9 (permalink)
|
|
DriverHeaven Newbie
Join Date: May 2003
Posts: 10
|
code looks good, although I would use math.random instead 
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|