Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Understanding Simulation: Pros, Cons, Common Mistakes, and Generators, Slides of Computer Science

An overview of simulations, their advantages and disadvantages, common mistakes, and the importance of generating good random numbers. It covers various simulation techniques, including time-driven, event-driven, and trace-driven simulations, and discusses the role of simulation languages and event schedulers.

Typology: Slides

2012/2013

Uploaded on 04/27/2013

divyaa
divyaa 🇮🇳

4.4

(59)

71 documents

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Performance
Engineering
Simulation
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Understanding Simulation: Pros, Cons, Common Mistakes, and Generators and more Slides Computer Science in PDF only on Docsity!

Performance

Engineering

Simulation

Simulation

OVERVIEW:

  • A simulation is any action that mimics reality.
  • Chess simulates war.
  • Monopoly simulates real estate investment.
  • Any game is, in fact, a model of a reality.

Example:

  • Computers simulate monopoly (that simulates ....)
  • Computers simulate population growth/energy supplies.
  • Computers simulate expansion of the Universe.
  • Computers can simulate computers!!

Simulation

COMMON MISTAKES:

Since modeling is not something to dive into lightly, what warnings are needed up- front?

Engineers inherently don’t trust models. We tend to believe only things we can see. So you need to generate belief in your model among your “customers”. Be very careful giving out answers to your model – don’t do so before you believe the results yourself. Here are a number of issues you need to take into account:

  • You need to get the level of detail right! It’s very hard to know how much detail you need. There’s a tendency among engineers for too much detail – after all, we’re used to writing code. At the other extreme – too little detail can leave valuable mechanisms unaccounted for.
  • Unverified or invalid models. You need to be constantly checking that your model matches reality. This is not easy. It requires finding things you can measure – such as the last version of the mechanism you’re modeling.

Pitfalls

Simulation

COMMON MISTAKES:

  • The language of the simulation. If the innards of the model require a lot

of code (random number generators, event handlers, etc.) you can waste a great deal of time writing your own. Conversely, simple models don’t need fancy simulation packages. More on this later.

  • Mechanical Issues. The simulation didn’t run long enough to be able to

get the number of samples you need or to avoid end conditions. Your random number generator wasn’t really random.

Pitfalls

Simulation

This section describes briefly some of the terms used in Simulation.

State Variables: All the program variables needed to define where the simulation is at time T.

Event: A change in the system state. Arrivals and departures from any center is an event.

Time Driven Simulations: Where time is what matters. The state variables are defined in terms of time. They can be either continuous or discrete.

Event Driven Simulations: Where changes of state (events) are what matters. State variables are defined in terms of these events.

Simulation Lingo

Simulation

This section describes briefly some of the terms used in Simulation.

Deterministic or Probabilistic: Every time you run the model, do you get the same answer or a different answer. Either can be correct, but you should know beforehand what to expect. With a probabilistic model, running it longer doesn’t give it a better result.

Open and Closed: Open means jobs/inputs are coming in external to the model. Closed means all jobs recycle through the model.

Stable and Unstable: Does the model converge to some answer or not.

Simulation Lingo

Simulation

TRACE-DRIVEN SIMULATIONS:

  • You gather, independently, from some “real” environment, a set of inputs. Then you play it back through the simulator.
  • Nice in that you can keep your inputs constant and change the way the system handles those inputs.
  • You can verify that your model behaves the same as the real environment at the time the data was collected.
  • Engineering managers can be most convinced by this – it kind of “looks like” reality.

Example:

Collecting the disk activity at a Brokerage Firm at market open. Then running that data back through a real operating system.

Example:

Collecting user keystrokes used to make queries of a database. Then playing back those keystrokes.

Types of Simulations

Simulation

TIME-DRIVEN SIMULATIONS:
  • Useful for phenomena that occur at regular intervals.

Example: The instruction fetch cycle - on each clock tick the CPU tries to obtain an instruction ( or part of an instruction from memory.)

Example: Rainfall, water usage, and the resultant height of a reservoir.

Types of Simulations

Simulation

EVENT-DRIVEN SIMULATIONS:
  • Useful for phenomena that may occur at any point in time.

Example: A CPU - disk system, where processes use variable amounts of time at each resource.

See the schematic of an event driven simulation below.

Example: Cars being serviced at a tool booth. Look at the picture on a later page.

Question: How long would it take to write this simulation?

Types of Simulations

Simulation

EVENT-BASED
SIMULATION
CONTROL FLOW

Types of Simulations

Initialize

Determine Next Event

T = T( next_event )

Event 1

Event Queue

case = next_event

Generate New Event

Event 4

Generate New Event

Event 3

Generate New Event

Event 2

Generate New Event

Update Statistics

Simulation

THE EVENT SCHEDULER:

One of the key pieces that is provided by a simulation package is an event scheduler.

It works exactly like the scheduler in a operating system;

  • accepting events that will be executed at some future time,
  • handing out, when requested, the next event that will happen.

You want this scheduler to be efficient.

It may be called on to maintain hundreds of upcoming events.

To do this requires a low-cost way to insert a future event in a time-ordered queue.

Event Scheduler

Simulation

Generating good random numbers is an art form. There are well known techniques for doing this and you are best off using the work of those who have gone before you.

All numbers are in fact “pseudo-random”. Think of a 16 bit random number containing a sequence of 65,536 numbers. Each of those numbers, when used as the seed of a generator produces another of the 65,536 numbers, and so on. They actually form a sequence. A good generator will produce all the 65,536 numbers before it repeats.

Linear Congruential Generators (LCGs) have good generation properties. These are of the general form

X (^) n = ( a Xn-1 + b ) mod m

The correct choice of a, b, and m matter a great deal.

Random Number Generators

Simulation

if (first_time) { while( random_seed.high > 1000000 ) random_seed.high -= 1000000; X = (long)random_seed.high + (long)random_seed.low; first_time = FALSE; } if ( X == 0 ) X = 1; X_div_q = X / q; X_mod_q = X % q; X = a * X_mod_q - r * X_div_q; if ( X < 0 ) X = X + m; return( ((double)X)/(double)m );

} / End of get_random_number /

Random Number Generators

Simulation

TESTING RANDOM NUMBER GENERATORS:

Do random numbers produced by Excel, meet the properties of randomness? Let s find out!

Here are the steps:

  1. Generate 50,000 random numbers (in this case there were 5 columns of 10, numbers). Use the
  2. Take the histogram of these numbers. You see the result in the rightmost two columns. Picture Sim-1 shows the result of this.
  3. In Picture Sim-2 is a plot of the distribution. Note that the plot cheats big time!! The vertical scale has been adjusted by Excel to use the full range. But in fact the variation between the largest and smallest is very little.

Random Number Generators