maryam-alikahakii
شنبه 13 تیر 1388, 13:03 عصر
من الگوریتم red را با متلب نوشتم اما همه بسنه ها را accept میکند میشه یک نگاهی بیندازید ببینید مشکلش چیه؟
function [k] = red(n)
%
%
%
min_th=5;
max_th=15;
maxp=1/50;
w_q=0.2;
q=40;
time=2;
q_time=15;
k=0;
count=-1; % packets since last marked packet
avg=0;%average queue size
for i=1:n
if (q~=0)% q :current queue size
avg=avg + w_q*(q-avg) % w_q:queue weight
else
m=(time - q_times)/s % time: current time,q_time:start of the queu idle time,s:transmission time for a small packet
avag=(1-w(q))^m * avg
end
if(avg>=min_th && avg<max_th)
count=count+1;
p_b=maxp*(avg-min_th)/(max_th-min_th)
p_a=(p_b/(1-count*p_b))
R=rand(1,1)
if(R<p_a)
disp('drop the arriving packet')
count =0;
k=k+1;
else
disp('accept arriving packet')
end
if (avg>=max_th)
disp('drop the arriving packet')
count=0;
k=k+1
else count=-1;
end
end
plot(k,q);
end
end
function [k] = red(n)
%
%
%
min_th=5;
max_th=15;
maxp=1/50;
w_q=0.2;
q=40;
time=2;
q_time=15;
k=0;
count=-1; % packets since last marked packet
avg=0;%average queue size
for i=1:n
if (q~=0)% q :current queue size
avg=avg + w_q*(q-avg) % w_q:queue weight
else
m=(time - q_times)/s % time: current time,q_time:start of the queu idle time,s:transmission time for a small packet
avag=(1-w(q))^m * avg
end
if(avg>=min_th && avg<max_th)
count=count+1;
p_b=maxp*(avg-min_th)/(max_th-min_th)
p_a=(p_b/(1-count*p_b))
R=rand(1,1)
if(R<p_a)
disp('drop the arriving packet')
count =0;
k=k+1;
else
disp('accept arriving packet')
end
if (avg>=max_th)
disp('drop the arriving packet')
count=0;
k=k+1
else count=-1;
end
end
plot(k,q);
end
end