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 a default name will be used: <class_name>_<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)
Adds a device to the end of the routing history.
- Parameters:
device (PartFlowController) – Item to be added to routing history.
- 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.
- remove_from_routing_history(index)
Removes an item from the routing history.
- Parameters:
index (int) – Index of an element in the routing history to be removed.
- Raises:
IndexError – If the provided index is outside the routing history’s range.
- 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:
PartHandler
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.
- property capacity
Maximum number of Parts that can be stored in the Buffer.
- property cycle_time
Cycle time is not used by the buffer.
- 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. Each Part within a Batch counts as a separate Part.
- Return type:
int
- property minimum_delay
Minimum time between any one Part being passed to the Buffer and that same Part being passed to downstream Devices
- notify_upstream_of_available_space()
Communicate to all immediate upstreams that this PartFlowController can accept a new Part.
Should be called automatically when space for a Part becomes available.
- 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(name=None, upstream=None, decider_override=None)
Bases:
PartFlowController
Device that can prevent certain Parts from passing between upstream and downstream devices.
DecisionGate does not hold/buffer any parts.
Warning
DecisionGate should ONLY use the state of the Part being passed to determine if the Part should pass. This means the same Part will either always pass or never pass unless its state changes. If DecisionGate blocks a Part from upstream and later it would allow the same Part to pass, there is no guarantee that another attempt to pass the Part is going to be made causing the Part to get stuck.
- Parameters:
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 of PartFlowController, default=None) – List of devices from which Parts can be received.
decider_override (function, default=None) – Function receives two arguments: this DecisionGate and the Part to be passed. Function should return True if the Part can pass and False otherwise. If not None this function will be used instead of DecisionGate.part_pass_decider
- give_part(part)
Try to pass a Part to this PartFlowController.
- Parameters:
part (Part) – Part that is being passed.
- Returns:
True if the Part has been accepted, otherwise False.
- Return type:
bool
- part_pass_decider(part)
Decider for whether a Part is allowed to pass through this device.
This decider will not be used if the DecisionGate was provided a <decider_override> on creation.
Warning
DecisionGate should ONLY use the state of the Part being passed to determine if the Part should pass. This means the same Part will either always pass or never pass unless its state changes. If DecisionGate blocks a Part from upstream and later it would allow the same Part to pass, there is no guarantee that another attempt to pass the Part is going to be made causing the Part to get stuck.
- Parameters:
part (Part) – Part the upstream is trying to pass.
- Returns:
Whether the <part> should be allowed to pass.
- Return type:
bool
simprocesd.model.factory_floor.group module
- class simprocesd.model.factory_floor.group.Group(group_name, devices, input_override=None, output_override=None)
Bases:
object
A grouping of devices for the purpose of using them in multiple production path locations.
The first device in the device list will be set as the input device for the group and will receive Parts that are passed to the group. The last device will be set as the output device for the group and Parts that leave the the output device will be routed out of the Group. Group will set upstream for the input device(s) and the downstream for the output devices.
Once a group is created use get_new_group_path to create a new production line device. Parts that go into this GroupPath will be routed to an input device in the group and once the Part leaves the group it will be routed back out of the same GroupPath.
- Parameters:
group_name (str) – Name of the group.
devices (list of PartFlowController) – List of devices that are part of this Group.
input_override (list of PartFlowController, default=None) – If set, override input devices for the Group with this list. These devices will be added to devices list if not already a part of it.
output_override (list of PartFlowController, default=None) – If set, override output devices for the Group with this list. These devices will be added to devices list if not already a part of it.
- Raises:
TypeError – If any of the devices are not PartFlowController or a subclass of it. If any of the Group devices have an upstream or a downstream that is not another device in the Group.
- get_new_group_path(name=None, upstream=None)
Create a new GroupPath that acts like a device.
The new GroupPath that will route the Parts it receives to the Group’s Device(s) and when the Parts exit the Group they will exit from the same GrouPath they entered.
- Parameters:
name (str, default=None) – Name of the GroupPath Asset that will be created. If name is None then a default name will be used: <class_name>_<asset_id>
upstream (list of PartFlowController, default=None) – List of devices from which Parts can be received.
- class simprocesd.model.factory_floor.group.GroupInput(group, input_devices)
Bases:
PartFlowController
- give_part(part)
Try to pass a Part to this PartFlowController.
- Parameters:
part (Part) – Part that is being passed.
- Returns:
True if the Part has been accepted, otherwise False.
- Return type:
bool
- notify_upstream_of_available_space()
Communicate to all immediate upstreams that this PartFlowController can accept a new Part.
Should be called automatically when space for a Part becomes available.
- set_upstream(new_upstream_list)
Replace a set of upstream PartFlowControllers.
- Parameters:
new_upstream (list of PartFlowController) – PartFlowControllers that will replace the current collection of upstreams. If None, then an empty list will be used.
- Raises:
TypeError – If an object in the list is not a PartFlowController or a child of that class.
AssertionError – If an element in new_upstream includes itself.
- space_available_downstream()
Notify of available space downstream.
Will attempt to pass a Part downstream if a ready Part is available.
- property upstream
List of upstream PartFlowControllers.
Can be changed using set_upstream(new_upstream).
- class simprocesd.model.factory_floor.group.GroupOutput(group, output_devices)
Bases:
PartFlowController
- property downstream
List of downstream PartFlowControllers.
This list shouldn’t be set or modified directly because it’s dependent on upstream settings of other PartFlowControllers.
- give_part(part)
Try to pass a Part to this PartFlowController.
- 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 of available space downstream.
Will attempt to pass a Part downstream if a ready Part is available.
- class simprocesd.model.factory_floor.group.GroupPath(group, name=None, upstream=None)
Bases:
PartFlowController
See Group documentation for how GroupPath is used.
- Parameters:
group (Group) – Group where Parts will go when routed to this GroupPath.
name (str, default=None) – Name of the Asset. If name is None then a default name will be used: <class_name>_<asset_id>
upstream (list of PartFlowController, default=None) – List of PartFlowControllers from which Parts can be received.
- give_part(part)
Try to pass a Part to this PartFlowController.
- 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 of available space downstream.
Will attempt to pass a Part downstream if a ready Part is available.
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
- 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, quality=1)
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) – Starting quality of the Part.
- quality
A numerical representation for the quality of the Part.
- Type:
float
- add_routing_history(device)
Adds a device to the end of the routing history.
- Parameters:
device (PartFlowController) – Item to be added to routing history.
- remove_from_routing_history(index)
Removes an item from the routing history.
- Parameters:
index (int) – Index of an element in the routing history to be removed.
- Raises:
IndexError – If the provided index is outside the routing history’s range.
- property routing_history
Ordered list of devices that the part passed through. First entry is usually a Source.
- class simprocesd.model.factory_floor.part.PartGenerator(name_prefix, value=0, quality=1)
Bases:
object
Creates new Parts with specified starting parameters.
- Parameters:
name_prefix (str) – What the name of each generated Part will start with. Generated names follow the pattern: <name_prefix>_<n> where <n> starts with 1 and increments with each generated Part.
value (float, default=0) – Starting value of generated Parts.
quality (float, default=1) – Starting quality of generated Parts.
- generate_part_helper(part_name, part_counter)
Helper method for generating a new Part.
Provides additional arguments to make part generation easier.
- Parameters:
part_name (str) – Auto-generated name for the new Part. (See class description)
part_counter (int) – Count of the Part being created starting with 1.
- Returns:
New uninitialized Part.
- Return type:
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:
PartHandler
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 Asset. If name is None then a default name will be used: <class_name>_<asset_id>
upstream (list of PartFlowController, default=None) – List of devices from which Parts can be received.
value (float, default=0) – Starting value of the Asset.
output_batch_size (int, default=None) – Specify the batch size for the output. If set to None then the output will be individual Parts.
- property output_batch_size
Output Batch size. If None then the output will be individual Parts instead of Batches.
simprocesd.model.factory_floor.part_flow_controller module
- class simprocesd.model.factory_floor.part_flow_controller.PartFlowController(name=None, upstream=None, value=0)
Bases:
Asset
Base production line device.
Passes Parts from upstream to downstream without buffering any Parts or any delays in time.
- Parameters:
name (str, default=None) – Name of the Asset. If name is None then a default name will be used: <class_name>_<asset_id>
upstream (list of PartFlowController, default=None) – List of devices from which Parts can be received.
value (float, default=0) – Starting value of the Asset.
- property block_input
When set to True this PartFlowController will not accept new Parts.
- property downstream
List of downstream PartFlowControllers.
This list shouldn’t be set or modified directly because it’s dependent on upstream settings of other PartFlowControllers.
- static downstream_priority_sorter(downstream)
Sort the downstream list in a descending priority of where Parts should be passed to first.
Default implementation gives higher priority to downstreams that have been waiting for a Part the longest.
Note
Overwrite this static function to change how all PartFlowControllers prioritize where Parts are passed.
- Parameters:
downstream (list) – A list of downstream PartFlowControllers.
- Returns:
A sorted list of downstream PartFlowControllers sorted from highest to lowest priority.
- Return type:
list
- get_sorted_downstream_list()
Get the sorted list of downstream PartFlowControllers.
- Returns:
A sorted list of downstream PartFlowControllers.
- Return type:
list
- give_part(part)
Try to pass a Part to this PartFlowController.
- Parameters:
part (Part) – Part that is being passed.
- Returns:
True if the Part has been accepted, otherwise False.
- Return type:
bool
- is_operational()
Check whether the PartFlowController is operational.
- Returns:
True if part handling and processing can currently be performed, otherwise False.
- Return type:
bool
- property joined_groups
List of Groups that this PartFlowController is a part of.
- notify_upstream_of_available_space()
Communicate to all immediate upstreams that this PartFlowController can accept a new Part.
Should be called automatically when space for a Part becomes available.
- set_upstream(new_upstream)
Replace a set of upstream PartFlowControllers.
- Parameters:
new_upstream (list of PartFlowController) – PartFlowControllers that will replace the current collection of upstreams. If None, then an empty list will be used.
- Raises:
TypeError – If an object in the list is not a PartFlowController or a child of that class.
AssertionError – If an element in new_upstream includes itself.
- space_available_downstream()
Notify of available space downstream.
Will attempt to pass a Part downstream if a ready Part is available.
- property upstream
List of upstream PartFlowControllers.
Can be changed using set_upstream(new_upstream).
- property waiting_for_part_start_time
Simulation time of when this device started waiting for the next Part. Is None if not currently waiting for a Part.
Because PartFlowController does not hold Parts it instead looks at the immediate downstream devices and returns the earliest waiting_for_part_start_time from them.
simprocesd.model.factory_floor.part_handler module
- class simprocesd.model.factory_floor.part_handler.PartHandler(name=None, upstream=None, cycle_time=0, value=0)
Bases:
PartFlowController
Production line device that can hold a Part for a specified duration.
Can hold up to 1 Part and has a cycle time delay between accepting a Part and passing that Part downstream.
- Parameters:
name (str, default=None) – Name of the Asset. If name is None then a default name will be used: <class_name>_<asset_id>
upstream (list of PartFlowController, default=None) – List of devices from which Parts can be received.
cycle_time (float, default=0) – How long an accepted Part will be held before trying to pass it downstream.
value (float, default=0) – Starting value of the Asset.
- add_receive_part_callback(callback)
Register a function to be called when the PartHandler receives a new Part.
Callback signature: callback(part_handler, part)part_handler - PartHandler that received the new Part.part - Part that was received.If the cycle time is changed within this callback then the new cycle time will be used for the Part that triggered the callback. All future cycles would also use the new cycle time unless it is changed again.
- Parameters:
callback (function) – Function to be called.
- property cycle_time
Time between accepting a Part and passing it downstream.
Setting a new cycle time will affect all future cycles but not a cycle that is already in progress. A cycle starts when a Part is accepted.
- give_part(part)
Try to pass a Part to this PartFlowController.
- 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.
- notify_upstream_of_available_space()
Communicate to all immediate upstreams that this PartFlowController can accept a new Part.
Should be called automatically when space for a Part becomes available.
- offset_next_cycle_time(offset)
Offset the cycle time only for the next 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.
- set_upstream(new_upstream)
Replace a set of upstream PartFlowControllers.
- Parameters:
new_upstream (list of PartFlowController) – PartFlowControllers that will replace the current collection of upstreams. If None, then an empty list will be used.
- Raises:
TypeError – If an object in the list is not a PartFlowController or a child of that class.
AssertionError – If an element in new_upstream includes itself.
- space_available_downstream()
Notify of available space downstream.
Will schedule an attempt to pass a Part downstream but only if it was waiting for downstream space to become available.
- property waiting_for_part_start_time
Simulation time of when this device started waiting for the next Part. Is None if not currently waiting for a Part.
simprocesd.model.factory_floor.part_processor module
- class simprocesd.model.factory_floor.part_processor.PartProcessor(name=None, upstream=None, cycle_time=0, value=0, resources_for_processing=None)
Bases:
PartHandler
,Maintainable
Production device that can modify Parts.
Extends PartHandler to closer simulate a production machine: - Parts can be modified in a callback function by adding it with add_finish_processing_callback. When the processing cycle finishes the callback will be called with the Part as a parameter. - Implements Maintainable so it can be a target of Maintainer’s work orders. - Can require resources from ResourceManager in order to process Parts. If specified resources are unavailable then new Parts will not be accepted by the PartProcessor.
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.
PartProcessor 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 Asset. If name is None then a default name will be used: <class_name>_<asset_id>
upstream (list of PartFlowController, default=None) – List of PartFlowControllers from which Parts can be received.
cycle_time (float, default=0) – How long it takes to process a Part.
value (float, default=0) – Starting value of the Asset.
resources_for_processing (Dictionary, default=None) – A dictionary specifying resources needed for processing 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 before a Part is accepted and they will be released when the processing of the Part is done. If the processed Part can be passed and a new Part is provided immediately then the PartProcessor will skip releasing and re-acquiring the resources.
Note
If PartProcessor fails with a Part that hasn’t been fully processed then the Part is lost. A lost Part can be captured by using add_shutdown_callback.
- add_finish_processing_callback(callback)
Register a function to be called when the PartProcessor finishes processing a Part.
Callback signature: callback(machine, part)part_processor - PartProcessor doing the processing.part - Part that was processed.- Parameters:
callback (function) – Function to be called.
- add_restored_callback(callback)
Register a function to be called when the PartProcessor is restored after a shutdown or failure.
Callback signature: callback(machine)part_processor - PartProcessor that was restored.- Parameters:
callback (function) – Function to be called.
- add_shutdown_callback(callback)
Register a function to be called when the PartProcessor shuts down.
Callback signature: callback(machine, part)part_processor - PartProcessor that was shutdown.is_failure - True if the shutdown occurred due to failure, False otherwise.part - Part that was lost or None if no Part was lost.- Parameters:
callback (function) – Function to be called.
- 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 PartFlowController is operational.
- Returns:
True if part handling and processing can currently be performed, otherwise False.
- Return type:
bool
- restore_functionality()
Restore the PartProcessor from a shutdown and failed states.
Does nothing if not in a shutdown or failed states.
- schedule_failure(time, message='')
Schedule a failure for this PartProcessor.
When the PartProcessor fails it will lose functionality and any Part in the middle of processing will be lost. For capturing the lost Part see add_shutdown_callback.
- 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 the PartProcessor.
Part being processed will pause and resume processing when PartProcessor is restored. New parts cannot be accepted. Does nothing if the PartProcessor is already in a shutdown or failed state.
Call restore_functionality to bring PartProcessor back online.
Warning
Do not to call in the middle of another operation from this PartProcessor, 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
Total time that the PartProcessor been operational (not shutdown).
- property utilization_time
Total time that the PartProcessor spent processing Parts.
simprocesd.model.factory_floor.sink module
- class simprocesd.model.factory_floor.sink.Sink(name=None, upstream=None, cycle_time=0, collect_parts=False)
Bases:
PartHandler
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 of PartFlowController, default=None) – List of devices from which Parts can be received.
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
- 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, part_generator=None, cycle_time=0.0, starting_parts=inf)
Bases:
PartHandler
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 next Part until previous Part is passed downstream.
Note
Source value will decrease by the value of every Part that is passed downstream. This is how Source tracks the costs of producing Parts.
- Parameters:
name (str, default=None) – Name of the Asset. If name is None then a default name will be used: <class_name>_<asset_id>
part_generator (PartGenerator, default=None) – Factory for generating Parts that the Source will supply. If None then the a default PartGenerator() will be used.
cycle_time (float, default=0) – How long it takes to produce a Part.
starting_parts (int, optional) – Number of available Parts to supply to downstream. Infinite if not set.
- adjust_part_count(value)
Update the number of remaining Parts.
Increase or decrease the number of Parts this Source can supply/produce. Cannot decrease by more than the remaining Parts count.
- Parameters:
value (int) – Number by which to adjust the remaining Parts count. If positive then the count will be increased, otherwise the count will be decreased. Remaining Parts count will never be decreased below 0.
- 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.
- property remaining_parts
How many Parts parts are left to be produced.
- set_upstream(new_upstream_list)
Source cannot have upstream Devices.
- Raises:
ValueError – if new_upstream_list is not an empty list.