Docsity

Simulacion, Apuntes de Estadística Económica

Toggle sidebar
bg1
2
Simulation Examples
This chapter presents several examples of simulations that can be performed
by devising a simulation table either manually or with a spreadsheet. The
simulation table provides a systematic method for tracking system state over
time. These examples provide insight into the methodology of discrete system
simulation and the descriptive statistics used for predicting system performance.
The simulations in this chapter entail three steps:
1. Determine the characteristics of each of the inputs to the simulation.
Quite often, these may be modeled as probability distributions, either
continuous or discrete.
2. Construct a simulation table. Each simulation table is different, for each
is developed for the problem at hand. An example of a simulation ta-
ble is shown in Table 2.1. In this example there are pinputs, xij ,j =
1,2,...,p, and one response, yi, for each of repetitions i=1,2,...,n.
Initialize the table by filling in the data for repetition 1.
3. For each repetition i, generate a value for each of the pinputs, and eval-
uate the function, calculating a value of the response yi. The input values
may be computed by sampling values from the distributions determined
in step 1. A response typically depends on the inputs and one or more
previous responses.
This chapter gives a number of simulation examples in queueing, inven-
tory, and reliability. The two queueing examples provide a single-server and
23
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Vista previa parcial del texto

¡Descarga Simulacion y más Apuntes en PDF de Estadística Económica solo en Docsity!

Simulation Examples

This chapter presents several examples of simulations that can be performed

by devising a simulation table either manually or with a spreadsheet. The

simulation table provides a systematic method for tracking system state over

time. These examples provide insight into the methodology of discrete system

simulation and the descriptive statistics used for predicting system performance.

The simulations in this chapter entail three steps:

1. Determine the characteristics of each of the inputs to the simulation.

Quite often, these may be modeled as probability distributions, either

continuous or discrete.

2. Construct a simulation table. Each simulation table is different, for each

is developed for the problem at hand. An example of a simulation ta-

ble is shown in Table 2.1. In this example there are p inputs, x ij , j =

1 , 2 ,... , p, and one response, y i , for each of repetitions i = 1 , 2 ,... , n.

Initialize the table by filling in the data for repetition 1.

3. For each repetition i, generate a value for each of the p inputs, and eval-

uate the function, calculating a value of the response y i. The input values

may be computed by sampling values from the distributions determined

in step 1. A response typically depends on the inputs and one or more

previous responses.

This chapter gives a number of simulation examples in queueing, inven-

tory, and reliability. The two queueing examples provide a single-server and

24 Chap. 2 Simulation Examples

two-server system, respectively. (Chapter 6 provides more insight into queue-

ing models.) The first inventory example involves a problem that has a closed-

form solution; thus the simulation solution can be compared to the mathemat-

ical solution. The second inventory example pertains to the classic order-level

model.

Finally, there is an example that introduces the concept of random normal

numbers and a model for the determinination of lead-time demand.

2.1 Simulation of Queueing Systems

A queueing system is described by its calling population, the nature of the ar-

rivals, the service mechanism, the system capacity, and the queueing discipline.

These attributes of a queueing system are described in detail in Chapter 6. A

simple single-channel queueing system is portrayed in Figure 2.1.

Server Waiting line Calling population

Figure 2.1 Queueing system.

In the single-channel queue, the calling population is infinite; that is, if a

unit leaves the calling population and joins the waiting line or enters service,

there is no change in the arrival rate of other units that may need service.

Arrivals for service occur one at a time in a random fashion; once they join the

waiting line, they are eventually served. In addition, service times are of some

random length according to a probability distribution which does not change

over time. The system capacity has no limit, meaning that any number of units

can wait in line. Finally, units are served in the order of their arrival (often

called FIFO: first in, first out) by a single server or channel.

Table 2.1 Simulation Table

Inputs (^) Response Repetitions xi 1 xi 2 · · · xij · · · xip yi 1 2 3 · · · n

26 Chap. 2 Simulation Examples

Arrival event

Unit enters service

Unit enters queue for service

No Server Yes busy ?

Figure 2.3 Unit-entering-system flow diagram.

If the server is busy, the unit enters the queue. If the server is idle and the

queue is empty, the unit begins service. It is not possible for the server to be

idle and the queue to be nonempty.

Not empty Enter queue Impossible

Empty Enter queue Enter service

Busy Idle

Server status

Queue status

Figure 2.4 Potential unit actions upon

arrival.

After the completion of a service the server may become idle or remain

busy with the next unit. The relationship of these two outcomes to the status

of the queue is shown in Figure 2.5. If the queue is not empty, another unit

will enter the server and it will be busy. If the queue is empty, the server will

be idle after a service is completed. These two possibilities are shown as the

shaded portions of Figure 2.5. It is impossible for the server to become busy if

the queue is empty when a service is completed. Similarly, it is impossible for

the server to be idle after a service is completed when the queue is not empty.

Not empty

Impossible

Empty Busy Impossible Idle

Server outcomes

Queue status

Figure 2.5 Server outcomes after service

completion.

Now, how can the events described above occur in simulated time? Sim-

ulations of queueing systems generally require the maintenance of an event

list for determining what happens next. The event list tracks the future times

Sec. 2.1 Simulation of Queueing Systems 27

at which the different types of events occur. Simulations using event lists are

described in Chapter 3. This chapter simplifies the simulation by tracking each

unit explicitly. Simulation clock times for arrivals and departures are computed

in a simulation table customized for each problem. In simulation, events usu-

ally occur at random times, the randomness imitating uncertainty in real life.

For example, it is not known with certainty when the next customer will arrive

at a grocery checkout counter, or how long the bank teller will take to complete

a transaction. In these cases, a statistical model of the data is developed from

either data collected and analyzed, or subjective estimates and assumptions.

The randomness needed to imitate real life is made possible through the

use of “random numbers.” Random numbers are distributed uniformly and

independently on the interval (0, 1). Random digits are uniformly distributed

on the set { 0 , 1 , 2 ,... , 9 }. Random digits can be used to form random numbers

by selecting the proper number of digits for each random number and placing

a decimal point to the left of the value selected. The proper number of digits

is dictated by the accuracy of the data being used for input purposes. If the

input distribution has values with two decimal places, two digits are taken from

a random-digits table (such as Table A.1) and the decimal point is placed to the

left to form a random number.

Random numbers can also be generated in simulation packages and in

spreadsheets such as Excel ®^. For example, Excel has a macro function called

RAND() that returns a “random” number between 0 and 1. When numbers

are generated using a procedure, they are often referred to as pseudo-random

numbers. Since the method is known, it is always possible to know the sequence

of numbers that will be generated prior to the simulation. The most commonly

used methods for generating random numbers are discussed in Chapter 7.

In a single-channel queueing system interarrival times and service times

are generated from the distributions of these random variables. The examples

that follow show how such times are generated. For simplicity, assume that the

times between arrivals were generated by rolling a die five times and recording

the up face. Table 2.2 contains a set of five interarrival times generated in this

manner. These five interarrival times are used to compute the arrival times of

six customers at the queueing system.

Table 2.2 Interarrival and Clock

Times

Interarrival Arrival Customer Time Time on Clock 1 − 0 2 2 2 3 4 6 4 1 7 5 2 9 6 6 15

Sec. 2.1 Simulation of Queueing Systems 29

Table 2.5 Chronological

Ordering of

Events

Customer Clock Event Type Number Time Arrival 1 0 Departure 1 2 Arrival 2 2 Departure 2 3 Arrival 3 6 Arrival 4 7 Departure 3 9 Arrival 5 9 Departure 4 11 Departure 5 12 Arrival 6 15 Departure 6 19

at which each event occurs. The second column of Table 2.4 records the clock

time of each arrival event, while the last column records the clock time of each

departure event. The occurrence of the two types of events in chronological

order is shown in Table 2.5 and Figure 2.6.

4 0

1

2

Number of customers in the systtem 8 12 16 20 Clock time

1 2 3 4 5

4 5

6

Figure 2.6 Number of customers in the system.

It should be noted that Table 2.5 is ordered by clock time, in which case

the events may or may not be ordered by customer number. The chronological

ordering of events is the basis of the approach to discrete-event simulation

described in Chapter 3.

Figure 2.6 depicts the number of customers in the system at the various

clock times. It is a visual image of the event listing of Table 2.5. Customer 1

30 Chap. 2 Simulation Examples

Table 2.6 Distribution of Time Between Arrivals

Time between Arrivals Cumulative Random-Digit (Minutes) Probability Probability Assignment 1 0.125 0.125 001 − 125 2 0.125 0.250 126 − 250 3 0.125 0.375 251 − 375 4 0.125 0.500 376 − 500 5 0.125 0.625 501 − 625 6 0.125 0.750 626 − 750 7 0.125 0.875 751 − 875 8 0.125 1.000 876 − 000

is in the system from clock time 0 to clock time 2. Customer 2 arrives at clock

time 2 and departs at clock time 3. No customers are in the system from clock

time 3 to clock time 6. During some time periods two customers are in the

system, such as at clock time 8, when both customers 3 and 4 are in the system.

Also, there are times when events occur simultaneously, such as at clock time

9, when customer 5 arrives and customer 3 departs.

Example 2.1 follows the logic described above while keeping track of

a number of attributes of the system. Example 2.2 is concerned with a two-

channel queueing system. The flow diagrams for a multichannel queueing

system are slightly different from those for a single-channel system. The devel-

opment and interpretation of these flow diagrams is left as an exercise for the

reader.

EXAMPLE 2.1 Single-Channel Queue

A small grocery store has only one checkout counter. Customers arrive at this

checkout counter at random from 1 to 8 minutes apart. Each possible value of

interarrival time has the same probability of occurrence, as shown in Table 2.6.

The service times vary from 1 to 6 minutes with the probabilities shown in

Table 2.7. The problem is to analyze the system by simulating the arrival and

service of 20 customers.

Table 2.7 Service-Time Distribution

Service Time Cumulative Random-Digit (Minutes) Probability Probability Assignment 1 0.10 0.10 01 − 10 2 0.20 0.30 11 − 30 3 0.30 0.60 31 − 60 4 0.25 0.85 61 − 85 5 0.10 0.95 86 − 95 6 0.05 1.00 96 − 00

32 Chap. 2 Simulation Examples

Table 2.8 Time-Between-Arrivals Determination

Time between Time between Random Arrivals Random Arrivals Customer Digits (Minutes) Customer Digits (Minutes) 1 − − 11 109 1 2 913 8 12 093 1 3 727 6 13 607 5 4 015 1 14 738 6 5 948 8 15 359 3 6 309 3 16 888 8 7 922 8 17 106 1 8 753 7 18 212 2 9 235 2 19 493 4 10 302 3 20 535 5

arrivals, enter the fourth column of Table 2.6 and read 8 minutes from the first

column of the table. Alternatively, we see that 0.913 is between the cumulative

probabilities 0.876 and 1.000, again resulting in 8 minutes as the generated time.

Service times for all 20 customers are shown in Table 2.9. These service

times were generated based on the methodology described above, together with

the aid of Table 2.7. The first customer’s service time is 4 minutes because the

random digits 84 fall in the bracket 61–85, or alternatively because the derived

random number 0.84 falls between the cumulative probabilities 0.61 and 0.85.

Table 2.9 Service Times Generated

Service Service Random Time Random Time Customer Digits (Minutes) Customer Digits (Minutes) 1 84 4 11 32 3 2 10 1 12 94 5 3 74 4 13 79 4 4 53 3 14 05 1 5 17 2 15 79 5 6 79 4 16 84 4 7 91 5 17 52 3 8 67 4 18 55 3 9 89 5 19 30 2 10 38 3 20 50 3

Sec. 2.1 Simulation of Queueing Systems 33

The essence of a manual simulation is the simulation table. These ta-

bles are designed for the problem at hand, with columns added to answer the

questions posed. The simulation table for the single-channel queue, shown in

Table 2.10, is an extension of the type of table already seen in Table 2.4. The

first step is to initialize the table by filling in cells for the first customer. The

first customer is assumed to arrive at time 0. Service begins immediately and

finishes at time 4. The customer was in the system for 4 minutes. After the

first customer, subsequent rows in the table are based on the random numbers

for interarrival time and service time and the completion time of the previous

customer. For example, the second customer arrives at time 8. Thus, the server

(checkout person) was idle for 4 minutes. Skipping down to the fourth cus-

tomer, it is seen that this customer arrived at time 15 but could not be served

until time 18. This customer had to wait in the queue for 3 minutes. This pro-

cess continues for all 20 customers. Extra columns have been added to collect

statistical measures of performance such as each customer’s time in the system

and the server’s idle time (if any) since the previous customer departed. In

order to compute summary statistics, totals are formed as shown for service

times, time customers spend in the system, idle time of the server, and time the

customers wait in the queue.

In the exercises, the reader is asked to implement the simulation table for

the single-channel queue, Table 2.10, in Excel or another spreadsheet. Here

we give some hints when using Excel. The key column to compute is column

E, the “Time Service Begins”. (We leave for the reader the question of how to

compute the random interarrival and service times, but suggest the RAND()

random number generator or other built-in distribution in Excel.) First, the

reader may fill in row 1 for the first customer manually. The values for the

remaining customers must use macro formulas (which begin with an equals

sign in Excel). Note that a customer begins service at the later of its own

arrival time (column C) or the completion time (column G) of the previous

customer. Therefore, for customer 10, service begins at E10 = MAX(C10,

G9), where MAX() is the Excel macro function that returns the maximum

value in a range or list of cells. This easily generalizes to other customers.

(The statistical measures in columns H and I are easily computed by simple

subtractions–also left for the reader.) A final hint on how to verify your spread-

sheet model: instead of using a random function for arrivals and service times,

type in the actual values given in Table 2.10 in columns B and D. If your for-

mulas are correct, the spreadsheet should duplicate Table 2.10 exactly. After

verification, replace the numbers by an appropriate random function. Then

on each recalculation of the spreadsheet (function key F9 in Excel), it will

generate new random numbers and you will get a new ‘’run” of the simula-

tion.

Some of the findings from the simulation in Table 2.10 are as follows:

Sec. 2.1 Simulation of Queueing Systems 35

Table 2.

Simulation Table for Queueing Problem

A

B

C

D

E

F^

G

H

I

Time Since

Service

Time

Time Customer

Time

Time Customer

Idle Time

Last Arrival

Arrival

Time

Service

Waits in Queue

Service

Spends in System

of Server

Customer

(Minutes)

Time

(Minutes)

Begins

(Minutes)

Ends

(Minutes)

(Minutes)

36 Chap. 2 Simulation Examples

5. The average time between arrivals is 4.3 minutes. This is determined in

the following manner:

average time between

arrivals (minutes)

sum of all times

between arrivals (minutes)

number of arrivals − 1

= 4 .3 minutes

One is subtracted from the denominator because the first arrival is as-

sumed to occur at time 0. This result can be compared to the expected

time between arrivals by finding the mean of the discrete uniform dis-

tribution whose endpoints are a = 1 and b = 8. The mean is given

by

E(A) =

a + b

= 4 .5 minutes

The expected time between arrivals is slightly higher than the average.

However, as the simulation becomes longer, the average value of the time

between arrivals will approach the theoretical mean, E(A).

6. The average waiting time of those who wait is 4.3 minutes. This is deter-

mined in the following manner:

Average waiting time of

those who wait (minutes)

total time customers wait in queue (minutes)

total number of customers who wait

= 4 .3 minutes

7. The average time a customer spends in the system is 6.2 minutes. This

can be determined in two ways. First, the computation can be achieved

by the following relationship:

average time customer

spends in the system

(minutes)

total time customers spend in the

system (minutes)

total number of customers

= 6 .2 minutes

The second way of computing this same result is to realize that the fol-

lowing relationship must hold:

average time average time average time

customer spends customer spends customer spends

in the system = waiting in the + in service

(minutes) queue (minutes) (minutes)

38 Chap. 2 Simulation Examples

Table 2.13 Service Distribution of Baker

Service Time Cumulative Random-Digit (Minutes) Probability Probability Assignment 3 0.35 0.35 01 − 35 4 0.25 0.60 36 − 60 5 0.20 0.80 61 − 80 6 0.20 1.00 81 − 00

solution would be different if the decision were made at random or by any other

rule.)

The problem is to find how well the current arrangement is working.

To estimate the system measures of performance, a simulation of 1 hour of

operation is made. A longer simulation would yield more reliable results, but

for purposes of illustration a l-hour period has been selected.

The simulation proceeds in a manner similar to Example 2.1. Here there

are more events: a customer arrives, a customer begins service from Able, a

customer completes service from Able, a customer begins service from Baker,

and a customer completes service from Baker. The simulation table is shown

in Table 2.14.

In later exercises, the reader is asked to implement the simulation table,

Table 2.14, in a spreadsheet such as Excel. Here we provide a few hints (and

rules!). The row for the first customer is filled in manually, with the random-

number function RAND() or another random function replacing the random

digits. After the first customer, the cells for the other customers must be based

on logic and formulas. For example, the “Clock Time of Arrival” (column D)

in the row for the second customer is computed as follows:

D2 = D1 + C

using notation similar to that used by most spreadsheets. (C2 is the time be-

tween arrivals 1 and 2.) This formula is easily generalized for any customer.

The logic to compute who gets a given customer, and when that service

begins, is more complex. Here we give a hint using the Excel macro function

IF(), which returns one of two values depending on whether a condition is true

or false. [The syntax is IF( condition, value if true, value if false).] The logic

goes as follows when a customer arrives: If the customer finds Able idle, the

customer begins service immediately with Able. If Able is not idle but Baker is,

then the customer begins service immediately with Baker. If both are busy, the

Sec. 2.1 Simulation of Queueing Systems 39

customer begins service with the first server to become free. The logic requires

that we compute when Able and Baker will become free, for which we use the

built-in Excel function for maximum over a range, MAX(). For example, for

customer 10, Able will become free at MAX(H$1:H9), since service comple-

tion time is in column H and we need to look at customers 1–9. (Using H$

instead of H1 works better with Excel when formulas are copied. The dollar

sign indicates an absolute reference versus a relative reference to a cell.) The

resulting formula to compute whether and when Able serves customer 10 is as

follows:

F10 = IF(D10>MAX(H$1:H9),D10, IF(D10>MAX(K$1:K9),’’’’,

MIN(MAX(H$1:H9),MAX(K$1:K9))))

In this formula, note that if the first condition (Able idle when customer 10

arrives) is true, then the customer begins immediately at the arrival time in

D10. Otherwise, a second IF() function is evaluated, which says if Baker is

idle, put nothing (“”) in the cell. Otherwise, the function returns the time that

Able or Baker becomes idle, whichever is first [the minimum or MIN() of their

respective completion times]. A similar formula applies to cell I10 for “Time

Service Begins” for Baker. For service times for Able, you could use another

IF() function to make the cell blank or have a value:

G10 = IF(F10 > 0,new service time, "")

H10 = IF(F10 > 0, F10+G10, "")

and similarly for Baker. With these hints, we leave the formula for

new service time as well as the remainder of the solution to the reader.

The analysis of Table 2.14 results in the following:

1. Over the 62-minute period Able was busy 90% of the time.

2. Baker was busy only 69% of the time. The seniority rule keeps Baker less

busy (and gives Able more tips).

3. Nine of the 26 arrivals (about 35%) had to wait. The average waiting time

for all customers was only about 0.42 minute (25 seconds), which is very

small.

4. Those nine who did have to wait only waited an average of 1.22 minutes,

which is quite low.

5. In summary, this system seems well balanced. One server cannot handle

all the diners, and three servers would probably be too many. Adding

an additional server would surely reduce the waiting time to nearly zero.

However, the cost of waiting would have to be quite high to justify an

additional server. m

Sec. 2.2 Simulation of Inventory Systems 41

2.2 Simulation of Inventory Systems

An important class of simulation problems involves inventory systems. A sim-

ple inventory system is shown in Figure 2.7. This inventory system has a periodic

review of length N , at which time the inventory level is checked. An order is

made to bring the inventory up to the level M. At the end of the first review

period, an order quantity, Q 1 , is placed. In this inventory system the lead time

(i.e., the length of time between the placement and receipt of an order) is zero.

Since demands are not usually known with certainty, the order quantities are

probabilistic. Demand is shown as being uniform over the time period in Fig-

ure 2.7. In actuality, demands are not usually uniform and do fluctuate over

time. One possibility is that demands all occur at the beginning of the cycle.

Another is that the lead time is random of some positive length.

M

Amount in inventory

T Time

I

N N N

Q 1 Q 2

Q 3

Figure 2.7 Probabilistic order-level inventory system.

Notice that in the second cycle, the amount in inventory drops below

zero, indicating a shortage. In Figure 2.7, these units are backordered; when

the order arrives, the demand for the backordered items is satisfied first. To

avoid shortages, a buffer, or safety, stock would need to be carried.

Carrying stock in inventory has an associated cost attributed to the inter-

est paid on the funds borrowed to buy the items (this also could be considered

as the loss from not having the funds available for other investment purposes).

Other costs can be placed in the carrying or holding cost column: renting of stor-

age space, hiring guards, and so on. An alternative to carrying high inventory

is to make more frequent reviews, and consequently, more frequent purchases

or replenishments. This has an associated cost: the ordering cost. Also, there is

a cost in being short. Customers may get angry, with a subsequent loss of good

will. Larger inventories decrease the possibilities of shortages. These costs

must be traded off in order to minimize the total cost of an inventory system.

The total cost (or total profit) of an inventory system is the measure of

performance. This can be affected by the policy alternatives. For example,

42 Chap. 2 Simulation Examples

in Figure 2.7, the decision maker can control the maximum inventory level,

M , and the length of the cycle, N. What effect does changing N have on the

various costs?

In an (M, N) inventory system, the events that may occur are: the demand

for items in the inventory, the review of the inventory position, and the receipt

of an order at the end of each review period. When the lead time is zero, as in

Figure 2.7, the last two events occur simultaneously.

In the following example for deciding how many newspapers to buy, only

a single time period of specified length is relevant and only a single procurement

is made. Inventory remaining at the end of the single time period is sold for

scrap or discarded. A wide variety of real-world problems are of this form,

including the stocking of spare parts, perishable items, style goods, and special

seasonal items [Hadley and Whitin, 1963].

EXAMPLE 2.3 The Newspaper Seller’s Problem

A classical inventory problem concerns the purchase and sale of newspapers.

The paper seller buys the papers for 33 cents each and sells them for 50 cents

each. Newspapers not sold at the end of the day are sold as scrap for 5 cents

each. Newspapers can be purchased in bundles of 10. Thus, the paper seller can

buy 50, 60, and so on. There are three types of newsdays, “good,” “fair,” and

“poor,” with probabilities of 0.35, 0.45, and 0.20, respectively. The distribution

of papers demanded on each of these days is given in Table 2.15. The problem

is to determine the optimal number of papers the newspaper seller should

purchase. This will be accomplished by simulating demands for 20 days and

recording profits from sales each day.

The profits are given by the following relationship:

Profit =

( revenue

from sales

cost of

newspapers

lost profit from

excess demand

salvage from sale

of scrap papers

Table 2.15 Distribution of Newspapers

Demanded

Demand Probability Distribution Demand Good Fair Poor 40 0.03 0.10 0. 50 0.05 0.18 0. 60 0.15 0.40 0. 70 0.20 0.20 0. 80 0.35 0.08 0. 90 0.15 0.04 0. 100 0.07 0.00 0.