SJF Non-preemptive scheduling-Algorithmus

Ich bin ganz frisch auf dieser scheduling-algorithmen. Ich habe bequem mit SJF non-preemptive und ich verstehe es von einem Stift und Papier Gantt-Diagramm-Sicht aber nicht ganz so aus Programmier-Sicht. Mein code ist unten und wenn es erfolgreich ausgeführt wird, mein Mathe falsch ist. Wie kann ich es beheben?

TESTFALL
Prozess Platzen Ankunft
P1 20 0
P2 3 3
P3 2 5

Erwartete Ergebnisse
Avg warten 11,3
Avg turnaround-Zeit von 19,6
Avg response time von 10,6

Tatsächlichen Ausgänge
avg warten von 8,3
avg turnaround-Zeit von 6,6
avg response time von 14

    #include <iostream>
    using namespace std;

    void SJF_NP(int n, int burst[], int arrival[], int throughput)
    {
      cout << "Output for SJF_Non_Preemptive scheduling algorithm" << endl;

      int i, j, temp, temp2;
      double tot, avgwait, avgturnaround, avgresponse, tp;

      //array instantiations                                                                                          
      int start[n], end[n], wait[n];

      //calculations                                                                                                  
      for(i=1;i<=n;i++)
        {
          for(j=i+1;j<=n;j++)
            {
              if (i>=2 && burst[i-1]>burst[j-1])
                {
                  temp = burst[i-1];
                  temp2 = arrival[i-1];
                  burst[i-1]=burst[j-1];
                  arrival[i-1]=arrival[j-1];
                  burst[j-1]=temp;
                  arrival[j-1]=temp2;
                }
            }
          if(i==1)
            {
              start[0]=0;
              end[0]=burst[0];
              wait[0]=0;
            }
          else
            {
              start[i-1]=end[i-2];
              end[i-1]=start[i-1]+burst[i-1];
              wait[i-1]=start[i-1]+arrival[i-1];
            }
          //throughput                                                                                                
          if (start[i+1] <= throughput)
            tp = i+1;
        }

      //output                                                                                                        
      cout << "\n\nPROCESS \t BURST TIME\tARRIVAL TIME\tWAIT TIME\tSTART TIME\tEND TIME\n";
      for (i=0;i<n;i++){
        cout << "\nP[" << i + 1 << "]" << "\t\t" << burst[i] << "\t\t" << arrival[i] << "\t\t" << wait[i] << "\t\t" << start[i] << "\t\t" << end[i];
      }
      //avg wait time                                                                                                 
      for(i=1,tot=0;i<n;i++){
        tot+=wait[i-1];
        avgwait=tot/n;
      }
      //avg turnaround time                                                                                           
      for(i=1,tot=0;i<n;i++){
        tot+=end[i-1];
        avgturnaround=tot/n;
      }
      //avg response time                                                                                             
      for(i=1,tot=0;i<n;i++){
        tot+=start[i-1];
        avgresponse=tot/n;
      }
      cout << "\n\nAverage Wait Time: " << avgwait;
      cout << "\nAverage Response Time: " << avgturnaround;
      cout << "\nAverage Turnaround Time: " << avgresponse;
      cout << "\nThroughput for (" << throughput << "): " << tp << endl;
    }
  • Sind Sie eher nützliche Hilfe, wenn Sie Eingaben, die erwarteten Ausgaben und die tatsächlichen Ausgaben.
  • EINGABE: P[1]: Burst: 20, Ankunft: 0. P[2]: Burst: 3, Ankunft 3. P[3]: Burst: 2, Ankunft 5... Erwartete Ergebnisse: Avg warten 11,3, Avg turnaround-Zeit von 19,6, Avg response time von 10,6.... Die tatsächlichen Ausgänge: avg warten, 8.3, avg turnaround-Zeit von 6.6, avg response time von 14....
  • Wie Sie sehen können, alle meine mathematischen Berechnungen sind aus... Nicht zu wissen was ich falsch mache. Benötigen Sie Hilfe. Wenn Sie wollen mehr details bitte Fragen
  • Noch auf der Suche für einige dringend benötigte Hilfe!!
InformationsquelleAutor user4612042 | 2015-03-02
Schreibe einen Kommentar