Bonjour,
Ci-dessous un code de l'algorithme d'ordonnancement EDF. J'ai besoin de programmer un réseau de capteurs en introduisant l'EDF et je trouve que c'est une bonne plateforme pour commencer.
Je connais le principe de fonctionnement de l'EDF, mais, en lisant ce code, j'arrive pas à bien comprendre le principe suivi. Je suis débutante en programmation, pourriez-vous m'aider?
Code:#include<iostream> using namespace std; class EDF { int releasetime; int executiontime; int deadlinetime; int relativedeadline; int startingtime; int x[3]; int e[3]; int z[3]; int d[3]; public: void task_entering(); void task_arrange(); }; void EDF::task_entering() { int slack,period; cout<<"Enter your relative dedline :\n"; cin>>relativedeadline; for(int i=0;i<3;i++) { cout<<"release time is :\n"; cin>>releasetime; cout<<"deadline time is:\n"; cin>>deadlinetime; d[i] = deadlinetime; period = deadlinetime - releasetime; x[i] = period; cout<<"execution time is :\n"; cin>>executiontime; e[i] = executiontime; slack = deadlinetime - executiontime; z[i] = slack; }} void EDF::task_arrange() { int temp,y[3]; for(int j=0;j<=2;j++) { y[j]=x[j]; } for (int j=0; j<2; j++) { for(int k = (j+1); k < 3; k++) { if (y[j] < y[k]) { temp= y[j]; y[j] = y[k]; y[k] = temp; temp= z[j]; z[j] = z[k]; z[k] = temp; temp= d[j]; d[j] = z[k]; d[k] = temp; } } } for(int j=2, k=1;j>=0;j--,k++) { cout<<"The Task with deadline period of "<<z[j]<<" will be T"<<k<<"\n"; } int sum = 0; startingtime = 0; while(startingtime <= relativedeadline){ for(int j=0;j<=2;j++) { if(y[2] == x[j]){ if(d[2] < d[1] && d[2] < d[0]){ if(startingtime <= relativedeadline){ sum = startingtime + e[j]; if(sum >= relativedeadline) cout<<"("<<startingtime<<"-"<<relativedeadline<<",T"<<j+1<<")\t"; else cout<<"("<<startingtime<<"-"<<startingtime + e[j]<<",T"<<j+1<<")\t"; startingtime = sum; d[2] = d[2] * 2;}}} else if(y[1] == x[j]){ if(d[1] < d[2] && d[1] < d[0]){ if(startingtime <= relativedeadline){ sum = startingtime + e[j]; if(sum >= relativedeadline) cout<<"("<<startingtime<<"-"<<relativedeadline<<",T"<<j+1<<")\t"; else cout<<"("<<startingtime<<"-"<<startingtime + e[j]<<",T"<<j+1<<")\t"; startingtime = sum; d[1] = d[1] * 2;}}} else if(y[0] == x[j]){ if(d[0] < d[1] && d[0] < d[2]){ if(startingtime <= relativedeadline){ sum = startingtime + e[j]; if(sum >= relativedeadline) cout<<"("<<startingtime<<"-"<<relativedeadline<<",T"<<j+1<<")\t"; else cout<<"("<<startingtime<<"-"<<startingtime + e[j]<<",T"<<j+1<<")\t"; startingtime = sum; d[0] = d[0] * 2;}}} } }} main() { EDF CPU; Repeat: CPU.task_entering(); CPU.task_arrange(); cout<<endl; goto Repeat; }
-----