1 / 19

Day 13.

Day 13. 0. Intro. 1. Review concepts of simulation. 2. “Random” numbers. 3. Dynamic queues. 4. Lab using RANDSIM.CPP. 0. Intro. Make sure you have kept a copy of 4A on a drive somewhere.

Download Presentation

Day 13.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Day 13. 0. Intro. 1. Review concepts of simulation. 2. “Random” numbers. 3. Dynamic queues. 4. Lab using RANDSIM.CPP.

  2. 0. Intro. Make sure you have kept a copy of 4A on a drive somewhere. See Assignment 4B—requires additional concepts presented today, and will work through the algorithm carefully on Tuesday after Spring Break. CSC Get Together is Today!!!

  3. 1. Review Concepts of Simulation. 3 definitions. Def 1. Simulation in general. A simulation is a model of (A) a real world object AND (B) the processes affecting it. Changes in the model represent changes in the object.

  4. Review Concepts of Simulation. Def 2. Computer Simulation. A computer simulation is a simulation (as defined by Def. 1) using: (A) 1 or more data structures to represent real world objects e.g. queues, servers; (B) operations on data structures to represent changes in the objects e.g. enq, deq, updatequeue, EngageServer.

  5. Review Concepts of Simulation. Def 3. Time-driven simulation. A time-driven simulation is a computer simulation (as defined by Def. 2) driven by a counter that represents a clock: Clock = 0; while (Clock < SimulationTimeLimit){ Clock++; // clock ticks RunSimulation (); }

  6. 2. Random numbers. But, you say, how, oh, how, do I simulate something that may or may not happen, such as the arrival of a customer for a queue. You may well ask. And well you may. The problem is computer operations are deterministic—either they must happen or they must NOT happen.

  7. Random numbers. How then, can we simulate something that may only probably happen? E.g., what if, on average, there is a 50% chance a new customer arrives each minute on Saturday afternoon, but only a 10% chance a new customer arrives on Monday morning?

  8. Random numbers. In truth, the computer does not really allow any chance events (it is a deterministic device), but we can simulate probabilities using the “random” number generator. This is a paradox, because nothing the computer does is truly random, since everything it does is algorithmic. Truly random events are things like the decay of a radioactive nucleus, or other quantum events (if QM is true).

  9. Random numbers. However, we can capture important characteristics of random events, even using an algorithm. We can then generate a “pseudo-random” sequence of numbers / events—meaning? To simulate truly random numbers we need to capture 2 key ideas.

  10. Random numbers. (1) Internally, a sequence is random-looking if there is no simple predictable pattern e.g. 1 3 5 7 does not even look random, because it conforms to the rule n’ = n+2. (2) Externally, a sequence seems random if each number is equally likely to occur (there is no bias), e.g. 2 2 5 2 does not look random.

  11. Random numbers. In fact, though, one cannot definitively say whether a finite sequence is intrinsically random or not—it depends on how it is generated: 2 2 5 2 might be generated by a fluke. Also 7 3 9 1 might seem random with 4 digits, but then repeat indefinitely according to an algorithm.

  12. Random numbers. The only numbers which we are confident are random are transcendentals like Pi, which has been checked for billions of places and has no predictable pattern or significant repeats. However, for simulations, true randomness is not required, since any simulation will last a finite amount of time, and we cannot distinguish random/non-random absolutely in this case.

  13. Random numbers. All we need for a finite simulation is number sequences that look random. Just as for a geometry program, a finite approximation for Pi suffices, likewise for “random numbers”. And for this, there are clever algorithms, that typically start from a seed that uses a finite approximation to Pi or something else believed to be truly random.

  14. Random numbers. What does C++ have to offer? Within <stdlib.h> there is a pseudo-random number generator which can be accessed by rand(). The function rand() returns a pseudo-random number between 0 and RAND_MAX. For PCs, RAND_MAX is 32767.

  15. Random numbers. See clock diagram. How then do we simulate a 20% chance? if (rand() < int (0.2 * RAND_MAX)) cout << “The event occurred”; else cout << “The event did not occur.”;

  16. Random numbers. If repeatedly called, this will generate a pseudo-random sequence. But if we run the same program twice? Get the same sequence. Why? Same algorithm operating on the same seed = initial value.

  17. Random numbers. If we want to change this, can re-set the seed, using srand (Num); However, for 4B you don’t need to do this. See RANDSIM.CPP

  18. 3. Dynamic queues (Batman). For assignment 4A and 4B, you are using a static circular queue. An alternative would be to use a dynamic queue. See diagrams.

  19. 4. Lab: using RANDSIM.CPP. See what happens with the following probabilities: .2 .5 .8

More Related