![]() Remove the next task from the print queue and assign it to the If the printer is not busy and if a task is waiting, The queue is empty to start.ĭoes a new print task get created? If so, add it to the queue with Main Simulation Steps ¶Ĭreate a queue of print tasks. Real situation as closely as possible given that you know general Tasks could be created in a row or we may wait quite a while for a task If the number isġ80, we say a task has been created. Generating a random number between 1 and 180 inclusive. \(\frac \)įor every second we can simulate the chance that a print task occurs by Means that on average there will be one task every 180 seconds: This is to consider the ratio of tasks to time. Given second, a print task is going to be created? The way to answer If there are 10 students in the lab and each prints twice, then thereĪre 20 print tasks per hour on average. Means that there is equal chance of any length from 1 to 20 appearing. If each lengthįrom 1 to 20 is equally likely, the actual length for a print task canīe simulated by using a random number between 1 and 20 inclusive. Students may print a paper from 1 to 20 pages in length. To model this situation we need to use some probabilities. This is equal to the average amount of time a task waitsįigure 4: Computer Science Laboratory Printing Queue ¶ Of interestįor us is the average amount of time students will wait for their papers Queue to see if there are any remaining tasks to process. When the printer completes a task, it will look at the ![]() We will add them to a waiting list, a queue of print tasks attached to Will need to construct representations for students, printing tasks, and We could decide by building a simulation that models the laboratory. The slower printing speedĬould make students wait too long. It would produce only five pages per minute. The printer could be switched to give better quality, but then Lab is older, capable of processing 10 pages per minute of draft The length of these tasks ranges from 1 to 20 pages. These students typically print up to twice during that time, and OnĪny average day about 10 students are working in the lab at any given If it cannot, students will be waiting too long for printing andĬonsider the following situation in a computer science laboratory. Might be whether the printer is capable of handling a certain amount of ![]() In a queue to be processed in a first-come first-served manner. Students send printing tasks to the shared printer, the tasks are placed Printing queue described earlier in this section. 4.22 The Ordered List Abstract Data TypeĪ more interesting simulation allows us to study the behavior of the.4.21 Implementing an Unordered List: Linked Lists.4.20 The Unordered List Abstract Data Type.4.9 Infix, Prefix and Postfix Expressions. ![]() 4.8 Converting Decimal Numbers to Binary Numbers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |