MAT 4830 Mathematical Modeling 07 Servicing Requests II http://myhome.spu.edu/lauw
HW Individual HW
HW HW 4 – well done One of you earned bonus points for your next exam.
HW HW 5 – I hope your MCM paper is explained better than this HW. Last night, I started this HW at 8pm and hoped that I would be home for dinner by 9:30pm. Describing how the codes works is not the same as explaining the idea of the solutions.
Preview Look at Server-Customer Systems with Queues Maple: The function nature of proc Use of user-defined proc Strings Handling
Server-Customer System with Queues Suppose requests cannot be rejects Requests will be assigned to the (first) server with the shortest wait One queue, multi-server (Post Office) We want to know the average waiting time of customers
Server-Customer System with Queues
Example 1: Suppose we have 1 server to handle requests.
Idea Generate 𝑛 customers If the server is busy, record the waiting time of the customer Compute the average waiting time
Tool: Clocks System Clock t: Indicate the current time Server Clock s: Indicate the completion time for the last customer being served
Tool: Clocks System Clock t: Indicate the current time Server Clock s: Indicate the completion time for the last customer being served if s<t, the server is idle
Tool: Clocks System Clock t: Indicate the current time Server Clock s: Indicate the completion time for the last customer being served if s≥t, the server is busy
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 First customer comes in at t=7 s<t? Idle?
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 The server will be busy until t=7+12=19
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 Next customer comes in 11 min. after the first customer. s<t? Idle?
Idea n T t S s W 1 7 12 19 2 11 18 15 33 3 8 26 40 4 41 48 5 6 47 10 58 9 57 66 Update the Wait counter with W=0+1
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 The server will be busy until t=19+14=33
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 Next customer comes in 8 min. after the last customer. s<t? Idle?
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 Update the Wait counter with W=1+(33-26)=8
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 The server will be busy until t=33+7=40
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 Next customer comes in 15 min. after the last customer. s<t? Idle?
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66 The server will be busy until t=41+7=48
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Idea n T t S s W 1 7 12 19 2 11 18 14 33 3 8 26 40 4 15 41 48 5 6 47 10 58 9 57 66
Example 2: Suppose we have 2 servers to handle requests Requests will be assigned to the server with the shortest wait
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Idea n T t S s1 s2 W 1 7 12 19 2 11 18 14 32 3 8 26 33 4 29 39 5 6 35 10 45 36 47
Example 3: Suppose we have 𝑚 servers to handle requests Requests will be assigned to the server with the shortest wait
Example 3: 𝒎 Servers 𝑠[1], 𝑠[2],…, 𝑠[𝑚] are the server clocks Find the (first) server with the minimum value Find 𝑘 such that
Maple Let us switch to Maple
The Function nature of proc Maple returns the result of the last executable statement in a procedure. We can also use return() to return the output. return() can be placed anywhere in the program. The output can be assigned to a variable Useful when called within another procedure
Example 4a Write a program to compute the function value of Of course, there are easier ways to do this. We only want to demo the point. Example 4b below does not represent the best programming practices
Example 4a
Example 4b
Example 4c Write a function(procedure) to Generate a normally generated random number 𝑥 with 𝑚𝑒𝑎𝑛=0 and 𝑠𝑡𝑑=1. Compute the square root of the cut off of 𝑥. Output this as the function value for the procedure. Call the cut off function from example 4b.
Example 4c
Maple: Strings Handling
Maple: Strings Handling Assignments
Maple: Strings Handling Subscripting
Maple: Strings Handling Subscripting
Maple: Strings Handling Subscripting
Maple: Strings Handling Counting