def calculate_times(self, queue, num_jobs, cpu_slice):

        completionTime = 0
        remaining_slice = 0
        while len(Priority.queue) > 0:
            running = queue.pop()
            print("JobId, Exec time, Priority", running.JobId,
                  running.execution_time, running.priority)
            Job.set_waiting_time(running, completionTime)
            job_burst = Job.get_execution_time(running)
            while job_burst > 0:
                job_burst = job_burst - cpu_slice
                if job_burst < 0:
                    remaining_slice = abs(job_burst)
                    completionTime = completionTime + job_burst + cpu_slice
                    cpu_slice = remaining_slice

                else:
                    completionTime = completionTime + cpu_slice
            Job.set_completion_time(running, completionTime)
            Job.set_turnaround_time(running, Job.get_completion_time(running))
            Priority.list_priority.append(running)

            print("Completion time", running.completion_time)
            print("Turnaround time", running.turnaroundTime)
            print("Waiting ", running.waiting_time)
        throughput = completionTime / num_jobs
        print(" Throughput ", completionTime, num_jobs, throughput)
        total_TurnarounTime = completionTime / num_jobs
        print("Average Turn around time ", total_TurnarounTime)
        return Priority.list_priority
Exemple #2
0
    def calculate_times(self, queue, num_jobs, cpu_slice):
        """
       This definition is responsible to run the priority scheduling algorithm and
       calculate waiting time, completion time, turnaround time for each process and
       total turnaround time and throughput.
       :param queue: queue containing jobs, sorted according to priorities.
       num_jobs: number of jobs
       cpu_slice: cpu time slice for which jobs can run.
       :return:
       """
        #completionTime is a responsible for keeping a count of total completion time
        completionTime = 0
        Total_completion = 0

        #remaining_slice is responsible for keeing a count of time slice remaining after
        # a particular process completes running
        remaining_slice = 0

        while len(
                Priority.queue) > 0:  # Run till the queue of jobs is not empty
            running = queue.pop()
            print("JobId:", running.JobId, "Execution time:",
                  running.execution_time, "Priority: ", running.priority)
            Job.set_waiting_time(running, completionTime)
            job_burst = Job.get_execution_time(running)
            while job_burst > 0:  # Run till execution time is still remaining
                job_burst = job_burst - cpu_slice
                if job_burst < 0:
                    remaining_slice = abs(job_burst)
                    completionTime = completionTime + job_burst + cpu_slice
                    cpu_slice = remaining_slice
                    #Total_completion = Total_completion + completionTime

                else:  # if execution time is 0 or less then 0, i.e if process is complete
                    completionTime = completionTime + cpu_slice

            # set completeion time of running job
            Job.set_completion_time(running, completionTime)

            # set turnaround time of running job
            Job.set_turnaround_time(running, Job.get_completion_time(running))

            # append a completed job to a list
            Priority.list_priority.append(running)

            print("Completion time", running.completion_time)
            print("Turnaround time", running.turnaroundTime)
            print("Waiting ", running.waiting_time)
            print(
                "-----------------------------------------------------------------"
            )

        # calculate total throughput
        Priority.priority_throughput = num_jobs / completionTime
        print("Priority Completion time:", completionTime)
        print(" Throughput ", Priority.priority_throughput)

        # calculate total turnaround time
        total_TurnarounTime = completionTime / num_jobs
        print("Average Turn around time ", total_TurnarounTime)
        print(
            "-----------------------------------------------------------------"
        )
        return Priority.list_priority
    def calculate_times(self, queue, num_jobs, cpu_slice):
        """
        This definition is responsible to run the CFS scheduling algorithm and
        calculate waiting time, completion time, turnaround time for each process and
        total turnaround time and throughput.
        :param queue: queue containing jobs, sorted according to execution.
        num_jobs: number of jobs
        cpu_slice: cpu time slice for which jobs can run.
        :return:
        """
        total_completion = 0
        completion_time = 0.0
        number_of_jobs = num_jobs
        while (len(queue) > 0):
            flag = 0
            temp_slice = (cpu_slice / number_of_jobs)
            for i in range(number_of_jobs):
                running = CFS.queue.pop()

                running.execution_time = running.execution_time - temp_slice
                running.cpu_burst = running.cpu_burst + temp_slice
                if (running.execution_time > 0):
                    CFS.queue.appendleft(running)
                    completion_time = completion_time + temp_slice

                elif running.execution_time <= 0:
                    flag = flag + 1
                    completion_time = completion_time + (
                        temp_slice - abs(running.execution_time))
                    # running.completion_time = completion_time

                    #total_completion = total_completion + completion_time

                    # set completeion time of running job
                    Job.set_completion_time(running, completion_time)

                    # set turnaround time of running job
                    Job.set_turnaround_time(running,
                                            Job.get_completion_time(running))

                    waitingTime = Job.get_completion_time(
                        running) - running.cpu_burst
                    # running.waiting_time = waitingTime

                    # set waiting time of running job
                    Job.set_waiting_time(running, waitingTime)

                    CFS.cfs_jobs.append(running)

                    print("JobId:", running.JobId)
                    print("Completion time", running.completion_time)
                    print("Turnaround time",
                          running.completion_time - running.arrival_time)
                    print("Waiting ", running.waiting_time)
                    print(
                        "-----------------------------------------------------------------"
                    )

            if flag > 0:
                number_of_jobs = number_of_jobs - flag

        print("CFS Completion time:", completion_time)

        CFS.cfs_throughput = num_jobs / completion_time
        print("Throughput ", self.cfs_throughput)

        # calculate total turnaround time
        total_TurnarounTime = completion_time / num_jobs

        print("Average Turn around time ", total_TurnarounTime)
        print(
            "-----------------------------------------------------------------"
        )

        return CFS.cfs_jobs