Ask Experts Questions for FREE Help !
Ask
    eraniichan's Avatar
    eraniichan Posts: 1, Reputation: 1
    New Member
     
    #1

    May 18, 2013, 03:21 AM
    Earliest deadline cpu scheduling
    I can't figure out how to show the correct diagram for this earliest deadline first algorithm. So far here is my code:
    Code:
     import java.util.*;
    
    
        class deadlineprototype
        {
    
    
        public static void main(String args[])
        {
    
    
        Scanner sc = new Scanner(System.in);
    
    
        System.out.println("enter no. of processes : ");
        int n=sc.nextInt();
        int job[]=new int[n+1];
        int burst[]=new int[n+1];
        int newburst[]=new int[n+1];
        int arrival[]=new int[n+1];
        int deadline[]=new int[n+1];
        int wt[]=new int[n+1];
        int turn[]=new int[n+1];
        int tot_turn=0;
        int tot_wait=0;
        float avg_turn=0;
        float avg_wait=0;
        int j;
    
        for(int m=1;m<=n;m++)
            {
            arrival[m]=m;
            }
        for(int m=1;m<=n;m++)
            {
            job[m]=m;
            }
    
        for(int m=1;m<=n;m++)
            {
            System.out.println("enter arrival time, burst time and deadline of process "+(m)+"(0 for none):");
            arrival[m]=sc.nextInt();
            burst[m]=sc.nextInt();
            deadline[m]=sc.nextInt();
    
        if (deadline[m]==0){
            deadline[m]=1000;
        }
            }
    
    
    
        int temp;
        for(int i=1;i<n;i++)
            {
            for(j=1;j<n;j++)
                {
    
                    if(deadline[i+1]<deadline[j])
                    {
                    temp=deadline[j+1];
                    deadline[j+1]=deadline[j];
                    deadline[j]=temp;
    
                    temp=job[j+1];
                    job[j+1]=job[j];
                    job[j]=temp;
    
                    temp=burst[j+1];
                    burst[j+1]=burst[j];
                    burst[j]=temp;
                    }
            }
            }
        turn[1]=burst[1];    
    
        for(int i=2;i<=n;i++)
            {
            turn[i]=burst[i]+turn[i-1];
            wt[i]=turn[i]-burst[i];
            }
        for(int i=1;i<=n;i++)
            {
            tot_turn+=(wt[i]+burst[i])-arrival[i];
            avg_turn=(float)tot_turn/n;
            tot_wait+=wt[i]-arrival[i];
            avg_wait=(float)tot_wait/n;
            }
        System.out.println("----------Earliest Deadline Scheduling Diagram----------");
        for(int m=1;m<=n;m++)
            {
        if(deadline[m]==1000){
                deadline[m]=0;
                }
        if(wt[m]==0){
                System.out.println("0"+wt[m]+" _____"); 
        }
        else{
        System.out.println(wt[m]+" _____"); 
        }
                System.out.println("  |     |");
    
                System.out.println("  |job "+job[m]+"|");
    
                System.out.println("  |_____|");
                        try
                     {
                     //newburst[m]=(burst[m]*1000);
                     Thread.sleep(1000);  
                     }catch (InterruptedException ie)
                     {
                     System.out.println(ie.getMessage());
                     }
        }
        System.out.println((wt[wt.length-1]+burst[burst.length-1]));
    If I input 2 processes this will be the output:

    Code:
    enter no. of processes : 
        2
        enter arrival time, burst time and deadline of process 1(0 for none):
        0 17 0
        enter arrival time, burst time and deadline of process 2(0 for none):
        0 13 10
        ----------Earliest Deadline Scheduling Diagram----------
        00 _____
           |           |
           | job 2  |
           | _____|
        13 _____
           |           |
           | job 1  |
           | _____|
        30
    It shows the correct intended output. But for 3 processes like this then it will output:

    Code:
    enter no. of processes : 
        3
        enter arrival time, burst time and deadline of process 1(0 for none):
        0 17 0
        enter arrival time, burst time and deadline of process 2(0 for none):
        0 13 10
        enter arrival time, burst time and deadline of process 3(0 for none):
        25 14 20
        ----------Earliest Deadline Scheduling Diagram----------
        00 _____
          |            |
          |job 2    |
          |_____  |
        13 _____
          |           |
          |job 3   |
          |_____ |
        27 _____
          |           |
          |job 1   |
          |_____ |
        44
    It shows an incorrect output, that job 1 should come after job 2 and instead of job 3. But then again if I input 5 process it will show correct output again:

    Code:
    enter no. of processes : 
        5
        enter arrival time, burst time and deadline of process 1(0 for none):
        0 17 0
        enter arrival time, burst time and deadline of process 2(0 for none):
        0 13 10
        enter arrival time, burst time and deadline of process 3(0 for none):
        25 14 20
        enter arrival time, burst time and deadline of process 4(0 for none):
        25 10 15
        enter arrival time, burst time and deadline of process 5(0 for none):
        30 5 0
        ----------Earliest Deadline Scheduling Diagram----------
        00 _____
          |          |
          |job 2   |
          |_____|
        13 _____
          |          |
          |job 1  |
          |_____|
        30 _____
          |            |
          |job 4    |
          |_____|
        40 _____
          |            |
          |job 3    |
          |_____ |
        54 _____
          |            |
          |job 5    |
          |_____ |
        59
    And now I wonder what codes is causing the program to show incorrect input. Please help with this problem thanks in advance!

Check out some similar questions!

The fan in my CPU won't turn on when the CPU is plugged in! [ 1 Answers ]

I have an E-machine T3616 CPU, and just last night everything was working fine and then this morning I tried to turn my computer on but something was wrong. So we opened it up and found out that the fans wasn't turning on. When we turn the computer on, the fan isn't turned on. What can we do?

College Football scheduling [ 4 Answers ]

I live in "Gator Country"---here in No. Florida where the UoF team is a secular religion. Someone told me somethimng that I want to verify as accurate. To wit, ranked teams like the Gators, are able to use their largesse to purchase a cakewalk schedule where they play mostly unranked or...

Interview re-scheduling [ 1 Answers ]

I was schedule for an interview for my I-485 for next week and the USCIS sent me another notice this week re-scheduling for next month ,I am little concern.

Scheduling workouts. [ 3 Answers ]

Got to a problem... I've been running regularly for the past 2 years. Recently I started getting a bit bored with the routine and decided to add a fitness class - the class consists of 20 minutes cardio, 20 minutes strength training, and 20 minutes stretching/core excercises. Here's the...

Scheduling Information [ 4 Answers ]

What is Submission of Scheduling Information?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.