Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.01 KB | None | 0 0
  1. import random
  2.  
  3. class FCFS:
  4.     pamiec = []
  5.     strony = []
  6.    
  7.     def __init__(self, ilosc_ramek, Lista):
  8.        
  9.         self.ilosc_ramek = ilosc_ramek
  10.  
  11.         for i in range(ilosc_ramek):
  12.             self.pamiec.append([])
  13.  
  14.         #for i in range(ilosc_odwolan):
  15.            # self.strony.append(random.randint(1,odwolania))
  16.         self.strony = Lista
  17.     def Symulacja(self):
  18.  
  19.         iterator_strony = 0
  20.         iterator_ramki = 0
  21.         iteracje = 0
  22.         blad = 0
  23.  
  24.         print self.strony
  25.  
  26.         while(not iterator_strony is len(self.strony)):
  27.             if(iterator_ramki != len(self.pamiec)):
  28.                 if(iteracje > 0):
  29.                     if(all([False for elem in self.pamiec if self.strony[iterator_strony] in elem])):
  30.                        blad += 1
  31.                        self.pamiec[iterator_ramki][0] = self.strony[iterator_strony]
  32.                        iterator_strony += 1
  33.                        iterator_ramki += 1
  34.                    
  35.                        print self.pamiec
  36.                     else:
  37.                         iterator_strony += 1
  38.                         print self.pamiec
  39.                 else:
  40.                     self.pamiec[iterator_ramki].append(self.strony[iterator_strony])
  41.                     blad += 1
  42.                     iterator_ramki += 1
  43.                     iterator_strony += 1
  44.                     print self.pamiec
  45.             else:
  46.                 iterator_ramki = 0
  47.                 iteracje += 1
  48.         print "Brak: " + str(blad)
  49.         return self.pamiec
  50.          
  51. class OPT:
  52.     ilosc_ramek = 0
  53.     pamiec = []
  54.     strony = []
  55.  
  56.     pamiec_temp = FCFS.pamiec[:]
  57.    
  58.     print pamiec_temp
  59.  
  60.  
  61.     def __init__(self, ilosc_ramek, Lista):
  62.         self.ilosc_ramek = ilosc_ramek
  63.         self.pamiec = strony[:]
  64.  
  65.         for i in range(ilosc_ramek):
  66.             pamiec.append([])
  67.     #def NajmniejUzywane(ramka1, ramka2, ramka3):
  68.  
  69.     def Symulacja(self):
  70.         ilosc = self.ilosc_ramek
  71.         uzywane = 10
  72.  
  73.         iterator_strony = 0
  74.         iterator_ramki = 0
  75.  
  76.  
  77.         while (not iterator_strony != len(self.strony)):
  78.             if(iterator_ramki != len(self.pamiec)):
  79.                 if(iteracje > 0):
  80.                     #if[
  81.                     print "siema
  82.  
  83.                else:
  84.                    self.pamiec[iterator_ramki].append(self.strony[iterator_strony])
  85.                    blad += 1
  86.                    iterator_ramki += 1
  87.                    iterator_strony += 1
  88.                    print self.pamiec
  89.            else:
  90.                iterator_ramki = 0
  91.                iteracje += 1
  92.  
  93. class LRU:
  94.    pamiec = []
  95.    strony = []
  96.    ilosc_ramek = 0
  97.  
  98.  
  99.    def __init__(self, Lista, ilosc_ramek):
  100.        strony = Lista[:]
  101.        self.ilosc_ramek = ilosc_ramek
  102.  
  103.        pamiec = [[] for pusty in range(self.ilosc_ramek)]
  104.    def Symulacja(self):
  105.        
  106.        iterator_ramki = 0
  107.        iterator_strony = 0
  108.  
  109.        while
  110.  
  111.  
  112.  
  113. x = FCFS(3, [1,2,3,4,1,2,5,1,2,3,4,5])
  114. x.Symulacja()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement