├── 2021-06-22-TaskOffloading (+Complexity Analysis)-arXiv_v3.pdf ├── 2021-06-23-TaskOffloading- Submitted Version to IEEE TCOM.pdf ├── DTO.m ├── Figures ├── 1a. A typical task offloading example.png ├── 1b. System model.png ├── 2a. Acceptance Ratio vs. T for K=30.png ├── 2a. Acceptance ratio vs. K for T=40 ms.png ├── 3a. Convergence of admission control algorithm for T=20 ms and K=30.png ├── 3b. Acceptance ratio of joint vs. disjoint methods in terms of T_RAN for T=30 ms and K=30.png ├── 4a. Average radio transmission and execution latencies vs D for T=20 ms and K=30.png ├── 4a. Average radio transmission and execution latencies vs L for T=20 ms and K=30.png ├── 5. Placement of the different classes of tasks at 3 different tiers of nodes for K=30.png └── 6. Acceptance ration of LTO and JTO vs max acceptable latency.png ├── JTO.m ├── LICENSE ├── README.md ├── channel.mat └── pathbetweennodes.m /2021-06-22-TaskOffloading (+Complexity Analysis)-arXiv_v3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/2021-06-22-TaskOffloading (+Complexity Analysis)-arXiv_v3.pdf -------------------------------------------------------------------------------- /2021-06-23-TaskOffloading- Submitted Version to IEEE TCOM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/2021-06-23-TaskOffloading- Submitted Version to IEEE TCOM.pdf -------------------------------------------------------------------------------- /DTO.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear; 3 | close all; 4 | cvx_quiet true 5 | 6 | %% Inputs: 7 | K = input('Number of Single-Antenna Users: '); 8 | Tau_max = input('Maximum Acceptable Latency of Each Task: ' ); 9 | T_scaler = input('Ratio of Ran Latency to the Maximum Accepteable latency: ' ); 10 | L_max = input('Computational Load of Each Task: '); 11 | D_max = input('Data size of Each Task: '); 12 | %% Initialization 13 | %K=30;%input('number of single-antenna users: '); %number of single-antenna users 14 | N_ant=32;%input('number of antennas: '); %number of antennas 15 | N=6;%input('number of nfv-enabled nodes: '); %number of nodes 16 | L_R=4;%input('number of RRHs: '); %number of RRHs 17 | %%Definition of matrixes 18 | %H=(1/sqrt(2))*randn(N_ant,L_R,K)+1i*(1/sqrt(2))*randn(N_ant,L_R,K); %complex gaussian (H in SINR (12) formula) 19 | while true 20 | flag_connectedgraph=zeros(N-1,1); 21 | % A=randi([0 1],N); %adj matrix of nfv_enabled nodes of Graph G 22 | % A=triu(A,1)+triu(A)';%making A symmetric (it is necessary for an adj matrix for an undirected graph) 23 | % A=A-diag(diag(A))+diag(ones(N,1)); %diag entries=1 24 | % A=[1 1 0 1 1 0 25 | % 1 1 1 0 1 1 26 | % 0 1 1 1 1 1 27 | % 1 0 1 1 1 1 28 | % 1 1 1 1 1 0 29 | % 0 1 1 1 0 1]; 30 | A=[1 1 1 1 0 0 31 | 1 1 1 0 1 0 32 | 1 1 1 1 1 1 33 | 1 0 1 1 0 1 34 | 0 1 1 0 1 1 35 | 0 0 1 1 1 1]; 36 | 37 | parfor n=2:N 38 | paths2n=pathbetweennodes(A,1,n); 39 | flag_connectedgraph(n-1,1)=isempty(paths2n);%if the node is not connected it returns an empty cell, which this answer is 1 40 | end 41 | 42 | if sum(flag_connectedgraph)==0 43 | break; 44 | end 45 | end 46 | path=ones(N,1);%number of possible paths between 1 and j (for each j) 47 | parfor j=2:N 48 | path(j)=length(pathbetweennodes(A,1,j));%returns number of available paths between 1 and j 49 | end 50 | %% Graph's links and nodes setup 51 | delta_link=20*ones(N,N)+ .00001*randn(N,N); 52 | %C_node=10*rand(N,1); %C_n %Computational Capacity of node n % 53 | C_node=5*ones(N,1); 54 | %C_link=10*rand(N,N).*A; 55 | C_link=20*ones(N,N); 56 | %C_front=10*rand(L_R,1);%Fronthaul links capacity vector 57 | C_front=30*ones(L_R,1); 58 | cost_link=10*ones(N,N)+ .001*randn(N,N); 59 | delta_link=triu(delta_link,1)+triu(delta_link)';%symmetric 60 | delta_link=delta_link-diag(diag(delta_link));%make diag entries 0 61 | delta_link=delta_link.*A; 62 | cost_link=triu(cost_link,1)+triu(cost_link)';%symmetric 63 | cost_link=cost_link-diag(diag(cost_link));%make diag entries 0 64 | cost_link=cost_link.*A; 65 | C_link=C_link.*A; 66 | C_link=C_link.*(10000*eye(N))+C_link; %Diag should be big enough 67 | %% Link to path indicator 68 | I_l2p=zeros(N,N,max(path),N); %(3) link to path indicator 69 | for m=1:N 70 | for mm=1:N 71 | for n=1:N 72 | if n~=1 73 | paths2n=pathbetweennodes(A,1,n); 74 | for b=1:path(n) 75 | bth_path=cell2mat(paths2n(b)); 76 | for i=1:length(bth_path)-1 77 | if bth_path(i)==m && bth_path(i+1)==mm 78 | I_l2p(m,mm,b,n)=1; 79 | I_l2p(mm,m,b,n)=1; 80 | end 81 | end 82 | end 83 | else %n==1 84 | I_l2p(m,mm,:,1)=0; 85 | I_l2p(1,1,1,1)=1; 86 | end 87 | end 88 | end 89 | end 90 | %% Calculation of Delay for All paths in the Graph 91 | prop=nan(N,max(path)); 92 | for n=1:N 93 | for b=1:path(n) 94 | if(n==1) %Caused bugs 95 | prop(n,b)=0; 96 | else 97 | prop(n,b)=0; 98 | paths2n=pathbetweennodes(A,1,n);%Cell Array containing all paths from 1 to n 99 | bth_path=cell2mat(paths2n(b));%bth path for task k 100 | %%%bth_path contians error:Index exceeds array bounds. 101 | for i=1:length(bth_path)-1 102 | prop(n,b)=prop(n,b)+delta_link(bth_path(i),bth_path(i+1)); %(8) 103 | end 104 | end 105 | end 106 | end 107 | %% Channel & Noise Power & Path Loss Generation 108 | H_tilde=(1/sqrt(2))*randn(N_ant,L_R,K)+1i*(1/sqrt(2))*randn(N_ant,L_R,K); %complex gaussian (H in SINR (12) formula) 109 | radius=100*rand(K,1); 110 | azimuth=2*pi*rand(K,1); 111 | Location=[radius.*cos(azimuth), radius.*sin(azimuth)]; 112 | Location_site=[50,50;-50,50;-50,-50;50,-50]; 113 | Distance=zeros(K,L_R); 114 | for k=1:K 115 | for l=1:L_R 116 | Distance(k,l)=10e-3*norm(Location(k,:)-Location_site(l,:));%Distance in Km 117 | % Distance(k,l)=norm(Location(k,:)-Location_site(l,:));%Distance in meter 118 | end 119 | end 120 | Path_loss_dB=128.1+37.6*log10(Distance); 121 | Path_loss_linear=10.^(Path_loss_dB/10); 122 | % alpha=3; %Path loss exponent 123 | % Path_loss_linear=Distance.^alpha; 124 | H=zeros(N_ant,L_R,K); 125 | for k=1:K 126 | for l=1:L_R 127 | %H(:,l,k)=(1/sqrt(Path_loss_linear(k,l))).*H_tilde(:,l,k); 128 | H(:,l,k)=sqrt(1/Path_loss_linear(k,l)).*H_tilde(:,l,k); 129 | end 130 | end 131 | sigma=2.0e7*10^(-180/10); %variance in SINR formula 132 | sigma=sqrt(sigma); 133 | H=H/sigma; 134 | H_initial=H; 135 | load('channel.mat') 136 | sigma=1; 137 | %% Simulation Setup 138 | % Tau_scaler=30; 139 | %Tau_ran_scaler=Tau_scaler-Tau_scaler/20; 140 | %count_tau=Tau_scaler/20:Tau_scaler/20:Tau_scaler-Tau_scaler/20; 141 | % count_tau=1:1:29; 142 | count_tau=1; 143 | Acceptance_ratio=zeros(length(count_tau),1); 144 | Tx_power=zeros(length(count_tau),1); 145 | Exe_cost=zeros(length(count_tau),1); 146 | Acceptance_ratio_power=zeros(length(count_tau),1); 147 | Task_offloading_cost=zeros(length(count_tau),1); 148 | count_tau_integer=0; 149 | for Tau_ran_scaler=count_tau 150 | count_tau_integer=count_tau_integer+1; 151 | H=H_initial; 152 | %Tau=rand(K,1); %max tolerable latency for kth task 153 | Tau=Tau_max*ones(K,1); 154 | % Tau_ran=Tau_ran_scaler*ones(K,1); 155 | %Tau_ran=Tau_ran_scaler*ones(K,1); 156 | Tau_ran=T_scaler*Tau_max*ones(K,1); 157 | %L=rand(K,1);%Load vector for kth task 158 | % L=10*ones(K,1); 159 | L = L_max*ones(K,1); 160 | %D=rand(K,1);%Data Size vector for kth task 161 | % D=5*ones(K,1); 162 | D = D_max*ones(K,1); 163 | %Tau=sort(Tau,'descend'); 164 | %delta_link=.01*rand(N,N);%prop delay of EACH link % 165 | 166 | %% we change K to K_set here 167 | K_set=1:K;%Set of all users 168 | v=zeros(N,length(K_set)); %dec var for placing task k in node n 169 | e=zeros(N,max(path),length(K_set)); 170 | 171 | % for k=K_set 172 | % [n,b]=find(prop==max(max(prop))); 173 | % v(n,k)=1; %determines offloaded node (only one) for task k 174 | % e(n,b,k)=1; 175 | % end 176 | % for k=K_set 177 | % x=N*rand+1;%random variable 178 | % x=floor(x); 179 | % v(x,k)=1; %determines offloaded node (only one) for task k 180 | % y=path(x)*rand+1; 181 | % b=floor(y); 182 | % e(x,b,k)=1; %just offloaded k in a single path 183 | % end 184 | for k=K_set 185 | v(1,k)=1; %determines offloaded node (only one) for task k 186 | e(1,1,k)=1; %just offloaded k in a single path 187 | end 188 | %% Tau_prop (8) 189 | 190 | Tau_prop=zeros(length(K_set),1);%Tau Prop for each task k 191 | 192 | parfor k=K_set 193 | [n,b]=find(e(:,:,k)==1);%n=offloaded node and bth offloaded path number 194 | if(n==1) %Caused bugs 195 | Tau_prop(k,1)=0; 196 | else 197 | paths2n=pathbetweennodes(A,1,n);%Cell Array containing all paths from 1 to n 198 | bth_path=cell2mat(paths2n(b));%bth path for task k 199 | %%%bth_path contians error:Index exceeds array bounds. 200 | for i=1:length(bth_path)-1 201 | Tau_prop(k,1)=Tau_prop(k,1)+delta_link(bth_path(i),bth_path(i+1)); %(8) 202 | end 203 | %paths2n={};%clear paths2n 204 | end 205 | end 206 | %% (12) calculating SINR for task k (12) 207 | %p=rand(length(K_set),1);%p (p_k) 208 | p_var=10^-4*ones(length(K_set),1);%Initialization of p for DC 209 | %p_var=10^-4* rand(length(K_set),1); 210 | %sigma=1; %variance in SINR formula 211 | 212 | RRH_assign=zeros(length(K_set),1);%each user is served by which RRH 213 | for k=K_set 214 | for l=1:L_R 215 | channel_gain(l)=norm(H(:,l,k)); 216 | end 217 | [~,RRH_assign(k)]=max(channel_gain);%~:max channel gain , which l has the most channel gain 218 | end %now we know which users use which RRH (l) 219 | %now we want to know which RRH serves UE k: 220 | subset=cell(0);%Each row will specifies which users are assigned to which RRH 221 | for l=1:L_R 222 | subset=[subset;{find(RRH_assign==l)}];%WARNING: some subset elements maybe empty (cell2mat will cause problem in case of being empty) 223 | end 224 | 225 | SINR=zeros(length(K_set),1);%Initialization SINR (12) 226 | r=zeros(length(K_set),1);%Initialization %r_k %achievable data rate for k (13) 227 | Tau_tx=zeros(length(K_set),1);%Initialization of transmission delay 228 | %% Calculation of I_l^k 229 | I_t2r=zeros(L_R,length(K_set)); % task k to RRH L_R indicator 230 | 231 | for l=1:L_R 232 | for j=K_set 233 | if sum(j==cell2mat(subset(l))') 234 | I_t2r(l,j)=1; 235 | end 236 | end 237 | end 238 | %% Calculation of h_k 239 | H_user=zeros(N_ant,length(K_set)); 240 | for k=K_set 241 | H_user(:,k)=sum((H(:,:,k)*diag(I_t2r(:,k))).'); 242 | end 243 | %% Calculation of (12) and (13) and Tau_tx 244 | parfor k=K_set 245 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 246 | for l=1:L_R 247 | for j=cell2mat(subset(l))' 248 | if (j~=k) 249 | int=int+(p_var(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 250 | end 251 | end 252 | %numerator=numerator+ismember(k,cell2mat(subset(l)))*H(:,l,k);%numerator of SINR formula %dont know why it gets 0 most of the time 253 | end 254 | numerator=norm(H_user(:,k))^2; 255 | SINR(k)=(numerator*p_var(k))/(int+sigma^2);%SINR Formula 256 | r(k)=log2(1+SINR(k));%formula (13) 257 | Tau_tx(k)=D(k)/r(k);%Calculating transmission delay 258 | end %some values of SINR is 0, but it shouldn't be 259 | s=Tau_tx+Tau_prop+ones(length(K_set),1)*1.0e20*max(Tau); %s_k (1000) 260 | %% begin while 261 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 262 | %ADMISSION CONTROL FOR DISJOINT METHOD 263 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 264 | I_max=100; %max allowed iteration of feasibilty problem algorithm 265 | K_reject=[]; 266 | count_convergence=1; 267 | while true 268 | count=0;%counter of while loop for convergence of feasibility problem (16) 269 | elastic_stack=zeros(length(K_set),I_max); 270 | %rate_lower_bound=zeros(length(K_set),I_max); 271 | 272 | while true 273 | convergence_check=sum(s); 274 | count=count+1; 275 | disp('count'); 276 | disp(count); 277 | %% ADMISSION CONTROL ALGORITHM FOR DISJOINT METHOD - RADIO PART 278 | channel_gain=zeros(L_R,1); 279 | RRH_assign=zeros(length(K_set),1);%each user is served by which RRH 280 | for k=K_set 281 | for l=1:L_R 282 | channel_gain(l)=norm(H(:,l,k)); 283 | end 284 | [~,RRH_assign(k)]=max(channel_gain);%~:max channel gain , which l has the most channel gain 285 | end %now we know which users use which RRH (l) 286 | %now we want to know which RRH serves UE k: 287 | subset=cell(0);%Each row will specifies which users are assigned to which RRH 288 | for l=1:L_R 289 | subset=[subset;{find(RRH_assign==l)}];%WARNING: some subset elements maybe empty (cell2mat will cause problem in case of being empty) 290 | end 291 | 292 | %% Calculation of I_l^k 293 | I_t2r=zeros(L_R,length(K_set)); % task k to RRH L_R indicator 294 | 295 | for l=1:L_R 296 | for j=K_set 297 | if sum(j==cell2mat(subset(l))') 298 | I_t2r(l,j)=1; 299 | end 300 | end 301 | end 302 | %% calculation of h(p) g(p) nabla_g(p) nabla_h(p) 303 | nabla_h=zeros(length(K_set),length(K_set)); %h(p) in (26) %based on (22) for convex approximation 304 | %(26) 305 | for k=K_set 306 | for i=K_set 307 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 308 | numerator=0;%accumulator for numerator of SINR Formula 309 | for l=1:L_R 310 | for j=cell2mat(subset(l))' 311 | int=int+(p_var(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 312 | end 313 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 314 | end 315 | nabla_h(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 316 | end 317 | end 318 | h=zeros(length(K_set),1); 319 | g=zeros(length(K_set),1); 320 | for k=K_set 321 | int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 322 | int_g=0; 323 | for l=1:L_R 324 | for j=cell2mat(subset(l))' 325 | int_h=int_h+(p_var(j)*abs(H(:,l,k)'*H(:,l,j))^2)/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 326 | if j~=k 327 | int_g=int_g+(p_var(j)*abs(H(:,l,k)'*H(:,l,j))^2)/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 328 | end 329 | end 330 | end 331 | h(k)=log2(int_h+sigma^2);%h(p) in (22) 332 | g(k)=log2(int_g+sigma^2); 333 | end 334 | 335 | %% g(p) in (26) based on (22) for convex approx. 336 | nabla_g=zeros(length(K_set),length(K_set)); 337 | for k=K_set 338 | for i=K_set 339 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 340 | numerator=0;%accumulator for numerator of SINR Formula 341 | for l=1:L_R 342 | for j=cell2mat(subset(l))' 343 | if j~=k 344 | int=int+(p_var(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 345 | end 346 | end 347 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 348 | end 349 | if i==k 350 | nabla_g(k,i)=0; 351 | else 352 | nabla_g(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 353 | end 354 | end 355 | end 356 | %% Calculation of h_tilde & Ie 357 | 358 | h_tilde=zeros(length(K_set),L_R,length(K_set));%Fraction of h and g in (22) 359 | 360 | for k=K_set 361 | for l=1:L_R 362 | for j=K_set 363 | h_tilde(k,l,j)=(I_t2r(l,j)*abs(H(:,l,k)'*H(:,l,j))^2)/abs(H(:,l,j)'*H(:,l,j)); 364 | end 365 | end 366 | end 367 | 368 | X=zeros(length(K_set),length(K_set));%matrices for h(p) - g(p) in C3 of (27) 369 | Y=zeros(length(K_set),1); 370 | 371 | for k=K_set 372 | for j=K_set 373 | X(k,j)=sum(h_tilde(k,:,j)); 374 | end 375 | Y(k,1)=sum(h_tilde(k,:,k)); 376 | end 377 | Ie=zeros(N,N,length(K_set)); %parameter for inner summations of C3 in (27) 378 | for m=1:N 379 | for mm=1:N 380 | for k=K_set 381 | temp1=zeros(max(path),N); 382 | temp2=zeros(N,max(path)); 383 | temp1(:,:)=I_l2p(m,mm,:,:); 384 | temp2(:,:)=e(:,:,k); 385 | Ie(m,mm,k)=sum(sum(temp1.*(temp2)')); 386 | end 387 | end 388 | end 389 | nabla_Tau_tx=zeros(length(K_set),length(K_set));% 390 | for k=K_set 391 | nabla_Tau_tx(k,:)=(-D'.*(nabla_h(k,:)-nabla_g(k,:)))./((h(k)-g(k))^2); %(23) 392 | % nabla_Tau_tx(k,:)=(-D'.*(nabla_h(k,:)-nabla_g(k,:))); %(23) 393 | end 394 | %% Calculation of p_var 395 | disp('POWER ALLOCATION PROBLEM'); 396 | count_p=0; 397 | while true 398 | count_p=count_p+1; 399 | disp('count_p'); 400 | disp(count_p); 401 | cvx_begin 402 | variable p(length(K_set)) 403 | % minimize sum(nabla_Tau_tx*(p-p_var)) 404 | %maximize sum((log(X*p + ones(length(K_set),1)*(sigma^2) )/log(2))-g-nabla_g*(p - p_var)) 405 | subject to 406 | 407 | for k=K_set 408 | temp=zeros(L_R,length(K_set)); 409 | temp(:,:)=h_tilde(k,:,:); 410 | log(sum(temp*p)+sigma^2)/log(2)-g(k)-nabla_g(k,:)*(p - p_var) >= D(k)/(Tau_ran(k)+s(k)) %h(p) in (22) %C1 in (27) 411 | p(k)>=0 %c5 in (27) 412 | p(k)<=0.5 413 | end 414 | 415 | 416 | for l=1:L_R 417 | I_t2r(l,:)*(h+nabla_h*(p - p_var)-log(X*p - diag(Y)*p + ones(length(K_set),1)*(sigma^2) )/log(2)) <= C_front(l,1) %C4 in (27) 418 | end 419 | cvx_end 420 | disp(cvx_status) 421 | % disp('cvx_optval') 422 | % disp(cvx_optval) 423 | 424 | % r_convex=h+nabla_h*(p-p_var)-g; 425 | r_concave=zeros(length(K_set),1); 426 | for k=K_set 427 | temp=zeros(L_R,length(K_set)); 428 | temp(:,:)=h_tilde(k,:,:); 429 | r_concave(k,1)=log(sum(temp*p)+sigma^2)/log(2)-g(k)-nabla_g(k,:)*(p - p_var); 430 | end 431 | Tau_tx=D./r_concave; 432 | disp('Tau_tx<=Tau_ran+s'); 433 | disp((Tau_tx<=Tau_ran+s)'); 434 | disp('Tau_tx-Tau_ran-s'); 435 | disp((Tau_tx-Tau_ran-s)'); 436 | %% Calculated concave approximation of r_k for obtained values of p (p-var) 437 | g(k)=log2(int_g+sigma^2);%g(p) in (22) 438 | for k=K_set 439 | % int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 440 | int_g=0; 441 | for l=1:L_R 442 | for i=cell2mat(subset(l))' 443 | % int_h=int_h+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 444 | if i~=k 445 | int_g=int_g+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 446 | end 447 | end 448 | end 449 | g(k)=log2(int_g+sigma^2);%g(p) in (22) 450 | end 451 | 452 | r_convex=h+nabla_h*(p-p_var)-g; 453 | 454 | 455 | h=zeros(length(K_set),1); 456 | %g=zeros(length(K_set),1); 457 | r_original=zeros(length(K_set),1); 458 | 459 | parfor k=K_set 460 | int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 461 | %int_g=0; 462 | for l=1:L_R 463 | for i=cell2mat(subset(l))' 464 | int_h=int_h+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 465 | % if i~=k 466 | % int_g=int_g+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 467 | % end 468 | end 469 | end 470 | h(k)=log2(int_h+sigma^2);%h(p) in (22) 471 | %g(k)=log2(int_g+sigma^2);%g(p) in (22) 472 | r_original(k,1)=h(k)-g(k); 473 | temp=zeros(L_R,length(K_set)); 474 | temp(:,:)=h_tilde(k,:,:); 475 | end 476 | 477 | nabla_h=zeros(length(K_set),length(K_set)); %h(p) in (26) %based on (22) for convex approximation 478 | %(26) 479 | for k=K_set 480 | for i=K_set 481 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 482 | numerator=0;%accumulator for numerator of SINR Formula 483 | for l=1:L_R 484 | for j=cell2mat(subset(l))' 485 | int=int+(p(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 486 | end 487 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 488 | end 489 | nabla_h(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 490 | end 491 | end 492 | 493 | nabla_g=zeros(length(K_set),length(K_set)); 494 | for k=K_set 495 | for i=K_set 496 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 497 | numerator=0;%accumulator for numerator of SINR Formula 498 | for l=1:L_R 499 | for j=cell2mat(subset(l))' 500 | if j~=k 501 | int=int+(p(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 502 | end 503 | end 504 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 505 | end 506 | if i==k 507 | nabla_g(k,i)=0; 508 | else 509 | nabla_g(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 510 | end 511 | end 512 | end 513 | %r_concave=h_p_var-g-nabla_g*(p-p_var); 514 | % DC_objective(count_p,count)=sum(nabla_Tau_tx*(p-p_var)); 515 | if norm(p_var-p)<=10e-3 || count_p==1 516 | p_var=p; 517 | break; 518 | end 519 | p_var=p; 520 | %p_var' 521 | end 522 | Tau_tx=D./r_concave; 523 | %% solving s(k) 524 | disp('ELASTIC VARIABLES PROBLEM'); 525 | cvx_begin 526 | variable sss(length(K_set)) 527 | minimize ( sum(sss) ) 528 | subject to 529 | for k=K_set 530 | sss(k)>=Tau_tx(k)-Tau_ran(k) 531 | sss(k) >= 0 532 | end 533 | % for k=K_reject 534 | % sss(k)==0 535 | % end 536 | cvx_end 537 | s=sss; 538 | disp(cvx_status) 539 | disp('elasticization variable '); 540 | disp(s); 541 | disp('Tau_tx<=Tau_ran+s'); 542 | disp((Tau_tx<=Tau_ran+s)'); 543 | disp('Tau_tx-Tau_ran-s'); 544 | disp((Tau_tx-Tau_ran-s)'); 545 | convergence(count_convergence)=sum(s); 546 | count_convergence=count_convergence+1; 547 | elastic_stack(:,count)=s; 548 | disp('The ratio of objective improvement') 549 | disp((convergence_check-sum(s))/convergence_check) 550 | if (convergence_check-sum(s))/convergence_check <1.0e-1|| count>=I_max || convergence_check-sum(s)<1.0e-2 551 | break; 552 | end 553 | end 554 | if max(s)>=.000001 555 | K_set=1:length(K_set)-1; 556 | [~,k_reject]=max(s); 557 | H(:,:,k_reject)=[]; 558 | %c(k_reject)=[]; 559 | p(k_reject)=[]; 560 | p_var(k_reject)=[]; 561 | e(:,:,k_reject)=[]; 562 | v(:,k_reject)=[]; 563 | s(k_reject)=[]; 564 | L(k_reject)=[]; 565 | D(k_reject)=[]; 566 | Tau(k_reject)=[]; 567 | Tau_prop(k_reject)=[]; 568 | Tau_tx(k_reject)=[]; 569 | Tau_ran(k_reject)=[]; 570 | %Tau_exe(k_reject)=[]; 571 | else 572 | break; 573 | end 574 | end 575 | Acceptance_ratio_power(count_tau_integer,1)=length(K_set)/K; 576 | %% POWER ALLOCATION ALGORITHM FOR DISJOINT METHOD - OPTIMIZATION 577 | disp('power problem '); 578 | count_p=0; 579 | while true 580 | count_p=count_p+1; 581 | disp('count_p'); 582 | disp(count_p); 583 | cvx_begin 584 | variable p(length(K_set)) 585 | % minimize ( sum(nabla_Tau_tx*(p-p_var)) ) 586 | %minimize ( -100*ones(1,length(K_set))*(p-p_var)) 587 | minimize (sum(p)) 588 | subject to 589 | 590 | for k=K_set 591 | temp=zeros(L_R,length(K_set)); 592 | temp(:,:)=h_tilde(k,:,:); 593 | log(sum(temp*p)+sigma^2)/log(2)-g(k)-nabla_g(k,:)*(p - p_var) >= D(k)/(Tau_ran(k)) %h(p) in (22) %C1 in (27) 594 | p(k)>=0 %c5 in (27) 595 | p(k)<=0.5 596 | end 597 | 598 | for l=1:L_R 599 | I_t2r(l,:)*(h+nabla_h*(p - p_var)-log(X*p - diag(Y)*p + ones(length(K_set),1)*(sigma^2) )/log(2)) <= C_front(l,1) %C4 in (27) 600 | end 601 | cvx_end 602 | disp(cvx_status) 603 | disp('cvx_optval') 604 | disp(cvx_optval) 605 | cost_power=cvx_optval; 606 | 607 | % r_convex=h+nabla_h*(p-p_var)-g; 608 | r_concave=zeros(length(K_set),1); 609 | parfor k=K_set 610 | temp=zeros(L_R,length(K_set)); 611 | temp(:,:)=h_tilde(k,:,:); 612 | r_concave(k,1)=log(sum(temp*p)+sigma^2)/log(2)-g(k)-nabla_g(k,:)*(p - p_var); 613 | end 614 | Tau_tx=D./r_concave; 615 | disp('Tau_tx<=Tau_ran+s'); 616 | disp((Tau_tx<=Tau_ran+s)'); 617 | disp('Tau_tx-Tau_ran-s'); 618 | disp((Tau_tx-Tau_ran-s)'); 619 | %% Calculated concave approximation of r_k for obtained values of p (p-var) 620 | g(k)=log2(int_g+sigma^2);%g(p) in (22) 621 | for k=K_set 622 | % int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 623 | int_g=0; 624 | for l=1:L_R 625 | for i=cell2mat(subset(l))' 626 | % int_h=int_h+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 627 | if i~=k 628 | int_g=int_g+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 629 | end 630 | end 631 | end 632 | g(k)=log2(int_g+sigma^2);%g(p) in (22) 633 | end 634 | 635 | r_convex=h+nabla_h*(p-p_var)-g; 636 | 637 | 638 | h=zeros(length(K_set),1); 639 | %g=zeros(length(K_set),1); 640 | r_original=zeros(length(K_set),1); 641 | 642 | for k=K_set 643 | int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 644 | %int_g=0; 645 | for l=1:L_R 646 | for i=cell2mat(subset(l))' 647 | int_h=int_h+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 648 | % if i~=k 649 | % int_g=int_g+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 650 | % end 651 | end 652 | end 653 | h(k)=log2(int_h+sigma^2);%h(p) in (22) 654 | %g(k)=log2(int_g+sigma^2);%g(p) in (22) 655 | r_original(k,1)=h(k)-g(k); 656 | temp=zeros(L_R,length(K_set)); 657 | temp(:,:)=h_tilde(k,:,:); 658 | end 659 | 660 | nabla_h=zeros(length(K_set),length(K_set)); %h(p) in (26) %based on (22) for convex approximation 661 | %(26) 662 | for k=K_set 663 | for i=K_set 664 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 665 | numerator=0;%accumulator for numerator of SINR Formula 666 | for l=1:L_R 667 | for j=cell2mat(subset(l))' 668 | int=int+(p(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 669 | end 670 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 671 | end 672 | nabla_h(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 673 | end 674 | end 675 | 676 | nabla_g=zeros(length(K_set),length(K_set)); 677 | for k=K_set 678 | for i=K_set 679 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 680 | numerator=0;%accumulator for numerator of SINR Formula 681 | for l=1:L_R 682 | for j=cell2mat(subset(l))' 683 | if j~=k 684 | int=int+(p(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 685 | end 686 | end 687 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 688 | end 689 | if i==k 690 | nabla_g(k,i)=0; 691 | else 692 | nabla_g(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 693 | end 694 | end 695 | end 696 | if norm(p_var-p)<=10e-3 || count_p==10 697 | p_var=p; 698 | break; 699 | end 700 | p_var=p; 701 | %p_var' 702 | end 703 | Tau_tx=D./r_concave; 704 | Tx_power(count_tau_integer,1)=cost_power; 705 | 706 | 707 | %% ADMISSION CONTROL AND TASK OFFLOADING ALGORITHM FOR DISJOINT METHID 708 | s=Tau_tx+Tau_prop+ones(length(K_set),1)*1.0e3*max(Tau); 709 | while true 710 | if isempty(s)==1 711 | 712 | break; 713 | end 714 | count=0;%counter of while loop for convergence of feasibility problem (16) 715 | elastic_stack=zeros(length(K_set),I_max); 716 | %rate_lower_bound=zeros(length(K_set),I_max); 717 | 718 | while true 719 | convergence_check=sum(s); 720 | count=count+1; 721 | disp('count'); 722 | disp(count); 723 | 724 | 725 | %% cvx for (19) 726 | disp('computational capacity problem '); 727 | %constraint_bound=Tau+s-Tau_prop-Tau_tx %%%temporary 728 | cvx_begin 729 | variable c(length(K_set)) 730 | %minimize ( sum(v*pow_p(c,3)) ) 731 | minimize ( sum(L(K_set).*inv_pos(c)) ) 732 | subject to 733 | for k=K_set 734 | c(k) >= (L(k))/(Tau(k)+s(k)-Tau_prop(k)-Tau_ran(k)) 735 | c(k) >= 0 736 | end 737 | for n=1:N 738 | v(n,:)*c <= C_node(n) 739 | end 740 | cvx_end %end of (20) 741 | disp(cvx_status) 742 | Tau_exe=L(K_set)./c;% (Formula (7) for execution delay) (Load/capacity 743 | % disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 744 | % disp(Tau_tx+Tau_prop+Tau_exe<=Tau+s); 745 | % disp('Tau_exe '); 746 | % disp(Tau_exe); 747 | %% MOSEK ... Optimization of binary variables 748 | Idelta=zeros(N,max(path)); 749 | r_aug=zeros(N,max(path),length(K_set)); 750 | for n=1:N 751 | for b=1:path(n) 752 | Idelta(n,b)=sum(sum(I_l2p(:,:,b,n).*delta_link))/2; 753 | r_aug(n,b,:)=r_convex; 754 | end 755 | end 756 | 757 | Idelta_aug=zeros(N,max(path),length(K_set)); 758 | for k=K_set 759 | Idelta_aug(:,:,k)=Idelta; 760 | end 761 | 762 | I_l2p_aug=zeros(N,N,N,max(path),length(K_set)); 763 | for m=1:N 764 | for mm=1:N 765 | temp=zeros(max(path),N); 766 | 767 | temp(:,:)=I_l2p(m,mm,:,:); 768 | for k=K_set 769 | I_l2p_aug(m,mm,:,:,k)=temp'; 770 | end 771 | end 772 | end 773 | 774 | v_aug=zeros(N,max(path),length(K_set)); 775 | for n=1:N 776 | for b=1:max(path) 777 | for k=K_set 778 | v_aug(n,b,k)=v(n,k); 779 | end 780 | end 781 | end 782 | 783 | 784 | %% solving (30) for v,e,gamma 785 | disp('BINARY VARIABLES PROBLEM'); 786 | cvx_begin 787 | cvx_solver MOSEK 788 | variable e_var(N,max(path),length(K_set)) binary 789 | variable gamma_var(N,max(path),length(K_set)) binary 790 | variable v_var(N,length(K_set)) binary 791 | 792 | minimize sum(sum(sum(e_var.*Idelta_aug))) 793 | subject to 794 | for k=K_set 795 | %%%%%%%%%%%%%%%%%%%%%%%%C1-a DCP error 796 | sum(sum(e_var(:,:,k).* Idelta)) <= Tau(k)+s(k)-Tau_ran(k)-Tau_exe(k) %C1-f 797 | sum(sum(e_var(:,:,k)))==1 %C8 798 | sum(v_var(:,k)) == 1 %C7 799 | sum(sum(gamma_var(:,:,k))) == 1 %C9 800 | 801 | for n=1:N 802 | for b=1:path(n) 803 | gamma_var(n,b,k) <= v_var(n,k)+1-e_var(n,b,k) %C15 804 | v_var(n,k) <= gamma_var(n,b,k)+1-e_var(n,b,k) %C16 805 | gamma_var(n,b,k) <= e_var(n,b,k) %C17 806 | end 807 | if path(n)2 Dimensional arrays, which cause error 829 | e_var=full(e_var); 830 | v_var=full(v_var); 831 | %% Tau_prop for obtained v_var & e_var 832 | for k=K_set 833 | Tau_prop(k)=sum(sum(gamma_var(:,:,k).* Idelta)); 834 | end 835 | v=v_var; 836 | e=e_var; 837 | 838 | for n=1:N 839 | for k=K_set 840 | if abs(v(n,k)-1)<.5 841 | v(n,k)=1; 842 | else 843 | v(n,k)=0; 844 | end 845 | for b=1:max(path) 846 | if abs(e(n,b,k)-1)<.5 847 | e(n,b,k)=1; 848 | else 849 | e(n,b,k)=0; 850 | end 851 | end 852 | end 853 | end 854 | 855 | 856 | % disp('Tau_prop '); 857 | % disp(Tau_prop); 858 | disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 859 | disp((Tau_tx+Tau_prop+Tau_exe<=Tau+s)'); 860 | disp('Tau_tx+Tau_prop+Tau_exe-Tau-s'); 861 | disp((Tau_tx+Tau_prop+Tau_exe-Tau-s)'); 862 | %% solving s(k) 863 | disp('elastic variables problem '); 864 | cvx_begin 865 | variable sss(length(K_set)) 866 | minimize ( sum(sss) ) 867 | subject to 868 | for k=K_set 869 | sss(k)>=Tau_prop(k)+Tau_exe(k)+Tau_ran(k)-Tau(k) 870 | sss(k) >= 0 871 | end 872 | for k=K_reject 873 | sss(k)==0 874 | end 875 | cvx_end 876 | s=sss; 877 | disp(cvx_status) 878 | % for k=K_set 879 | % s(k)=max(Tau_exe(k)+Tau_prop(k)+Tau_tx(k)-Tau(k),0); 880 | % end 881 | %constraint_bound_updated=Tau+s-Tau_tx-Tau_prop 882 | disp('elasticization variable '); 883 | disp(s); 884 | %% ASM Modification Algorithm 885 | disp('ASM Modification Algorithm'); 886 | s=s+(1.0e-9)*rand(length(s),1); % To differentiate the values of s(k) which may cause problems for finding sorted_indices entries 887 | sorted_tasks=sort(s); 888 | sorted_indices=zeros(length(K_set),1); 889 | for k=K_set 890 | sorted_indices(k,1)=find(sorted_tasks(k)==s); 891 | end 892 | C_tilde_node=zeros(N,1); 893 | for k=sorted_indices' 894 | parfor n=1:N 895 | C_tilde_node(n,1)=C_node(n,1)-v(n,:)*c+c(k)*v(n,k)-.0001; 896 | end 897 | C_tilde_link=zeros(N,N); 898 | parfor m=1:N 899 | for mm=1:N 900 | temp=zeros(length(K_set),1); 901 | temp1=zeros(max(path),N); 902 | temp1(:,:)=I_l2p(m,mm,:,:); 903 | for i=K_set 904 | if i~=k 905 | temp2=zeros(max(path),N); 906 | temp2(:,:)=r_aug(:,:,i)'; 907 | temp(i,1)=sum(sum(temp1.*e(:,:,i)'.*temp2)); 908 | end 909 | end 910 | C_tilde_link(m,mm)=C_link(m,mm)-sum(temp); 911 | end 912 | end 913 | Nodes_e=[]; % The set of nodes which have links with sufficient bandwidth 914 | feasiblepaths=zeros(N,max(path)); 915 | for n=1:N 916 | feasiblepaths_b=[]; 917 | for b=1:path(n) 918 | flag=[]; 919 | for m=1:N 920 | for mm=1:N 921 | if I_l2p(m,mm,b,n)==1 922 | if r_convex(k,1)<=C_tilde_link(m,mm) 923 | flag=[flag;1]; 924 | else 925 | flag=[flag;0]; 926 | end 927 | end 928 | end 929 | end 930 | if prod(flag)==1 931 | if ismember(n,Nodes_e)==0 932 | Nodes_e=[Nodes_e,n] ; 933 | end 934 | feasiblepaths_b=[feasiblepaths_b,b]; 935 | %break; 936 | end 937 | end 938 | feasiblepaths(n,1:length(feasiblepaths_b))=feasiblepaths_b; 939 | end 940 | Node_feasible=[]; 941 | for n=Nodes_e 942 | if C_tilde_node(n,1)>=c(k)-.001 943 | Node_feasible=[Node_feasible,n]; 944 | end 945 | end 946 | Tau_exe_prop=nan(N,max(path)); 947 | for n=Node_feasible 948 | % c(k)=C_tilde_node(n,1); 949 | for b=setdiff(feasiblepaths(n,:),0) 950 | Tau_exe_prop(n,b)=L(k)/C_tilde_node(n,1)+prop(n,b); 951 | end 952 | end 953 | [n_star,b_star]=find(Tau_exe_prop==min(min(Tau_exe_prop))); 954 | Tau_prop(k,1)=prop(n_star,b_star); 955 | v(:,k)=zeros(N,1); 956 | v(n_star,k)=1; 957 | e(:,:,k)=zeros(N,max(path)); 958 | e(n_star,b_star,k)=1; 959 | s_tilde=Tau_ran(k,1)+Tau_prop(k,1)+L(k)/C_tilde_node(n_star,1)-Tau(k,1); 960 | if s_tilde<0 961 | c(k)=L(k)/(Tau(k,1)-Tau_ran(k,1)-Tau_prop(k,1)); 962 | s(k)=0; 963 | else 964 | s(k)=s_tilde; 965 | c(k)=C_tilde_node(n_star,1); 966 | end 967 | Tau_exe(k,1)=L(k)/c(k); 968 | end 969 | disp('Elastic Variables'); 970 | disp(s); 971 | disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 972 | disp((Tau_tx+Tau_prop+Tau_exe<=Tau+s)'); 973 | disp('Tau_tx+Tau_prop+Tau_exe-Tau-s'); 974 | disp((Tau_tx+Tau_prop+Tau_exe-Tau-s)'); 975 | 976 | 977 | convergence(count_convergence)=sum(s); 978 | count_convergence=count_convergence+1; 979 | elastic_stack(:,count)=s; 980 | disp('The ratio of objective improvement') 981 | % disp((obj_feas(count-1)-sum(s))/obj_feas(count-1)) 982 | disp((convergence_check-sum(s))/convergence_check) 983 | % if abs(obj_feas(count-1)-sum(s))<10e-1 || abs(obj_feas(count-1)-sum(s))/obj_feas(count-1)<10e-2 || count>=I_max 984 | if (convergence_check-sum(s))/convergence_check <10e-2|| count>=I_max || convergence_check-sum(s)<10e-1 985 | break; 986 | end 987 | 988 | end 989 | if max(s)>=.000001 990 | %K_set=setdiff(K_set,find(s==max(s))); 991 | %K_reject=[K_reject; find(s==max(s))]; 992 | K_set=1:length(K_set)-1; 993 | [~,k_reject]=max(s); 994 | H(:,:,k_reject)=[]; 995 | c(k_reject)=[]; 996 | p(k_reject)=[]; 997 | p_var(k_reject)=[]; 998 | e(:,:,k_reject)=[]; 999 | v(:,k_reject)=[]; 1000 | s(k_reject)=[]; 1001 | L(k_reject)=[]; 1002 | D(k_reject)=[]; 1003 | Tau(k_reject)=[]; 1004 | Tau_prop(k_reject)=[]; 1005 | Tau_tx(k_reject)=[]; 1006 | Tau_exe(k_reject)=[]; 1007 | Tau_ran(k_reject)=[]; 1008 | r_convex(k_reject)=[]; 1009 | else 1010 | break; 1011 | end 1012 | end 1013 | %% TASK OFFLOADING OPTIMIZATION 1014 | cost_computation=sum(v*(c.^3)); 1015 | Igamma=zeros(N,max(path)); 1016 | for n=1:N 1017 | for b=1:path(n) 1018 | Igamma(n,b)=sum(sum(I_l2p(:,:,b,n).*cost_link))/2; 1019 | end 1020 | end 1021 | Igamma_aug=zeros(N,max(path),length(K_set)); 1022 | for k=K_set 1023 | Igamma_aug(:,:,k)=Igamma*r_convex(k,1); 1024 | end 1025 | cost_forwarding=sum(sum(sum(e.*Igamma_aug))); 1026 | ovreall_cost=zeros(I_max,1); 1027 | TO_cost=cost_computation+cost_forwarding; 1028 | count=0; 1029 | while true 1030 | TO_cost=cost_computation+cost_forwarding; 1031 | count=count+1; 1032 | disp('count'); 1033 | disp(count); 1034 | disp('computational capacity problem '); 1035 | %% cvx for (19) 1036 | %constraint_bound=Tau+s-Tau_prop-Tau_tx %%%temporary 1037 | cvx_begin 1038 | variable c(length(K_set)) 1039 | minimize ( sum(v*pow_p(c,3)) ) 1040 | % minimize ( sum(L(K_set).*inv_pos(c)) ) 1041 | subject to 1042 | for k=K_set 1043 | c(k) >= (L(k))/(Tau(k)-Tau_prop(k)-Tau_ran(k)) 1044 | c(k) >= 0 1045 | end 1046 | for n=1:N 1047 | v(n,:)*c <= C_node(n) 1048 | end 1049 | cvx_end %end of (20) 1050 | disp(cvx_status) 1051 | cost_computation=cvx_optval; 1052 | Tau_exe=L(K_set)./c;% (Formula (7) for execution delay) (Load/capacity 1053 | % disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 1054 | % disp(Tau_tx+Tau_prop+Tau_exe<=Tau+s); 1055 | % disp('Tau_exe '); 1056 | % disp(Tau_exe); 1057 | Exe_cost(count_tau_integer,1)=cost_computation; 1058 | %% MOSEK ... Optimization of binary variables 1059 | Idelta=zeros(N,max(path)); 1060 | Igamma=zeros(N,max(path)); 1061 | r_aug=zeros(N,max(path),length(K_set)); 1062 | for n=1:N 1063 | for b=1:path(n) 1064 | Idelta(n,b)=sum(sum(I_l2p(:,:,b,n).*delta_link))/2; 1065 | Igamma(n,b)=sum(sum(I_l2p(:,:,b,n).*cost_link))/2; 1066 | r_aug(n,b,:)=r_convex; 1067 | end 1068 | end 1069 | 1070 | Igamma_aug=zeros(N,max(path),length(K_set)); 1071 | for k=K_set 1072 | Igamma_aug(:,:,k)=Igamma*r_convex(k,1); 1073 | end 1074 | 1075 | I_l2p_aug=zeros(N,N,N,max(path),length(K_set)); 1076 | for m=1:N 1077 | for mm=1:N 1078 | temp=zeros(max(path),N); 1079 | 1080 | temp(:,:)=I_l2p(m,mm,:,:); 1081 | for k=K_set 1082 | I_l2p_aug(m,mm,:,:,k)=temp'; 1083 | end 1084 | end 1085 | end 1086 | 1087 | v_aug=zeros(N,max(path),length(K_set)); 1088 | for n=1:N 1089 | for b=1:max(path) 1090 | for k=K_set 1091 | v_aug(n,b,k)=v(n,k); 1092 | end 1093 | end 1094 | end 1095 | %% solving (30) for v,e,gamma 1096 | disp('binary variables problem '); 1097 | cvx_begin 1098 | cvx_solver MOSEK 1099 | variable e_var(N,max(path),length(K_set)) binary 1100 | variable gamma_var(N,max(path),length(K_set)) binary 1101 | variable v_var(N,length(K_set)) binary 1102 | 1103 | minimize sum(sum(sum(e_var.*Igamma_aug))) 1104 | subject to 1105 | for k=K_set 1106 | %%%%%%%%%%%%%%%%%%%%%%%%C1-a DCP error 1107 | sum(sum(e_var(:,:,k).* Idelta)) <= Tau(k)+s(k)-Tau_ran(k)-Tau_exe(k) %C1-a 1108 | sum(sum(e_var(:,:,k)))==1 %C8 1109 | sum(v_var(:,k)) == 1 %C7 1110 | sum(sum(gamma_var(:,:,k))) == 1 %C9 1111 | 1112 | for n=1:N 1113 | for b=1:path(n) 1114 | gamma_var(n,b,k) <= v_var(n,k)+1-e_var(n,b,k) %C15 1115 | v_var(n,k) <= gamma_var(n,b,k)+1-e_var(n,b,k) %C16 1116 | gamma_var(n,b,k) <= e_var(n,b,k) %C17 1117 | end 1118 | if path(n)2 Dimensional arrays, which cause error in obtaining Tau_prop(k) 1141 | e_var=full(e_var); 1142 | v_var=full(v_var); 1143 | 1144 | %% Tau_prop for obtained v_var & e_var 1145 | for k=K_set 1146 | Tau_prop(k)=sum(sum(gamma_var(:,:,k).* Idelta)); 1147 | end 1148 | v=v_var; 1149 | e=e_var; 1150 | 1151 | for n=1:N 1152 | for k=K_set 1153 | if abs(v(n,k)-1)<.5 1154 | v(n,k)=1; 1155 | else 1156 | v(n,k)=0; 1157 | end 1158 | for b=1:max(path) 1159 | if abs(e(n,b,k)-1)<.5 1160 | e(n,b,k)=1; 1161 | else 1162 | e(n,b,k)=0; 1163 | end 1164 | end 1165 | end 1166 | end 1167 | 1168 | % disp('Tau_prop '); 1169 | % disp(Tau_prop); 1170 | disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 1171 | disp((Tau_tx+Tau_prop+Tau_exe<=Tau+s)'); 1172 | disp('Tau_tx+Tau_prop+Tau_exe-Tau-s'); 1173 | disp((Tau_tx+Tau_prop+Tau_exe-Tau-s)'); 1174 | %% Convergence criterion 1175 | ovreall_cost(count,1)=cost_computation+cost_forwarding; %last iteration's sum(s) (feasibility problem) 1176 | disp('ovreall_cost') 1177 | disp(ovreall_cost(1:count)) 1178 | if abs(TO_cost-ovreall_cost(count))<10e-3 || count>=I_max 1179 | break; 1180 | end 1181 | end 1182 | Task_offloading_cost(count_tau_integer,1)=cost_computation+cost_forwarding; 1183 | Acceptance_ratio(count_tau_integer,1)=length(K_set)/K; 1184 | end 1185 | % save('disjoint_vars.mat','Acceptance_ratio','Task_offloading_cost','count_tau','Tx_power','Acceptance_ratio_power','Exe_cost','H_initial'); 1186 | %% Outputs 1187 | disp('Acceptance Ratio:') 1188 | disp(length(K_set)/K) 1189 | disp('Radio Transmission Latency:') 1190 | disp(Tau_tx) 1191 | disp('Propagation Latency:') 1192 | disp(Tau_prop) 1193 | disp('Execution Latency:') 1194 | disp(Tau_exe) -------------------------------------------------------------------------------- /Figures/1a. A typical task offloading example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/1a. A typical task offloading example.png -------------------------------------------------------------------------------- /Figures/1b. System model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/1b. System model.png -------------------------------------------------------------------------------- /Figures/2a. Acceptance Ratio vs. T for K=30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/2a. Acceptance Ratio vs. T for K=30.png -------------------------------------------------------------------------------- /Figures/2a. Acceptance ratio vs. K for T=40 ms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/2a. Acceptance ratio vs. K for T=40 ms.png -------------------------------------------------------------------------------- /Figures/3a. Convergence of admission control algorithm for T=20 ms and K=30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/3a. Convergence of admission control algorithm for T=20 ms and K=30.png -------------------------------------------------------------------------------- /Figures/3b. Acceptance ratio of joint vs. disjoint methods in terms of T_RAN for T=30 ms and K=30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/3b. Acceptance ratio of joint vs. disjoint methods in terms of T_RAN for T=30 ms and K=30.png -------------------------------------------------------------------------------- /Figures/4a. Average radio transmission and execution latencies vs D for T=20 ms and K=30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/4a. Average radio transmission and execution latencies vs D for T=20 ms and K=30.png -------------------------------------------------------------------------------- /Figures/4a. Average radio transmission and execution latencies vs L for T=20 ms and K=30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/4a. Average radio transmission and execution latencies vs L for T=20 ms and K=30.png -------------------------------------------------------------------------------- /Figures/5. Placement of the different classes of tasks at 3 different tiers of nodes for K=30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/5. Placement of the different classes of tasks at 3 different tiers of nodes for K=30.png -------------------------------------------------------------------------------- /Figures/6. Acceptance ration of LTO and JTO vs max acceptable latency.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/Figures/6. Acceptance ration of LTO and JTO vs max acceptable latency.png -------------------------------------------------------------------------------- /JTO.m: -------------------------------------------------------------------------------- 1 | clc; 2 | clear; 3 | close all; 4 | cvx_quiet true 5 | %% Inputs: 6 | K = input('Number of Single-Antenna Users: '); 7 | T_max = input('Maximum Acceptable Latency of Each Task: ' ); 8 | L_max = input('Computational Load of Each Task: '); 9 | D_max = input('Data size of Each Task: '); 10 | %% Initialization 11 | %K=30;%input('number of single-antenna users: '); %number of single-antenna users 12 | N_ant=32;%input('number of antennas: '); %number of antennas 13 | N=6;%input('number of nfv-enabled nodes: '); %number of nodes 14 | L_R=4;%input('number of RRHs: '); %number of RRHs 15 | %%Definition of matrices 16 | while true 17 | flag_connectedgraph=zeros(N-1,1); 18 | A=randi([0 1],N); %adj matrix of nfv_enabled nodes of Graph G 19 | A=triu(A,1)+triu(A)';%making A symmetric (it is necessary for an adj matrix for an undirected graph) 20 | A=A-diag(diag(A))+diag(ones(N,1)); %diag entries=1 21 | A=[1 1 0 1 1 0 22 | 1 1 1 0 1 1 23 | 0 1 1 1 1 1 24 | 1 0 1 1 1 1 25 | 1 1 1 1 1 0 26 | 0 1 1 1 0 1]; 27 | 28 | for n=2:N 29 | paths2n=pathbetweennodes(A,1,n); 30 | flag_connectedgraph(n-1,1)=isempty(paths2n);%if the node is not connected it returns an empty cell, which this answer is 1 31 | end 32 | 33 | if sum(flag_connectedgraph)==0 34 | break; 35 | end 36 | end 37 | path=ones(N,1);%number of possible paths between 1 and j (for each j) 38 | for j=2:N 39 | path(j)=length(pathbetweennodes(A,1,j));%returns number of available paths between 1 and j 40 | end 41 | %% Channel & Path Loss Generation 42 | H_tilde=(1/sqrt(2))*randn(N_ant,L_R,K)+1i*(1/sqrt(2))*randn(N_ant,L_R,K); %complex gaussian (H in SINR (12) formula) 43 | radius=100*rand(K,1); 44 | azimuth=2*pi*rand(K,1); 45 | Location=[radius.*cos(azimuth), radius.*sin(azimuth)]; 46 | Location_site=[50,50;-50,50;-50,-50;50,-50]; 47 | D=zeros(K,L_R); 48 | for k=1:K 49 | for l=1:L_R 50 | D(k,l)=10e-3*norm(Location(k,:)-Location_site(l,:));%D in Km 51 | end 52 | end 53 | Path_loss_dB=128.1+37.6*log10(D); 54 | Path_loss_linear=10.^(Path_loss_dB/10); 55 | H=zeros(N_ant,L_R,K); 56 | for k=1:K 57 | for l=1:L_R 58 | H(:,l,k)=(1/sqrt(Path_loss_linear(k,l))).*H_tilde(:,l,k); 59 | end 60 | end 61 | %% Simulation Setup 62 | 63 | %Tau=rand(K,1); %max tolerable latency for kth task 64 | Tau = T_max*ones(K,1); 65 | %Tau = 15*ones(K,1); 66 | %L=rand(K,1);%Load vector for kth task 67 | L = L_max*ones(K,1); 68 | %L=10*ones(K,1); 69 | %D=rand(K,1);%Data Size vector for kth task 70 | %D=5*ones(K,1); 71 | D = D_max*ones(K,1); 72 | %Tau=sort(Tau,'descend'); 73 | %delta_link=.01*rand(N,N);%prop delay of EACH link % 74 | delta_link=10*ones(N,N)+ .001*randn(N,N); 75 | %C_node=10*rand(N,1); %C_n %Computational Capacity of node n % 76 | C_node=10*ones(N,1); 77 | %C_link=10*rand(N,N).*A; 78 | C_link=20*ones(N,N); 79 | %C_front=10*rand(L_R,1);%Fronthaul links capacity vector 80 | C_front=30*ones(L_R,1); 81 | %% 82 | 83 | delta_link=triu(delta_link,1)+triu(delta_link)';%symmetric 84 | delta_link=delta_link-diag(diag(delta_link));%make diag entries 0 85 | delta_link=delta_link.*A; 86 | C_link=C_link.*(10000*eye(N))+C_link; %Diag should be big enough 87 | %% Link to path indicator 88 | I_l2p=zeros(N,N,max(path),N); %(3) link to path indicator 89 | for m=1:N 90 | for mm=1:N 91 | for n=1:N 92 | if n~=1 93 | paths2n=pathbetweennodes(A,1,n); 94 | for b=1:path(n) 95 | bth_path=cell2mat(paths2n(b)); 96 | for i=1:length(bth_path)-1 97 | if bth_path(i)==m && bth_path(i+1)==mm 98 | I_l2p(m,mm,b,n)=1; 99 | I_l2p(mm,m,b,n)=1; 100 | end 101 | end 102 | end 103 | else %n==1 104 | I_l2p(m,mm,:,1)=0; 105 | I_l2p(1,1,1,1)=1; 106 | end 107 | end 108 | end 109 | end 110 | %% Calculation of Delay for All paths in the Graph 111 | prop=nan(N,max(path)); 112 | for n=1:N 113 | for b=1:path(n) 114 | if(n==1) %Caused bugs 115 | prop(n,b)=0; 116 | else 117 | prop(n,b)=0; 118 | paths2n=pathbetweennodes(A,1,n);%Cell Array containing all paths from 1 to n 119 | bth_path=cell2mat(paths2n(b));%bth path for task k 120 | %%%bth_path contians error:Index exceeds array bounds. 121 | for i=1:length(bth_path)-1 122 | prop(n,b)=prop(n,b)+delta_link(bth_path(i),bth_path(i+1)); %(8) 123 | end 124 | end 125 | end 126 | end 127 | %% we change K to K_set here 128 | K_set=1:K;%Set of all users 129 | v=zeros(N,length(K_set)); %dec var for placing task k in node n 130 | 131 | e=zeros(N,max(path),length(K_set)); 132 | % for k=K_set 133 | % x=N*rand+1;%random variable 134 | % x=floor(x); 135 | % v(x,k)=1; %determines offloaded node (only one) for task k 136 | % y=path(x)*rand+1; 137 | % b=floor(y); 138 | % e(x,b,k)=1; %just offloaded k in a single path 139 | % end 140 | for k=K_set 141 | v(1,k)=1; %determines offloaded node (only one) for task k 142 | e(1,1,k)=1; %just offloaded k in a single path 143 | end 144 | %% Tau_prop (8) 145 | 146 | Tau_prop=zeros(length(K_set),1);%Tau Prop for each task k 147 | 148 | for k=K_set 149 | [n,b]=find(e(:,:,k)==1);%n=offloaded node and bth offloaded path number 150 | if(n==1) %Caused bugs 151 | Tau_prop(k,1)=0; 152 | else 153 | paths2n=pathbetweennodes(A,1,n);%Cell Array containing all paths from 1 to n 154 | bth_path=cell2mat(paths2n(b));%bth path for task k 155 | %%%bth_path contians error:Index exceeds array bounds. 156 | for i=1:length(bth_path)-1 157 | Tau_prop(k,1)=Tau_prop(k,1)+delta_link(bth_path(i),bth_path(i+1)); %(8) 158 | end 159 | %paths2n={};%clear paths2n 160 | end 161 | end 162 | %% (12) calculating SINR for task k (12) 163 | %p=rand(length(K_set),1);%p (p_k) 164 | p_var=10^2* ones(length(K_set),1);%Initialization of p for DC 165 | %p_var=10^-4* rand(length(K_set),1); 166 | sigma=2*10e6*10^(-180/10); %variance in SINR formula 167 | sigma=sqrt(sigma); 168 | 169 | RRH_assign=zeros(length(K_set),1);%each user is served by which RRH 170 | for k=K_set 171 | for l=1:L_R 172 | channel_gain(l)=norm(H(:,l,k)); 173 | end 174 | [~,RRH_assign(k)]=max(channel_gain);%~:max channel gain , which l has the most channel gain 175 | end %now we know which users use which RRH (l) 176 | %now we want to know which RRH serves UE k: 177 | subset=cell(0);%Each row will specifies which users are assigned to which RRH 178 | for l=1:L_R 179 | subset=[subset;{find(RRH_assign==l)}];%WARNING: some subset elements maybe empty (cell2mat will cause problem in case of being empty) 180 | end 181 | 182 | SINR=zeros(length(K_set),1);%Initialization SINR (12) 183 | r=zeros(length(K_set),1);%Initialization %r_k %achievable data rate for k (13) 184 | Tau_tx=zeros(length(K_set),1);%Initialization of transmission delay 185 | 186 | 187 | 188 | %% Calculation of I_l^k 189 | I_t2r=zeros(L_R,length(K_set)); % task k to RRH L_R indicator 190 | 191 | for l=1:L_R 192 | for j=K_set 193 | if sum(j==cell2mat(subset(l))') 194 | I_t2r(l,j)=1; 195 | end 196 | end 197 | end 198 | %% Calculation of h_k 199 | H_user=zeros(N_ant,length(K_set)); 200 | for k=K_set 201 | H_user(:,k)=sum((H(:,:,k)*diag(I_t2r(:,k))).'); 202 | end 203 | %% Calculation of (12) and (13) and Tau_tx 204 | for k=K_set 205 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 206 | for l=1:L_R 207 | for j=cell2mat(subset(l))' 208 | if (j~=k) 209 | int=int+(p_var(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 210 | end 211 | end 212 | %numerator=numerator+ismember(k,cell2mat(subset(l)))*H(:,l,k);%numerator of SINR formula %dont know why it gets 0 most of the time 213 | end 214 | numerator=norm(H_user(:,k))^2; 215 | SINR(k)=(numerator*p_var(k))/(int+sigma^2);%SINR Formula 216 | r(k)=log2(1+SINR(k));%formula (13) 217 | Tau_tx(k)=D(k)/r(k);%Calculating transmission delay 218 | end %some values of SINR is 0, but it shouldn't be 219 | s=Tau_tx+Tau_prop+ones(length(K_set),1)*100000*max(Tau); %s_k (1000) 220 | %% begin while 221 | 222 | I_max=100; %max allowed iteration of feasibilty problem algorithm 223 | K_reject=[]; 224 | count_convergence=1; 225 | while true 226 | obj_feas=zeros(I_max,1); 227 | count=0;%counter of while loop for convergence of feasibility problem (16) 228 | elastic_stack=zeros(length(K_set),I_max); 229 | %rate_lower_bound=zeros(length(K_set),I_max); 230 | 231 | while true 232 | convergence_check=sum(s); 233 | count=count+1; 234 | % disp('count'); 235 | % disp(count); 236 | channel_gain=zeros(L_R,1); 237 | RRH_assign=zeros(length(K_set),1);%each user is served by which RRH 238 | for k=K_set 239 | for l=1:L_R 240 | channel_gain(l)=norm(H(:,l,k)); 241 | end 242 | [~,RRH_assign(k)]=max(channel_gain);%~:max channel gain , which l has the most channel gain 243 | end %now we know which users use which RRH (l) 244 | %now we want to know which RRH serves UE k: 245 | subset=cell(0);%Each row will specifies which users are assigned to which RRH 246 | for l=1:L_R 247 | subset=[subset;{find(RRH_assign==l)}];%WARNING: some subset elements maybe empty (cell2mat will cause problem in case of being empty) 248 | end 249 | 250 | %% Calculation of I_l^k 251 | I_t2r=zeros(L_R,length(K_set)); % task k to RRH L_R indicator 252 | 253 | for l=1:L_R 254 | for j=K_set 255 | if sum(j==cell2mat(subset(l))') 256 | I_t2r(l,j)=1; 257 | end 258 | end 259 | end 260 | 261 | % disp('computational capacity problem '); 262 | %% cvx for (19) 263 | %constraint_bound=Tau+s-Tau_prop-Tau_tx %%%temporary 264 | cvx_begin 265 | variable c(length(K_set)) 266 | %minimize ( sum(v*pow_p(c,3)) ) 267 | %minimize ( sum(L(K_set).*inv_pos(c)) ) 268 | subject to 269 | for k=K_set 270 | c(k) >= (L(k))/(Tau(k)+s(k)-Tau_prop(k)-Tau_tx(k)); 271 | c(k) >= 0; 272 | end 273 | for n=1:N 274 | v(n,:)*c <= C_node(n); 275 | end 276 | cvx_end %end of (20) 277 | disp(cvx_status) 278 | Tau_exe=L(K_set)./c;% (Formula (7) for execution delay) (Load/capacity 279 | % disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 280 | % disp(Tau_tx+Tau_prop+Tau_exe<=Tau+s); 281 | % disp('Tau_exe '); 282 | % disp(Tau_exe); 283 | %% calculation of h(p) g(p) nabla_g(p) nabla_h(p) 284 | 285 | 286 | nabla_h=zeros(length(K_set),length(K_set)); %h(p) in (26) %based on (22) for convex approximation 287 | %(26) 288 | for k=K_set 289 | for i=K_set 290 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 291 | numerator=0;%accumulator for numerator of SINR Formula 292 | for l=1:L_R 293 | for j=cell2mat(subset(l))' 294 | int=int+(p_var(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 295 | end 296 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 297 | end 298 | nabla_h(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 299 | end 300 | end 301 | h=zeros(length(K_set),1); 302 | g=zeros(length(K_set),1); 303 | for k=K_set 304 | int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 305 | int_g=0; 306 | for l=1:L_R 307 | for j=cell2mat(subset(l))' 308 | int_h=int_h+(p_var(j)*abs(H(:,l,k)'*H(:,l,j))^2)/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 309 | if j~=k 310 | int_g=int_g+(p_var(j)*abs(H(:,l,k)'*H(:,l,j))^2)/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 311 | end 312 | end 313 | end 314 | h(k)=log2(int_h+sigma^2);%h(p) in (22) 315 | g(k)=log2(int_g+sigma^2); 316 | end 317 | 318 | %% g(p) in (26) based on (22) for convex approx. 319 | nabla_g=zeros(length(K_set),length(K_set)); 320 | for k=K_set 321 | for i=K_set 322 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 323 | numerator=0;%accumulator for numerator of SINR Formula 324 | for l=1:L_R 325 | for j=cell2mat(subset(l))' 326 | if j~=k 327 | int=int+(p_var(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 328 | end 329 | end 330 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 331 | end 332 | if i==k 333 | nabla_g(k,i)=0; 334 | else 335 | nabla_g(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 336 | end 337 | end 338 | end 339 | %% Calculation of h_tilde & Ie 340 | 341 | h_tilde=zeros(length(K_set),L_R,length(K_set));%Fraction of h and g in (22) 342 | 343 | for k=K_set 344 | for l=1:L_R 345 | for j=K_set 346 | h_tilde(k,l,j)=(I_t2r(l,j)*abs(H(:,l,k)'*H(:,l,j))^2)/abs(H(:,l,j)'*H(:,l,j)); 347 | end 348 | end 349 | end 350 | 351 | X=zeros(length(K_set),length(K_set));%matrices for h(p) - g(p) in C3 of (27) 352 | Y=zeros(length(K_set),1); 353 | 354 | for k=K_set 355 | for j=K_set 356 | X(k,j)=sum(h_tilde(k,:,j)); 357 | end 358 | Y(k,1)=sum(h_tilde(k,:,k)); 359 | end 360 | Ie=zeros(N,N,length(K_set)); %parameter for inner summations of C3 in (27) 361 | for m=1:N 362 | for mm=1:N 363 | for k=K_set 364 | temp1=zeros(max(path),N); 365 | temp2=zeros(N,max(path)); 366 | temp1(:,:)=I_l2p(m,mm,:,:); 367 | temp2(:,:)=e(:,:,k); 368 | Ie(m,mm,k)=sum(sum(temp1.*(temp2)')); 369 | end 370 | end 371 | end 372 | 373 | 374 | nabla_Tau_tx=zeros(length(K_set),length(K_set));% 375 | for k=K_set 376 | nabla_Tau_tx(k,:)=(-D'.*(nabla_h(k,:)-nabla_g(k,:)))./((h(k)-g(k))^2); %(23) 377 | % nabla_Tau_tx(k,:)=(-D'.*(nabla_h(k,:)-nabla_g(k,:))); %(23) 378 | end 379 | %% Calculation of p_var 380 | % disp('power problem '); 381 | %r_test=zeros(length(K_set),1); 382 | % p_var' 383 | % disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 384 | % disp(Tau_tx+Tau_prop+Tau_exe<=Tau+s); 385 | % for k=K_set 386 | % rate_lower_bound(k,count)=D(k)/(Tau(k)+s(k)-Tau_prop(k)-Tau_exe(k)); 387 | % end 388 | count_p=0; 389 | while true 390 | count_p=count_p+1; 391 | % disp('count_p'); 392 | % disp(count_p); 393 | cvx_begin 394 | variable p(length(K_set)) 395 | % minimize sum(nabla_Tau_tx*(p-p_var)) 396 | % maximize sum((log(X*p + ones(length(K_set),1)*(sigma^2) )/log(2))-g-nabla_g*(p - p_var)) 397 | subject to 398 | 399 | for k=K_set 400 | temp=zeros(L_R,length(K_set)); 401 | temp(:,:)=h_tilde(k,:,:); 402 | log(sum(temp*p)+sigma^2)/log(2)-g(k)-nabla_g(k,:)*(p - p_var) >= D(k)/(Tau(k)+s(k)-Tau_prop(k)-Tau_exe(k)); %h(p) in (22) %C1 in (27) 403 | p(k)>=0; %c5 in (27) 404 | end 405 | 406 | for m=1:N 407 | for mm=1:N 408 | temp=zeros(1,length(K_set)); 409 | temp(1,:)=Ie(m,mm,:); 410 | temp*(h+nabla_h*(p - p_var)-log(X*p - diag(Y)*p + ones(length(K_set),1)*(sigma^2) )/log(2)) <= C_link(m,mm); %C3 in (27) 411 | end 412 | end 413 | 414 | for l=1:L_R 415 | I_t2r(l,:)*(h+nabla_h*(p - p_var)-log(X*p - diag(Y)*p + ones(length(K_set),1)*(sigma^2) )/log(2)) <= C_front(l,1); %C4 in (27) 416 | end 417 | cvx_end 418 | % disp(cvx_status) 419 | % disp('cvx_optval') 420 | % disp(cvx_optval) 421 | 422 | % r_convex=h+nabla_h*(p-p_var)-g; 423 | r_concave=zeros(length(K_set),1); 424 | for k=K_set 425 | temp=zeros(L_R,length(K_set)); 426 | temp(:,:)=h_tilde(k,:,:); 427 | r_concave(k,1)=log(sum(temp*p)+sigma^2)/log(2)-g(k)-nabla_g(k,:)*(p - p_var); 428 | end 429 | Tau_tx=D./r_concave; 430 | 431 | % for k=K_set 432 | % s(k)=max(Tau_exe(k)+Tau_prop(k)+Tau_tx(k)-Tau(k),0)+.0001; 433 | % end 434 | 435 | % for m=1:N 436 | % for mm=1:N 437 | % temp=zeros(1,length(K_set)); 438 | % temp(1,:)=Ie(m,mm,:); 439 | % AA(m,mm)=temp*(h+nabla_h*(p - p_var)-log(X*p - diag(Y)*p + ones(length(K_set),1)*(sigma^2) )/log(2)); 440 | % end 441 | % end 442 | 443 | % disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s') 444 | % disp((Tau_tx+Tau_prop+Tau_exe<=Tau+s)') 445 | % disp('Tau_tx+Tau_prop+Tau_exe-Tau-s') 446 | % disp((Tau_tx+Tau_prop+Tau_exe-Tau-s)') 447 | 448 | %% Calculated concave approximation of r_k for obtained values of p (p-var) 449 | g(k)=log2(int_g+sigma^2);%g(p) in (22) 450 | for k=K_set 451 | % int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 452 | int_g=0; 453 | for l=1:L_R 454 | for i=cell2mat(subset(l))' 455 | % int_h=int_h+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 456 | if i~=k 457 | int_g=int_g+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 458 | end 459 | end 460 | end 461 | g(k)=log2(int_g+sigma^2);%g(p) in (22) 462 | end 463 | 464 | r_convex=h+nabla_h*(p-p_var)-g; 465 | 466 | 467 | h=zeros(length(K_set),1); 468 | %g=zeros(length(K_set),1); 469 | r_original=zeros(length(K_set),1); 470 | 471 | for k=K_set 472 | int_h=0;%accumulator for interference of k (in denominator of SINR formula (12)) 473 | %int_g=0; 474 | for l=1:L_R 475 | for i=cell2mat(subset(l))' 476 | int_h=int_h+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 477 | % if i~=k 478 | % int_g=int_g+(p(i)*abs((H(:,l,k)'*H(:,l,i))^2))/(norm(H(:,l,i))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 479 | % end 480 | end 481 | end 482 | h(k)=log2(int_h+sigma^2);%h(p) in (22) 483 | %g(k)=log2(int_g+sigma^2);%g(p) in (22) 484 | r_original(k,1)=h(k)-g(k); 485 | temp=zeros(L_R,length(K_set)); 486 | temp(:,:)=h_tilde(k,:,:); 487 | end 488 | 489 | nabla_h=zeros(length(K_set),length(K_set)); %h(p) in (26) %based on (22) for convex approximation 490 | %(26) 491 | for k=K_set 492 | for i=K_set 493 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 494 | numerator=0;%accumulator for numerator of SINR Formula 495 | for l=1:L_R 496 | for j=cell2mat(subset(l))' 497 | int=int+(p(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 498 | end 499 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 500 | end 501 | nabla_h(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 502 | end 503 | end 504 | 505 | nabla_g=zeros(length(K_set),length(K_set)); 506 | for k=K_set 507 | for i=K_set 508 | int=0;%accumulator for interference of k (in denominator of SINR formula (12)) 509 | numerator=0;%accumulator for numerator of SINR Formula 510 | for l=1:L_R 511 | for j=cell2mat(subset(l))' 512 | if j~=k 513 | int=int+(p(j)*abs((H(:,l,k)'*H(:,l,j))^2))/(norm(H(:,l,j))^2);%denominator of SINR formula %%% .8 or .^ ?????? problem 514 | end 515 | end 516 | numerator=numerator+(I_t2r(l,i)*abs(H(:,l,k)'*H(:,l,i))^2)/norm(H(:,l,i))^2;%numerator of SINR formula %dont know why it gets 0 most of the time 517 | end 518 | if i==k 519 | nabla_g(k,i)=0; 520 | else 521 | nabla_g(k,i)=numerator/(log(2)*(int+sigma^2));%(26) %based on (22) for convex approximation 522 | end 523 | end 524 | end 525 | %r_concave=h_p_var-g-nabla_g*(p-p_var); 526 | % DC_objective(count_p,count)=sum(nabla_Tau_tx*(p-p_var)); 527 | if norm(p_var-p)<=10e-3 || count_p==1 528 | p_var=p; 529 | break; 530 | end 531 | p_var=p; 532 | %p_var' 533 | end 534 | 535 | 536 | Tau_tx=D./r_concave; 537 | %disp('power') 538 | 539 | 540 | % disp('Tau_tx '); 541 | % disp(Tau_tx); 542 | %% MOSEK ... Optimization of binary variables 543 | Idelta=zeros(N,max(path)); 544 | r_aug=zeros(N,max(path),length(K_set)); 545 | for n=1:N 546 | for b=1:path(n) 547 | Idelta(n,b)=sum(sum(I_l2p(:,:,b,n).*delta_link))/2; 548 | r_aug(n,b,:)=r_convex; 549 | end 550 | end 551 | 552 | Idelta_aug=zeros(N,max(path),length(K_set)); 553 | for k=K_set 554 | Idelta_aug(:,:,k)=Idelta; 555 | end 556 | 557 | I_l2p_aug=zeros(N,N,N,max(path),length(K_set)); 558 | for m=1:N 559 | for mm=1:N 560 | temp=zeros(max(path),N); 561 | 562 | temp(:,:)=I_l2p(m,mm,:,:); 563 | for k=K_set 564 | I_l2p_aug(m,mm,:,:,k)=temp'; 565 | end 566 | end 567 | end 568 | 569 | v_aug=zeros(N,max(path),length(K_set)); 570 | for n=1:N 571 | for b=1:max(path) 572 | for k=K_set 573 | v_aug(n,b,k)=v(n,k); 574 | end 575 | end 576 | end 577 | 578 | % disp('binary variables problem '); 579 | %% solving (30) for v,e,gamma 580 | cvx_begin 581 | cvx_solver MOSEK 582 | variable e_var(N,max(path),length(K_set)) binary 583 | variable gamma_var(N,max(path),length(K_set)) binary 584 | variable v_var(N,length(K_set)) binary 585 | 586 | minimize sum(sum(sum(e_var.*Idelta_aug))) 587 | subject to 588 | for k=K_set 589 | %%%%%%%%%%%%%%%%%%%%%%%%C1-a DCP error 590 | sum(sum(e_var(:,:,k).* Idelta)) <= Tau(k)+s(k)-Tau_tx(k)-Tau_exe(k); %C1-a 591 | sum(sum(e_var(:,:,k)))==1 %C8 592 | sum(v_var(:,k)) == 1 %C7 593 | sum(sum(gamma_var(:,:,k))) == 1 %C9 594 | 595 | for n=1:N 596 | for b=1:path(n) 597 | gamma_var(n,b,k) <= v_var(n,k)+1-e_var(n,b,k); %C15 598 | v_var(n,k) <= gamma_var(n,b,k)+1-e_var(n,b,k); %C16 599 | gamma_var(n,b,k) <= e_var(n,b,k); %C17 600 | end 601 | if path(n)=Tau_prop(k)+Tau_exe(k)+Tau_tx(k)-Tau(k) 664 | sss(k) >= 0 665 | end 666 | for k=K_reject 667 | sss(k)==0 668 | end 669 | cvx_end 670 | s=sss; 671 | disp(cvx_status) 672 | % for k=K_set 673 | % s(k)=max(Tau_exe(k)+Tau_prop(k)+Tau_tx(k)-Tau(k),0); 674 | % end 675 | %constraint_bound_updated=Tau+s-Tau_tx-Tau_prop 676 | % disp('elasticization variable '); 677 | % disp(s); 678 | %% ASM Modification Algorithm 679 | % disp('ASM Modification Algorithm'); 680 | sorted_tasks=sort(s); 681 | sorted_indices=zeros(length(K_set),1); 682 | for k=K_set 683 | sorted_indices(k,1)=find(sorted_tasks(k)==s); 684 | end 685 | C_tilde_node=zeros(N,1); 686 | for k=sorted_indices' 687 | for n=1:N 688 | C_tilde_node(n,1)=C_node(n,1)-v(n,:)*c+c(k)*v(n,k)-.0001; 689 | end 690 | C_tilde_link=zeros(N,N); 691 | for m=1:N 692 | for mm=1:N 693 | temp=zeros(length(K_set),1); 694 | temp1=zeros(max(path),N); 695 | temp1(:,:)=I_l2p(m,mm,:,:); 696 | for i=K_set 697 | if i~=k 698 | temp2=zeros(max(path),N); 699 | temp2(:,:)=r_aug(:,:,i)'; 700 | temp(i,1)=sum(sum(temp1.*e(:,:,i)'.*temp2)); 701 | end 702 | end 703 | C_tilde_link(m,mm)=C_link(m,mm)-sum(temp); 704 | end 705 | end 706 | Nodes_e=[]; % The set of nodes which have links with sufficient bandwidth 707 | feasiblepaths=zeros(N,max(path)); 708 | for n=1:N 709 | feasiblepaths_b=[]; 710 | for b=1:path(n) 711 | flag=[]; 712 | for m=1:N 713 | for mm=1:N 714 | if I_l2p(m,mm,b,n)==1 715 | if r_convex(k,1)<=C_tilde_link(m,mm) 716 | flag=[flag;1]; 717 | else 718 | flag=[flag;0]; 719 | end 720 | end 721 | end 722 | end 723 | if prod(flag)==1 724 | if ismember(n,Nodes_e)==0 725 | Nodes_e=[Nodes_e,n] ; 726 | end 727 | feasiblepaths_b=[feasiblepaths_b,b]; 728 | %break; 729 | end 730 | end 731 | feasiblepaths(n,1:length(feasiblepaths_b))=feasiblepaths_b; 732 | end 733 | Node_feasible=[]; 734 | for n=Nodes_e 735 | if C_tilde_node(n,1)>=c(k)-.001 736 | Node_feasible=[Node_feasible,n]; 737 | end 738 | end 739 | Tau_exe_prop=nan(N,max(path)); 740 | for n=Node_feasible 741 | % c(k)=C_tilde_node(n,1); 742 | for b=setdiff(feasiblepaths(n,:),0) 743 | Tau_exe_prop(n,b)=L(k)/C_tilde_node(n,1)+prop(n,b); 744 | end 745 | end 746 | [n_star,b_star]=find(Tau_exe_prop==min(min(Tau_exe_prop))); 747 | Tau_prop(k,1)=prop(n_star,b_star); 748 | v(:,k)=zeros(N,1); 749 | v(n_star,k)=1; 750 | e(:,:,k)=zeros(N,max(path)); 751 | e(n_star,b_star,k)=1; 752 | s_tilde=Tau_tx(k,1)+Tau_prop(k,1)+L(k)/C_tilde_node(n_star,1)-Tau(k,1); 753 | if s_tilde<0 754 | c(k)=L(k)/(Tau(k,1)-Tau_tx(k,1)-Tau_prop(k,1)); 755 | s(k)=0; 756 | else 757 | s(k)=s_tilde; 758 | c(k)=C_tilde_node(n_star,1); 759 | end 760 | Tau_exe(k,1)=L(k)/c(k); 761 | end 762 | % disp('Elastic Variables'); 763 | % disp(s); 764 | % disp('Tau_tx+Tau_prop+Tau_exe<=Tau+s'); 765 | % disp((Tau_tx+Tau_prop+Tau_exe<=Tau+s)'); 766 | % disp('Tau_tx+Tau_prop+Tau_exe-Tau-s'); 767 | % disp((Tau_tx+Tau_prop+Tau_exe-Tau-s)'); 768 | 769 | 770 | convergence(count_convergence)=sum(s); 771 | count_convergence=count_convergence+1; 772 | elastic_stack(:,count)=s; 773 | % obj_feas(count,1)=sum(s); %last iteration's sum(s) (feasibility problem) 774 | % if count>1 775 | % disp('The ratio of objective improvement') 776 | % disp((obj_feas(count-1)-sum(s))/obj_feas(count-1)) 777 | % disp((convergence_check-sum(s))/convergence_check) 778 | % if abs(obj_feas(count-1)-sum(s))<10e-1 || abs(obj_feas(count-1)-sum(s))/obj_feas(count-1)<10e-2 || count>=I_max 779 | if (convergence_check-sum(s))/convergence_check <10e-2|| count>=I_max || convergence_check-sum(s)<10e-1 780 | break; 781 | end 782 | 783 | end 784 | if max(s)>=.01 785 | %K_set=setdiff(K_set,find(s==max(s))); 786 | %K_reject=[K_reject; find(s==max(s))]; 787 | K_set=1:length(K_set)-1; 788 | [~,k_reject]=max(s); 789 | H(:,:,k_reject)=[]; 790 | c(k_reject)=[]; 791 | p(k_reject)=[]; 792 | p_var(k_reject)=[]; 793 | e(:,:,k_reject)=[]; 794 | v(:,k_reject)=[]; 795 | s(k_reject)=[]; 796 | L(k_reject)=[]; 797 | D(k_reject)=[]; 798 | Tau(k_reject)=[]; 799 | Tau_prop(k_reject)=[]; 800 | Tau_tx(k_reject)=[]; 801 | Tau_exe(k_reject)=[]; 802 | else 803 | break; 804 | end 805 | end 806 | %% Outputs 807 | disp('Acceptance Ratio:') 808 | disp(K_set/K) 809 | disp('Radio Transmission Latency:') 810 | disp(Tau_tx) 811 | disp('Propagation Latency:') 812 | disp(Tau_prop) 813 | disp('Execution Latency:') 814 | disp(Tau_exe) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # task-offloading 2 | MATLAB code for the simulation of our paper entitled "**Energy-Efficient Task Offloading Under E2E Latency Constraints**" 3 | 4 | How to cite: 5 | M. Tajallifar, S. Ebrahimi, M. Javan, N. Mokari, L. Chiaraviglio, "Energy-Efficient Task Offloading Under E2E Latency Constraints", IEEE Transactions on Communications, 2021. 6 | 7 | Preprint on arXiv: 8 | https://arxiv.org/abs/1912.00187 9 | 10 | ResearchGate: 11 | https://www.researchgate.net/publication/337654553_Energy-Efficient_Task_Offloading_Under_E2E_Latency_Constraints 12 | 13 | IEEE Xplore: 14 | https://ieeexplore.ieee.org/document/9638479 15 | https://doi.org/10.1109/TCOMM.2021.3132909 16 | 17 | IEEE DataPort: 18 | https://ieee-dataport.org/open-access/energy-efficient-task-offloading-under-e2e-latency-constraints 19 | https://doi.org/10.21227/w5tv-yz53 20 | 21 | 22 | **Abstract**: 23 | 24 | In this paper, we propose a novel resource management scheme that jointly allocates the transmit power and computational resources in a centralized radio access network architecture. The network comprises a set of computing nodes to which the requested tasks of different users are offloaded. The optimization problem minimizes the energy consumption of task offloading while takes the end-to-end-latency, i.e., the transmission, execution, and propagation latencies of each task, into account. We aim to allocate the transmit power and computational resources such that the maximum acceptable latency of each task is satisfied. Since the optimization problem is non-convex, we divide it into two sub-problems, one for transmit power allocation and another for task placement and computational resource allocation. Transmit power is allocated via the convex-concave procedure. In addition, a heuristic algorithm is proposed to jointly manage computational resources and task placement. We also propose a feasibility analysis that finds a feasible subset of tasks. Furthermore, a disjoint method that separately allocates the transmit power and the computational resources is proposed as the baseline of comparison. A lower bound on the optimal solution of the optimization problem is also derived based on exhaustive search over task placement decisions and utilizing Karush–Kuhn–Tucker conditions. Simulation results show that the joint method outperforms the disjoint method in terms of acceptance ratio. Simulations also show that the optimality gap of the joint method is less than 5%. 25 | 26 | 27 | **Published in**: IEEE Transactions on Communications ( Volume: 70, Issue: 3, March 2022) 28 | 29 | **Date of Publication**: 06 December 2021 30 | 31 | 32 | 33 | **A typical task offloading example**: 34 | ![A typical task offloading example](https://github.com/sinaebrahimi/task-offloading/blob/main/Figures/1a.%20A%20typical%20task%20offloading%20example.png) 35 | 36 | **System model**: 37 | ![System model](https://github.com/sinaebrahimi/task-offloading/blob/main/Figures/1b.%20System%20model.png) 38 | 39 | 40 | **Usage Guide**: 41 | **Notes on the simulation files**: 42 | 43 | _DTO.m_ simulates the **disjoint task offloading (DTO)** method in the manuscript. This file receives the following parameters as its **inputs**: 44 | 45 | 1. Number of single-antenna users, which is equal to the number of tasks, that is, K 46 | 2. Maximum acceptable latency of tasks, that is, T=T_k, \forall k 47 | 3. Ratio of RAN latency to the maximum acceptable latency, that is, T_{RAN}/T 48 | 4. Computational load of each task, that is, L=L_k, \forall k 49 | 5. Data size of each task, that is, D=D_k, \forall k. 50 | 51 | After receiving the parameters, _DTO.m_ **executes** the disjoint method and returns the outputs as in the following: 52 | 53 | 1. Acceptance Ratio 54 | 2. Radio Transmission latency of all tasks, that is, T_k^{tx} \forall k 55 | 3. Propagation latency of all tasks, that is, T_k^{prop} \forall k 56 | 4. Execution latency of all tasks, that is, T_k^{exe} \forall k 57 | 58 | _JTO.m_ simulates the **joint task offloading (JTO)** method in the manuscript. This file receives the following parameters as its **inputs**: 59 | 60 | 1. Number of single-antenna users, which is equal to the number of tasks. 61 | 2. Maximum acceptable latency of tasks, that is, T=T_k, \forall k 62 | 3. Computational load of each task, that is, L=L_k, \forall k 63 | 4. Data size of each task, that is, D=D_k, \forall k. 64 | 65 | After receiving the parameters, _JTO.m_ **executes** the disjoint method and returns the outputs as in the following: 66 | 67 | 1. Acceptance Ratio 68 | 2. Radio Transmission latency of all tasks, that is, T_k^{tx} \forall k 69 | 3. Propagation latency of all tasks, that is, T_k^{prop} \forall k 70 | 4. Execution latency of all tasks, that is, T_k^{exe} \forall k 71 | 72 | 73 | 74 | 75 | It is worth mentioning that the rest of the files function as follows: 76 | 77 | - pathbetweennodes.m includes a function that returns all the paths between two nodes of a graph (Copyright 2014 Kelly Kearney). It is used multiple times in both JTO.m and DTO.m. 78 | - channel.mat is a file used for initializing the channel in DTO.m. 79 | - 2021-06-22-TaskOffloading (+Complexity Analysis)-arXiv_v3.pdf: the complete version of the paper (with complexity analysis) submitted in arXiv. 80 | - 2021-06-23-TaskOffloading- Submitted Version to IEEE TCOM.pdf: the version of the paper submitted to the IEEE TCOM (also available on researchgate). 81 | - Figures: This directory includes all the figures (in PNG format) in the paper. 82 | 83 | 84 | **Disclaimer**: We used the MOSEK solver and CVX package to solve all problems. Moreover, all simulation steps (including initialization, admission control mechanisms, and solving ILP problems with MOSEK toolbox) have been implemented in MATLAB software which is widely used to solve resource allocation problems. 85 | -------------------------------------------------------------------------------- /channel.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sinaebrahimi/task-offloading/1ef77aaf538b9a00340435b0fe2ee051e18abd9b/channel.mat -------------------------------------------------------------------------------- /pathbetweennodes.m: -------------------------------------------------------------------------------- 1 | function pth = pathbetweennodes(adj, src, snk, verbose) 2 | %PATHBETWEENNODES Return all paths between two nodes of a graph 3 | % 4 | % pth = pathbetweennodes(adj, src, snk) 5 | % pth = pathbetweennodes(adj, src, snk, vflag) 6 | % 7 | % 8 | % This function returns all simple paths (i.e. no cycles) between two nodes 9 | % in a graph. Not sure this is the most efficient algorithm, but it seems 10 | % to work quickly for small graphs, and isn't too terrible for graphs with 11 | % ~50 nodes. 12 | % 13 | % Input variables: 14 | % 15 | % adj: adjacency matrix 16 | % 17 | % src: index of starting node 18 | % 19 | % snk: index of target node 20 | % 21 | % vflag: logical scalar for verbose mode. If true, prints paths to 22 | % screen as it traverses them (can be useful for larger, 23 | % time-consuming graphs). [false] 24 | % 25 | % Output variables: 26 | % 27 | % pth: cell array, with each cell holding the indices of a unique path 28 | % of nodes from src to snk. 29 | 30 | % Copyright 2014 Kelly Kearney 31 | 32 | if nargin < 4 33 | verbose = false; 34 | end 35 | 36 | n = size(adj,1); 37 | 38 | stack = src; 39 | 40 | stop = false; 41 | 42 | pth = cell(0); 43 | cycles = cell(0); 44 | 45 | next = cell(n,1); 46 | for in = 1:n 47 | next{in} = find(adj(in,:)); 48 | end 49 | 50 | visited = cell(0); 51 | 52 | pred = src; 53 | while 1 54 | 55 | visited = [visited; sprintf('%d,', stack)]; 56 | 57 | [stack, pred] = addnode(stack, next, visited, pred); 58 | if verbose 59 | fprintf('%2d ', stack); 60 | fprintf('\n'); 61 | end 62 | 63 | if isempty(stack) 64 | break; 65 | end 66 | 67 | if stack(end) == snk 68 | pth = [pth; {stack}]; 69 | visited = [visited; sprintf('%d,', stack)]; 70 | stack = popnode(stack); 71 | elseif length(unique(stack)) < length(stack) 72 | cycles = [cycles; {stack}]; 73 | visited = [visited; sprintf('%d,', stack)]; 74 | stack = popnode(stack); 75 | end 76 | 77 | end 78 | 79 | 80 | function [stack, pred] = addnode(stack, next, visited, pred) 81 | 82 | newnode = setdiff(next{stack(end)}, pred); 83 | possible = arrayfun(@(x) sprintf('%d,', [stack x]), newnode, 'uni', 0); 84 | 85 | isnew = ~ismember(possible, visited); 86 | 87 | if any(isnew) 88 | idx = find(isnew, 1); 89 | stack = str2num(possible{idx}); 90 | pred = stack(end-1); 91 | else 92 | [stack, pred] = popnode(stack); 93 | end 94 | 95 | 96 | function [stack, pred] = popnode(stack) 97 | 98 | stack = stack(1:end-1); 99 | if length(stack) > 1 100 | pred = stack(end-1); 101 | else 102 | pred = []; 103 | end --------------------------------------------------------------------------------