Off Topic - Need some HW help

  • To unlock all of features of Rams On Demand please take a brief moment to register. Registering is not only quick and easy, it also allows you access to additional features such as live chat, private messaging, and a host of other apps exclusive to Rams On Demand.

iced

Well-Known Member
Joined
Jan 12, 2013
Messages
6,620
Wasn't really sure where else to turn but I did remember someone being able to switch the forums to PHP and mysql.

Anyway I think I am definitely in need some of programmers help - having trouble figuring out the algorithm for this.
Assume the following:

a. Disk spooling is NOT being used.

b. The printer does NOT have a hardware buffer to hold the output while the printer is printing

(The theme music from Mission Impossible is playing faintly in the background).

SIMULATE the following scenario

A hypothetical program computes for three 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 (by hand is OK). The Y axis is from zero to 8 seconds, and the X axis is nonlinear and displays all nine cases of buffers.

Thus far my code in python:
import random
import Queue

q = Queue.Queue()
print("This program simulates a printer printing records while dealing with interrupts over 9 different buffers.")
print("Number of Loops: 500")
print("Number of Buffers: 9")
print("Record Generation Time: 3")
print("Minimum/Maximum print time: .075/4.75")

def main(q):
buffers= [0,1,2,3,4,5,10,25,100];
for buffer in buffers:
sum = 0
for i in range (1, 500):
q.put(i)
time= (random.uniform (0.75,4.75)+3)
sum = sum + time;
average= (sum/500);
while not q.empty():
q.get()
print("For Buffer",buffer,",the average time is",average,".");
main(q)

The buffer 0 works correctly - however, the rest don't. The average time for the 100 buffers is around 3.25 secs or so, (low 3's), 0 is 5.75'ish.

I can't think of a way to account for the buffer times - I think it might involve something like average = (sum - (buffers*3))/ 500

