Vertical and Horizontal retrieval ( MRT ) on Tapes | Python3 program to print Horizontal filling ; 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 ; vector is used because n number of records can insert in one tape with size constraint ; Null vector obtained to use fresh vector 'v ; initialize variables to 0 for each iteration ; sum is used for checking whether i 'th tape is full or not ; check sum less than size of tape ; increment in j for next record ; 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 tapes [ ] ; sorting of an array is required to attain greedy approach of algorithm
def horizontalFill ( records , tape , nt ) : NEW_LINE INDENT sum = 0 ; NEW_LINE Retrieval_Time = 0 ; NEW_LINE current = 0 ; NEW_LINE v = [ ] ; NEW_LINE for i in range ( nt ) : NEW_LINE DEDENT ' NEW_LINE INDENT v . clear ( ) ; NEW_LINE Retrieval_Time = 0 ; NEW_LINE sum = 0 ; NEW_LINE print ( " tape " , i + 1 , " : ▁ [ ▁ " , end = " " ) ; NEW_LINE sum += records [ current ] ; NEW_LINE while ( sum <= tape [ i ] ) : NEW_LINE INDENT print ( records [ current ] , end = " ▁ " ) ; NEW_LINE v . append ( records [ current ] ) ; NEW_LINE current += 1 ; NEW_LINE sum += records [ current ] ; print ( " ] " , end = " " ) ; NEW_LINE DEDENT for i in range ( len ( v ) ) : NEW_LINE INDENT Retrieval_Time += v [ i ] * ( len ( v ) - i ) ; NEW_LINE DEDENT Mrt = Retrieval_Time / len ( v ) ; NEW_LINE print ( " tMRT ▁ : " , Mrt ) ; NEW_LINE 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 horizontalFill ( records , tape , m ) ; NEW_LINE DEDENT