The University of British Columbia Computer Science 405 Practice Midterm Solutions Instructor: Kees van den Doel Time: 45 mins Total marks: 100 The solutions provided here are much more verbose than what I expect you to write to give you some additional information. 1. (15) Describe the difference between: a. (3) Discrete time and continuous time simulation. In DT simulation time takes on a discrete set of values, the state changes discontinuously. In cont. time sim. time is a continuous variable. b. (3) Real-time and offline simulation. A real-time simulation is synchronized with actual physical time. It may involve external realworld inputs. An offline simulation runs at its own time rate which can be slower of faster than real time. c. (3) An event and an event notice. An event notice tell you an event is going to happen. THe event is the thing that happens. d. (3) An activity and a delay. An activity is a time period whose duration is known at the time the activity starts. A delay is an unknown time period, which is usually the sum of many activities, some of which do not exist yet. d. (3) A system and a state. A system is a collection of entities that are considered to be a whole. The configuration of a system is completely described by its state, which is a set of (usually time-depent) variables. 2. (15) Briefly explain these concepts: a. (3) Simulation by process interaction. Each entity lives in it s own process and interacts with other processes. b. (3) Central limit theorem. The average of a large number (N) of random variables from the same pdf or pmf follows approximately the normal distribution with the same mean and standard deviation scaled by 1/ N. c. (3) Monte Carlo simulation. The term Monte Carlo Method is very general. A Monte Carlo method is a stochastic technique, meaning that it is based on using random numbers and probability to investigate problems. Monte Carlo methods are employed in a wide variety of fields including economics, finance, physics, chemistry, engineering, and even the study of traffic flows. Each field using Monte Carlo
methods may apply them in different ways, but in essence they are using random numbers to examine some problem and approximate its outcome. As such Monte Carlo methods give us a way to model complex systems that are often extremely hard to investigate with other types of techniques. The term Monte Carlo was introduced by von Neumann and Ulam during World War II, as a code word for the secret work at Los Alamos; it was suggested by the gambling casinos at the city of Monte Carlo in Monaco. The Monte Carlo method was then applied to problems related to the atomic bomb. d. (3) Poisson process. Events are indepent and have constant probability to occur over every small (infinitesimal) time interval. Events have no memory. e. (3) A critical queuing system. A stable system is a system where the queue length does not grow over time. An unstable system is a system where the queue length grows over time. If we slowly increase a variable (say the arrival rate) of a stable system at some point it may change from stable to unstable. At the transition the system is said to be critical. The behavior AT the critical point can be many things. Indeed, the study of critical systems is a discipline in it s own. More general, a system is usually said to be critical when something in the system (called the order parameter changes discontinuously when we change a parameter continuously. In our case the order parameter is lim < QL(t) > t with < QL > the mean queue length. For a stable system it is a constant. If we increase the arrival rate all of a sudden if will jump to infinity. Another example of an order parameter is the resistance to deformation of water. If we decrease the temperature beyond the freezing point water turns into ice and the order parameter jumps from essentially zero to some very large value. 3. (8) Would you recomm to perform a simulation prior to implementing the ideas below? Briefly argue why or why not. a. A large supermarket considers firing 25% of its checkout cashiers to save money. Yes, so we can see if the queue s would be come intolerably large, or: No let s just fire them and if there s a problem we ll hire new ones. b. A pharmaceutical company considers testing a new drug which supposedly slows aging on humans. No, the human aging process is not understood well enough that we can simulate this. c. An architect has come up with a plan for a concert hall in the form of a pyramid. There is some concern this will affect the acoustics. We should simulate the sound in the space, hich involves known acoustical principles. (There is software available to do precisely this.) d. An airplane manufacturer thinks a jet in the shape of a W may have better performance than a V shaped jet and considers sping $100000000 on developing such a machine. Simulation is used extensively in airplane manufacturing. Simulation is a must here. cs405 Page 2 of 6
4. (30) People arrive at a self-service cafeteria at the rate of one every 30 ± 20 seconds. (This notation indicates a uniform distribution over the interval [10 50].) 40% go to the sandwich counter, where one worker makes a sandwich in 60 ± 30 seconds. The rest go to the main counter, where one server spoons the prepared meal onto a plate in 45 ± 30 seconds. All customers must pay a single cashier, which takes 25 ± 10 seconds. For all customers, eating takes 20 ± 10 minutes. After eating, 10% of the people go back for dessert, sping an additional 10 ± 2 minutes in the cafeteria. Construct an event scheduling simulation of this situation, appropriate for measuring the average time spent in the cafeteria per customer. The simulation will have to run for 24 hrs. Define the state space variables. Define the event set. Provide the rules for processing each event. Define the initial state and the initialization of the future event list. You don t have to explain the event scheduling algorithm itself. State = {Q S, Q M, Q C, s, m, c}, where Q S,Q M and Q C are queue lengths : 0..α, s, m and c are busy states (0 1) E = {A, F S, F M, F C, S},corresponding to arrival, finish S, finish M, finish C and stop. State(0) = {0, 0, 0, 0, 0, 0}, and EL(0) = {A(0), S(24)} R A : generate r uniform on [0,1] if(r<.4) if(s==1) qs ++; s=1; create Fs(t +60 ± 30)- >FEL if(m==1) qm ++; m=1; F M (t +45±30)- >FEL F A (t+30±20)->fel R FS if (qs>0) qs--; F S (t+60±30)->fel s=0; if (c==1) cs405 Page 3 of 6
qc++; F C (t+25±10)->fel c=1; R FM if(qm>0) qm--; F M (t+45±30)->fel m=1; qc++; F C (t+25±10)->fel c=1; R FC if(qc>0) qc--; F C (t+25±10)->fel c=0; compute D=20±10; r=rand; if(r<.1) D=D+10±2; //add this delay to all other service times 5. (10) a. (5) How can we generate random numbers on [ 1 1] with pdf P (x) = 3 2 x2 from a uniform random number generator on [0 1]? Generate r, then x = g(r) with g = F 1. F (x) = P (t) dt = x 1 3 2 t2 dt = 2 3 x3 + 1 2 = r x = (2r 1) 1 3 = g(r) cs405 Page 4 of 6
b. (5) Let r be random numbers uniform on [0 1]. What is the pdf P (x) of x = 1/r? Does it have the correct property of a pdf, namely P (x)dx = 1? P (y) = with g = 1, Q(x) = 1 for x [0, 1]. r { Q(g 1 ) d dy g 1 (y) = d dy g 1 (y) = 1 y 2 for y 1 0 y < 1 p(y) dy = 1 1 y 2 dy = 1 (1) 6. (12) Customers arrive at a store according to a Poisson process. The mean interarrival time is 2 minutes. a. (3) What is the probability that at least 2 customers arrive during a time interval of 4 minutes? P n (t) = (λt)n e λt n! with λ = 1 2. 1 P 0 (4) P 1 (4) = 1 e 1 2 4 2e 1 2 4 = 0.5940 b. (3) The first customer arrived after 1 minute. What is the probability that the second customer arrives less than 1 minute later? P = λe λt 1 p(t)dt = 1 1 e 1 2 t dt = e 1 2 t 1 0 = 1 e 1 2 = 0.3935 0 2 0 OR: 1 P 0 (1) = 1 e 1 2 =.3935. c. (3) The first customer arrived after 10 minutes. What is the probability that the second customer arrives less than 1 minute later? Same as b. d. (3) After the store has been open for 8 hours, the number of customers n are counted. What is the probability distribution for n? Give a formula. with λ = 1 2, T = 8 60. p n = (λt )n ) e λt n! 7. (10) A random variable x can take on discrete values (negative integers and 0) as well as continuous values (positive real numbers). It can be modeled by a pdf P (x) for the continuous values and a pmf p(x) for the discrete values. a. (5) Write down a condition that states that the chance of x taking on any value is 1. i=0 p(x) + 0 P (x)dx = 1 cs405 Page 5 of 6
b. (5) Write down a formula for the expectation value < x > of x.. < x >= x=0 xp(x) + 0 xp (x)dx cs405 Page 6 of 6