any help is appreciated! (i know most people are gonna be like 'Wtf'! Obviously i'm not asking you then! lol :) )
 

-X-

Medium-sized Lebowski
Joined
Jun 20, 2010
Messages
35,576
Name
The Dude
Beats me. I only install the stuff and let it do it's thing.

But I do know how to use Google.

START

FIRST METHOD
I started by calling a method I made that had two variables - number of iterations, and buffer size. I used it to launch the number of trials I did, and to record the total time in seconds. I just added the return from my next method for a few thousand times. (Or however long I ran it)

SECOND METHOD
Next, you want to start simulating the 500-print jobs in a method! When the method started. I made a "wasted time" variable, an integer, for the sake of tracking how long we sat there, waiting for the printer to finish a job.Right before the start of the loop, I decided to start a "Printer" object, initializing it with my buffer variable as a field. I'll get to it in a moment. It's mainly the meat of the problem!

Finally, we start the main loop! Doing 500 iterations of the loop. This should be fairly easy; you're making a double using a random number generator from 0-4, and adding 0.75 to the value.

On each iteration of the loop, you need to check (before you send the job to the printer) if the printer buffer is full. Again, this is the 'Printer" object that I'll get to. If the printer is full, you need to wait. Remember the "wasted time" variable I talked about before? This is where it gets used, adding the value remaining in the current printer job to itself. Getting the printer's current job is another step I did in the printer object.

Finally, we now know that the printer has space in the buffer, we've generated a job time, and we're good to go! I, personally, made a "job cycle" method, that I called now using the random time we made. It could be accomplished in two steps, but I chose to just do them in one. We'll get to the printer in a moment, but all that's left in the simulation method is actually adding up the total amount of time and returning; I multiplied 500*3 seconds, for the normal time from each job, and then added the wasted time that iterated over the loop.Then, I made a call to the printer that handled anything left in the buffer.

PRINTER OBJECT - CONSTRUCTOR/INIT
Now, this printer object has one very important feature; the buffer! I chose to represent it using a linked list, more specifically a double-headed queue. This let me push objects on, pop them off, and put them in queue at the end. This did mean I had to use a private int to represent length, to make sure the printer never went over the buffer size, though. Inside the constructor when I called the printer, I set a field "bufferMax", and started a second field, "buffer", which was the linked list.

FIRST METHOD
The first non-constructor inside of the printer is a means to check if the buffer is full. It checks if the size of the linked list is equal to the bufferSize variable plus one. It's plus one, because the current job is part of the queue too! It's a simple boolean return, true (full) or false (space is free)

SECOND METHOD
In case the buffer is full, we need to empty it out. This method cleared a single space, by removing the first item from the queue, and returning the value. This number was the number previously added to my "wasted time" value.

THIRD METHOD
This method was the meat of the printer. I made a variable, and set it equal to 3 seconds. Then, I started a multi-condition while loop. So long as this printer time value was above 0, and the queue was not empty, it would keep going.
Inside this loop, the first value was removed from the queue, and I subtracted it from the "printer time" variable. If printer time was less than 0, I added a job to the front of the queue (that's why it was double ended!) equal to negative printer time (so, it's a positive value. Ex. a 4.5 second job would add 1.5 seconds back to the front)

Finally, once that whole cluster of stuff concerning printing was done, I added a new value to the queue. This was the time we called the method with, the randomly generated time. This was a void/null method, so there's no return. That's it.

FOURTH METHOD
This is a while loop that goes through the rest of the linked list/queue/buffer, adds the times, and returns it. If you've gotten this far, I trust you know how to do it!

END

That's it! So, we have in the end an application that runs 500 printer jobs, making sure an arbitrarily sized buffer is not full, and tallying time all along. Once that time is tallied, it averages it over another arbitrarily defined number of times; I outputted that average to the console, in order to record it.

http://instaedu.com/Computer-Scienc...-the-background-SIMULATE-the-following-scen2/
 

iced

Well-Known Member
Joined
Jan 12, 2013
Messages
6,620
  • Thread Starter Thread Starter
  • #3
Beats me. I only install the stuff and let it do it's thing.

But I do know how to use Google.

START

FIRST METHOD
I started by calling a method I made that had two variables - number of iterations, and buffer size. I used it to launch the number of trials I did, and to record the total time in seconds. I just added the return from my next method for a few thousand times. (Or however long I ran it)

SECOND METHOD
Next, you want to start simulating the 500-print jobs in a method! When the method started. I made a "wasted time" variable, an integer, for the sake of tracking how long we sat there, waiting for the printer to finish a job.Right before the start of the loop, I decided to start a "Printer" object, initializing it with my buffer variable as a field. I'll get to it in a moment. It's mainly the meat of the problem!

Finally, we start the main loop! Doing 500 iterations of the loop. This should be fairly easy; you're making a double using a random number generator from 0-4, and adding 0.75 to the value.

On each iteration of the loop, you need to check (before you send the job to the printer) if the printer buffer is full. Again, this is the 'Printer" object that I'll get to. If the printer is full, you need to wait. Remember the "wasted time" variable I talked about before? This is where it gets used, adding the value remaining in the current printer job to itself. Getting the printer's current job is another step I did in the printer object.

Finally, we now know that the printer has space in the buffer, we've generated a job time, and we're good to go! I, personally, made a "job cycle" method, that I called now using the random time we made. It could be accomplished in two steps, but I chose to just do them in one. We'll get to the printer in a moment, but all that's left in the simulation method is actually adding up the total amount of time and returning; I multiplied 500*3 seconds, for the normal time from each job, and then added the wasted time that iterated over the loop.Then, I made a call to the printer that handled anything left in the buffer.

PRINTER OBJECT - CONSTRUCTOR/INIT
Now, this printer object has one very important feature; the buffer! I chose to represent it using a linked list, more specifically a double-headed queue. This let me push objects on, pop them off, and put them in queue at the end. This did mean I had to use a private int to represent length, to make sure the printer never went over the buffer size, though. Inside the constructor when I called the printer, I set a field "bufferMax", and started a second field, "buffer", which was the linked list.

FIRST METHOD
The first non-constructor inside of the printer is a means to check if the buffer is full. It checks if the size of the linked list is equal to the bufferSize variable plus one. It's plus one, because the current job is part of the queue too! It's a simple boolean return, true (full) or false (space is free)

SECOND METHOD
In case the buffer is full, we need to empty it out. This method cleared a single space, by removing the first item from the queue, and returning the value. This number was the number previously added to my "wasted time" value.

THIRD METHOD
This method was the meat of the printer. I made a variable, and set it equal to 3 seconds. Then, I started a multi-condition while loop. So long as this printer time value was above 0, and the queue was not empty, it would keep going.
Inside this loop, the first value was removed from the queue, and I subtracted it from the "printer time" variable. If printer time was less than 0, I added a job to the front of the queue (that's why it was double ended!) equal to negative printer time (so, it's a positive value. Ex. a 4.5 second job would add 1.5 seconds back to the front)

Finally, once that whole cluster of stuff concerning printing was done, I added a new value to the queue. This was the time we called the method with, the randomly generated time. This was a void/null method, so there's no return. That's it.

FOURTH METHOD
This is a while loop that goes through the rest of the linked list/queue/buffer, adds the times, and returns it. If you've gotten this far, I trust you know how to do it!

END

That's it! So, we have in the end an application that runs 500 printer jobs, making sure an arbitrarily sized buffer is not full, and tallying time all along. Once that time is tallied, it averages it over another arbitrarily defined number of times; I outputted that average to the console, in order to record it.

http://instaedu.com/Computer-Scienc...-the-background-SIMULATE-the-following-scen2/

I was actually all over this site looking for this question lol... but where I bolded is where I am lost
 

-X-

Medium-sized Lebowski
Joined
Jun 20, 2010
Messages
35,576
Name
The Dude
Wish I could help, dude. I taught myself all this stuff, but I'm a complete novice when it comes to php.
 

iced

Well-Known Member
Joined
Jan 12, 2013
Messages
6,620
  • Thread Starter Thread Starter
  • #5
Wish I could help, dude. I taught myself all this stuff, but I'm a complete novice when it comes to php.
yea this is really more about figuring out the math part of it and some small coding. I get that a buffer takes away the computing 3 seconds part of it..i just cant figure out how to put it into code
 

-X-

Medium-sized Lebowski
Joined
Jun 20, 2010
Messages
35,576
Name
The Dude
Well, we have one guy around here who's pretty brilliant when it comes to this stuff, but I don't know if he's free this week. He's got some other stuff going on with family and whatnot. I'd tell you who that is, but I don't want to volunteer his time, ya know? I think you'll figure it out on your own though.
 

iced

Well-Known Member
Joined
Jan 12, 2013
Messages
6,620
  • Thread Starter Thread Starter
  • #7
Well, we have one guy around here who's pretty brilliant when it comes to this stuff, but I don't know if he's free this week. He's got some other stuff going on with family and whatnot. I'd tell you who that is, but I don't want to volunteer his time, ya know? I think you'll figure it out on your own though.

my brain is shot trying to figure this thing out as it is lol.. my teacher already gave me a "week or 2 extension" from last tuesday