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.
- We will define the scripted inter-arrival time at the start event first.
- Parametrize the two timer events, that are attached to the activity "Work"
- 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
- Note: If the simulation time is past 09:00 o'clock it will advance to the next day's 09:00 o'clock
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
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
Figure 4 - The conditions at the branching exclusive gateway
As described in the introduction of this lesson, we modeled a simple work-from-9-5-process.
- The process starts at 9 o'clock
- The "Work" activity is being executed for 8 hours
- There are two events attached to the activity
- "Have a break" will be executed 1 hour after the activity has been started
- The process then executes the "Have a break" activity
- Afterwards (at the gateway) it decides whether to work on
- This again depends on the current time. If it is past 17 o'clock the process will finish
- 'Elsewise it will return to the "Work" activity
- At the "Quit working for today" event the simulation checks the Python script
- If the time is past 17 o'clock, the event will be executed instantaneously
- Else it will be scheduled to 17 o'clock