
"""simple docstring"""





from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


UpperCamelCase_					:						Optional[int]				= logging.get_logger(__name__)

# General docstring
UpperCamelCase_					:						Optional[int]				= '''RegNetConfig'''

# Base docstring
UpperCamelCase_					:						Tuple				= '''facebook/regnet-y-040'''
UpperCamelCase_					:						List[str]				= [1, 1088, 7, 7]

# Image classification docstring
UpperCamelCase_					:						List[str]				= '''facebook/regnet-y-040'''
UpperCamelCase_					:						Optional[int]				= '''tabby, tabby cat'''

UpperCamelCase_					:						Tuple				= [
    '''facebook/regnet-y-040''',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]



class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					Tuple       ,   _snake_case						:					int       ,   _snake_case						:					int = 3       ,   _snake_case						:					int = 1       ,   _snake_case						:					int = 1       ,   _snake_case						:					Optional[str] = "relu"       ,   **_snake_case						:					List[Any]       ,   )      -> List[str]:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								# The padding and conv has been verified in
								# https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
								A_				 =						tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2	)
								A_				 =						tf.keras.layers.ConvaD(
								    filters=_snake_case       ,   kernel_size=_snake_case       ,   strides=_snake_case       ,   padding="VALID"       ,   groups=_snake_case       ,   use_bias=_snake_case       ,   name="convolution"       ,   )
								A_				 =						tf.keras.layers.BatchNormalization(epsilon=1e-5       ,   momentum=0.9       ,   name="normalization"	)
								A_				 =						ACTaFN[activation] if activation is not None else tf.identity






			def      lowerCamelCase__     (				self						:					Union[str, Any]       ,   _snake_case						:					Any	)      -> Tuple:







								"""simple docstring"""
								A_				 =						self.convolution(self.padding(_snake_case	)	)
								A_				 =						self.normalization(_snake_case	)
								A_				 =						self.activation(_snake_case	)
								return hidden_state





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					Optional[int]       ,   _snake_case						:					RegNetConfig       ,   **_snake_case						:					List[Any]	)      -> str:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						config.num_channels
								A_				 =						TFRegNetConvLayer(
								    out_channels=config.embedding_size       ,   kernel_size=3       ,   stride=2       ,   activation=config.hidden_act       ,   name="embedder"       ,   )






			def      lowerCamelCase__     (				self						:					List[str]       ,   _snake_case						:					Union[str, Any]	)      -> Union[str, Any]:







								"""simple docstring"""
								A_				 =						shape_list(_snake_case	)[1]
								if tf.executing_eagerly() and num_channels != self.num_channels:
													raise ValueError(
													    "Make sure that the channel dimension of the pixel values match with the one set in the configuration."	)

								# When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
								# So change the input format from `NCHW` to `NHWC`.
								# shape = (batch_size, in_height, in_width, in_channels=num_channels)
								A_				 =						tf.transpose(_snake_case       ,   perm=(0, 2, 3, 1)	)
								A_				 =						self.embedder(_snake_case	)
								return hidden_state





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					List[str]       ,   _snake_case						:					int       ,   _snake_case						:					int = 2       ,   **_snake_case						:					Any	)      -> int:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						tf.keras.layers.ConvaD(
								    filters=_snake_case       ,   kernel_size=1       ,   strides=_snake_case       ,   use_bias=_snake_case       ,   name="convolution"	)
								A_				 =						tf.keras.layers.BatchNormalization(epsilon=1e-5       ,   momentum=0.9       ,   name="normalization"	)






			def      lowerCamelCase__     (				self						:					Optional[int]       ,   _snake_case						:					tf.Tensor       ,   _snake_case						:					bool = False	)      -> tf.Tensor:







								"""simple docstring"""
								return self.normalization(self.convolution(_snake_case	)       ,   training=_snake_case	)





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					str       ,   _snake_case						:					int       ,   _snake_case						:					int       ,   **_snake_case						:					str	)      -> Dict:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						tf.keras.layers.GlobalAveragePoolingaD(keepdims=_snake_case       ,   name="pooler"	)
								A_				 =						[
								    tf.keras.layers.ConvaD(filters=_snake_case       ,   kernel_size=1       ,   activation="relu"       ,   name="attention.0"	),
								    tf.keras.layers.ConvaD(filters=_snake_case       ,   kernel_size=1       ,   activation="sigmoid"       ,   name="attention.2"	),
								]






			def      lowerCamelCase__     (				self						:					int       ,   _snake_case						:					Any	)      -> str:







								"""simple docstring"""
								# [batch_size, h, w, num_channels] -> [batch_size, 1, 1, num_channels]
								A_				 =						self.pooler(_snake_case	)
								for layer_module in self.attention:
													A_				 =						layer_module(_snake_case	)
								A_				 =						hidden_state * pooled
								return hidden_state





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					str       ,   _snake_case						:					RegNetConfig       ,   _snake_case						:					int       ,   _snake_case						:					int       ,   _snake_case						:					int = 1       ,   **_snake_case						:					Union[str, Any]	)      -> List[str]:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						in_channels != out_channels or stride != 1
								A_				 =						max(1       ,   out_channels // config.groups_width	)
								A_				 =						(
								    TFRegNetShortCut(_snake_case       ,   stride=_snake_case       ,   name="shortcut"	)
								    if should_apply_shortcut
								    else tf.keras.layers.Activation("linear"       ,   name="shortcut"	)
								)
								# `self.layers` instead of `self.layer` because that is a reserved argument.
								A_				 =						[
								    TFRegNetConvLayer(_snake_case       ,   kernel_size=1       ,   activation=config.hidden_act       ,   name="layer.0"	),
								    TFRegNetConvLayer(
								        _snake_case       ,   stride=_snake_case       ,   groups=_snake_case       ,   activation=config.hidden_act       ,   name="layer.1"	),
								    TFRegNetConvLayer(_snake_case       ,   kernel_size=1       ,   activation=_snake_case       ,   name="layer.2"	),
								]
								A_				 =						ACTaFN[config.hidden_act]






			def      lowerCamelCase__     (				self						:					Tuple       ,   _snake_case						:					Union[str, Any]	)      -> str:







								"""simple docstring"""
								A_				 =						hidden_state
								for layer_module in self.layers:
													A_				 =						layer_module(_snake_case	)
								A_				 =						self.shortcut(_snake_case	)
								hidden_state += residual
								A_				 =						self.activation(_snake_case	)
								return hidden_state





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					Dict       ,   _snake_case						:					RegNetConfig       ,   _snake_case						:					int       ,   _snake_case						:					int       ,   _snake_case						:					int = 1       ,   **_snake_case						:					Tuple	)      -> Optional[Any]:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						in_channels != out_channels or stride != 1
								A_				 =						max(1       ,   out_channels // config.groups_width	)
								A_				 =						(
								    TFRegNetShortCut(_snake_case       ,   stride=_snake_case       ,   name="shortcut"	)
								    if should_apply_shortcut
								    else tf.keras.layers.Activation("linear"       ,   name="shortcut"	)
								)
								A_				 =						[
								    TFRegNetConvLayer(_snake_case       ,   kernel_size=1       ,   activation=config.hidden_act       ,   name="layer.0"	),
								    TFRegNetConvLayer(
								        _snake_case       ,   stride=_snake_case       ,   groups=_snake_case       ,   activation=config.hidden_act       ,   name="layer.1"	),
								    TFRegNetSELayer(_snake_case       ,   reduced_channels=int(round(in_channels / 4	)	)       ,   name="layer.2"	),
								    TFRegNetConvLayer(_snake_case       ,   kernel_size=1       ,   activation=_snake_case       ,   name="layer.3"	),
								]
								A_				 =						ACTaFN[config.hidden_act]






			def      lowerCamelCase__     (				self						:					Optional[Any]       ,   _snake_case						:					Optional[int]	)      -> List[str]:







								"""simple docstring"""
								A_				 =						hidden_state
								for layer_module in self.layers:
													A_				 =						layer_module(_snake_case	)
								A_				 =						self.shortcut(_snake_case	)
								hidden_state += residual
								A_				 =						self.activation(_snake_case	)
								return hidden_state





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					Optional[Any]       ,   _snake_case						:					RegNetConfig       ,   _snake_case						:					int       ,   _snake_case						:					int       ,   _snake_case						:					int = 2       ,   _snake_case						:					int = 2       ,   **_snake_case						:					Optional[Any]	)      -> Optional[Any]:







								"""simple docstring"""
								super().__init__(**_snake_case	)

								A_				 =						TFRegNetXLayer if config.layer_type == "x" else TFRegNetYLayer
								A_				 =						[
								    # downsampling is done in the first layer with stride of 2
								    layer(_snake_case       ,   _snake_case       ,   _snake_case       ,   stride=_snake_case       ,   name="layers.0"	),
								    *[layer(_snake_case       ,   _snake_case       ,   _snake_case       ,   name=F'layers.{i+1}'	) for i in range(depth - 1	)],
								]






			def      lowerCamelCase__     (				self						:					Dict       ,   _snake_case						:					str	)      -> List[Any]:







								"""simple docstring"""
								for layer_module in self.layers:
													A_				 =						layer_module(_snake_case	)
								return hidden_state





