Vertical and Horizontal retrieval ( MRT ) on Tapes | Python3 program to print Vertical filling ; 2D matrix for vertical insertion on tapes ; It is used for checking whether tape is full or not ; It is used for calculating total retrieval time ; It is used for calculating mean retrieval time ; It is used for calculating mean retrieval time ; vertical insertion on tape ; initialize variables to 0 for each iteration ; Used for getting ' sum ' sizes of records in tape to determine whether tape is full or not ; if tape is not full ; check for ability of tapes to hold value ; initialize variables to 0 for each iteration ; display elements of tape ; calculating total retrieval time ; MRT formula ; calculating mean retrieval time using formula ; v . size ( ) is function of vector is used to get size of vector ; Driver Code ; store the size of records [ ] ; store the size of tape [ ] ; sorting of an array is required to attain greedy approach of algorithm
import numpy as np NEW_LINE def vertical_Fill ( records , tape , m , n ) : NEW_LINE INDENT v = np . zeros ( ( m , n ) ) ; NEW_LINE sum = 0 ; NEW_LINE Retrieval_Time = 0 ; NEW_LINE Mrt = None ; NEW_LINE z = 0 ; j = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for k in range ( i ) : NEW_LINE INDENT sum += v [ j ] [ k ] ; NEW_LINE DEDENT if ( sum + records [ z ] <= tape [ j ] ) : NEW_LINE INDENT v [ j ] [ i ] = records [ z ] ; NEW_LINE z += 1 ; NEW_LINE DEDENT DEDENT if ( v [ 2 ] [ i ] == 0 ) : NEW_LINE INDENT break ; NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT Retrieval_Time = 0 ; NEW_LINE print ( " tape " , i + 1 , " : ▁ [ " , end = " " ) ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( v [ i ] [ j ] != 0 ) : NEW_LINE INDENT print ( v [ i ] [ j ] , end = " ▁ " ) ; else : break ; print ( " ] " , end = " " ) ; NEW_LINE DEDENT DEDENT k = 0 ; NEW_LINE while v [ i ] [ k ] != 0 : NEW_LINE INDENT Retrieval_Time += v [ i ] [ k ] * ( j - k ) ; NEW_LINE k += 1 ; NEW_LINE DEDENT Mrt = Retrieval_Time / j ; NEW_LINE print ( " MRT ▁ : " , Mrt ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT records = [ 15 , 2 , 8 , 23 , 45 , 50 , 60 , 120 ] ; NEW_LINE tape = [ 25 , 80 , 160 ] ; NEW_LINE n = len ( records ) ; NEW_LINE m = len ( tape ) ; NEW_LINE records . sort ( ) ; NEW_LINE vertical_Fill ( records , tape , m , n ) ; NEW_LINE DEDENT