88from colorama import Fore , Style , init
99from tqdm import tqdm
1010
11+ from most_queue .constants import DEFAULT_NUM_STATES
1112from most_queue .random .utils .create import create_distribution
1213from most_queue .random .utils .load import calc_qs_load
1314from most_queue .sim .utils .qs_queue import QsQueueDeque , QsQueueList
@@ -39,7 +40,7 @@ def __init__(self, num_of_channels, buffer=None, verbose=True, buffer_type="list
3940 self .generator = np .random .default_rng ()
4041
4142 self .free_channels = self .n
42- self .num_of_states = 100000
43+ self .num_of_states = DEFAULT_NUM_STATES
4344 self .load = 0 # utilization factor
4445
4546 # to track the length of the continuous channel occupancy period:
@@ -131,11 +132,13 @@ def set_servers(self, params, kendall_notation: str = "M"):
131132 for _i in range (self .n )
132133 ]
133134
134- def calc_load (self ):
135- """
136- Calculates the load factor of the QS
135+ def calc_load (self ) -> float :
137136 """
137+ Calculates the load factor (utilization) of the queueing system.
138138
139+ Returns:
140+ float: The utilization factor (load) of the system, between 0 and 1.
141+ """
139142 return calc_qs_load (
140143 self .source_kendall_notation ,
141144 self .source_params ,
@@ -144,9 +147,13 @@ def calc_load(self):
144147 self .n ,
145148 )
146149
147- def send_task_to_channel (self , is_warm_start = False , tsk = None ):
150+ def send_task_to_channel (self , is_warm_start : bool = False , tsk = None ) -> None :
148151 """
149- Sends a job to the service channel
152+ Sends a job to an available service channel.
153+
154+ Args:
155+ is_warm_start: Whether this is a warm start scenario.
156+ tsk: Task to send. If None, a new task is created.
150157 """
151158
152159 if tsk is None :
@@ -169,9 +176,13 @@ def send_task_to_channel(self, is_warm_start=False, tsk=None):
169176
170177 break
171178
172- def send_task_to_queue (self , new_tsk = None ):
179+ def send_task_to_queue (self , new_tsk = None ) -> None :
173180 """
174- Send Task to Queue
181+ Send a task to the queue.
182+
183+ Args:
184+ new_tsk: Task to add to queue. If None, a new task is created.
185+ If buffer is full, the task will be dropped.
175186 """
176187
177188 if new_tsk is None :
@@ -188,9 +199,13 @@ def send_task_to_queue(self, new_tsk=None):
188199 self .dropped += 1
189200 self .in_sys -= 1
190201
191- def arrival (self , moment = None , ts = None ):
202+ def arrival (self , moment : float | None = None , ts = None ) -> None :
192203 """
193- Actions upon arrival of the job by the QS.
204+ Handle job arrival event in the queueing system.
205+
206+ Args:
207+ moment: Optional specific arrival moment. If None, uses current arrival_time.
208+ ts: Optional task object. If None, a new task is created.
194209 """
195210
196211 self .arrived += 1
@@ -215,9 +230,16 @@ def arrival(self, moment=None, ts=None):
215230 else : # there are free channels:
216231 self .send_task_to_channel (tsk = ts )
217232
218- def serving (self , c , is_network = False ):
233+ def serving (self , c : int , is_network : bool = False ):
219234 """
220- Actions upon receipt of a service job with - channel number
235+ Handle service completion event for a channel.
236+
237+ Args:
238+ c: Channel number that completed service.
239+ is_network: Whether this is part of a network simulation.
240+
241+ Returns:
242+ Task: The task that completed service.
221243 """
222244 time_to_end = self .servers [c ].time_to_end_service
223245 end_ts = self .servers [c ].end_service ()
@@ -244,9 +266,13 @@ def serving(self, c, is_network=False):
244266
245267 return end_ts
246268
247- def send_head_of_queue_to_channel (self , channel_num , is_network = False ):
269+ def send_head_of_queue_to_channel (self , channel_num : int , is_network : bool = False ) -> None :
248270 """
249- Send first Task (head of queue) to Channel
271+ Send the first task from the queue (head) to an available channel.
272+
273+ Args:
274+ channel_num: Channel number to send the task to.
275+ is_network: Whether this is part of a network simulation.
250276 """
251277 que_ts = self .queue .pop ()
252278
@@ -262,9 +288,9 @@ def send_head_of_queue_to_channel(self, channel_num, is_network=False):
262288 self .servers [channel_num ].start_service (que_ts , self .ttek )
263289 self .free_channels -= 1
264290
265- def run_one_step (self ):
291+ def run_one_step (self ) -> None :
266292 """
267- Run Open step of simulation
293+ Execute one step of the simulation (either an arrival or service completion event).
268294 """
269295
270296 num_of_server_earlier = - 1
@@ -286,9 +312,15 @@ def run_one_step(self):
286312 # Arrival
287313 self .arrival ()
288314
289- def run (self , total_served ) -> QueueResults :
315+ def run (self , total_served : int ) -> QueueResults :
290316 """
291- Run simulation process
317+ Run the complete simulation process.
318+
319+ Args:
320+ total_served: Number of jobs to serve before stopping the simulation.
321+
322+ Returns:
323+ QueueResults: Results object containing statistics from the simulation.
292324 """
293325 start = time .process_time ()
294326
@@ -322,29 +354,40 @@ def run(self, total_served) -> QueueResults:
322354
323355 return QueueResults (v = v , w = w , p = p , duration = self .time_spent , utilization = self .calc_load ())
324356
325- def refresh_busy_stat (self , new_a ) :
357+ def refresh_busy_stat (self , new_a : float ) -> None :
326358 """
327- Updating statistics of the busy period
359+ Update statistics of the busy period.
360+
361+ Args:
362+ new_a: New busy period duration to include in statistics.
328363 """
329364 self .busy = refresh_moments_stat (self .busy , new_a , self .busy_moments )
330365
331- def refresh_v_stat (self , new_a ) :
366+ def refresh_v_stat (self , new_a : float ) -> None :
332367 """
333- Updating statistics of sojourn times
368+ Update statistics of sojourn times.
369+
370+ Args:
371+ new_a: New sojourn time value to include in statistics.
334372 """
335373 self .v = refresh_moments_stat (self .v , new_a , self .served )
336374
337- def refresh_w_stat (self , new_a ) :
375+ def refresh_w_stat (self , new_a : float ) -> None :
338376 """
339- Updating statistics of wait times
377+ Update statistics of wait times.
378+
379+ Args:
380+ new_a: New waiting time value to include in statistics.
340381 """
341382 self .w = refresh_moments_stat (self .w , new_a , self .taked )
342383
343- def get_p (self ):
384+ def get_p (self ) -> list [ float ] :
344385 """
345- Returns a list with probabilities of QS states
346- p[j] - the probability that there will be exactly j jobs
347- in the QS at a random moment in time
386+ Returns a list with probabilities of queueing system states.
387+
388+ Returns:
389+ list[float]: List where p[j] is the probability that there will be exactly j jobs
390+ in the system at a random moment in time.
348391 """
349392 res = [0.0 ] * len (self .p )
350393 for j in range (0 , self .num_of_states ):
0 commit comments