round robin Loop.... help plz

3 ビュー (過去 30 日間)
Ayda
Ayda 2012 年 4 月 23 日
編集済み: Walter Roberson 2018 年 5 月 11 日
Good morning\evening ppl =)
i wrote a code for round robin algorithm i had a small problem in the loop and i don't know how to fix it
Any help please, =)
my code
clc
numOfJobs=5
CPUTime=[10 6 2 4 8]
CPUTime_copy=CPUTime;
CPUTime_copy2=CPUTime;
quantum=1;
totalCPUtime= sum(CPUTime)
total_temp=totalCPUtime;
complete_RR=[];
start=[];
wait=[];
while (totalCPUtime ~= 0)
for i=1:1:numOfJobs
if CPUTime(i)>0
if(CPUTime(i)>quantum)
CPUTime(i)=CPUTime(i)-1;
total_temp=total_temp-1;
else
CPUTime(i)=CPUTime(i)-1;
total_temp=total_temp-1;
complete_RR(i)=totalCPUtime-total_temp;
end
end
start(i)=i;
wait(i)=totalCPUtime-total_temp-CPUTime_copy(i);
end
end
start
wait
complete_RR

採用された回答

Richard Brown
Richard Brown 2012 年 4 月 23 日
You're never updating totalCPUtime so your while loop never exits
  1 件のコメント
Ayda
Ayda 2012 年 4 月 24 日
thanxs
i should do this while (total_temp ~= 0)

サインインしてコメントする。

その他の回答 (1 件)

Jamal Nasir
Jamal Nasir 2018 年 5 月 11 日
編集済み: Walter Roberson 2018 年 5 月 11 日
%%%this code for Calculate Average waiting Time in Round Robin and Average Turn around Time
%%%%by Jamal Nasir %%%%University of Almustansiryah %%%Iraq
clc
clear all
j=3;
job=randperm(10,j);
jobi=job;
flag=job>0;
Quant=2;
tw=sum(job);
job1=[];
x=1:j;
x1=[];
n=0;
f1=[];
while tw>0
n=n+1;
job1=[job1,job];
for i=1:j
if flag(i)>0
if job(i)>Quant
job(i)=job(i)-Quant;
else
job(i)=0;
flag(i)=0;
end
end
end
tw=sum(job);
x1=[x1,x];
f1=[f1,flag];
end
k=length(f1);
for m=1:j
to=0;wt=0;
for i=1:k
if x1(i)~=m
if job1(i)>=Quant
t=Quant;
else
t=job1(i);
end
wt=wt+t;
else
if job1(i)>=Quant
t1=Quant;
else
t1=job1(i);
end
if t1<job1(i)
to=to+t1;
else
break;
end
end
end
wait(m)=wt;
end
AvWaitTime=mean(wait)
AvTurnAroundTime=mean(wait+jobi)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by