bpo.simulator module¶
Classes:
A |
|
|
A simulation event. |
|
A |
|
An enumeration for the types of event that can happen in the simulator. |
|
A Reporter consists of |
Abstract class that must be implemented by each concrete reporter element. |
|
|
A Simulator simulates a specified |
A |
|
|
An enumeration for the unit in which simulation time is measured. |
- class bpo.simulator.CaseReporterElement[source]¶
Bases:
bpo.simulator.ReporterElementA
ReporterElementthat keeps information about cases, specifically:cases completed: the number of cases that completed during the simulation run.
cases cycle time: the average of the cycle times of the completed cases.
This information is returned by the
CaseReporterElement.summarize()method by the specified labels.Methods:
report(event)Is invoked when a simulation event occurs.
restart()Is invoked when a simulation run starts.
Is invoked when a simulation run ends.
- report(event)[source]¶
Is invoked when a simulation event occurs. Can store information about the event.
- Parameters
event – the simulation
Eventthat occurred.
- class bpo.simulator.Event(event_type, moment, task, resource=None, nr_tasks=0, nr_resources=0)[source]¶
Bases:
objectA simulation event.
- Parameters
event_type – the
EventType.moment – the moment in simulation time at which the event happens.
task – the task that triggered, or None for event_type == PLAN_TASKS.
resource – the resource that performs the task, or None for event_type not in [START_TASK, COMPLETE_TASK]
nr_tasks – the number of tasks that must be planned, or 0 for event_type != PLAN_TASKS
nr_resources – the number of resources that is available, or 0 for event_type != PLAN_TASKS
- class bpo.simulator.EventLogReporterElement(filename, timeunit=TimeUnit.SECONDS, initial_time=datetime.datetime(2020, 1, 1, 0, 0), time_format='%Y-%m-%d %H:%M:%S.%f', data_fields=[])[source]¶
Bases:
bpo.simulator.ReporterElementA
ReporterElementthat stored the simulation events that occur in an event log. TheEventLogReporterElement.summarize()method does not return any information. As simulation time is a numerical value, some processing is done to convert simulation time into a time format that can be read and interpreted by a process mining tool. To that end, the timeunit in which simulation time is measured must be passed as well as the initial_time moment in calendar time from which the simulation time will be measured. A particular simulation_time moment will then be stored in the log as: initial_time + simulation_time timeunits. Data can also be reported on by specifying the corresponding data fields. The names of these data fields must correspond to names of data fields as they appear in the problem.- Parameters
filename – the name of the file in which the event log must be stored.
timeunit – the
TimeUnitof simulation time.initial_time – a datetime value.
time_format – a datetime formatting string.
data_fields – the data fields to report in the log.
Methods:
report(event)Is invoked when a simulation event occurs.
restart()Is invoked when a simulation run starts.
Is invoked when a simulation run ends.
- report(event)[source]¶
Is invoked when a simulation event occurs. Can store information about the event.
- Parameters
event – the simulation
Eventthat occurred.
- class bpo.simulator.EventType(value)[source]¶
Bases:
enum.EnumAn enumeration for the types of event that can happen in the simulator.
Attributes:
A case arrives.
A case completes.
A task completes.
An action is performed to assign tasks to resources.
Resources are scheduled every full clock tick.
A task starts.
A task becomes ready to perform (but is not assigned to a resource).
A task is assigned to a resource.
- CASE_ARRIVAL¶
A case arrives.
- COMPLETE_CASE¶
A case completes.
- COMPLETE_TASK¶
A task completes.
- PLAN_TASKS¶
An action is performed to assign tasks to resources.
- SCHEDULE_RESOURCES¶
Resources are scheduled every full clock tick.
- START_TASK¶
A task starts.
- TASK_ACTIVATE¶
A task becomes ready to perform (but is not assigned to a resource).
- TASK_PLANNED¶
A task is assigned to a resource.
- class bpo.simulator.Reporter(warmup=0, reporter_elements=None)[source]¶
Bases:
objectA Reporter consists of
ReporterElementand reports on the information that is kept by its elements. Consequently, it does not do much itself, it mainly passes on events to and received aggregate information from its elements.It receives a
Reporter.report()call, each time a simulation event occurs, which it forwards to its elements to enable them to store information about that event. It receives aReporterElement.summarize()call when a simulation run completes. It then collects the summaries from each of its elements and returns them in one list. It receives aReporterElement.restart()call when a simulation run starts, which it forwards to its elements to enable them to restart.During the specified warmup time, the reporter will ignore all events.
- Parameters
warmup – a duration in simulation time.
reporter_elements – a list of
ReporterElementinstances, when None are provided, creates a reporter with aTaskReporterElementand aCase ReporterElement.
Methods:
aggregate(summaries)report(event)restart()
- class bpo.simulator.ReporterElement[source]¶
Bases:
abc.ABCAbstract class that must be implemented by each concrete reporter element. A reporter element is part of a
Reporter. It receives aReporterElement.report()call, each time a simulation event occurs. It can then store information about that event. Once a simulation run is completed, it receives aReporterElement.summarize()call. It must then report aggregate information that it stored about the events. Each time a simulation run starts, it receives aReporterElement.restart()call, upon which it must erase all previously stored information.Methods:
report(event)Is invoked when a simulation event occurs.
restart()Is invoked when a simulation run starts.
Is invoked when a simulation run ends.
- abstract report(event)[source]¶
Is invoked when a simulation event occurs. Can store information about the event.
- Parameters
event – the simulation
Eventthat occurred.
- class bpo.simulator.Simulator(problem, reporter, planner)[source]¶
Bases:
objectA Simulator simulates a specified
Problemusing a specifiedPlanner. The results of the simulation are generated using the specifiedReporter. There are two main entry points into the simulator:simulate(), which simulates the (single) problem instance passed with the constructor; andreplicate(), which simulates a collection of problem instances passed via the replicate method itself.
Attributes:
The tasks that are currently assigned.
The set of resources that are currently available.
The set of resources that are currently away (on a break, home, or working in another process) and consequently not available.
The cases of which a task is currently being performed or must still be performed.
The resources that are currently busy.
The current simulation time.
The resources that are currently reserved.
The tasks that are currently not assigned.
Methods:
The number of resources that is currently desired to be working now according to the problem schedule.
Re-initializes the simulation, such that it can be run again.
replicate(problem, planner, reporter, ...)Creates a simulator for each of the problem_instances, using the specified planner and reporter.
simulate(running_time)Runs the simulation for the instance that was passed in the constructor.
The number of resources that is actually on the work floor now, either available, busy or reserved.
- assigned_tasks¶
The tasks that are currently assigned. A dict task.id -> (task, resource, start), where:
- available_resources¶
The set of resources that are currently available. Each resource is a label that identifies a resource in the
Problem.
- away_resources_weights¶
The set of resources that are currently away (on a break, home, or working in another process) and consequently not available. An away resource is a pair (resource, weight), such that the weight is the weight belonging to the resource according to the problem, i.e.: away_resources_weights[i] == problem.resource_weights[problem.resources.index(away_resources[i])]
- busy_cases¶
The cases of which a task is currently being performed or must still be performed. A dict case_id -> [active task_id] that maps case identifiers for which a task exists to the identifiers of those tasks.
- busy_resources¶
The resources that are currently busy. A dict resource -> (task, start), where:
task is an instance of
Taskis the task that the resource is working on.start is the moment in simulation time at which the resource started working on the task.
- desired_nr_resources()[source]¶
The number of resources that is currently desired to be working now according to the problem schedule.
- Returns
a number of resources.
- now¶
The current simulation time.
- static replicate(problem, planner, reporter, simulation_time, replications)[source]¶
Creates a simulator for each of the problem_instances, using the specified planner and reporter. Simulates each problem instance by calling the
simulate()method on it using the specified simulation time. Returns the list of summaries generated by the reporter, one summary for each simulated problem_instance.- Parameters
- Returns
a list of summaries, generated by the reporter, one for each element of problem_instances.
- reserved_resources¶
The resources that are currently reserved. A dict resource -> (task, start), where:
- simulate(running_time)[source]¶
Runs the simulation for the instance that was passed in the constructor. The simulator generates events (i.e. cases with their associated arrival times, data, and tasks) as they are produced by the problem instance. The simulator generates a plan event each time a task or resource becomes available. Events are handled by the reporter.
If the target utilization rate is set to a value (a fraction f) other than None, the simulator will ensure that resources are occupied for approximately the targeted fraction f of the time. It does that by making resources busy with ‘other tasks’ (i.e. tasks other than the ones of the problem being simulated, like tasks in another process). These ‘other tasks’ are not specified further and their activity is not logged, but the resources are being kept busy on those tasks.
- Parameters
running_time – the amount of simulation time the simulation should be run for.
- class bpo.simulator.TasksReporterElement[source]¶
Bases:
bpo.simulator.ReporterElementA
ReporterElementthat keeps information about tasks, specifically:tasks completed: the number of tasks that completed during the simulation run.
task proc time: the average of the processing times of the completed tasks.
task wait time: the average of the waiting times of the completed tasks.
This information is returned by the
TasksReporterElement.summarize()method by the specified labels.Methods:
report(event)Is invoked when a simulation event occurs.
restart()Is invoked when a simulation run starts.
Is invoked when a simulation run ends.
- report(event)[source]¶
Is invoked when a simulation event occurs. Can store information about the event.
- Parameters
event – the simulation
Eventthat occurred.
- class bpo.simulator.TimeUnit(value)[source]¶
Bases:
enum.EnumAn enumeration for the unit in which simulation time is measured.
Attributes:
Measured in days.
Measured in hours.
Measured in minutes.
Measured in seconds.
- DAYS¶
Measured in days.
- HOURS¶
Measured in hours.
- MINUTES¶
Measured in minutes.
- SECONDS¶
Measured in seconds.