class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			def __init__(				self						:					Union[str, Any]       ,   _snake_case						:					RegNetConfig       ,   **_snake_case						:					int	)      -> List[Any]:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						[]
								# based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
								self.stages.append(
								    TFRegNetStage(
								        _snake_case       ,   config.embedding_size       ,   config.hidden_sizes[0]       ,   stride=2 if config.downsample_in_first_stage else 1       ,   depth=config.depths[0]       ,   name="stages.0"       ,   )	)
								A_				 =						zip(config.hidden_sizes       ,   config.hidden_sizes[1:]	)
								for i, ((in_channels, out_channels), depth) in enumerate(zip(_snake_case       ,   config.depths[1:]	)	):
													self.stages.append(TFRegNetStage(_snake_case       ,   _snake_case       ,   _snake_case       ,   depth=_snake_case       ,   name=F'stages.{i+1}'	)	)






			def      lowerCamelCase__     (				self						:					Any       ,   _snake_case						:					tf.Tensor       ,   _snake_case						:					bool = False       ,   _snake_case						:					bool = True	)      -> TFBaseModelOutputWithNoAttention:







								"""simple docstring"""
								A_				 =						() if output_hidden_states else None

								for stage_module in self.stages:
													if output_hidden_states:
																		A_				 =						hidden_states + (hidden_state,)

													A_				 =						stage_module(_snake_case	)

								if output_hidden_states:
													A_				 =						hidden_states + (hidden_state,)

								if not return_dict:
													return tuple(v for v in [hidden_state, hidden_states] if v is not None	)

								return TFBaseModelOutputWithNoAttention(last_hidden_state=_snake_case       ,   hidden_states=_snake_case	)





@keras_serializable
class __lowerCAmelCase				(					tf.keras.layers.Layer      ):




			"""simple docstring"""







			snake_case	      =				RegNetConfig




			def __init__(				self						:					Optional[int]       ,   _snake_case						:					Optional[Any]       ,   **_snake_case						:					List[Any]	)      -> Any:







								"""simple docstring"""
								super().__init__(**_snake_case	)
								A_				 =						config
								A_				 =						TFRegNetEmbeddings(_snake_case       ,   name="embedder"	)
								A_				 =						TFRegNetEncoder(_snake_case       ,   name="encoder"	)
								A_				 =						tf.keras.layers.GlobalAveragePoolingaD(keepdims=_snake_case       ,   name="pooler"	)






			@unpack_inputs
			def      lowerCamelCase__     (				self						:					Union[str, Any]       ,   _snake_case						:					tf.Tensor       ,   _snake_case						:					Optional[bool] = None       ,   _snake_case						:					Optional[bool] = None       ,   _snake_case						:					bool = False       ,   )      -> TFBaseModelOutputWithPoolingAndNoAttention:







								"""simple docstring"""
								A_				 =						(
								    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
								)
								A_				 =						return_dict if return_dict is not None else self.config.use_return_dict

								A_				 =						self.embedder(_snake_case       ,   training=_snake_case	)

								A_				 =						self.encoder(
								    _snake_case       ,   output_hidden_states=_snake_case       ,   return_dict=_snake_case       ,   training=_snake_case	)

								A_				 =						encoder_outputs[0]
								A_				 =						self.pooler(_snake_case	)

								# Change to NCHW output format have uniformity in the modules
								A_				 =						tf.transpose(_snake_case       ,   perm=(0, 3, 1, 2)	)
								A_				 =						tf.transpose(_snake_case       ,   perm=(0, 3, 1, 2)	)

								# Change the other hidden state outputs to NCHW as well
								if output_hidden_states:
													A_				 =						tuple([tf.transpose(_snake_case       ,   perm=(0, 3, 1, 2)	) for h in encoder_outputs[1]]	)

								if not return_dict:
													return (last_hidden_state, pooled_output) + encoder_outputs[1:]

								return TFBaseModelOutputWithPoolingAndNoAttention(
								    last_hidden_state=_snake_case       ,   pooler_output=_snake_case       ,   hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states       ,   )





