Exemplo n.º 1
0
    def nextfit(self, joblist, index):
        ondeck = []
        # we start looking at the last index that we assigned a job
        c = index
        # we look at each job we have
        for job in joblist:
            # flag keeps track of if a job has been added or not
            flag = True
            # we then check each partition starting where we last added a job
            # only covers from index to the end of the partition list
            while c < len(self.partitions):
                # If the job fits inside, then we add it and flag this job to end the inner loop
                # moving on to the next job in the list
                if job.getsize() <= self.partitions[c].getsize(
                ) and flag and self.partitions[c].getstatus() != 'Loaded':
                    self.partitions[c].addjob(job)
                    if self.partitions[c].getfragmentation() != 0:
                        self.addpartition(
                            partition.partition(
                                name=("P" + str(len(self.partitions))),
                                size=(self.partitions[c].getsize() -
                                      job.getsize()),
                                address=str(
                                    int(self.partitions[c].getaddress()) +
                                    job.getsize())))
                        self.partitions[c].setsize(job.getsize())
                    # we set a job so now we want to mark the index as this one
                    index = c
                    flag = False
                c += 1
            # reset c to start from the front of the list
            c = 0
            # while loop covers from 0 to index we last set a job at
            while c < index:
                # If the job fits inside, then we add it and flag this job to end the inner loop
                # moving on to the next job in the list
                if job.getsize() <= self.partitions[c].getsize(
                ) and flag and self.partitions[c].getstatus() != 'Loaded':
                    self.partitions[c].addjob(job)
                    if self.partitions[c].getfragmentation() != 0:
                        self.addpartition(
                            partition.partition(
                                name=("P" + str(len(self.partitions))),
                                size=(self.partitions[c].getsize() -
                                      job.getsize()),
                                address=str(
                                    int(self.partitions[c].getaddress()) +
                                    job.getsize())))
                        self.partitions[c].setsize(job.getsize())
                    index = c
                    flag = False
                c += 1
            # Job was not added to any partition, it was too big or all partitions were full
            if flag:
                # add the job to the list of jobs that are waiting to be executed
                ondeck.append(job)

        return [ondeck, index]
Exemplo n.º 2
0
def createpartitions():
    tmp = []
    # create and append standard partitions to return
    tmp.append(partition.partition(name='P0', size=1500, address='0000'))
    tmp.append(partition.partition(name='P1', size=10, address='1500'))
    tmp.append(partition.partition(name='P2', size=500, address='1510'))
    tmp.append(partition.partition(name='P3', size=100, address='2010'))
    tmp.append(partition.partition(name='P4', size=25, address='2110'))
    return tmp
Exemplo n.º 3
0
 def worstfit(self, joblist):
     ondeck = []
     for job in joblist:
         target = ''
         fit = -1
         for part in self.partitions:
             # print(part.getsize() - job.getsize())
             if (part.getsize() - job.getsize() > fit) and (
                     part.getstatus() != 'Loaded') and (job.getsize() <=
                                                        part.getsize()):
                 fit = part.getsize() - job.getsize()
                 target = part
         if target == '':
             ondeck.append(job)
         else:
             target.addjob(job)
             if target.getfragmentation() != 0:
                 self.addpartition(
                     partition.partition(
                         name=("P" + str(len(self.partitions))),
                         size=(target.getsize() - job.getsize()),
                         address=str(
                             int(target.getaddress()) + job.getsize())))
                 target.setsize(job.getsize())
     return ondeck
Exemplo n.º 4
0
    def combinepartitions(self):
        total = 0
        tmpparts = []
        for part in self.partitions:
            if part.getstatus() != 'Loaded':
                # print(self.partitions[x].getsize())
                total += part.getsize()
                # self.partitions.remove(part)
            else:
                tmpparts.append(part)
        tmpparts.append(
            partition.partition(name=("P" + str(len(self.partitions))),
                                size=total))

        self.partitions = tmpparts
Exemplo n.º 5
0
 def firstfit(self, joblist):
     ondeck = []
     # we look at each job we have
     for job in joblist:
         # flag keeps track of if a job has been added or not
         flag = True
         # we then check each partition in order
         for x in range(len(self.partitions)):
             # If the job fits inside, then we add it and flag this job to end the inner loop
             # moving on to the next job in the list
             if job.getsize() <= self.partitions[x].getsize(
             ) and flag and self.partitions[x].getstatus() != 'Loaded':
                 # add the job to the partition
                 self.partitions[x].addjob(job)
                 # if our fragmentation is 0, check prevents creating a new partition with 0 size
                 if self.partitions[x].getfragmentation != 0:
                     # create a new partition for the empty memory that is caused by the job added add a name
                     # using the length of the current partition list (length is always one number above the last
                     # name because it is zero indexed) add a size (the difference between the partition we added
                     # the job to and the job size itself) the address is just the old address of the partition we
                     # added the job to plus the job size
                     self.addpartition(
                         partition.partition(
                             name=("P" + str(len(self.partitions))),
                             size=(self.partitions[x].getsize() -
                                   job.getsize()),
                             address=str(
                                 int(self.partitions[x].getaddress()) +
                                 job.getsize())))
                     # because we created a new partition for the unused memory, we need to reset the size of the
                     # current partition that we added the job to it just becomes the size of the job itself
                     self.partitions[x].setsize(job.getsize())
                 # the job was added so we change our flag
                 flag = False
         # Job was not added to any partition, it was too big or all partitions were full
         if flag:
             # add job to the ondeck list
             ondeck.append(job)
     # return waiting jobs
     return ondeck