clear all
clc
x=1:1:40;
%直接使用路径损耗为4
%求能量,直接将动差函数n=1即可
P_u=1;%用户最大发射功率
% lamda_1=1e-6;%基站密度
% lamda_2=5e-6;
lamda_u=5e-5;%用户密度
gama_0=10^(-9);%基站端的接收功率-60dBm
alpha=4;
sim_num=1;
noise_power_per_HZ = 10 ^ (-174 / 10) * 0.001;%噪声功率-174dBm/Hz
array_length=length(x);
P_1_static=10;
P_2_static=100;
EE= zeros(array_length , 1);
EE_1= zeros(array_length , 1);
F_down_and_up_sucess= zeros(array_length , 1);
All_success= zeros(array_length , 1);
t=0.5;%SINR阈值
lamda_1=1e-6;%基站密度
W=1e6;%带宽
for i=1:1:array_length
% t=0.5;%SINR阈值
k=10^(-1+(i-1)*2/(array_length-1));%这是为了表示基站密度关系而加的
lamda_2=5*lamda_1;
P_2_max=2;
P_1_max=10*P_2_max;
M=20;%3*i;%子信道个数
P_2=P_2_max/M;
P_1=P_1_max/M;%宏基站功率
delay_threshold_1=0.05;
delay_threshold_2=0.001;
% theta=1;
% t=10^(-2+(i-1)*4/(array_length-1));%SINR阈值
theta=10^((i-1)*4/(array_length-1));%CRE偏置
% for j=1:50
% a=j;
% [P_delay_1(j),P_delay_2(j),P_delay(j)]=Delay_probability_invoking(lamda_1,lamda_2,P_1,P_2,alpha,theta,a,lamda_u);
% if P_delay_1(j)<delay_threshold_1 & P_delay_2(j)<delay_threshold_2
% M=j;
% break
% end
% end
% MMM(i)=20;
%wwww=Delay_probability(lamda_1,lamda_2,P_1,P_2,alpha,theta,M,lamda_u);
[theta_dB(i),EE(i,1),down_SINR_coverage(i,1),downrate(i,1),uprate(i,1),t_db(i), F_down_and_up_sucess(i,1),F_M_m_1(i,1),y_up_1(i,1),y_down(i,1),k_dB(i),...
y_down_1(i,1),y_down_2(i,1),y_up_1_1(i,1),y_up_1_2(i,1),SE(i,1),P_busy_1(i,1),P_busy_2(i,1)...
,y_up_mean_achievable_rate_1(i,1),y_up_mean_achievable_rate_2(i,1),y_down_mean_achievable_rate(i,1),y_down_mean_achievable_rate_1(i,1),...
y_down_mean_achievable_rate_2(i,1),Rate_hotspot(i,1),Rate_nonhotspot(i,1),m(i,1),Delay_probability(i,1),EE_up(i,1),SE_up(i,1),EE_all(i,1)]...
=DL_Optimal_value_calculate(P_1,P_2,P_1_static,P_2_static,P_u,lamda_1,lamda_2,lamda_u,gama_0,t,alpha,theta,k,M,W);
Finish_Precentage = i/(3*array_length) * 100
end
gcf1=1;
figure(gcf1);
hold off;
hold on;
[AX,H1,H2]=plotyy(theta_dB,EE(:,1),theta_dB,SE(:,1));%'m.-','DisplayName','\lambda_2/\lambda_1=50','LineWidth',1)
hold on;
set(get(AX(1),'Ylabel'),'String','EE(Mbits/Joule)') %设置Y轴名称
set(get(AX(2),'Ylabel'),'String','SE(bits/s/Hz)')
% set(AX(1),'XColor','k','YColor','b');%设置轴颜色
% set(AX(2),'XColor','k','YColor','r');
set(AX(2),'YLim',[5,7]) %Y轴范围
set(AX(2),'YTick',[5:0.1:7]) %Y轴刻度
legend([H1,H2],{'EE';'SE'});%显示图例
% set(H1,'LineStyle','-','color','b');
% set(H2,'LineStyle','-','color','r');
grid on;
xlabel('P_1/P_2(dB)')
% xlabel('\theta(dB)')
gcf2=2;
figure(gcf2);
hold on;
% plot(theta_dB,EE(:,1),'b.-','DisplayName','\lambda_2/\lambda_1=50','LineWidth',1)
hold on;
plot(theta_dB,y_down_1(:,1),'b.-','DisplayName','Analy:\theta=10dB','LineWidth',1)
hold on;
plot(theta_dB,y_down_2(:,1),'r.-','DisplayName','Analy:\theta=10dB','LineWidth',1)
grid on;
xlabel('M')
ylabel('SE(Bit/Sec/Hz)')
% set(gca,'YLim', [0 0.01], 'XLim',[-60 60] )
gcf3=3;
figure(gcf3);
% semilogx(m,EE(:,1))
plot(theta_dB,down_SINR_coverage(:,1),'r.-','DisplayName','Analy:\theta=10dB','LineWidth',1)
grid on;
xlabel('\lambda_2/\lambda_1(dB)')
ylabel('h')
% % set(gca,'YLim', [0 0.01], 'XLim',[-60 60] )
%% 最优计算
% 参数初始化
% G=1;
% popsize = 200; %种群规模
% c1 = 2;
% c2 = 2;%学习因子
% gbest(G) = 0; %全局最优解
% best_fitness = zeros(G,1); %全局最优函数值
% %pbest = 0; %局部最优解
% %eita_min = 0;
% %eita_max = 1;
% itime = 0; %当前迭代次数
% gen = 40; %迭代次数
% max_v = 10; %最大速度
% best_in_history = zeros(G,gen);%初始化全局历史最优解
%
% for g=1:G
%
% pop(popsize,5) = 0;
% %初始化种群,第1列为eita值,第2列为速度分量,第3列为个体\eta最优值,
% %第4列为个体最优适应值,第5列为当前个体适应值
%
%
% %1. 初始化粒子位置和速度
% for i=1:popsize
% pop(i,1)=10^( rand()*40/10 ); %初始化粒子位置,0-1之间,步长为其速度
% pop(i,3) = pop(i,1); %初始状态个体最优值等于初始位置
% pop(i,2) = 10^((rand()*0.02-0.01)*40/10);%初始化粒子速度,值为-0.01~0.01,间隔为0.0001??????????????????????????????????????粒子速度如何调整合适?
% pop(i,4) = inf;
% pop(i,5) = inf;
% end
%
%
% gbest(g) = pop(1,1); %全局最优值初始为种群第一个粒子的位置
%
% %2. 计算适应值并赋值,寻找局部最优值
%
% while itime<=gen
% itime = itime + 1;
%
% for i = 1:popsize
% [theta_dB(i),EE(i,1),down_SINR_coverage(i,1),downrate(i,1),uprate(i,1),t_db(i), F_down_and_up_sucess(i,1),F_M_m_1(i,1),y_up_1(i,1),y_down(i,1),k_dB(i),...
% y_down_1(i,1),y_down_2(i,1),y_up_1_1(i,1),y_up_1_2(i,1),SE(i,1),P_busy_1(i,1),P_busy_2(i,1)...
% ,y_up_mean_achievable_rate_1(i,1),y_up_mean_achievable_rate_2(i,1),y_down_mean_achievable_rate(i,1),y_down_mean_achievable_rate_1(i,1),...
% y_down_mean_achievable_rate_2(i,1),Rate_hotspot(i,1),Rate_nonhotspot(i,1),m(i,1),Delay_probability(i,1),EE_up(i,1),SE_up(i,1),EE_all(i,1)]...
% =DL_Optimal_value_calculate(P_1,P_2,P_1_static,P_2_static,P_u,lamda_1,lamda_2,lamda_u,gama_0,t,alpha,pop(i,1),k,M,W);
% pop(i,5) = EE(i,1);
% if pop(i,4)>pop(i,5); %若当前适应值优于个体最优值,则进行更新
% pop(i,4) = pop(i,5);
% pop(i,3) = pop(i,1); %位置更新
% end
% end
% %3.寻找全局最优值
%
% if best_fitness(g) < max(pop(:,4))
% best_fitness(g) = max(pop(:,4));
% row = find(pop(:,4) == best_fitness(g));
% gbest(g) = pop(row(1),1);
% end
% best_in_history(g,itime) = best_fitness(g);%记录当前全局最优值
%
% if itime-1>0
% if abs(best_in_history(g,itime-1)-best_in_history(g,itime))==0
% break;
% end
% end
%
% %调整粒子速度与位置
% %更新速度
% for i = 1:popsize
% pop(i,2) = (0.9+itime./gen.*0.5).*pop(i,2)+c1.*rand().*(pop(i,3)-pop(i,1))+c2.*rand().*(gbest(g)-pop(i,1));
% %pop(i,2) = 0.01*pop(i,2)+c1*rand()*(pop(i,3)-pop(i,1))+c2*rand()*(gbest-pop(i,1));
% if abs(pop(i,2))>max_v
% if(pop(i,2)>0)
% pop(i,2)=max_v;
% else
% pop(i,2)=-max_v;
% end
% end
% end
% %更新位置
% for i = 1:popsize
% pop(i,1)=pop(i,1)+pop(i,2);
% end
% Finish_Precentage = 2*i/(3*array_length) * 100
% end
% gbest_dB(g)=10*log10(gbest(g));
% end
%
%
[Y_col,Ind_row]=min(y_down_mean_achievable_rate_2(:,1))%每列的最大值及行号
[Y_col,Ind_row]=max(SE(:,1))%每列的最大值及行号
% % kk_db=10*log10(theta)
% % [Y_col,Ind_row]=max(F_down_and_up_sucess)
% %%
% gcf3=3;
% figure(gcf3);
% hold on;
% hold on
% plot(gbest_dB(1),best_fitness(1),'bd','LineWidth',5,'markersize',8);
% gcf4=4;
% figure(gcf4);
% hold on;
% [X,Y]=meshgrid(alpha,t_w);
% mesh(alpha,t_w,R_average);
% hold on
% grid on