⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delaycomplexity_adaptivep.m

📁 L. Dong and A. P. Petropulu, 揗ultichannel ALLIANCES: A Cross-layer Cooperative Scheme for Wireless
💻 M
字号:
% adaptive p scheme for bursty traffic
% delay evaluation (Fig. 4, right) and ML complexity evaluation (Fig. 5)

clear all
close all
G=4; % number of subchannels
M=500; % total simulated slots
J=32; % number of users
simurange=16; % largest K to simulate

num_trial=20; % number of Monta-Carlo experiments

WorkLoad=[0:simurange-1]/simurange+0.01; % traffic

avg_delay=zeros(G,simurange); % delay

for ss=1:num_trial
    ss
    
    
    for ii = 1:simurange  % K , i.e., K users simulteneously generate high-rate traffic
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        % at the first 100 slots, generate high-rate traffic then keep silent
        Lamda=0.3;
        Traffic=zeros(J,M+J);
        tmp=randperm(J);
        Traffic(tmp(1:ii),1:100) = rand(ii,100)< Lamda; 
        
        count_pack=zeros(G,1);
        count_pack1=0;  
        
        
        for Np=1:G  % for p=1,2,3,4 respectively
            num_op(ss,Np,ii)=0;  % number of operations (for complexity of ML)
            flag=zeros(1,J);
            time_table=zeros(J,(M+J)*G);
            
            % the position of packets in time axis
            pos_pack=zeros(J,(M+J)*G);
            for nn=1:J
                temp=find(Traffic(nn,:)>=1);
                for mm=1:G
                    pos_pack(nn,mm:G:G*(length(temp)-1)+mm)=temp;
                end
            end
            
            sm_traffic = G*Traffic; % one large packet equals G normal packets
            Loads = zeros(1,J);        
            flag_CTE=0;
            
            for t1 = 1:M
                
                newLoads = sm_traffic(:,t1)';
                Loads = Loads + newLoads; % new traffic
                
                flag_CTE=max(0,flag_CTE-1);
                
                if  flag_CTE==0
                    
                    Trans=Loads>0;
                    num_active=sum(Trans);
                    active = find(Trans)';
                    
                    if   num_active>0 
                        
                        % at most transmit p packets 
                        Num_tranpack=min(Np,Loads(active));  % a vector storing number of transmited packet of each active user
                        
                        % randomly select subchannels
                        subch=[];
                        active1=[];
                        rand('state',sum(100*clock));
                        for rrr=1:num_active
                            tmp1=randperm(G);
                            subch=[subch tmp1(1:Num_tranpack(rrr))];
                            active1=[active1 active(rrr)*ones(1,Num_tranpack(rrr))];
                        end
                        num_active1=length(active1);
                        
                        % after randomly selecting subchannels, see how
                        % many packets in each subchannel
                        for pp=1:G
                            temp=find(subch==pp);
                            ch(pp)=length(temp);    % number of packets in each subchannel
                            if ch(pp)>0
                                num_op(ss,Np,ii)=num_op(ss,Np,ii)+4^ch(pp); % complexity of ML
                            end
                        end
                        
                        % calculate processing time and maximum time
                        [process_time, maxtime]=caltime(G,subch,num_active1); 
                        
                        % record the delay time for each packet
                        for kk=1:num_active1 
                            flag(active1(kk))=flag(active1(kk))+1;
                            t_gen=pos_pack(active1(kk),flag(active1(kk)));
                            time_table(active1(kk),flag(active1(kk)))=process_time(kk)+t1-t_gen;
                        end
                        
                        ret_array = zeros(1,J);
                        ret_array(active)=Num_tranpack;
                        
                        Loads = Loads - ret_array;  % update the queue
                        
                        flag_CTE=ceil(num_active1/G); % length of CTE
                        
                        count_pack(Np)=count_pack(Np)+num_active1; % count packets
                        
                        
                    end
                    
                end
                
            end
            avg_delay(Np,ii)=avg_delay(Np,ii)+sum(sum(time_table))/count_pack(Np);
        end                  
    end
end

plot(1:simurange,avg_delay'/num_trial,'linewidth',2)
legend('p=1','p=2','p=3','p=4')
xlabel('K'),
ylabel('delay (slots)')
figure
semilogy(1:simurange,squeeze(mean(num_op,1)),'linewidth',2)
legend('p=1','p=2','p=3','p=4')
xlabel('K'),
ylabel('number of operations')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -