您现在的位置是:首页 >学无止境 >【优化布局】基于matlab Kmean算法求解4G网络中无人机布局优化问题【含Matlab源码 2613期】网站首页学无止境
【优化布局】基于matlab Kmean算法求解4G网络中无人机布局优化问题【含Matlab源码 2613期】
⛄一、Kmean算法简介
kmeans聚类可以说是聚类算法中最为常见的,它是基于划分方法聚类的,原理是先初始化k个簇类中心,基于计算样本与中心点的距离归纳各簇类下的所属样本,迭代实现样本与其归属的簇类中心的距离为最小的目标(如下目标函数)。
其优化算法步骤为:
1.随机选择 k 个样本作为初始簇类中心(k为超参,代表簇类的个数。可以凭先验知识、验证法确定取值);
2.针对数据集中每个样本 计算它到 k 个簇类中心的距离,并将其归属到距离最小的簇类中心所对应的类中;
3.针对每个簇类,重新计算它的簇类中心位置;
4.重复迭代上面 2 、3 两步操作,直到达到某个中止条件(如迭代次数,簇类中心位置不变等)。
⛄二、部分源代码
%*************** personal information *************************************************
%
%
close all
clear all
clc
%***************************** global variables ********************************************
REPerB=842;%resource elements per resourse block
Category=[1,2,3];% 1:urban, 2:suburban,3:rural
F_HATA=1500;%MHz
NoiceFigure=10; %dB
BI=15;
NoisePower= -174 +10log10(180*10^3)+NoiceFigure+BI;
SINRmin=-9.3;%d
Lbody=3;%dB body loss
Lbpl=18;%dB building penetration loss
Lj=2;%jumber loos
Ga=5;% gain
%***************************** end global variables ******************************************
%***************************** configuration of MeNB ******************************************
MeNB(1).x=500;% x coordinate
MeNB(1).y=500;% y coordinate
MeNB(1).ChannelBandwidth=20;%MHz
MeNB(1).carrier=1.8*10^9;%MHz
MeNB(1).takeBitPerMilisec=100000;%MHz
MeNB(1).powerTransmit=45; %dBm
MeNB(1).height=100; %metres
for i=1:20
MeNB(1).UEdata(i)=0;%MHz
end
MaxPathLoss=Calculate_MaxPathLoss(MeNB(1).powerTransmit,NoisePower,SINRmin);%Max Path Loss
%***************************** End configuration of MeNB ******************************************
%***************************** configuration of 20-UEs %*****************************************
% Here we locate the Ues In the Grid
for i=1:50
UE(i).x=400;% x coordinate
UE(i).y=500;% y coordinate
UE(i).height=1.7;
UserLocationX(i)= 0;
UserLocationY(i)= 0;
UserLocationZ(i)= 0;
end
i=1
x=400;% x coordinate
y=500
while i<51
x=randi(1000, 1, 1);
y=randi(1000, 1, 1);
if (x<400 || x>500) && (y<400 || y>500)
UE(i).x=x;% x coordinate
UE(i).y=y;% y coordinate
UserLocationX(i)= UE(i).x;
UserLocationY(i)= UE(i).y;
UserLocationZ(i)= 1.7;
i=i+1;
end
end
%***************************** End configuration of 20-UEs %*****************************************
%***************************** scatter plot of UEs and ENB %*****************************************
figure(‘Color’, ‘white’)
plot(UserLocationX, UserLocationY, ‘^’, ‘MarkerSize’, 5, ‘LineWidth’, 3), hold on
BaseStationX = 500;
BaseStationY = 500;
plot(BaseStationX, BaseStationY, ‘rs’, ‘MarkerSize’, 5, ‘LineWidth’, 4), hold on, grid on, grid minor
hleg = legend(‘User Location’, ‘Base Station’);
set(hleg, ‘Location’, ‘NorthEastOutside’);
xlabel(‘coordinate Χ’);
ylabel(‘coordinate Υ’);
%***************************** End scatter plot of UEs and ENB %*****************************************
%***************************** initialization phase of UEs *****************************************
% Here we calculate some parameters of the UEs before they moving(PL,SINR,CQI,Max throughput, max resurceBlock that the UE xan take )
for i=1:50
UE(i).distancefrom_eNB_m(1)=round(Distance(MeNB(1).x,MeNB(1).y,UE(i).x,UE(i).y));%calculate distance between each UE ad eNB
UE(i).PL_dB(1) =(HATA_Model((UE(i).distancefrom_eNB_m(1)/1000),F_HATA(1),MeNB(1).height, UE(i).height,Category(2)))+Lbody+Lbpl+Lj;%calculate Path Loss for each UE
UE(i).PowerReceive_dBmW(1)= MeNB(1).powerTransmit -UE(i).PL_dB+Ga;%calculate Power receive ( Pr) for each UE
UE(i).SNR_dB(1)=UE(i).PowerReceive_dBmW-NoisePower;%calculate SINR for each UE [dB]
UE(i).SNR(1)= 10^(UE(i).SNR_dB(1)/10);%calculate SINR for each UE
UE(i).CQI(1)=CQI_calculation(UE(i).SNR_dB(1));%calculate CQI for each UE [dB]
UE(i).MODULATION(1)= Modulation_calculation(UE(i).SNR_dB(1));%calculate Modulation scheme for each UE depending on CQI [dB]
UE(i).resurceBlock(1)=setRB(UE(i).SNR_dB(1));%calculate how many resource block can each UE receive [dB]
% UE(i).throughput(1)=throughput_calculation( UE(i).MODULATION,UE(i).resurceBlock(1),UE(i).SNR_dB(1));%calculate throughput each UE receive [dB]
end
%{
Ues request service from provider
calcualation of servise priority
sheduler give as many resources as needed min{ can_decode,service_requires}
%}
for i=1:50
UE(i).QCI(1)=QCI_example_service();
UE(i).ExampleServise(1)=ExampleServise_calculation(UE(i).QCI);
UE(i).Priority=Priority_calculation(UE(i).QCI);
UE(i).Resource_Block_Allocation(1)=Resource_Block_Allocation_calculation( UE(i).QCI(1), UE(i).resurceBlock(1));
UE(i).throughput(1)=throughput_calculation( UE(i).MODULATION(1),UE(i).Resource_Block_Allocation(1), UE(i).SNR_dB(1));
end
%%--------------- Selecting Data of interest ---------------------
% ---------------------------- Code ------------------------------
Table_UE = struct2table(UE);
data = Table_UE(:,1:2);
data = table2array(data);
%________________________________________________________________
%________________________________________________________________
%%------------ Selecting Optimal Number of Clusters ------------
% -------------- Method 1: Using the Elbow Method ---------------
% ---------------------------- Code -----------------------------
WCSS = [];
for k = 1:20
sumd = 0;
[idx,C,sumd] = kmeans(data,k);
WCSS(k) = sum(sumd);
end
⛄三、运行结果
⛄四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1]刘雅文,蒋妍,潘大志.改进二进制和声搜索算法求解多维背包问题[J].计算机与现代化 2022-08-15
3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除