Bases: Node
Parameters: |
-
state
(str )
–
Current state of the source node. One of :
- SETUP_STATE: Initial setup phase before item generation starts.
- GENERATING_STATE: Actively generating and dispatching items.
- BLOCKED_STATE: Waiting to transfer item when edge is full (in blocking mode).
-
inter_arrival_time
(None, int, float, generator, or callable , default:
0
)
–
Time between item generations. Can be:
- None: Used when the setup time depends on parameters of the node object (like current state of the object) or environment.
- int or float: Used as a constant delay.
- Callable: A function that returns a delay (int or float).
- Generator: A generator function yielding delay values over time.
-
flow_item_type
(str , default:
'item'
)
–
Type of item to be generated. Default is "item". Can be
- "item" : Smallest unit of discrete item and it cannot hold other items inside.
- "pallet" : Entities that can store multiple smaller units of items
-
blocking
(bool , default:
False
)
–
If True, the source waits until it can put an item into the out edge.
-
out_edge_selection
(None or str or callable , default:
'FIRST_AVAILABLE'
)
–
Criterion or function for selecting the out edge.
Options include "RANDOM", "FIRST", "LAST", "ROUND_ROBIN", "FIRST_AVAILABLE".
- None: Used when out edge selection 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.
- "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 Source node is responsible for generating items that flow in the simulation model. It operates in two modes:
blocking and non-blocking.
when blocking=True
:
- After each inter_arrival_time
, the source generates an item.
- If the selected out edge is full, the source waits until space is available.
- Once space is available, the item is transferred to the selected edge.
- inter_arrival_time
must not be None
.
when blocking=False
:
- After each inter_arrival_time
, the source generates an item.
- If the selected out edge is full, the item is discarded immediately.
- If space is available, the item is transferred without waiting.
- inter_arrival_time
must not be 0.
Raises: |
-
ValueError
–
If inter_arrival_time is 0 in non-blocking mode or if out_edge_selection is not a valid type.
-
ValueError
–
If out_edge_selection is not a string or callable.
-
ValueError
–
If out_edges is not provided or has less than one edge.
-
ValueError
–
If in_edges is provided, as Source nodes should not have input edges.
-
ValueError
–
If out_edges already has an edge when trying to add a new one.
|
Output performance metrics:
The key performance metrics of the Source node is captured in stats
attribute (dict) during a simulation run.
last_state_change_time : Time when the state was last changed.
num_item_generated : Total number of items generated.
num_item_discarded : Total number of items discarded due to lack of space in out edge.
total_time_spent_in_states: Dictionary with total time spent in each state.
add_out_edges(edge)
Adds an out_edge to the source node. Raises an error if the source already has an
out_edge or if the edge already exists in the out_edges list.
Parameters: |
-
edge
(Edge Object )
–
The edge to be added as an out_edge.
|
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.
|