Beispiel #1
0
    def calc(self):
        self.int_le3yon_a7md_m7mod()
        self.quantum = round(self.quantum)
        if self.quantum == 0:  #not givven
            self.setQuantum()

        self.calcQuantums()
        self.Sort('arrival_time')
        self.currentTime = (
            self.list_process[0]).arrival_time  #begin when first process come
        self.pushIfcamed(self.list_process, self.queue, self.currentTime, 1)

        #(self.queue).append(self.list_process[0]) #push first process to queue
        while True:
            if self.isAllEnded():
                break
            if len(self.queue) != 0:
                if (self.queue[0]).elementsNumber > 0 and (
                        self.queue[0]).elementsNumber <= 1:
                    a = element()
                    a.p = self.queue[0]
                    a.start = self.currentTime
                    a.end = self.currentTime + int(self.quantum * (
                        (self.queue[0]).elementsNumber))
                    a.duration = a.end - a.start
                    (self.list_element).append(a)
                    (self.queue[0]).state = 'ended'
                    del self.queue[0]
                    self.currentTime = a.end
                    self.pushIfcamed(self.list_process, self.queue,
                                     self.currentTime, a.duration)

                elif (self.queue[0]).elementsNumber > 1:
                    a = element()
                    a.p = self.queue[0]
                    a.start = self.currentTime
                    a.end = self.currentTime + self.quantum
                    a.duration = self.quantum
                    (self.list_element).append(a)
                    (self.queue[0]).elementsNumber -= 1
                    self.currentTime += self.quantum
                    self.pushIfcamed(self.list_process, self.queue,
                                     self.currentTime, self.quantum)
                    (self.queue).append(self.queue[0])
                    del self.queue[0]
            else:
                self.currentTime += 1
                self.pushIfcamed(self.list_process, self.queue,
                                 self.currentTime, 1)
Beispiel #2
0
 def addElement(self, start, proc):
     a = element()
     a.start = start
     a.end = proc.burst_time + start
     a.p = proc
     a.duration = a.start - a.end
     self.list_element.append(a)
Beispiel #3
0
 def empty(self):
     if len(self.list_element) != 0:
         for i in range(len(self.list_element)):
             if self.list_element[i] != self.list_element[-1]:
                 if self.list_element[i].end != self.list_element[i +
                                                                  1].start:
                     a = element()
                     a.p.name = 'empty'
                     a.start = self.list_element[i].end
                     a.end = self.list_element[i + 1].start
                     self.list_element.insert(i + 1, a)
Beispiel #4
0
    def calc(self):
        self.Sort()
        if self.preemptive == 0:
            self.calc_non_p()

        else:
            current_list_p = []
            t = []  # time
            current_p = None
            for q in self.list_process:
                t.append(q.arrival_time)
            t = list(dict.fromkeys(t))  # remove dub
            t.sort()
            i = 0
            x = len(t)
            while i < x:  # this loop iterates on every arrival_time and at the end of each process
                for j in self.list_process:  # 7ad geh  ?
                    if t[i] == j.arrival_time:
                        current_list_p.append(j)  # tab t3ala ya m3lm
                        current_list_p.sort(
                            key=operator.attrgetter('burst_time'))
                if current_p is None:  # may happen at end of process or at arrival_time
                    if len(current_list_p
                           ) != 0:  # because of the last iteration
                        current_p = current_list_p[0]
                        current_element = element()
                        self.list_element.append(current_element)
                        self.list_element[-1].p = current_p
                        self.list_element[-1].start = t[i]
                        if x == i + 1:  # because of the last iteration
                            self.list_element[
                                -1].end = t[i] + current_p.burst_time
                            del current_list_p[0]
                            t.append(t[i] + current_p.burst_time)
                            current_p = None
                        else:  # da l 3ady
                            if t[i] + current_p.burst_time <= t[i + 1]:
                                self.list_element[
                                    -1].end = t[i] + current_p.burst_time
                                del current_list_p[0]
                                if t[i] + current_p.burst_time != t[i + 1]:
                                    t.insert(i + 1,
                                             t[i] + current_p.burst_time)
                                current_p = None
                            elif t[i] + current_p.burst_time > t[i + 1]:
                                current_p.burst_time = current_p.burst_time - (
                                    t[i + 1] - t[i])
                else:  # may happen when a process arrive when another process is running
                    if current_p.burst_time <= current_list_p[0].burst_time:
                        if i == len(t) - 1:  # because of the last iteration
                            self.list_element[
                                -1].end = t[i] + current_p.burst_time
                            t.append(t[i] + current_p.burst_time)
                            del current_list_p[0]
                            current_p = None
                        else:  # da l 3ady
                            if t[i] + current_p.burst_time <= t[i + 1]:
                                self.list_element[
                                    -1].end = t[i] + current_p.burst_time
                                del current_list_p[0]
                                if t[i] + current_p.burst_time != t[i + 1]:
                                    t.insert(i + 1,
                                             t[i] + current_p.burst_time)
                                current_p = None
                            elif t[i] + current_p.burst_time > t[i + 1]:
                                current_p.burst_time = current_p.burst_time - (
                                    t[i + 1] - t[i])
                    else:
                        self.list_element[-1].end = t[i]
                        current_p = current_list_p[0]
                        current_element = element()
                        self.list_element.append(current_element)
                        self.list_element[-1].p = current_p
                        self.list_element[-1].start = t[i]
                        if i == len(t) - 1:  # because of the last iteration
                            self.list_element[
                                -1].end = t[i] + current_p.burst_time
                            t.append(t[i] + current_p.burst_time)
                            del current_list_p[0]
                            current_p = None
                        else:  # da l 3ady
                            if t[i] + current_p.burst_time <= t[i + 1]:
                                self.list_element[
                                    -1].end = t[i] + current_p.burst_time
                                del current_list_p[0]
                                if t[i] + current_p.burst_time != t[i + 1]:
                                    t.insert(i + 1,
                                             t[i] + current_p.burst_time)
                                current_p = None
                            elif t[i] + current_p.burst_time > t[i + 1]:
                                current_p.burst_time = current_p.burst_time - (
                                    t[i + 1] - t[i])
                x = len(t)
                i = i + 1