Snm Mat-347 Simulacion Ev Discretos

download Snm Mat-347 Simulacion Ev Discretos

of 39

Transcript of Snm Mat-347 Simulacion Ev Discretos

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    1/39

    Gua de Referencia

    MAT-347SIMULACION

    M.Sc. Ing. Sandro Nieto Mndez

    2014

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    2/39

    Generacin de VariablesAleatorias

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    3/39

    3

    Variables Aleatorias

    Solucin:

    Generar variables aleatorias que sigan algn tipode distribucin que mejor represente ese suceso.

    Transformar un nmero aleatorio, en una variablealeatoria.

    Adems de tener como entrada valoresconstantes (parmetros, condicionesexperimentales, etc.), para reproducir elcomportamiento de un sistema no determinstico

    (estocstico), un modelo de simulacin requierevalores de variables aleatorias, cuya calidadincidir en la calidad de los resultados obtenidoscomo salida del modelo.

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    4/39

    4

    Variables Aleatorias

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    5/39

    5

    Variables Aleatorias

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    6/39

    6

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    7/39

    7

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    8/39

    8

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    9/39

    9

    Mtodos para generar valores de

    variables aleatorias

    Mtodo de la Transformada Inversa

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    10/39

    10

    Mtodo de la Transformada Inversa

    La funcin dedensidad

    La funcin dedistribucinacumulativa

    )()( xXPxf

    )()( xXPxF

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    11/39

    11

    Mtodo de la Transformada Inversa

    xx

    t

    t

    xxPxF )()(

    dtxPxF t)()(

    Caso Discreto

    Caso Contnuo

    Luego hacer:

    )()( 1 uFxuxF

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    12/39

    12

    Mtodo de la Transformada Inversa

    F(x)

    1

    u

    0x

    )(1 uFx

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    13/39

    13

    Mtodo de la Transformada Inversa

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    14/39

    14

    Variables Discretas

    Distribucin de Bernoulli

    casootroen

    xp

    xp

    xXPxf

    0

    1

    01

    )()(

    Cual ser la Funcin de Distribucin Acumulada?

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    15/39

    15

    Variables Discretas

    Distribucin de Bernoulli

    11

    101

    00

    )()(

    xxp

    x

    xXPxF

    El algoritmo se reduce a:

    Generar U ~Uni(0,1).Escogerx = 0 si F(-1) U < F(0)

    0 U < 1- p

    Escogerx = 1 si F(0) U < F(1)

    1- p U < 1

    1-p

    1

    10 2

    u

    u

    0

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    16/39

    16

    Variables Continuas

    La distribucin exponencial

    0)( xexf x

    Cual ser la Funcin de Distribucin Acumulada?

    Cmo se calcular x?

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    17/39

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    18/39

    18

    Variables Discretas- Poisson

    ei

    iXPifi

    !)()(

    )(*1)1(

    !3*

    4!4)4(

    !2*

    3!3)3(

    1*

    2!2)2(

    1)1(

    )0(

    34

    23

    2

    iXPi

    iXP

    eeXP

    eeXP

    eeXP

    eXP

    eXP

    Desarrollando:

    n

    i

    iXPiF0

    1)()(

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    19/39

    19

    Variables Discretas- Poisson

    Algoritmo

    1. Generar U

    2. i = 0; p = ; F = p

    3. Mientras F

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    20/39

    20

    Variables Discretas- Poisson

    Un proceso de Poisson de intensidad, corresponde a una serie deeventos tal que los intervalos detiempo entre eventos sucesivos sonvariables aleatorias independientesexponenciales de parmetro .

    T=1

    e1 e2 e3 e4 e5 e60 tiempo

    d.exp d.exp d.exp d.exp d.exp d.exp

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    21/39

    21

    Variables Discretas- Poisson

    Algoritmo

    1. i=0

    2. t=-1/ *ln(U)3. Mientras t

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    22/39

    22

    Variables Continuas

    Uniforme en el intervalo (a,b)

    La distribucin uniforme en elintervalo (a,b) (U(a,b)) tiene comofuncin de densidad la siguiente:

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    23/39

    23

    Variables Continuas

    Uniforme en el intervalo (a,b)

    Algoritmo

    1. Introducir a, b

    2. Generar u

    3. x=a+(b-a)*u

    4. retornar x

    uabax

    ab

    axu

    xFu

    )(

    )(

    Haciendo:

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    24/39

    24

    Variables Continuas

    Distribucin Normal

    12

    21

    n

    n

    uZ

    n

    i

    i

    xZ

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    25/39

    25

    Variables Continuas

    Distribucin Normal

    Aprovechando que la suma de 12 variablesaleatorias [0,1], tiene el valor esperado de6 y varianza 1.

    12

    1

    1

    6*

    :Entonces12

    2*

    i

    i

    n

    i

    i

    ux

    n

    nu

    x

    Algoritmo:

    1. Introducir S (valor esperado)

    2. Introducir V (desviacin estandar3. suma =0

    4. Para k = 1 hasta 12 hacer

    5. suma = suma + u(0,1)

    6. retornar s+(v *(suma-6))

    x=0

    PARA i=1 HASTA 12

    Genera u ( nmero aleatorio en (0,1))

    x=x+u (para conseguir una varianza 1)

    FIN_PARA

    x=x-6 (para conseguir una media 0)

    Salida x

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    26/39

    Types of simulation

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    27/39

    27

    Types of simulation

    There are three major ways to approach discrete

    simulation.

    Each approach offers a different way to look at a

    simulation problem. Each, in its own way, suggestsmechanisms to model real situations.

    These are:

    event scheduling,

    activity scanning,

    and process interaction ( object orientation).

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    28/39

    28

    Event Scheduling

    An eventis anything that changes the system

    statistics (also known as the stateof the

    system) other than the passage of time.

    The essential idea of event scheduling is to

    move along the time scale until an event

    occurs and then, depending on the event,

    modify the system state and possiblyschedule new events.

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    29/39

    29

    Event Scheduling-Algorithm

    ALGORITMO PARA EVENT SCHEDULING

    Inicio ES

    perform initialization (set beginning_time and ending_time, file initial events

    into event_list, initialize component state descriptors);

    retrieve (and remove) event notice with earliest time from event_list

    the event notice consists of : (event_time, event_type,component_indicator);

    TIME:= event_time;

    while (TIME < ending_time) do

    case event_type of

    1: execute event_routine_1;

    2: execute event_routine_2;

    .....................

    n: execute event_routine_n;

    endcase;retrieve (and remove) event notice with earliest time from event_list;

    TIME:= event_time;

    endwhile;

    endES.

    cada procedimiento event_routine_i modeliza la transicin de estado del sistema

    resultante de los cambios de estado de las componentes provocados por la ocurrencia de un

    suceso de tipo i.

    Step 1:

    Remove the event notice for

    the imminent event from FEL

    Step 2:

    Advance CLOCK to imminent

    event time

    Step 3:

    Execute imminent event,

    update system state

    Step 4:

    Generate future events (ifnecessary) and place their

    event notices

    on FEL ranked by event time.

    Step 5:

    Update cumulative statistics

    and counters

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    30/39

    30

    Event

    Scheduling

    Flowchart

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    31/39

    31

    Event Scheduling-Example

    Ar r ival Event

    1. Check the status of the ATM(s) (idle or busy)

    (a) If there is an idle machine

    (i) Start serving the customer, update idle status

    (ii) Generate a departure event for this customer (b) If all busy, place customer in queue

    2. Generate new arrival event for next customer.

    Departure Event

    1. Check queue (empty or not)

    (a) If empty, set ATM to idle (b) If not empty then do

    (i) Choose a waiting customer, start serving the customer

    (ii) Generate a departure event for this customer

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    32/39

    32

    Activity Scanning

    Uses a fixed time increment and a rule-based

    approach to decide whether any activities can

    begin at each point in simulated time.

    At each clock advance, the conditions for

    each activity is checked and if the conditions

    are true, then the corresponding activity

    begins.(Condition, action).

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    33/39

    33

    Activity Scanning

    In this approach, events are considered to beactivities of duration zero time units, and all activitiesare classified as B or C activities, where B activitiesare bound to occur, but C activities are conditional

    upon certain conditions being true. Using this classification, the B-type activities and

    events can be scheduled ahead of time (just as inthe event scheduling approach). This allows creationof a FEL containing B-type activities, where

    variable times can be used for these activities.Scanning to check if any C-type activities can beginhappens at the end of each time advance, after allB-type events have been completed

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    34/39

    34

    Activity Scanning

    ALGORITMO PARA ACTIVITY SCANNING

    Inicio AS;

    perform intialization (set beginning_time and ending_time, set component clock T[i]

    for each ative_type component i, initialize component state descriptors);

    TIME:= event_time;

    while (TIME < ending_time) do

    SCAN: for j:= highest_priority tolowest_priority do

    set i to component with priority j;

    if (T[i]= TIME and cond_routine_i evaluates true)

    then execute act_routine_i;

    exit to SCAN;

    endif;

    endfor;

    TIME:= minimum of all T[i]such that T[i]> TIME;

    endwhile;endAS.

    Cada procedimiento cond_routine_i evalua las condiciones especficas de activacin para

    la componente i, devuelve como resultado los valores cierto (true) o falso (false).

    Cada procedimiento act_routine_i modeliza la transicin de estado del sistema resultante

    del cambio de estado de la componente i.

    Se supone que cada componente tiene una prioridad nica.

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    35/39

    35

    Activity Scanning

    Phase A:

    Remove the imminent event from the FEL and advance the clockto its event time.

    Remove any other events from the FEL that have the same

    event time.Phase B:

    Execute all B-type events that were removed from the FEL.

    Phase C:

    Scan the conditions that trigger each C-type activity and activate

    any whose conditions are met. Re-scan until no additional C-type activities can begin or events

    occur

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    36/39

    36

    Activity Scanning-Example

    In this model, there are three activities:

    1. An arrival occurs

    2. A service is completed

    3. A service begins

    The actions associated with these activities are

    1. (Arrival) Put customer in queue, generate next arrival2. (Completion) Declare server idle

    3. (Begin) Make server busy, remove customer from queue, generate

    completion.

    There is one new activity: the beginning of service. It is not triggered

    by any other activity. Instead, it occurs when the following twoconditions are satisfied:

    1. There are customers in the queue

    2. A server is idle

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    37/39

    37

    Process Interaction

    The simulation model is defined in terms of entities or objectsand their life cycle as they flow through the system, demandingresources and queueing to wait for resources.

    Since in this view, a process is the life cycle of one entity,constraints on different processes cause them to interact.

    Those simulation languages that are written with this view inmind, allow the analyst to describe the process flow in terms ofhigh level block or network constructs, while the interactionamong processes is handled automatically.

    The process interaction approaches use a variable time advance;that is, when all events and system state changes have occurredat one instant of simulated time, the simulation clock is advancedto the time of the next imminent even on FEL

    ALGORITMO PARA PROCESS INTERACTION

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    38/39

    38

    Process

    Interaction

    ALGORITMO PI ;

    perform initialization (set beginning_time and ending_time, file initial events into

    future events list (FEL) and current events list (CEL) as appropiate,

    initialize component state descriptors);

    TIME:= beginning_time;

    while (TIME ending_time) do (CEL scan and time advance)

    retrieve first CEL entry (i.e. event not ice);

    (CEL scan)

    while (last entry in CEL has not been processed) do

    while (cond_seg evaluates true and current component has not

    terminated and rescan not indicated) do

    execute act_seg;

    determine next step for this component;

    endwhile;

    if (current component changed steps)

    then remove old CEL entry;

    if (current co mponent did not terminate)

    then file new CEL entry;

    endif;

    endif;

    if (rescan ind icated) then position to first CEL entry;

    else position to next CEL entry in sequence;

    endif;

    endwhile;

  • 8/12/2019 Snm Mat-347 Simulacion Ev Discretos

    39/39

    39

    Process Interaction - Example

    1. A SOURCE that generates arriving customers

    2. A QUEUE to hold waiting customers

    3. A FACILITY to serve customers

    If a program provides these components as basic buildingblocks, then the modeler need only provide the parameters: theinterarrival times, the queue discipline, and the service times.

    At this point, the computer must do all of the following work:

    SOURCE must generate customers

    When a customer arrives, it must either be placed in QUEUE orsent to FACILITY

    When a customer arrives at FACILITY, a processing time mustbe generated

    When FACILITY becomes idle, the QUEUE must be checked formore customers.