امتیاز موضوع:
  • 0 رأی - میانگین امتیازات: 0
  • 1
  • 2
  • 3
  • 4
  • 5
HRRN
نویسنده پیام
Ghoghnus آفلاین
مدیر بخش
*****

ارسال‌ها: 1,478
موضوع‌ها: 261
تاریخ عضویت: آذر ۱۳۸۸

تشکرها : 1644
( 3909 تشکر در 1436 ارسال )
ارسال: #1
HRRN
CPP program for Highest Response Ratio Next (HRRN) Scheduling 
کد:
// CPP program for Highest Response Ratio Next (HRRN) Scheduling
#include <bits/stdc++.h>
using namespace std;
// Defining process details
struct process {
    char name;
    int at, bt, ct, wt, tt;
    int completed;
    float ntt;
} p[10];
    
int n;
    
// Sorting Processes by Arrival Time
void sortByArrival()
{
    struct process temp;
    int i, j;
    
    // Selection Sort applied
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
    
            // Check for lesser arrival time
            if (p[i].at > p[j].at) {
    
                // Swap earlier process to front
                temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }
}
    
int main()
{
    int i, j, t, sum_bt = 0;
    char c;
    float avgwt = 0, avgtt = 0;
    n = 5;
    
    // predefined arrival times
    int arriv[] = { 1, 2, 4, 22, 0 };
    
    // predefined burst times
    int burst[] = { 3, 6, 4, 5, 2 };
    
    // Initializing the structure variables
    for (i = 0, c = 'A'; i < n; i++, c++) {
        p[i].name = c;
        p[i].at = arriv[i];
        p[i].bt = burst[i];
    
        // Variable for Completion status
        // Pending = 0
        // Completed = 1
        p[i].completed = 0;
    
        // Variable for sum of all Burst Times
        sum_bt += p[i].bt;
    }
    
    // Sorting the structure by arrival times
    sortByArrival();
    cout << "Name " << " Arrival Time " << " Burst Time " << " Waiting Time "
    << " TurnAround Time " << " Normalized TT" ;
    for (t = p[0].at; t < sum_bt;) {
    
        // Set lower limit to response ratio
        float hrr = -9999;
    
        // Response Ratio Variable
        float temp;
    
        // Variable to store next processs selected
        int loc;
        for (i = 0; i < n; i++) {
    
            // Checking if process has arrived and is Incomplete
            if (p[i].at <= t && p[i].completed != 1) {
    
                // Calculating Response Ratio
                temp = (p[i].bt + (t - p[i].at)) / p[i].bt;
    
                // Checking for Highest Response Ratio
                if (hrr < temp) {
    
                    // Storing Response Ratio
                    hrr = temp;
    
                    // Storing Location
                    loc = i;
                }
            }
        }
    
        // Updating time value
        t += p[loc].bt;
    
        // Calculation of waiting time
        p[loc].wt = t - p[loc].at - p[loc].bt;
    
        // Calculation of Turn Around Time
        p[loc].tt = t - p[loc].at;
    
        // Sum Turn Around Time for average
        avgtt += p[loc].tt;
    
        // Calculation of Normalized Turn Around Time
        p[loc].ntt = ((float)p[loc].tt / p[loc].bt);
    
        // Updating Completion Status
        p[loc].completed = 1;
    
        // Sum Waiting Time for average
        avgwt += p[loc].wt;
        cout<< "\n" << p[loc].name <<"\t" << p[loc].at;
        cout << "\t\t" << p[loc].bt <<"\t\t"<< p[loc].wt;
        cout <<"\t\t"<< p[loc].tt <<"\t\t"<< p[loc].ntt;
    }
    cout << "\nAverage waiting time: " << avgwt / n << endl;
    cout <<"Average Turn Around time:"<< avgtt / n;
}
//This code is contributed by shivi_Aggarwal

[تصویر:  a.jpg]

باور کنیم
همانگونه که در غیبت مقصریم در ظهور موثریم!
نیستیم؟

زیر شمشیر غمش رقص کنان باید رفت #  کان که شد کُشته ی او نیک سرانجام افتاد



 چشمک - بهینه شده برای ورژن جدید دانلود پروژه برنامه نويسي
۳۱-تير-۱۳۹۹, ۱۰:۵۷:۰۹
وب سایت ارسال‌ها
پاسخ
Ghoghnus آفلاین
مدیر بخش
*****

ارسال‌ها: 1,478
موضوع‌ها: 261
تاریخ عضویت: آذر ۱۳۸۸

