📄 hrrn.m
字号:
function [newP,QReady]=HRRN(QReady,Qlen,GlobalCycle)
%It is SURE that there are processes in the queue now. now just to choose one
%The order is not important, so we can sort the queue first,then pick the
%first one.
%
%NOTE: newP is not newp!!!!!!!!!!!!
%only for HRRN
newP=-1; % if newp is -1 when return, we can find some problem because we can not access TB(-1)!!
%calculate the return ratio=waitingtime/Tb, Note when there is empty
%element, we get 0/0=Inf, which Inf is a big number!!Not GOOD
% disp('------before sub----');
% QReady
for i=1:Qlen
if QReady(i,1)~=0
QReady(i,4)=GlobalCycle-QReady(i,3); % get the waiting time
end
end
% QReady
for i=1:Qlen
if QReady(i,1)~=0
QReady(i,4)=QReady(i,4)/QReady(i,2); % return ratio=waitingtime/Tb
end
end
QReady=sortrows(QReady,-4); %by the return ratio,descending
% disp('------after sub----');
% QReady
%QReady(i,4)
%the result could be zero, so should differ for empty element
[Y,Index]=max(QReady(:,4)); %find the first max return ratio
maxIndex=Index;
% Y
%--------------------------------------------
if Y==0 %if 0 then there are two situation: empty element or process no not waiting
% fprintf('xxxxxxx\n');
for i=1:Qlen %find the first process with 0 waitingtime
if QReady(i,1)>0
newP=QReady(i,1); %save the info
maxIndex=i;
break;
end
i=i+1;
end
end
%----------------------------------------------
newP=QReady(Index,1);
QReady(:,4)=0; %restore to the 0 state
if newP<=0
fprintf('Not good! newP=%d\n',newP);
return;
end
%--------------------------------------------------
QReady(maxIndex,:)=0; %move it out from the Queue by set 0
QReady=sortrows(QReady,-1);% move 0 out from the Queue
%QReady=sortrows(QReady,-3); %Resort. by descending order
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -