Model 12 - Scripted Delay

Goals of this lesson

  • Learn how to use a Scripted Delay for simulation purposes

Model 12 shows a work day process. The work starts at 9 a.m. and has several pauses. After each pause the branching Gateway checks, whether the simulation time is past 5 p.m. If this condition evaluates to true the process terminates at the end event, otherwise the process will return to the task.

With the tools described until now, we are not able to define an exact time (or date), to start a process. That’s what Scripted Delay was developed for. It enables the user to define a point in time, when something should happen depending on the simulation time. The denotation Scripted Delay originates from the programming language Python, that is used here.

How-to

12 model
Figure 1. Model 12 - Scripted Delay / IYOPRO-Link

Approach

  1. We will define the scripted inter-arrival time at the start event first.

  2. Parametrize the two timer events, that are attached to the activity "Work"

  3. Create the conditions for the branching gateway

Scripted inter-arrival time

  • Click the start event (make sure you selected simulation from the property set)

  • Open up the Time Editor to set up the inter-arrival time of the start event

  • Now select Time Instant from the drop-down-box in the top-left corner of the time editor

  • From the second drop-down-box (right to the previous one) select Scripted Time Instants

  • The Time Editor now contains an input-box, in which you can write your Python code

  • Put this line into the text area: Result=SimulationContext.Time.GotoHour(9); (see Figure 2)

    • This tells the simulation to advance to 09:00 o’clock when the event is being initialized by the simulation

      If the simulation time is past 09:00 o’clock it will advance to the next day’s 09:00 o’clock
TimeEditor Python Scripted TimeInstant1
Figure 2. Assigning the starting time for the start event

Configuring the attached events

  • "Have a break" contains a constant inter-arrival time of 1 hour.

    • The activity "Work" lasts 8 hours, which means that it will be interrupted every hour to have a break

    • "Having a break" lasts 0.1 hours or 6 minutes.

  • "Quit working for today" has a scripted time assigned, see Figure 3 for the code

    • First we check whether the current time has not yet reached 17 o’clock (SimulationContext.Time.Hour < 17)

    • If this is true: We assign the arrival time of the event to 17 o’clock

    • If this if false: We assign the arrival time to the current time, which means that it will be executed right away

Scripted TimeInstant Attacahed Event
Figure 3. Assigning the arrival time of event "Quit working for today"

The conditions at the exclusive gateway

  • We also need to check whether the employee has to quit working after the "Having a break" activity

  • Therefore put the condition depicted in Figure 4 on the left sequence flow at the branching exclusive gateway

    • We again check whether the current time is not past 17 o’clock by evaluating: SimulationContext.Time.Hour < 17

    • If true: the employee has to go on working

    • if false: the employee can quit

  • The second condition checks the exact opposite: SimulationContext.Time.Hour >= 17

    • The current time must be equal or bigger than 17

  • Of course we could make this more simple by putting up only one condition and then make the other edge a default sequence flow

Scripted Condition
Figure 4. The conditions at the branching exclusive gateway

Explanation

As described in the introduction of this lesson, we modeled a simple work-from-9-5-process.

  1. The process starts at 9 o’clock

  2. The "Work" activity is being executed for 8 hours

  3. There are two events attached to the activity

    1. "Have a break" will be executed 1 hour after the activity has been started

      1. The process then executes the "Have a break" activity

      2. Afterwards (at the gateway) it decides whether to work on

      3. This again depends on the current time. If it is past 17 o’clock the process will finish

      4. 'Elsewise it will return to the "Work" activity

    2. At the "Quit working for today" event the simulation checks the Python script

      1. If the time is past 17 o’clock, the event will be executed instantaneously

      2. Else it will be scheduled to 17 o’clock

Report

See below for the run configuration, which we set up to receive the report statistics from below.

Please refer to the section Experiment Results for more information on the report specific data.

Run configuration

  • Stochastic Seed: 12345

  • Simulation start date: 1/1/2014 12:00:00 a.m.

  • Simulation stop time: 240

  • Simulation stop time unit: Hours

Report statistics

  • From Figure 5 we learn, that the processing time of this model is exactly 8 hours

  • Figure 6 shows us that the "Having a break" activity lasts exactly 6 minutes

  • These are the values with which we configured the model, so far so good

  • But what about the mean value of the "Work" activity

    • We set up a constant duration of 1 hour. So why is it not exactly 1 hour?

    • Because our worker is having a break 7 times a day, which sums up to 42 minutes a day.

    • After he had 7 breaks, he still has 18 minutes to work before the second (attached) event fires and ends the process (see Min-Value from Figure 6)

    • Just do the math: He works 7 hours and 18 minutes which is 7.3, then divide this by 8 (Observations per day) and multiply it with 60.

      • This results in 54.75 minutes, or 54 minutes and 45 seconds

model12 process cycle
Figure 5. The processing times
model12 activity
Figure 6. The activity details
model12 events
Figure 7. The event details
Also note that the gateway always fires the same sequence flow (see Figure 8)
model12 gateways
Figure 8. The gateway details