Bases: Node
Machine represents a processing node in a factory simulation.
This Machine can have multiple input edges and output edges.
Parameters: |
-
state
(str )
–
Current state of the machine node. One of :
- SETUP_STATE: Initial setup phase before machine starts to operate.
- IDLE_STATE: Worker threads waiting to receive items.
- PROCESSING_STATE: Actively processing items.
- BLOCKED_STATE: When all the worker threads are waiting to push the processed item but the out going edge is full.
-
blocking
(bool , default:
True
)
–
If True, the source waits until it can put an item into the out edge. If False, it discards the item if the out edge is full and cannot accept the item that is being pushed by the machine.
-
work_capacity
(int , default:
1
)
–
Maximum no. of processing that can be performed simultaneously.1 worker thread can process one item.
-
processing_delay
((None, int, float, Generator, Callable) , default:
0
)
–
Delay for processing items. Can be:
- None: Used when the processing time depends on parameters of the node object (like current state of the object) or environment.
- int or float: Used as a constant delay.
- Generator: A generator function yielding delay values over time.
- Callable: A function that returns a delay (int or float).
-
in_edge_selection
(None or str or callable , default:
'FIRST_AVAILABLE'
)
–
Criterion or function for selecting the edge.
Options include "RANDOM", "ROUND_ROBIN", "FIRST_AVAILABLE".
- None: None: Used when edge selction depends on parameters of the node object (like current state of the object) or environment.
- str: A string that specifies the selection method.
- "RANDOM": Selects a random edge.
- "ROUND_ROBIN": Selects edges in a round-robin manner.
- "FIRST_AVAILABLE": Selects the first out edge that can give an item.
- callable: A function that returns an edge index.
-
out_edge_selection
(None or str or callable , default:
'FIRST_AVAILABLE'
)
–
Criterion or function for selecting the out edge.
Options include "RANDOM", "ROUND_ROBIN", "FIRST_AVAILABLE".
- None: None: Used when out edge selction depends on parameters of the node object (like current state of the object) or environment.
- str: A string that specifies the selection method.
- "RANDOM": Selects a random out edge in the out_edges list.
- "ROUND_ROBIN": Selects out edges in a round-robin manner.
- "FIRST_AVAILABLE": Selects the first out edge that can accept an item.
- callable: A function that returns an edge index.
|
Behavior
The machine node represents components that process or modify the items that flow in the simulation model. It can have multiple incoming edges
and multiple outgoing edge. Edge from which the item comes in and the edge to which processed item is pushed is decided using the method specified
in the parameter in_edge_selection
and out_edge_selection
. Machine will transition through the states- SETUP_STATE
, PROCESSING_STATE
, IDLE_STATE
and
BLOCKED_STATE
. The machine has a blocking behavior if blocking
=True
and gets blocked when all its worker threads have processed items and the out edge is full and
cannot accept the item that is being pushed by the machine and waits until the out edge can accept the item. If blocking
=False
, the machine will
discard the item if the out edge is full and cannot accept the item that is being pushed by the machine.
Raises: |
-
AssertionError
–
If the Machine has no input or output edges.
|
Output performance metrics:
The key performance metrics of the Machine node is captured in stats
attribute (dict) during a simulation run.
last_state_change_time : Time when the state was last changed.
num_item_processed : Total number of items generated.
num_item_discarded : Total number of items discarded.
total_time_spent_in_states: Dictionary with total time spent in each state.
update_state(new_state, current_time)
Update node state and track the time spent in the previous state.
Parameters: |
-
i
(int )
–
The index of the worker thread to update the state for.
-
new_state
(str )
–
The new state to transition to. Must be one of "SETUP_STATE", "GENERATING_STATE", "BLOCKED_STATE".
-
current_time
(float )
–
The current simulation time.
|
add_in_edges(edge)
Adds an in_edge to the node. Raises an error if the edge already exists in the in_edges list.
Parameters: |
-
edge
(Edge Object) )
–
The edge to be added as an in_edge.
|
add_out_edges(edge)
Adds an out_edge to the node. Raises an error if the edge already exists in the out_edges list.
Parameters: |
-
edge
(Edge Object) )
–
The edge to be added as an out_edge.
|