36
Chapter 12: Simulation and Modeling Invitation to Computer Science, C++ Version, Third Edition

Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

  • Upload
    lehanh

  • View
    223

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Chapter 12: Simulation and

Modeling

Invitation to Computer Science,

C++ Version, Third Edition

Page 2: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 2

Objectives

In this chapter, you will learn about:

� Computational modeling

� Running the model and visualizing results

Page 3: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 3

Introduction

� Simulation and modeling

� Probably the single most important scientific use

of computing today

� Having an impact on quantitative fields, such as chemistry, biology, medicine, meteorology,

ecology, geography, economics, etc.

Page 4: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 4

Computational Modeling:

Introduction to Systems and Models

� The scientific method

� Observe the behavior of a system

� Formulate a hypothesis about system behavior

� Design and carry out experiments to prove or disprove the validity of the hypothesis

� Often a model of the system is used

Page 5: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 5

Introduction to Systems and Models

(continued)

� A model

� An abstraction of the system being studied that

we claim behaves much like the original

� Computer simulation

� A physical system is modeled as a set of mathematical equations and/or algorithmic procedures

Page 6: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 6

Introduction to Systems and Models

(continued)

� Computer simulation (continued)

� Model is translated into a high-level language and executed on the Von Neumann computer

� Computational models

� Also called simulation models

� Used to:

� Design new systems

� Study and improve the behavior of existing systems

Page 7: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 7

Introduction to Systems and Models

(continued)

� Computational models (continued)

� Allow the use of an interactive design

methodology (sometimes called computational steering)

� Used in most branches of science and

engineering

Page 8: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 8

Figure 12.1

Using a Simulation in an

Interactive Design Environment

Page 9: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 9

Computational Models, Accuracy, and

Errors

� Proper balance between accuracy and

complexity must be achieved

� A model must be both:

� An accurate representation of the physical system

� Simple enough to implement as a program and solve on a computer in a reasonable amount of

time

Page 10: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 10

� To build a model

� Include important factors that act on the system

� Omit unimportant factors that only make the model harder to build, understand, and solve

Computational Models, Accuracy, and

Errors (continued)

Page 11: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 11

Computational Models, Accuracy, and

Errors (continued)

� Continuous model

� A set of equations that describe the behavior of a

system as a continuous function of time t

� Models that use statistical approximations

� Needed for systems that cannot be modeled using precise mathematical equations

Page 12: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 12

An Example of Model Building

� Discrete event simulation

� One of the most popular and widely used techniques for building computer models

� The behavior of a system is modeled only at an explicit and finite set of times

� Only the times when an event takes place are modeled

� Event: an activity that changes the state of the

system

Page 13: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 13

An Example of Model Building

(continued)

� To process an event

� Change the state of the simulated system in the same way that the actual system would change if

the event had occurred in real life

� Once finished, move to the next event

� When simulation is complete, the program

displays results that characterize the system’s

behavior

Page 14: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 14

An Example of Model Building

(continued)

� Problem

� You are the owner of a new take-out restaurant,

McBurgers, currently under construction

� You want to determine the proper number of

checkout stations needed

� You decide to build a model of McBurgers to determine the optimal number of servers

Page 15: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 15

Figure 12.3

System to Be Modeled

Page 16: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 16

An Example of Model Building

(continued)

� First: identify the events that can change the

system

� A new customer arriving

� An existing customer departing after receiving food and paying

� Next: develop an algorithm for each event

� Should describe exactly what happens to the system when this event occurs

Page 17: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 17

Figure 12.4

Algorithm for New Customer Arrival

Page 18: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 18

An Example of Model Building

(continued)

� The algorithm for the new customer arrival event

uses a statistical distribution (Figure 12.5) to

determine the time required to service the

customer

� Can model the statistical distribution of customer

service time using the algorithm in Figure 12.6

Page 19: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 19

Figure 12.5

Statistical Distribution of Customer Service Time

Page 20: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 20

Figure 12.6

Algorithm for Generating Random Numbers That Follow the Distribution Given in Figure 12.5

Page 21: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 21

Figure 12.7

Algorithm for Customer Departure Event

Page 22: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 22

An Example of Model Building

(continued)

� Must initialize parameters to the model

� Model must collect data that accurately

measures performance of the McBurgers

restaurant

Page 23: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 23

An Example of Model Building

(continued)

� When simulation is ready, the computer will

� Run the simulation

� Process all M customers

� Print out the results

Page 24: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 24

Figure 12.8

The Main Algorithm of our Simulation Model

Page 25: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 25

Running the Model and Visualizing

Results

� Scientific visualization

� Visualizing data in a way that highlights its

important characteristics and simplifies its interpretation

� An important part of computational modeling

� Different from computer graphics

Page 26: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 26

Running the Model and Visualizing

Results (continued)

� Scientific visualization is concerned with:

� Data extraction: which data values are important to display and which are not

� Data manipulation: convert the data to other forms

or to different units to enhance display

Page 27: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 27

� Output of a computer model can be represented

visually, such as through:

� A two-dimensional graph

� A three-dimensional image

� Visual representation of data helps identify

important features of the model’s output

Running the Model and Visualizing

Results (continued)

Page 28: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 28

Figure 12.9

Using a Two-Dimensional Graph to Display Output

Page 29: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 29

Figure 12.10: Using a Two-Dimensional Graph to Display and

Compare Two Data Values

Page 30: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 30

Figure 12.11

Three-Dimensional Image of a Region of the Earth’s Surface

Page 31: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 31

Figure 12.12

Three-Dimensional Model of a Methyl Nitrite Molecule

Page 32: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 32

Figure 12.13

Visualization of Gas Dispersion

Page 33: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 33

� Image animation

� One of the most powerful and useful forms of

visualization

� Shows how model’s output changes over time

� Created using many images, each showing

system state at a slightly later point in time

Running the Model and Visualizing

Results (continued)

Page 34: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 34

Figure 12.14

Use of Animation to Model Ozone Layers in the Atmosphere

Page 35: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 35

Summary

� A model is an abstraction of a system that

behaves much like the original

� Computer simulation:

� Physical system is modeled using mathematical equations and/or algorithmic procedures

� Model is translated into a high-level language

program and executed

Page 36: Chapter 12: Simulation and Modeling - Kent State …personal.kent.edu/~asamba/cs10051/CS-10051Chap12.pdf · Chapter 12: Simulation and Modeling ... Objectives In this chapter, you

Invitation to Computer Science, C++ Version, Third Edition 36

Summary

� Computational models allow the use of an

interactive design methodology

� Scientific visualization: visualizing data to

highlight its important characteristics and

simplify its interpretation