Skip to content

Commit ba13217

Browse files
authored
Add files via upload
1 parent e0efc97 commit ba13217

File tree

6 files changed

+569
-0
lines changed

6 files changed

+569
-0
lines changed

src/Cal_E_T7.m

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function [EL,EC,TL,TC,Cci]= Cal_E_T7(T_rate,tasks,N)
2+
3+
Beta=5e-7;
4+
5+
%based on tabel 1,2 in article
6+
Cff=730e6; %cycle/energy(j)
7+
Dff=860e3 ; %byte/energy(j)
8+
9+
%initialize energy j/bit
10+
EL=zeros(1,N);
11+
Et=zeros(1,N);
12+
Er=zeros(1,N);
13+
14+
%initialize time s/bit
15+
TL=zeros(1,N);
16+
Tr=zeros(1,N);
17+
Tt=zeros(1,N);
18+
19+
F_local=500e6; %cpu frequence cycle/s in local
20+
F_cloud=10e9; %cpu frequence cycle/s in cloud
21+
22+
%initialize output data
23+
D_out=(3*rand(1,N)); %between 1-3 MB
24+
%initialize input data [.1 .1 .1 .1 .1 .1 .1]
25+
D_in=randi([10,30],1,N); %between 10 -30 MB
26+
for ii=1:N
27+
D_in(ii)=1/D_in(ii);
28+
D_out(ii)=1/D_out(ii);
29+
end
30+
31+
32+
33+
Cci= D_in;
34+
35+
for i=1:N
36+
EL(i)= tasks(i)/(8*Cff); %conver byte to bit
37+
TL(i)=tasks(i)/(8*F_local); %s/bit
38+
39+
Er(i)=1/(8*Dff);
40+
Tr(i)=D_out(i)/T_rate;
41+
Tc1(i)=D_in(i)*tasks(i)/(8*F_cloud); %s/bit
42+
43+
Et(i) =1/(8*Dff);
44+
Tt(i)=D_in(i)/T_rate;
45+
TC(i)=Tr(i)+Tt(i)+Tc1(i);
46+
EC(i)=Er(i) + Et(i) + Beta*Cci(i);
47+
end

src/Cal_E_T8.m

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function [EL,EC,TL,TC,Cci]= Cal_E_T8(T_rate,D_in,D_out,tasks,N)
2+
3+
Beta=5e-7;
4+
5+
%based on tabel 1,2 in article
6+
Cff=730e6; %cycle/energy(j)
7+
Dff=860e3 ; %byte/energy(j)
8+
9+
10+
11+
% tasks=[330,300,900,100,900,960,900];%cycle/byte
12+
%tasks=[5330,6300,4900,2000,190,1960,8900,800,10,8900];%cycle/byte
13+
%tasks=randi([10,10000],1,10);
14+
N= size(tasks,2);
15+
16+
%initialize energy j/bit
17+
EL=zeros(1,N);
18+
Et=zeros(1,N);
19+
Er=zeros(1,N);
20+
21+
%initialize time s/bit
22+
TL=zeros(1,N);
23+
Tr=zeros(1,N);
24+
Tt=zeros(1,N);
25+
26+
F_local=500e6; %cpu frequence cycle/s in local
27+
F_cloud=10e9; %cpu frequence cycle/s in cloud
28+
29+
30+
31+
32+
Cci= D_in;
33+
34+
for i=1:N
35+
EL(i)= D_in(i)*tasks(i)/(8*Cff); %conver byte to bit
36+
TL(i)=D_in(i)*tasks(i)/(8*F_local); %s/bit
37+
38+
Er(i)=D_out(i)/(8*Dff);
39+
Tr(i)=D_out(i)/T_rate;
40+
Tc1(i)=D_in(i)*tasks(i)/(8*F_cloud); %s/bit
41+
42+
Et(i) =D_in(i)/(8*Dff);
43+
Tt(i)=D_in(i)/T_rate;
44+
TC(i)=Tr(i)+Tt(i)+Tc1(i);
45+
EC(i)=Er(i) + Et(i) +D_in(i)* Beta;
46+
47+
end

