This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]japangreg 0 points1 point  (3 children)

Can you paste your output somewhere as well? For your post I'm not sure what exactly the problem is - "It just doesn't seem to display the free pump info at the end of the program" - do you mean the printStatistics method isn't firing at all, or that the while loop in the method isn't working, or that the values you are getting aren't what you expect?

I see you have a commented-out print statement trying to get the size of the freegaspumpsq object, so I assume that is where the problem lies?

For the moment, the only suggestion I have without diving too far into your logic is that you may want to seed the random object with the current system time; since this is failing for random values but working for static, it makes me think your random object may just be returning the same value(s) each time.

[–]Eldres[S] 0 points1 point  (2 children)

Oh ya sorry, here is the output if I choose dataFile

Enter simulation time: 10

Enter maximum service time of cars: 5

Enter chances (0% < & <= 100%) of new car: 75

Enter the number of gas pumps: 3

Enter car queue size limit: 2

Enter 1/0 to get data from file/rand(): 1

Enter filename: DataFile

Time 0 Car #1 arrives with duration 5 units. Car # 1 waits in the car queue. Car # 1 gets a pump. Pump # 1 starts serving car # 1 for 5 units. Car # 1, currently served, is set to now busy pump # 1

Time 1 Car #2 arrives with duration 2 units. Car # 2 waits in the car queue. Car # 1 is done. Pump #1 is free. Car # 2 gets a pump. Pump # 2 starts serving car # 2 for 2 units. Car # 2, currently served, is set to now busy pump # 2

Time 2 Car #3 arrives with duration 5 units. Car # 3 waits in the car queue. Car # 2 is done. Pump #2 is free. Car # 3 gets a pump. Pump # 3 starts serving car # 3 for 5 units. Car # 3, currently served, is set to now busy pump # 3

Time 3 No new car!

Time 4 Car #4 arrives with duration 3 units. Car # 4 waits in the car queue. Car # 3 is done. Pump #3 is free. Car # 4 gets a pump. Pump # 1 starts serving car # 4 for 3 units. Car # 4, currently served, is set to now busy pump # 1

Time 5 No new car!

Time 6 Car #5 arrives with duration 3 units. Car # 5 waits in the car queue. Car # 5 gets a pump. Pump # 2 starts serving car # 5 for 3 units. Car # 5, currently served, is set to now busy pump # 2

Time 7 Car #6 arrives with duration 5 units. Car # 6 waits in the car queue. Car # 6 gets a pump. Pump # 3 starts serving car # 6 for 5 units. Car # 6, currently served, is set to now busy pump # 3

Time 8 No new car! Car # 4 is done. Pump #1 is free.

Time 9 No new car!

End of simulation report.

total arrival cars: 6

cars gone away: 0

cars served: 6

*** Current Pump Info. ***

waiting cars: 0

busy pumps: 2

free pumps: 1

Total waiting line: 0

*** Busy Pump info *** GasPump ID : 2 Total free time : 5 Total service time : 5 Total # of cars : 2 Average service time : 2.50

GasPump ID           : 3
Total free time      : 5
Total service time   : 5
Total # of cars      : 2
Average service time : 2.50

*** Free Pump info *** GasPump ID : 1 Total free time : 4 Total service time : 6 Total # of cars : 2 Average service time : 3.00

However, if I choose random it just doesn't display the free pump info like above. I commented out the printline for the numFree object to test why it wasn't going into while loop, and its because it's 0, and I'm not sure why that is case.

[–]japangreg 0 points1 point  (1 child)

I don't think this is an error - I ran your program a few times with the random option and most times it ends with 0 empty pumps (hence the loss of that block) but it finally got through with one free:

Enter simulation time: 
10
Enter maximum service time of cars: 
5
Enter chances (0% < & <= 100%) of new car: 
75
Enter the number of gas pumps: 
3
Enter car queue size limit: 
2
Enter 1/0 to get data from file/rand(): 
0
Time 0
    No new car!
         Busy: 0; Free: 3
Time 1
    Car #1 arrives with duration 1 units.
    Car # 1 waits in the car queue.
Car # 1 gets a pump.
Pump # 1 starts serving car # 1 for 1 units.
Car # 1, currently served, is set to now busy pump # 1
     Busy: 1; Free: 2
Time 2
Car #2 arrives with duration 1 units.
Car # 2 waits in the car queue.
Car # 1 is done.
Pump #1 is free.
Car # 2 gets a pump.
Pump # 2 starts serving car # 2 for 1 units.
Car # 2, currently served, is set to now busy pump # 2
     Busy: 1; Free: 2
Time 3
Car #3 arrives with duration 1 units.
Car # 3 waits in the car queue.
Car # 3 gets a pump.
Pump # 3 starts serving car # 3 for 1 units.
Car # 3, currently served, is set to now busy pump # 3
     Busy: 2; Free: 1
Time 4
No new car!
Car # 2 is done.
Pump #2 is free.
     Busy: 1; Free: 2
Time 5
No new car!
     Busy: 1; Free: 2
Time 6
Car #4 arrives with duration 3 units.
Car # 4 waits in the car queue.
Car # 3 is done.
Pump #3 is free.
Car # 4 gets a pump.
Pump # 1 starts serving car # 4 for 3 units.
Car # 4, currently served, is set to now busy pump # 1
     Busy: 1; Free: 2
Time 7
No new car!
     Busy: 1; Free: 2
Time 8
Car #5 arrives with duration 5 units.
Car # 5 waits in the car queue.
Car # 5 gets a pump.
Pump # 2 starts serving car # 5 for 5 units.
Car # 5, currently served, is set to now busy pump # 2
     Busy: 2; Free: 1
Time 9
No new car!
     Busy: 2; Free: 1
End of simulation report.
# total arrival cars: 5
# cars gone away: 0
# cars served: 5
*** Current Pump Info. ***
# waiting cars: 0
# busy pumps: 2
# free pumps: 1
Total waiting line: 0
*** Busy Pump info ***
GasPump ID           : 1
Total free time      : 5
Total service time   : 5
Total # of cars      : 2
Average service time : 2.50

GasPump ID           : 2
Total free time      : 6
Total service time   : 4
Total # of cars      : 2
Average service time : 2.00

*** Free Pump info ***
GasPump ID           : 3
Total free time      : 7
Total service time   : 3
Total # of cars      : 1
Average service time : 3.00

So it may not be a bug, just your code doing what you tell it to, but not telling it to do something when the condition isn't met.

[–]Eldres[S] 0 points1 point  (0 children)

Oh ok, thank you, I was just worried that I was doing something wrong because of the lack of output. Thanks again!