class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			snake_case	      =				RegNetConfig
			snake_case	      =				"regnet"
			snake_case	      =				"pixel_values"




			@property
			def      lowerCamelCase__     (				self						:					str	)      -> List[Any]:







								"""simple docstring"""
								return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)       ,   dtype=tf.floataa	)}





UpperCamelCase_					:						Dict				= R'''
    Parameters:
    This model is a Tensorflow
    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a
    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and
    behavior.
        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
'''

UpperCamelCase_					:						Optional[int]				= R'''
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConveNextImageProcessor.__call__`] for details.
        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''



@add_start_docstrings(
    "The bare RegNet model outputting raw features without any specific head on top."     ,				_lowercase     ,				)
class __lowerCAmelCase				(					_lowercase      ):




			"""simple docstring"""







			def __init__(				self						:					Optional[Any]       ,   _snake_case						:					RegNetConfig       ,   *_snake_case						:					Any       ,   **_snake_case						:					int	)      -> int:







								"""simple docstring"""
								super().__init__(_snake_case       ,   *_snake_case       ,   **_snake_case	)
								A_				 =						TFRegNetMainLayer(_snake_case       ,   name="regnet"	)






			@unpack_inputs
			@add_start_docstrings_to_model_forward(_snake_case	)
			@add_code_sample_docstrings(
			    checkpoint=_CHECKPOINT_FOR_DOC       ,   output_type=_snake_case       ,   config_class=_CONFIG_FOR_DOC       ,   modality="vision"       ,   expected_output=_EXPECTED_OUTPUT_SHAPE       ,   )
			def      lowerCamelCase__     (				self						:					Optional[Any]       ,   _snake_case						:					tf.Tensor       ,   _snake_case						:					Optional[bool] = None       ,   _snake_case						:					Optional[bool] = None       ,   _snake_case						:					Dict=False       ,   )      -> Union[TFBaseModelOutputWithPoolingAndNoAttention, Tuple[tf.Tensor]]:







								"""simple docstring"""
								A_				 =						(
								    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
								)
								A_				 =						return_dict if return_dict is not None else self.config.use_return_dict

								A_				 =						self.regnet(
								    pixel_values=_snake_case       ,   output_hidden_states=_snake_case       ,   return_dict=_snake_case       ,   training=_snake_case       ,   )
								if not return_dict:
													return (outputs[0],) + outputs[1:]

								return TFBaseModelOutputWithPoolingAndNoAttention(
								    last_hidden_state=outputs.last_hidden_state       ,   pooler_output=outputs.pooler_output       ,   hidden_states=outputs.hidden_states       ,   )





@add_start_docstrings(
    "\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    "     ,				_lowercase     ,				)
class __lowerCAmelCase				(					_lowercase     ,				_lowercase      ):




			"""simple docstring"""







			def __init__(				self						:					int       ,   _snake_case						:					RegNetConfig       ,   *_snake_case						:					Optional[int]       ,   **_snake_case						:					Tuple	)      -> Dict:







								"""simple docstring"""
								super().__init__(_snake_case       ,   *_snake_case       ,   **_snake_case	)
								A_				 =						config.num_labels
								A_				 =						TFRegNetMainLayer(_snake_case       ,   name="regnet"	)
								# classification head
								A_				 =						[
								    tf.keras.layers.Flatten(),
								    tf.keras.layers.Dense(config.num_labels       ,   name="classifier.1"	) if config.num_labels > 0 else tf.identity,
								]






			@unpack_inputs
			@add_start_docstrings_to_model_forward(_snake_case	)
			@add_code_sample_docstrings(
			    checkpoint=_IMAGE_CLASS_CHECKPOINT       ,   output_type=_snake_case       ,   config_class=_CONFIG_FOR_DOC       ,   expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,   )
			def      lowerCamelCase__     (				self						:					Optional[int]       ,   _snake_case						:					tf.Tensor = None       ,   _snake_case						:					tf.Tensor = None       ,   _snake_case						:					bool = None       ,   _snake_case						:					bool = None       ,   _snake_case						:					Optional[Any]=False       ,   )      -> Union[TFSequenceClassifierOutput, Tuple[tf.Tensor]]:







								"""simple docstring"""
								A_				 =						(
								    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
								)
								A_				 =						return_dict if return_dict is not None else self.config.use_return_dict

								A_				 =						self.regnet(
								    _snake_case       ,   output_hidden_states=_snake_case       ,   return_dict=_snake_case       ,   training=_snake_case	)

								A_				 =						outputs.pooler_output if return_dict else outputs[1]

								A_				 =						self.classifier[0](_snake_case	)
								A_				 =						self.classifier[1](_snake_case	)

								A_				 =						None if labels is None else self.hf_compute_loss(labels=_snake_case       ,   logits=_snake_case	)

								if not return_dict:
													A_				 =						(logits,) + outputs[2:]
													return ((loss,) + output) if loss is not None else output

								return TFSequenceClassifierOutput(loss=_snake_case       ,   logits=_snake_case       ,   hidden_states=outputs.hidden_states	)






"""simple docstring"""





from collections import deque



class __lowerCAmelCase				:




			"""simple docstring"""







			def __init__(				self						:					Optional[Any]       ,   _snake_case						:					str       ,   _snake_case						:					int       ,   _snake_case						:					int	)      -> None:







								"""simple docstring"""
								A_				 =						process_name  # process name
								A_				 =						arrival_time  # arrival time of the process
								# completion time of finished process or last interrupted time
								A_				 =						arrival_time
								A_				 =						burst_time  # remaining burst time
								A_				 =						0  # total time of the process wait in ready queue
								A_				 =						0  # time from arrival time to completion time





class __lowerCAmelCase				:




			"""simple docstring"""







			def __init__(				self						:					str       ,   _snake_case						:					int       ,   _snake_case						:					list[int]       ,   _snake_case						:					deque[Process]       ,   _snake_case						:					int       ,   )      -> None:







								"""simple docstring"""
								# total number of mlfq's queues
								A_				 =						number_of_queues
								# time slice of queues that round robin algorithm applied
								A_				 =						time_slices
								# unfinished process is in this ready_queue
								A_				 =						queue
								# current time
								A_				 =						current_time
								# finished process is in this sequence queue
								A_				 =						deque()




			def      lowerCamelCase__     (				self						:					List[str]	)      -> list[str]:







								"""simple docstring"""
								A_				 =						[]
								for i in range(len(self.finish_queue	)	):
													sequence.append(self.finish_queue[i].process_name	)
								return sequence




			def      lowerCamelCase__     (				self						:					str       ,   _snake_case						:					list[Process]	)      -> list[int]:







								"""simple docstring"""
								A_				 =						[]
								for i in range(len(_snake_case	)	):
													waiting_times.append(queue[i].waiting_time	)
								return waiting_times




			def      lowerCamelCase__     (				self						:					Tuple       ,   _snake_case						:					list[Process]	)      -> list[int]:







								"""simple docstring"""
								A_				 =						[]
								for i in range(len(_snake_case	)	):
													turnaround_times.append(queue[i].turnaround_time	)
								return turnaround_times




			def      lowerCamelCase__     (				self						:					Tuple       ,   _snake_case						:					list[Process]	)      -> list[int]:







								"""simple docstring"""
								A_				 =						[]
								for i in range(len(_snake_case	)	):
													completion_times.append(queue[i].stop_time	)
								return completion_times




			def      lowerCamelCase__     (				self						:					Optional[int]       ,   _snake_case						:					deque[Process]	)      -> list[int]:







								"""simple docstring"""
								return [q.burst_time for q in queue]




			def      lowerCamelCase__     (				self						:					int       ,   _snake_case						:					Process	)      -> int:







								"""simple docstring"""
								process.waiting_time += self.current_time - process.stop_time
								return process.waiting_time




			def      lowerCamelCase__     (				self						:					Dict       ,   _snake_case						:					deque[Process]	)      -> deque[Process]:







								"""simple docstring"""
								A_				 =						deque()  # sequence deque of finished process
								while len(_snake_case	) != 0:
													A_				 =						ready_queue.popleft()  # current process

													# if process's arrival time is later than current time, update current time
													if self.current_time < cp.arrival_time:
																		self.current_time += cp.arrival_time

													# update waiting time of current process
													self.update_waiting_time(_snake_case	)
													# update current time
													self.current_time += cp.burst_time
													# finish the process and set the process's burst-time 0
													A_				 =						0
													# set the process's turnaround time because it is finished
													A_				 =						self.current_time - cp.arrival_time
													# set the completion time
													A_				 =						self.current_time
													# add the process to queue that has finished queue
													finished.append(_snake_case	)

								self.finish_queue.extend(_snake_case	)  # add finished process to finish queue
								# FCFS will finish all remaining processes
								return finished




			def      lowerCamelCase__     (				self						:					List[str]       ,   _snake_case						:					deque[Process]       ,   _snake_case						:					int	)      -> tuple[deque[Process], deque[Process]]:







								"""simple docstring"""
								A_				 =						deque()  # sequence deque of terminated process
								# just for 1 cycle and unfinished processes will go back to queue
								for _ in range(len(_snake_case	)	):
													A_				 =						ready_queue.popleft()  # current process

													# if process's arrival time is later than current time, update current time
													if self.current_time < cp.arrival_time:
																		self.current_time += cp.arrival_time

													# update waiting time of unfinished processes
													self.update_waiting_time(_snake_case	)
													# if the burst time of process is bigger than time-slice
													if cp.burst_time > time_slice:
																		# use CPU for only time-slice
																		self.current_time += time_slice
																		# update remaining burst time
																		cp.burst_time -= time_slice
																		# update end point time
																		A_				 =						self.current_time
																		# locate the process behind the queue because it is not finished
																		ready_queue.append(_snake_case	)
													else:
																		# use CPU for remaining burst time
																		self.current_time += cp.burst_time
																		# set burst time 0 because the process is finished
																		A_				 =						0
																		# set the finish time
																		A_				 =						self.current_time
																		# update the process' turnaround time because it is finished
																		A_				 =						self.current_time - cp.arrival_time
																		# add the process to queue that has finished queue
																		finished.append(_snake_case	)

								self.finish_queue.extend(_snake_case	)  # add finished process to finish queue
								# return finished processes queue and remaining processes queue
								return finished, ready_queue






			def      lowerCamelCase__     (				self						:					Any	)      -> deque[Process]:







								"""simple docstring"""

								#  all queues except last one have round_robin algorithm
								for i in range(self.number_of_queues - 1	):
													A_ ,    A_				 =						self.round_robin(
													    self.ready_queue       ,   self.time_slices[i]	)
								#  the last queue has first_come_first_served algorithm
								self.first_come_first_served(self.ready_queue	)

								return self.finish_queue


if __name__ == "__main__":
		import doctest

		UpperCamelCase_					:						Tuple				= Process('''P1''', 0, 53)
		UpperCamelCase_					:						List[Any]				= Process('''P2''', 0, 17)
		UpperCamelCase_					:						Optional[int]				= Process('''P3''', 0, 68)
		UpperCamelCase_					:						Union[str, Any]				= Process('''P4''', 0, 24)
		UpperCamelCase_					:						Any				= 3
		UpperCamelCase_					:						List[str]				= [17, 25]
		UpperCamelCase_					:						List[str]				= deque([Pa, Pa, Pa, Pa])

		if len(time_slices) != number_of_queues - 1:
				raise SystemExit(0)

		doctest.testmod(extraglobs={'''queue''': deque([Pa, Pa, Pa, Pa])})

		UpperCamelCase_					:						str				= Process('''P1''', 0, 53)
		UpperCamelCase_					:						Dict				= Process('''P2''', 0, 17)
		UpperCamelCase_					:						List[Any]				= Process('''P3''', 0, 68)
		UpperCamelCase_					:						int				= Process('''P4''', 0, 24)
		UpperCamelCase_					:						Dict				= 3
		UpperCamelCase_					:						str				= [17, 25]
		UpperCamelCase_					:						Optional[int]				= deque([Pa, Pa, Pa, Pa])
		UpperCamelCase_					:						str				= MLFQ(number_of_queues, time_slices, queue, 0)
		UpperCamelCase_					:						int				= mlfq.multi_level_feedback_queue()

		# print total waiting times of processes(P1, P2, P3, P4)
		print(
		    F"""waiting time:\
        \t\t\t{MLFQ.calculate_waiting_time(mlfq, [Pa, Pa, Pa, Pa])}"""
		)
		# print completion times of processes(P1, P2, P3, P4)
		print(
		    F"""completion time:\
        \t\t{MLFQ.calculate_completion_time(mlfq, [Pa, Pa, Pa, Pa])}"""
		)
		# print total turnaround times of processes(P1, P2, P3, P4)
		print(
		    F"""turnaround time:\
        \t\t{MLFQ.calculate_turnaround_time(mlfq, [Pa, Pa, Pa, Pa])}"""
		)
		# print sequence of finished processes
		print(
		    F"""sequence of finished processes:\
        {mlfq.calculate_sequence_of_finish_queue()}"""
		)