src/GA.m

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
%in the name of allah
2+
function [Decision_Matrix,E_min,T_min]=GA(tasks,N)
3+
4+
mutation_probability = 0.5;
5+
number_of_generations = 100000;
6+
iter1=50; %number of iteration
7+
E_min=1;
8+
T_constraint=700; %time constraint
9+
T_rate=3e6; %bit/s
10+
EC=[];
11+
EL=[];
12+
TL=[];
13+
TC=[];
14+
15+
%calculate energy and time for tasks
16+
[EL,EC,TL,TC,Cci]= Cal_E_T7(T_rate,tasks,N);
17+
18+
%random genetic cells
19+
x = randi([0,1],1,N);
20+
if (x==ones(1,N) )
21+
x = randi([0,1],1,N);
22+
end
23+
if x==zeros(1,N)
24+
x = randi([0,1],1,N);
25+
end
26+
E=zeros(1,N);
27+
T=zeros(1,N);
28+
for k=1:N
29+
E(k)= x(k)*EL(k)+(1-x(k))*EC(k);
30+
T(k)= x(k)*TL(k)+(1-x(k))*TC(k);
31+
end
32+
33+
34+
E_min=1e20;
35+
T_min=1e20;
36+
37+
%Starting GA loop
38+
for o=1:number_of_generations
39+
40+
x = randi([0,1],1,N);
41+
if (x==ones(1,N) )
42+
x = randi([0,1],1,N);
43+
end
44+
if x==zeros(1,N)
45+
x = randi([0,1],1,N);
46+
end
47+
48+
%select point to cross over
49+
cut_point = round(2+rand*(N-2));
50+
51+
%new individual AB
52+
x = x(1:cut_point);
53+
x11=randi([0,1],1,N-cut_point);
54+
x = [x x11];
55+
56+
57+
%mutation AB
58+
ran_mut = rand;
59+
if ran_mut < mutation_probability
60+
gene_position = round(1 + rand(1,2)*(N-1));
61+
a=x(gene_position);
62+
fl=fliplr(a');
63+
x(gene_position) = fl;
64+
end
65+
66+
for k=1:N
67+
E(k)= x(k)*EL(k)+(1-x(k))*EC(k);
68+
T(k)= x(k)*TL(k)+(1-x(k))*TC(k);
69+
end
70+
if (( sum(E)<=E_min ) && ( sum(T) < T_constraint) )
71+
E_min=sum(E);
72+
T_min=sum(T);
73+
Xmin=x;
74+
end
75+
76+
77+
78+
end
79+
disp('GA')
80+
T_min
81+
E_min
82+
Decision_Matrix=Xmin;
83+
end
84+

src/Main.m

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
%in the name of Allah
2+
%% initialize
3+
4+
5+
clc;
6+
clear all;
7+
close all;
8+
disp( 'This program is designed to determine the offloading of tasks to reduce mobile energy');
9+
tasks=[5930,3900,1700,6880,6800,2400,5960,5400,8700,900,800,900,5900,7700,6200];%cycle/byte
10+
N= size(tasks,2);
11+
12+
Decision_Matrix_Dynamic = dynamic7(tasks,N);
13+
Decision_Matrix_GA = GA(tasks,N);
14+
disp ('Based on the energy specified for each task, the final decision system is executed as follows:');
15+
disp ('If the bit value is equal to 0, the work is done offloading and otherwise its done locally.');
16+
disp(' ');
17+
disp('Tasks ')
18+
tasks
19+
disp('Final Decision Matrix for GA Algorithm: ' )
20+
Decision_Matrix_GA
21+
disp('Final Decision Matrix for Dynamic Method: ');
22+
Decision_Matrix_Dynamic
23+
24+
disp('Please enter a key to view plots');
25+
pause
26+
27+
[E_min,E_min_GA,T_min,T_min_GA,TL1,TC1,EC1,EL1,TL1_GA,TC1_GA,EC1_GA,EL1_GA,Emin,Emin_GA,Tmin,Tmin_GA]=Plot(tasks,N);
28+
29+
30+
disp('E_min for Dynamic ')
31+
E_min
32+
33+
disp('E_min_GA for Genetic Algorithm ')
34+
E_min_GA
35+
36+
%
37+
% T = table(TL1,TC1,EC1,EL1,TL1_GA,TC1_GA,EC1_GA,EL1_GA);
38+
% csvwrite('trainlabels.csv',T)
39+
% writetable(T,'report.xls','WriteVariableNames',true,'Sheet',1);

0 commit comments

Comments
 (0)