Average Printing time

John_in_Parrish

New member
Joined
Oct 21, 2013
Messages
3
A hypothetical program computes for 3 seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator)


The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer. Plot the results



The way I have the problem set up is (3 + avg time) / # of buffers. When I go to plot it though it makes sense for the buffers 1 - 100 but not the 0 buffer since it is divided by 0. So I am assuming I am setting this problem up incorrectly. It is a programing question I have no problem with the programing part just need some help getting the mathematical formula for the problem. Thanks in advance for your help,

John
 
A hypothetical program computes for 3 seconds then outputs a variable length record to be printed. The printer takes from 0.75 to 4.75 seconds (average time is 2.75 seconds) to print each output record. (Use a random number generator)

The hypothetical program loops 500 times for each case of software buffers (0, 1, 2, 3, 4, 5, 10, 25, and 100 software output buffers). Calculate the AVERAGE time for the program to “virtually compute and print” a record from the 500 records, for EACH of the 9 choices of buffer. Plot the results

The way I have the problem set up is (3 + avg time) / # of buffers. When I go to plot it though it makes sense for the buffers 1 - 100 but not the 0 buffer since it is divided by 0. So I am assuming I am setting this problem up incorrectly. It is a programing question I have no problem with the programing part just need some help getting the mathematical formula for the problem. Thanks in advance for your help,

John
Since it says "virtually" and "use a random number generator," this is a simulation problem, NOT a "find the formula" problem. We usr the Monte Carlo technique to integrate problems where there is a difficult correlation between variables. In this problem, the correlation is that printing from the buffer is simultaneous with the computation.

I picture a master clock time variable, initialized to 0
You will also need a software buffer array with maximum dimension determined as a parameter (for nine different cases), all initialized to 0 -- what this array will actually contain it the printer time for that buffered output. You will also need to keep track of which buffer is currently being printed. Maybe a flag for "buffers full" (which would always be true if there are no buffers).

After initialization, make a loop for 500 times.
add 3 to the master clock for compute time.
Look at the buffer.. if the currently printing buffer is greater than 3 seconds, subtract 3;
..........................iif less than 3, set to 0, advance to next buffer, subtract whatever is left of 3 from that one
...........................if no unprinted buffers left, set index to 0
use random number to find print time for next output
Look at the buffer...if no buffer available, advance master clock by the time in the current buffer
...........................if there is room in the buffers, store the print time
[If max number of buffers =0, treat as special case]

After you finish the loop 500 times, you will have to flush any records still in buffers, by adding all of the remaining times to the master clock.

The final number in the master clock is the total time. Divide by 500 to get the average.

I didn't write any specific code, because I don't know what language you are using. BTW, my profession is writing Monte Carlo simulation codes for neutron scattering instrument design. My language of choice is Fortran.
 
Since it says "virtually" and "use a random number generator," this is a simulation problem, NOT a "find the formula" problem. We usr the Monte Carlo technique to integrate problems where there is a difficult correlation between variables. In this problem, the correlation is that printing from the buffer is simultaneous with the computation.

I picture a master clock time variable, initialized to 0
You will also need a software buffer array with maximum dimension determined as a parameter (for nine different cases), all initialized to 0 -- what this array will actually contain it the printer time for that buffered output. You will also need to keep track of which buffer is currently being printed. Maybe a flag for "buffers full" (which would always be true if there are no buffers).

After initialization, make a loop for 500 times.
add 3 to the master clock for compute time.
Look at the buffer.. if the currently printing buffer is greater than 3 seconds, subtract 3;
..........................iif less than 3, set to 0, advance to next buffer, subtract whatever is left of 3 from that one
...........................if no unprinted buffers left, set index to 0
use random number to find print time for next output
Look at the buffer...if no buffer available, advance master clock by the time in the current buffer
...........................if there is room in the buffers, store the print time
[If max number of buffers =0, treat as special case]

After you finish the loop 500 times, you will have to flush any records still in buffers, by adding all of the remaining times to the master clock.

The final number in the master clock is the total time. Divide by 500 to get the average.

I didn't write any specific code, because I don't know what language you are using. BTW, my profession is writing Monte Carlo simulation codes for neutron scattering instrument design. My language of choice is Fortran.

Wow, that is more difficult than I thought, How would I start this out in PYTHON? Thank you for your help,

John:smile:
 
AM I even close with this?

def main():
buffer= [0,1,2,3,4,5,10,25,100]
time= random.uniform(0.75,4.75)+3
sum=0
dict_of_buffers = {}
for i in range (1, 500):
sum = sum + time;
average= sum/1500
for buffer in range(0,1,2,3,4,5,10,25,100):
print("For Buffer",buffer,",the average time is",average,".")
dict_of_buffers[buffer] = average
 
AM I even close with this?

def main():
buffer= [0,1,2,3,4,5,10,25,100]
time= random.uniform(0.75,4.75)+3
sum=0
dict_of_buffers = {}
for i in range (1, 500):
sum = sum + time;
average= sum/1500
for buffer in range(0,1,2,3,4,5,10,25,100):
print("For Buffer",buffer,",the average time is",average,".")
dict_of_buffers[buffer] = average
Not terrible close, I think - at least as far as I understand the question.

The outermost loop is the nine buffer cases.
Code:
for buffer in range(0,1,2,3,4,5,10,25,100):
        [all the meat of the program]
    print("For Buffer",buffer,",the average time is",average,".")
end for (or some such loop closer?)

Since each value of buffer is a new case, all variables have to be reinitialized, and you have to define an array with dimension "buffer" to hold print times. The inner loop will be the 500 independent random tries .. note that the random number has to be inside the loop,k or else all 500 will be identical,
Code:
    sum = 0
    for i in range (1, 500):
        sum = sum+3
        print_time= random.uniform(0.75,4.75)
            [have to deal with the print queue]
    end for

If there is no buffer, and if print_time > 3,
then the added time for printing is print_time-3, and
Code:
        sum = sum + print_time - 3
That is, the printer is not going to be finished with this record within the 3 seconds of the next calculation, so there will be a delay.
On the other hand, if there IS a software buffer, you can assume no extra time is taken to load the output line into the queue as long as the queue is not full. I tried to outtline earlier some of the steps to keep control of the queue. If the buffer is huge, then because the mean print_time is less than the compute time, the average time will be just 3 seconds.

Good luck!
 
Top