تشکرها : 1644
( 3909 تشکر در 1436 ارسال )
ارسال: #2
RE: HRRN
کد بالا ورودی و خروجی با فایل
کد:
// CPP program for Highest Response Ratio Next (HRRN) Scheduling
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>

using namespace std;
// Defining process details
struct process {
    char name;
    int at, bt, ct, wt, tt;
    int completed;
    float ntt;
} p[10];
    
int n;
    
// Sorting Processes by Arrival Time
void sortByArrival()
{
    struct process temp;
    int i, j;
    
    // Selection Sort applied
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
    
            // Check for lesser arrival time
            if (p[i].at > p[j].at) {
    
                // Swap earlier process to front
                temp = p[i];
                p[i] = p[j];
                p[j] = temp;
            }
        }
    }
}
    
int main()
{
// Create a text string, which is used to output the text file
string myText;



 // Create and open a text file
ofstream MyFile("report.txt");


    int i, j, t, sum_bt = 0;
    char c;
    float avgwt = 0, avgtt = 0;
    n = 5;
    int imm=0;
    // predefined arrival times
    //int arriv[] = { 1, 2, 4, 22, 0 };
    

//initialie the array size
  int arriv[4];
  ifstream is("input.txt");
  int cnt= 0;
  int x;
  // check that array is not already full
  while (cnt < arriv[4] && is >> x)
  // and read integer from file
  arriv[cnt++] = x;
 
 

    
    // predefined burst times
    int burst[] = { 3, 6, 4, 5, 2 };
    
    // Initializing the structure variables
    for (i = 0, c = 'A'; i < n; i++, c++) {
        p[i].name = c;
        p[i].at = arriv[i];
        p[i].bt = burst[i];
    
        // Variable for Completion status
        // Pending = 0
        // Completed = 1
        p[i].completed = 0;
    
        // Variable for sum of all Burst Times
        sum_bt += p[i].bt;
    }
    
    // Sorting the structure by arrival times
    sortByArrival();
    MyFile << "Name " << " Arrival Time " << " Burst Time " << " Waiting Time "
    << " TurnAround Time " << " Normalized TT" ;
    for (t = p[0].at; t < sum_bt;) {
    
        // Set lower limit to response ratio
        float hrr = -9999;
    
        // Response Ratio Variable
        float temp;
    
        // Variable to store next processs selected
        int loc;
        for (i = 0; i < n; i++) {
    
            // Checking if process has arrived and is Incomplete
            if (p[i].at <= t && p[i].completed != 1) {
    
                // Calculating Response Ratio
                temp = (p[i].bt + (t - p[i].at)) / p[i].bt;
    
                // Checking for Highest Response Ratio
                if (hrr < temp) {
    
                    // Storing Response Ratio
                    hrr = temp;
    
                    // Storing Location
                    loc = i;
                }
            }
        }
    
        // Updating time value
        t += p[loc].bt;
    
        // Calculation of waiting time
        p[loc].wt = t - p[loc].at - p[loc].bt;
    
        // Calculation of Turn Around Time
        p[loc].tt = t - p[loc].at;
    
        // Sum Turn Around Time for average
        avgtt += p[loc].tt;
    
        // Calculation of Normalized Turn Around Time
        p[loc].ntt = ((float)p[loc].tt / p[loc].bt);
    
        // Updating Completion Status
        p[loc].completed = 1;
    
        // Sum Waiting Time for average
        avgwt += p[loc].wt;
        MyFile << "\n" << p[loc].name <<"\t" << p[loc].at;
        MyFile << "\t\t" << p[loc].bt <<"\t\t"<< p[loc].wt;
        MyFile <<"\t\t"<< p[loc].tt <<"\t\t"<< p[loc].ntt;
    }
    MyFile << "\nAverage waiting time: " << avgwt / n << endl;
    MyFile <<"Average Turn Around time:"<< avgtt / n;
    
     MyFile.close();
}
//This code is contributed by shivi_Aggarwal

[تصویر:  a.jpg]

باور کنیم
همانگونه که در غیبت مقصریم در ظهور موثریم!
نیستیم؟

زیر شمشیر غمش رقص کنان باید رفت #  کان که شد کُشته ی او نیک سرانجام افتاد



 چشمک - بهینه شده برای ورژن جدید دانلود پروژه برنامه نويسي
۳۱-تير-۱۳۹۹, ۱۰:۵۸:۰۹
وب سایت ارسال‌ها
پاسخ


پرش به انجمن:


کاربرانِ درحال بازدید از این موضوع: 1 مهمان

صفحه‌ی تماس | IranVig | بازگشت به بالا | | بایگانی | پیوند سایتی RSS