model.RepeatActivity#

This notebook provides an example of OpenCLSim’s model.RepeatActivity. The repeat activity repeats a set of sub_processes a given number of times.

0. Import libraries#

import datetime, time
import simpy

import shapely.geometry
import pandas as pd

import openclsim.core as core
import openclsim.model as model
import openclsim.plot as plot

1. Initialise simpy environment#

# setup environment
simulation_start = 0
my_env = simpy.Environment(initial_time=simulation_start)

2. Define object classes#

In this example we won’t use object classes

3. Create objects#

3.1. Create site object(s)#

No site objects are created

3.2. Create vessel object(s)#

No vessel objects are created

3.3 Create activity/activities#

# initialise registry
registry = {}
# create a list of the sub processes
sub_processes = [
    model.BasicActivity(
        env=my_env,
        name="Basic activity",
        registry=registry,
        duration=20,
    )
]

# create a 'repeat activity' that is made up of the 'sub_processes'
repeat_activity = model.RepeatActivity(
    env=my_env,
    name="Repeat activity",
    registry=registry,
    sub_processes=sub_processes,
    repetitions=3,
)

4. Register processes and run simpy#

# initate the simpy processes defined in the 'repeat activity' and run simpy
model.register_processes([repeat_activity])
my_env.run()

5. Inspect results#

5.1 Inspect logs#

display(plot.get_log_dataframe(repeat_activity, [repeat_activity]))
Activity Timestamp ActivityState type ref
0 Repeat activity 1970-01-01 00:00:00 START NaN NaN
1 Repeat activity 1970-01-01 00:00:00 START subprocess d588b74b-48a3-4d98-98f4-0d3afa90c115
2 Repeat activity 1970-01-01 00:00:20 STOP subprocess d588b74b-48a3-4d98-98f4-0d3afa90c115
3 Repeat activity 1970-01-01 00:00:20 START subprocess d588b74b-48a3-4d98-98f4-0d3afa90c115
4 Repeat activity 1970-01-01 00:00:40 STOP subprocess d588b74b-48a3-4d98-98f4-0d3afa90c115
5 Repeat activity 1970-01-01 00:00:40 START subprocess d588b74b-48a3-4d98-98f4-0d3afa90c115
6 Repeat activity 1970-01-01 00:01:00 STOP subprocess d588b74b-48a3-4d98-98f4-0d3afa90c115
7 Repeat activity 1970-01-01 00:01:00 STOP NaN NaN

5.2 Visualise gantt charts#

plot.get_gantt_chart([repeat_activity, *sub_processes])

Observe that the basic activity has a duration of 20 time units. The repeat activity has specified 3 repetitions.

The logs show that indeed three Basic activities have been completed. The simulation stops at t = 60.

Also the gantt charts shows this. You can find the edges of the basic activities by hovering with your mouse over the Basic activity bar. The horizontal time axis of the gantt chart ends at t = 60.