プログラミング
 Computer >> コンピューター >  >> プログラミング >> プログラミング

加重ジョブスケジューリング


さまざまなジョブのリストが表示され、開始時刻、終了時刻、およびそのジョブの利益もそれらのジョブに提供されます。私たちの仕事は、利益が最大で、互いに重複する仕事がない仕事のサブセットを見つけることです。

このアルゴリズムでは、テーブルを使用してサブ問題の結果を保存し、サブ問題の結果を使用して、問題全体をボトムアップ方式で解決できます。

このアルゴリズムの時間計算量はO(n ^ 2)ですが、二分探索法を使用して競合するジョブを検索することにより、O(n Log n)に変更できます。

入力と出力

Input:
The start time, finish time and profit of some jobs as matrix form. And number of jobs. Here 4 jobs are present.
3   5  25
1   2  50
6  15  75
2 100 100

Output:
The maximum profit 150.
The job sequence is job 2, job 4, or job 2, job 1, job 3. for both cases the max profit is 150 here.

アルゴリズム

findMaxProfit(jobList, n)

入力: ジョブリストとジョブの数。

出力: 仕事からの最大の利益。

Begin
   sort job list according to their ending time
   define table to store results
   table[0] := jobList[0].profit

   for i := 1 to n-1, do
      addProfit := jobList[i].profit
      nonConflict := find jobs which is not conflicting with others
      if any non-conflicting job found, then
         addProfit := addProfit + table[nonConflict]
      if addProfit > table[i - 1], then
         table[i] := addProfit
      else
         table[i] := table[i-1]
   done
   result := table[n-1]
   return result
End

#include <iostream>
#include <algorithm>
using namespace std;

struct Job {
   int start, end, profit;
};

bool comp(Job job1, Job job2) {
   return (job1.end < job2.end);
}

int nonConflictJob(Job jobList[], int i) {       //non conflicting job of jobList[i]
   for (int j=i-1; j>=0; j--) {
      if (jobList[j].end <= jobList[i-1].start)
         return j;
   }
   return -1;
}

int findMaxProfit(Job jobList[], int n) {
   sort(jobList, jobList+n, comp);           //sort jobs based on the ending time

   int *table = new int[n];       //create jon table
   table[0] = jobList[0].profit;

   for (int i=1; i<n; i++) {
      // Find profit including the current job
      int addProfit = jobList[i].profit;
      int l = nonConflictJob(jobList, i);
      if (l != -1)
         addProfit += table[l];
      table[i] = (addProfit>table[i-1])?addProfit:table[i-1];       //find maximum
   }

   int result = table[n-1];
   delete[] table;                 //clear table from memory
   return result;
}

int main() {
   Job jobList[] = {
      {3, 5, 25},
      {1, 2, 50},
      {6, 15, 75},
      {2, 100, 100}
   };

   int n = 4;
   cout << "The maximum profit: " << findMaxProfit(jobList, n);
   return 0;
}

出力

The maximum profit: 150

  1. 最短ジョブ優先(SJF)スケジューリングのためのC ++プログラム(非プリエンプティブ)

    与えられたプロセス、それぞれのプロセスのバースト時間と量子限界。タスクは、Shortest Job First Schedulingの非プリエンプティブ方式を使用して、待機時間、所要時間、およびそれぞれの平均時間を見つけて印刷することです。 最初のスケジュールの最短ジョブは何ですか? 最短ジョブ優先スケジューリングは、非プリエンプティブスケジューリング規律に従うジョブまたはプロセススケジューリングアルゴリズムです。この場合、スケジューラーは、完了時間が最小の待機キューからプロセスを選択し、CPUをそのジョブまたはプロセスに割り当てます。 SJFは平均待機時間を短縮し、スループットを向上さ

  2. Windows 10 GPUハードウェアのスケジューリング:オンにする価値はありますか?

    コンピューターのパフォーマンスを向上させる方法を探している場合は、Windows10のGPUハードウェアスケジューリングを有効にしてみてください。この機能は、2020年5月の更新でMicrosoftによって含まれ、それ以来、多くのゲーマーは、それが彼らに役立つかどうかを確認するためにそれを試みました。ただし、コンピュータのGPUはそれをサポートしていない可能性があります。 GPUハードウェアのスケジューリングについて詳しく知りたい場合は、GPUの仕組み、システム要件、およびそれをオンにする方法について説明しているので、読み続けてください。 GPUハードウェアスケジューリングはどのように機能