model.ParallelActivity#
This notebook provides an example of OpenCLSim’s model.ParallelActivity. The parallel activity initiate a set of sub_processes simultaneously.
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 reporting activity
reporting_activity = model.BasicActivity(
env=my_env,
name="Reporting activity",
registry=registry,
duration=0,
)
# create a list of the sub processes
sub_processes = [
model.BasicActivity(
env=my_env,
name="Basic activity 1",
registry=registry,
duration=14,
additional_logs=[reporting_activity],
),
model.BasicActivity(
env=my_env,
name="Basic activity 2",
registry=registry,
duration=5,
additional_logs=[reporting_activity],
),
model.BasicActivity(
env=my_env,
name="Basic activity 3",
registry=registry,
duration=220,
additional_logs=[reporting_activity],
),
]
# create a parallel activity
parallel_activity = model.ParallelActivity(
env= my_env,
name= "Parallel process",
registry= registry,
sub_processes= sub_processes,
)
4. Register processes and run simpy#
# initate the simpy processes defined in the 'parallel activity' and run simpy
model.register_processes([parallel_activity, reporting_activity])
my_env.run()
5. Inspect results#
5.1 Inspect logs#
display(plot.get_log_dataframe(reporting_activity, [*sub_processes, parallel_activity, reporting_activity]))
Activity | Timestamp | ActivityState | type | ref | |
---|---|---|---|---|---|
0 | Reporting activity | 1970-01-01 00:00:00 | START | NaN | NaN |
1 | Basic activity 1 | 1970-01-01 00:00:00 | START | additional log | 1191a9ea-ad45-4430-97b2-7906f178fff0 |
2 | Basic activity 2 | 1970-01-01 00:00:00 | START | additional log | da7fc1d6-a028-40d5-afdf-6e53076dbe29 |
3 | Basic activity 3 | 1970-01-01 00:00:00 | START | additional log | 95fe5443-f73b-43e4-a1a6-e357a4d1a37a |
4 | Reporting activity | 1970-01-01 00:00:00 | STOP | NaN | NaN |
5 | Basic activity 2 | 1970-01-01 00:00:05 | STOP | additional log | da7fc1d6-a028-40d5-afdf-6e53076dbe29 |
6 | Basic activity 1 | 1970-01-01 00:00:14 | STOP | additional log | 1191a9ea-ad45-4430-97b2-7906f178fff0 |
7 | Basic activity 3 | 1970-01-01 00:03:40 | STOP | additional log | 95fe5443-f73b-43e4-a1a6-e357a4d1a37a |
for act in [*sub_processes, parallel_activity]:
display(plot.get_log_dataframe(act, [*sub_processes, parallel_activity, reporting_activity]))
Activity | Timestamp | ActivityState | |
---|---|---|---|
0 | Basic activity 1 | 1970-01-01 00:00:00 | START |
1 | Basic activity 1 | 1970-01-01 00:00:14 | STOP |
Activity | Timestamp | ActivityState | |
---|---|---|---|
0 | Basic activity 2 | 1970-01-01 00:00:00 | START |
1 | Basic activity 2 | 1970-01-01 00:00:05 | STOP |
Activity | Timestamp | ActivityState | |
---|---|---|---|
0 | Basic activity 3 | 1970-01-01 00:00:00 | START |
1 | Basic activity 3 | 1970-01-01 00:03:40 | STOP |
Activity | Timestamp | ActivityState | type | ref | |
---|---|---|---|---|---|
0 | Parallel process | 1970-01-01 00:00:00 | START | NaN | NaN |
1 | Parallel process | 1970-01-01 00:00:00 | START | subprocess | 1191a9ea-ad45-4430-97b2-7906f178fff0 |
2 | Parallel process | 1970-01-01 00:00:00 | START | subprocess | da7fc1d6-a028-40d5-afdf-6e53076dbe29 |
3 | Parallel process | 1970-01-01 00:00:00 | START | subprocess | 95fe5443-f73b-43e4-a1a6-e357a4d1a37a |
4 | Parallel process | 1970-01-01 00:00:05 | STOP | subprocess | da7fc1d6-a028-40d5-afdf-6e53076dbe29 |
5 | Parallel process | 1970-01-01 00:00:14 | STOP | subprocess | 1191a9ea-ad45-4430-97b2-7906f178fff0 |
6 | Parallel process | 1970-01-01 00:03:40 | STOP | subprocess | 95fe5443-f73b-43e4-a1a6-e357a4d1a37a |
7 | Parallel process | 1970-01-01 00:03:40 | STOP | NaN | NaN |
5.2 Visualise gantt charts#
plot.get_gantt_chart([parallel_activity, *sub_processes])