simprocesd.model.factory_floor package
Submodules
simprocesd.model.factory_floor.action_scheduler module
- class simprocesd.model.factory_floor.action_scheduler.ActionScheduler(schedule, name=None, is_cyclical=True)
Bases:
Asset
Performs actions on registered objects based on a schedule.
An ActionScheduler consists of a number of states with set durations. When the current state changes a default or a configured action is performed. Many objects can be registered with a single ActionScheduler.
- Parameters
schedule (list) –
List of the state sequences for this schedule. Format: [(duration, state), (duration, state), …]
duration determines how long the state will persist before progressing to the next state.
state can be any object, it will be provided to the action calls as an argument.
name (str, default=None) – Name of this ActionScheduler.
is_cyclical (bool, default=True) – If True then the schedule will loop back to first state after going through the last state. If False then the last state will persist indefinitely once reached.
- property current_state
Currently active state.
- default_action(obj, time, new_state)
Default action to be performed for each registered object when state changes.
This action is only performed for objects that were registered without an override_action.
- Parameters
obj (object) – Registered object.
time (float) – Time of the state change which is also the current simulation time.
new_state (object) – New state of ActionScheduler.
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- register_object(obj, override_action=None)
Register an object for which to perform scheduled actions.
When state changes an action will be performed on registered objects. Performed action is ActionScheduler.defailt_action or override_action if one is provided.
Trying to register an object that was already registered with this ActionScheduler will do nothing.
- Parameters
obj (object) – Object to register with this ActionScheduler. Same object can be used later to unregister_object
override_action (function, default=None) – If provided this action will be performed instead of the ActionScheduler.default_action when state changes. Function signature is same as default_action: override_action(action_scheduler, obj, time, new_state) - action_scheduler: this ActionScheduler. - obj: registered object. - time: current simulation time. - new_state: new state of ActionScheduler.
- Returns
True if the object was registered, otherwise False.
- Return type
bool
- unregister_object(obj)
Unregister an object from ActionScheduler so actions are no longer performed for it.
Does nothing if the object was not already registered with this ActionScheduler.
- Parameters
obj (object) – Object to unregister from this ActionScheduler. Need to be one of the object that was registered earlier.the same object can be used later to unregister_object
- Returns
True if the object was unregistered, otherwise False.
- Return type
bool
simprocesd.model.factory_floor.asset module
- class simprocesd.model.factory_floor.asset.Asset(name=None, value=0, is_transitory=False)
Bases:
object
Base class to be used for all simulated assets in production.
- Parameters
name (str, default=None) – Name of the Asset. If name is None then the Asset’s name will be changed to Asset_<id>
value (float, default=0) – Starting value of the Asset.
is_transitory (bool, default=False) – If True the Asset needs to be initialized/re-initialized manually. For example, Part objects are initialized by the Source that produced them. If False then the Asset automatically registers with the System which will handle object initialization.
- add_cost(label, cost)
Decrease the value of the Asset and record the change in value_history.
- Parameters
label (str) – Label for the change in value
cost (float) – By how much to decrease the Asset’s value. Value of 0 is ignored.
- add_value(label, value)
Add to the value of the Asset and record the change in value_history.
- Parameters
label (str) – Label for the change in value.
value (float) – By how much to increase the Asset’s value. Value of 0 is ignored.
- property env
Simulation’s Environment instance or None if the Asset has not been initialized yet
- property id
Unique Asset ID.
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- property name
Name of the Asset.
- property value
Current value of the Asset.
- property value_history
History of value changes for this Asset. Each entry contains: (label, time of change, value delta, new asset value)
simprocesd.model.factory_floor.batch module
- class simprocesd.model.factory_floor.batch.Batch(name=None, parts=None)
Bases:
Part
A type of Part that can contain multiple other Parts.
Batch is an abstraction used for moving Parts together. It does not represent a physical object, just a grouping.
- Parameters
name (str, default=None) – Name of the Part. If name is None then the Part’s name will be changed to Part_<id>
parts (list, default=None) – List of Parts contained in the Batch. None means the Batch starts empty.
- parts
List of Parts contained in the Batch. Can be modified directly to change the contents of the Batch.
- Type
list
- add_routing_history(device)
- add_value(label, value)
Add to the value of the Asset and record the change in value_history.
- Parameters
label (str) – Label for the change in value.
value (float) – By how much to increase the Asset’s value. Value of 0 is ignored.
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- make_copy()
Create a copy of this Part.
- Returns
a copy of this Part with a unique ID and an empty routing_history. Returned Part is not initialized.
- Return type
- property value
Sum of values of the Parts.
simprocesd.model.factory_floor.buffer module
- class simprocesd.model.factory_floor.buffer.Buffer(name=None, upstream=None, minimum_delay=0, capacity=None, value=0)
Bases:
Device
A device that can store multiple parts.
Buffer stores received Parts and can pass the stored Parts downstream. At any given time Buffer can store a number of Parts up to its storage capacity.
Parts in the Buffer can only pass downstream in the order they were received.
- Parameters
name (str, default=None) – Name of the Buffer. If name is None the Asset’s name with be changed to Buffer_<id>
upstream (list, default=None) – A list of upstream Devices.
minimum_delay (float, default=0) – Minimum time between any one Part being passed to the Buffer and that same Part being passed to downstream Devices.
capacity (int, optional) – Maximum number of Parts that can be stored in the Buffer. No maximum if not set.
value (float, default=0) – Starting value of the machine.
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- level()
- Returns
Number of Parts currently stored in the Buffer.
- Return type
int
- notify_upstream_of_available_space()
Communicate to all immediate upstream Devices that this Device can accept a new Part.
If upstream Devices have a Part waiting to be passed they will try to do so in a separate Event scheduled for the current simulation time.
- property stored_parts
List of Parts currently stored in the Buffer.
simprocesd.model.factory_floor.decision_gate module
- class simprocesd.model.factory_floor.decision_gate.DecisionGate(should_pass_part, name=None, upstream=None)
Bases:
Device
Device that can conditionally prevent Parts from passing between upstream and downstream Devices.
DecisionGate does not hold/buffer any parts.
- Parameters
should_pass_part (function) – Function receives two arguments: this DecisionGate and the Part to be passed. Function should return True if the Part can pass and False otherwise.
name (str, default=None) – Name of the DecisionGate. If name is None then the DecisionGate’s name will be changed to DecisionGate_<id>
upstream (list, default=None) – A list of upstream Devices.
- give_part(part)
Try to pass a Part to this Device.
- Parameters
part (Part) – Part that is being passed.
- Returns
True if the Part has been accepted, otherwise False.
- Return type
bool
- space_available_downstream()
Notify this Device that downstream now can accept a Part.
This does not guarantee that this Device will pass a Part downstream because space could become unavailable before this Device gets the chance to pass its Part.
simprocesd.model.factory_floor.device module
- class simprocesd.model.factory_floor.device.Device(name=None, upstream=None, value=0)
Bases:
Asset
Base class for production devices.
Contains common logic for handling parts as they pass between Devices.
- Parameters
name (str, default=None) – Name of the Device. If name is None then the Device’s name will be changed to Device_<id>
upstream (list, default=None) – A list of upstream Device objects.
value (float, default=0) – Starting value of the Device.
- add_receive_part_callback(callback)
Setup a function to be called when the Machine receives a new Part.
Callback signature: callback(machine, part)machine - Machine to which the callback was added.part - Part that was lost or None if no Part was lost.If Machine cycle time is changed within the callback then it will be used as the processing time for the Part that was just received as well as all the future Parts.
- Parameters
callback (function) – Function to be called.
- property block_input
When set to True this Device will not accept new Parts from upstream.
- property downstream
List of downstream Devices, Devices that can receive Parts from this Device.
This list should not be set or modified directly because it’s dependent on upstream settings of other Devices.
- static downstream_priority_sorter(downstream)
Sort the downstream list in a descending priority of where Parts should be moved to first.
Default implementation gives higher priority to Devices that have been waiting for a Part the longest.
Note
Overwrite this static function to change how all Devices prioritize where Parts are passed.
- Parameters
downstream (list) – A list of downstream Devices.
- Returns
A list of downstream devices sorted from highest to lowest priority.
- Return type
list
- get_sorted_downstream_list()
Get the sorted list of downstream Devices.
- Returns
A sorted list of downstream devices.
- Return type
list
- give_part(part)
Try to pass a Part to this Device.
- Parameters
part (Part) – Part that is being passed.
- Returns
True if the Part has been accepted, otherwise False.
- Return type
bool
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- is_operational()
Check whether the Device is operational.
- Returns
True is the Device can perform part handling and processing functions, otherwise False.
- Return type
bool
- notify_upstream_of_available_space()
Communicate to all immediate upstream Devices that this Device can accept a new Part.
If upstream Devices have a Part waiting to be passed they will try to do so in a separate Event scheduled for the current simulation time.
- set_upstream(new_upstream_list)
Replace a set of upstream Devices with a new one.
- Parameters
new_upstream_list (list) – List of Devices that will replace the previous set of upstream Devices.
- Raises
TypeError – If an object in the list is not a Device and does not extend the Device class.
Warning
A device cannot have itself as the upstream.
- space_available_downstream()
Notify this Device that downstream now can accept a Part.
This does not guarantee that this Device will pass a Part downstream because space could become unavailable before this Device gets the chance to pass its Part.
- property upstream
List of upstream Devices, Devices that can feed Parts to this Device.
Can be changed using set_upstream(new_list).
- property waiting_for_part_start_time
Simulation time of when this device started waiting for the next Part. Is set to None if the device is not currently waiting for a Part.
simprocesd.model.factory_floor.machine module
- class simprocesd.model.factory_floor.machine.Machine(name=None, upstream=None, cycle_time=0, value=0, resources_for_processing=None)
Bases:
Device
,Maintainable
Machine is a Device that can process parts.
Machine accepts a Part, holds onto it for the duration of a cycle (processing time) and then passes it to a downstream Device when possible before accepting a new Part to process. To change the Part in some way when processing is done use add_finish_processing_callback.
Callback functions can be added to this machine by using functions: add_<trigger>_callback such as add_shutdown_callback. Multiple callbacks on the same trigger are called in the order they were added.
Machine extends Maintainable class with basic functionality and the class should be extended to simulate a more complex maintenance scheme.
- Parameters
name (str, default=None) – Name of the Device. If name is None then the Device’s name will be changed to Machine_<id>
upstream (list, default=None) – A list of upstream Devices.
cycle_time (float, default=0) – How long it takes to process a Part.
value (float, default=0) – Starting value of the Machine.
resources_for_processing (Dictionary, default=None) – A dictionary specifying resources needed for this Machine to process Parts. Each key-value entry in the dictionary identifies what resource (key) needs to be reserved and how much(value) of it needs to be reserved. These resources will be reserved at the beginning of Part processing and they will be released when the processing is done.
Warning
If Machine fails with a Part that hasn’t been fully processed then the Part is lost. A lost Part can be detected by using add_shutdown_callback and checking if part != None in the callback.
- add_finish_processing_callback(callback)
Setup a function to be called when the Machine finishes processing a Part.
Callback signature: callback(machine, part)machine - Machine to which the callback was added.part - Part that was received.- Parameters
callback (function) – Function to be called.
- add_restored_callback(callback)
Setup a function to be called when the Machine is restored after a shutdown or failure.
Callback signature: callback(machine)machine - Machine to which the callback was added.- Parameters
callback (function) – Function to be called.
- add_shutdown_callback(callback)
Setup a function to be called when the Machine shuts down.
Callback signature: callback(machine, part)machine - Machine to which the callback was added.is_failure - True if the shutdown occurred due to failure, False otherwise.part - Part that was received.- Parameters
callback (function) – Function to be called.
- property cycle_time
How long it takes to process one Part.
Setting a new cycle time will affect all future process cycles but not a cycle that is already in progress.
- end_work(tag)
Called by Maintainer when it finishes working on the work order.
- Parameters
tag (object) – Identifier for the work order.
- get_work_order_capacity(tag)
Called once when the work order is created to determine how much of the Maintainer’s capacity is needed to perform the work order.
- Parameters
tag (object) – Identifier for the work order.
- Returns
Needed capacity to perform the work order indicated by the tag.
- Return type
float
- get_work_order_cost(tag)
Called once to get the cost to Maintainer to perform the work order.
Returned value will be subtracted from Maintainer’s value. If the work order cost is tracked elsewhere then this should return 0 (default implementation).
- Parameters
tag (object) – Identifier for the work order.
- Returns
Needed capacity to perform the work order indicated by the tag.
- Return type
float
- get_work_order_duration(tag)
Called at the beginning of performing a work order to determine how long the work order will take.
- Parameters
tag (object) – Identifier for the work order.
- Returns
How long it will take to perform the work order indicated by the tag. Duration is measured in simulation time units.
- Return type
float
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- is_operational()
Check whether the Device is operational.
- Returns
True is the Device can perform part handling and processing functions, otherwise False.
- Return type
bool
- offset_next_cycle_time(offset)
Offset the cycle time of the next processing cycle.
The effects are cumulative across multiple calls of offset_next_cycle_time. If the cycle time plus the final offset are less than 0 then a cycle time of 0 will be used.
Once the next cycle starts the offset will reset to 0.
- Parameters
offset (float) – By how much to offset the cycle time of the next processing cycle.
- restore_functionality()
Restore Part related functionality and/or recover from a failed state.
Does nothing if machine is not in a shutdown or failed state.
- schedule_failure(time, message='')
Schedule a failure for this Machine.
When the Machine fails it will lose functionality any Part in the middle of processing will be lost.
- Parameters
time (float) – Simulation time when the failure should occur.
message (str, default='') – Message that will be associated with the failure event. Useful for debugging.
- shutdown()
Shutdown Part related functionality.
Part being processed will pause and resume processing when Machine is restored. New parts cannot be accepted but any Part that was already processed may still move downstream.
Does nothing if machine is already in a shutdown or failed state.
Call restore_functionality to bring Machine back online.
Warning
Do not to call in the middle of another operation from this Machine, safest way to call it is to schedule it as a separate event.
- start_work(tag)
Called by Maintainer when it begins working on the work order.
- Parameters
tag (object) – Identifier for the work order.
- property uptime
How much time has the Machine been operational (not shutdown).
- property utilization_time
How much time has the Machine spent on processing Parts.
simprocesd.model.factory_floor.maintainer module
- class simprocesd.model.factory_floor.maintainer.Maintainable
Bases:
object
An interface the Maintainer uses to create, prioritize, and execute work orders.
Maintainer can only perform work orders on classes that use Maintainable as one of their base classes.
- end_work(tag)
Called by Maintainer when it finishes working on the work order.
- Parameters
tag (object) – Identifier for the work order.
- get_work_order_capacity(tag)
Called once when the work order is created to determine how much of the Maintainer’s capacity is needed to perform the work order.
- Parameters
tag (object) – Identifier for the work order.
- Returns
Needed capacity to perform the work order indicated by the tag.
- Return type
float
- get_work_order_cost(tag)
Called once to get the cost to Maintainer to perform the work order.
Returned value will be subtracted from Maintainer’s value. If the work order cost is tracked elsewhere then this should return 0 (default implementation).
- Parameters
tag (object) – Identifier for the work order.
- Returns
Needed capacity to perform the work order indicated by the tag.
- Return type
float
- get_work_order_duration(tag)
Called at the beginning of performing a work order to determine how long the work order will take.
- Parameters
tag (object) – Identifier for the work order.
- Returns
How long it will take to perform the work order indicated by the tag. Duration is measured in simulation time units.
- Return type
float
- start_work(tag)
Called by Maintainer when it begins working on the work order.
- Parameters
tag (object) – Identifier for the work order.
- class simprocesd.model.factory_floor.maintainer.Maintainer(name='maintainer', capacity=inf, value=0)
Bases:
Asset
Asset that is responsible for performing requested work orders.
Requests are generally worked in a first come first serve order but a later request may be worked first when available capacity is insufficient for the earlier request.
Maintainer can work on multiple work orders at the same time as long the the combined needed capacity of the work orders is less than or equal to the Maintainer’s maximum capacity. Needed capacity is determined by Maintainable.get_work_order_capacity
Maintainer will not perform simultaneous work orders on the same target and will instead perform them sequentially even if there is enough capacity.
Note
Capacity units are not defined but need to be consistent across work order capacity requirements and Maintainer’s maximum capacity.
- Parameters
name (str, default=None) – Name of the Maintainer. If name is None then the Maintainer’s name will be changed to Maintainer_<id>
capacity (float, optional) – Maintainer’s maximum capacity.
value (float, default=0) – Starting value of the Asset.
- property available_capacity
How much of the Maintainer’s capacity is currently not being used.
- create_work_order(target, tag=None, info=None)
Request a new work order to be performed.
Creates a new work order and adds it to the back of the queue of work orders to be executed.
- Parameters
target (Maintainable) – Target of the work order to be performed.
tag (object, default=None) – Identifier the target uses to differentiate between various types of work orders that could be performed on it.
info (str, default=None) – A string to be included with datapoints that track the lifecycle of the order. Example uses: reason for the work order, source of the work order, a unique identifier, etc.
- Returns
True if the work order was added to the queue and False if it was rejected. Request will be rejected if the same work order request is already in the queue or is being worked on.
- Return type
bool
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- property total_capacity
Maximum capacity of the maintainer.
- try_working_requests()
Maintainer will look through the work order queue and attempt to start working on each one.
Work orders will be started if the Maintainer has enough available capacity to perform that work order.
Note
This function is called automatically when requests are made and when requests are completed. Normally there should be no need to call it manually.
simprocesd.model.factory_floor.part module
- class simprocesd.model.factory_floor.part.Part(name=None, value=0.0, quality=1.0)
Bases:
Asset
Representation of an item/part that passes between Devices in a production line.
- Parameters
name (str, default=None) – Name of the Part. If name is None then the Part’s name will be changed to Part_<id>
value (float, default=0) – Starting value of the Part.
quality (float, default=1.0) – Starting quality of the Part.
- quality
A numerical representation for the quality of the Part.
- Type
float
- add_routing_history(device)
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- make_copy()
Create a copy of this Part.
- Returns
a copy of this Part with a unique ID and an empty routing_history. Returned Part is not initialized.
- Return type
- property routing_history
Ordered list of devices that the part passed through. First entry is usually a Source.
simprocesd.model.factory_floor.part_batcher module
- class simprocesd.model.factory_floor.part_batcher.PartBatcher(name=None, upstream=None, value=0, output_batch_size=None)
Bases:
Device
Organize input items into Batches of specific size or into individual Parts.
Can accept Parts and Batches of Parts and re-organize them into the specified output format. PartBatcher has an internal buffer where it keeps excess input Parts and incomplete output Batches.
Notes
Output Batches are always newly created even if input is made up of Batches. Input Batch is always lost while Parts contained within it are kept.
- Parameters
name (str, default=None) – Name of the Device. If name is None then the Device’s name will be changed to Device_<id>
upstream (list, default=None) – A list of upstream Device objects.
value (float, default=0) – Starting value of the Device.
output_batch_size (int, default=None) – Specify the batch size for the output. If set to None then the output will be individual Parts.
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
simprocesd.model.factory_floor.sink module
- class simprocesd.model.factory_floor.sink.Sink(name=None, upstream=None, cycle_time=0, collect_parts=False)
Bases:
Machine
A Device that can receive any number of Parts but not pass those Parts. It is the end of a production line.
Note
Sink’s value will increase by the value attribute of each received Part. This is how Sink tracks the output value of produced Parts.
- Parameters
name (str, default=None) – Name of the Sink. If name is None then the Sink’s name will be changed to Sink_<id>
upstream (list, default=None) – A list of upstream Devices.
cycle_time (float, default=0) – Minimum time between receiving Parts.
collect_parts (bool, default=False) – If True then received Parts are stored throughout the simulation and can be accessed under ‘collected_parts’.
- collected_parts
List of received Parts in the order they were received.
- Type
list
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- property received_parts_count
Count of all received Parts.
When receiving a Batch this will increase by the number of Parts contained within the Batch.
- property value_of_received_parts
Summed value of all received Parts.
simprocesd.model.factory_floor.source module
- class simprocesd.model.factory_floor.source.Source(name=None, sample_part=None, cycle_time=0.0, max_produced_parts=inf)
Bases:
Machine
A Device that produces Part objects and supplies them to Devices downstream. It is the start of a production line.
Source will not start producing a next Part until previous Part is passed downstream.
Note
Source value will decrease by sample_part.value every time a new Part is created. This is how Source tracks the costs of producing Parts.
- Parameters
name (str, default=None) – Name of the Source. If name is None then the Source’s name will be changed to Source_<id>
sample_part (Part, default=None) – Source will produce copies of this Part and pass them downstream, sample_part itself is never passed. If sample_part is None then it will be set to Part()
cycle_time (float, default=0) – How long it takes to produce a Part.
max_produced_parts (int, optional) – Maximum number of Parts to produce. No maximum if not set.
- property cost_of_produced_parts
Returns the summed value of the parts that have been produced by this Source and passed downstream.
- initialize(env)
Prepare Asset for simulation and reset attributes to starting values.
In most cases this is called automatically by the System. Needs to be called manually if the Asset was initialized with is_transitory set to True.
- Parameters
env (Environment) – Environment used by the simulating System.
- property produced_parts
Returns the count of the parts that have been produced by this Source and passed downstream.
- set_upstream(new_upstream_list)
Source cannot have upstream Devices.
- Raises
ValueError – if new_upstream_list is not an empty list.