基于Matlab模拟DMD无人机控制matlab代码

简介: 基于Matlab模拟DMD无人机控制matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信      无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机

⛄ 内容介绍

无人机在军用、民用领域具备巨大的应用潜力,当前世界各国正在大力推进无人机的研发工作,而无人机自主控制是无人机研发中极富挑战性的关键问题。

⛄ 部分代码

function [xm,ynm,St_Data,ConstraintViolations] = RepairBestSolution(xm,ynm,St_Data)


DroneLocs = St_Data.totalDroneLocs;

m = DroneLocs;

n = St_Data.n;


gammaMax = St_Data.gammaMax;

gammaMin = St_Data.gammaMin;


realYnm = St_Data.realYnm;


UPPERTHRESHOLD = 0.99;

LOWERTHRESHOLD = 0.1;


%% Constraint 3: code to remove duplicate user connections

[~,constNum] = OnlyCheckConstraints(St_Data,ynm,xm); % Check if there are violations

if constNum(3) > 0

   AllUsersConnections = sum(ynm,2);

   UsersWithMoreConnections = find(AllUsersConnections > 1);

   for k = 1:length(UsersWithMoreConnections)

       thisUser = UsersWithMoreConnections(k);

       currUserTotalConnections = ynm(thisUser,:);

       bbb = find(currUserTotalConnections > UPPERTHRESHOLD);

       CoverageThisUser = realYnm(thisUser,bbb) == 0;

       ynm(thisUser,bbb(CoverageThisUser)) = 0;

       if sum(ynm(thisUser,:)) > 1      

           currUserTotalConnections = ynm(thisUser,:);

           bbb = find(currUserTotalConnections > UPPERTHRESHOLD);

           [~,indx] = max(sum(ynm(:,bbb)));

           ccc = zeros(1,m);

           ccc(1,bbb(indx)) = 1;

           ynm(thisUser,:) = ccc;

       end

   end

   xm = xm.*(sum(ynm)>0);

   ynm(:,~xm) = 0;

end


%% Constraint 5: Constraint Find under-utilized drones, UU:Under-Utilized

[~,constNum] = OnlyCheckConstraints(St_Data,ynm,xm); % Check if there are violations

if constNum(5) > 0

   DronesUtilitzation1 = sum(ynm);

   DronesUtilitzation2 = xm.*(DronesUtilitzation1 < gammaMin);

   UnderUtilizedDrones = find(DronesUtilitzation2 > 0);

   for i = 1:length(UnderUtilizedDrones) % LOOP: CHECK FOR ALL UU DRONES

       uuDrone1 = UnderUtilizedDrones(i); % Find ith UU drone

       nnDrone1 = find(ynm(:,uuDrone1) >= UPPERTHRESHOLD); % Find all connection to ith UU drone

       for j = 1:length(nnDrone1) % LOOP: CHECK FOR ALL USERS CONNECTED TO iTH UU DRONE

           user1 = nnDrone1(j); % Select jth user connected to ith UU drone

           user1PossibleConn = find(realYnm(user1,:) >= UPPERTHRESHOLD); % Find all possible connections for user1

           user1PossibleConn(user1PossibleConn == uuDrone1) = []; % Remove UU drone from the list

           [~,indx] = sort(sum(ynm(:,user1PossibleConn)),'descend');

           for k = 1:length(user1PossibleConn) % LOOP: CHECK FOR ALL POSSIBLE CONNECTIONS

               curr = user1PossibleConn(indx(k)); % Collect current possible connection option

               % Re-connect this user to some other drone on following

               % basis: (1) the user is in range of it, (2) the drone has

               % capacity to serve more users, (3) the drone is not under

               % utilized, (4) the drone is already deployed

               Flag1 = sum(ynm(:,curr))<gammaMax; % Check if the current drone has capacity

               Flag2 = sum(ynm(:,curr))>gammaMin-1; % Check if the current drone has capacity

               Flag3 = xm(curr) >= UPPERTHRESHOLD; % Check if the drone is already deployed

               if Flag1 && Flag2 && Flag3

                   ccc = zeros(1,m);

                   ccc(1,curr) = 1;

                   ynm(j,:) = ccc;

                   xm(curr) = 1;

               end

           end

       end

   end

end


%% Constraint 4: Find over-utilized drones, OU:Over-Utilized

[~,constNum] = OnlyCheckConstraints(St_Data,ynm,xm); % Check if there are violations

if constNum(4) > 0

   DronesUtilization = sum(ynm);

   OverUtilizedDrones = find(DronesUtilization > gammaMax);

   for i = 1:length(OverUtilizedDrones) % LOOP: CHECK FOR ALL OU DRONES

       ouDrone1 = OverUtilizedDrones(i); % Find ith OU drone

       totalConnections = sum(ynm(:,ouDrone1)); % Find total no. connected users

       nnDrone1 = find(ynm(:,ouDrone1) >= UPPERTHRESHOLD); % Find all connection to ith OU drone

       %uuOptions = sum(ynm(nnDrone1,:),2); % Find number of possible options for users

       OverConnections = totalConnections - gammaMax; % Find over connections

       xTemp = 0; % No. of shifted users from OU drone

       for j = 1:totalConnections % LOOP: FOR ALL OVER UTILIZED CONNECTIONS

           if xTemp < OverConnections

               curr = nnDrone1(j); % jth connected user to ith OU drone

               user1PossibleConn = find(realYnm(curr,:) >= UPPERTHRESHOLD); % Find all possible connections for jth user

               user1PossibleConn(user1PossibleConn == ouDrone1) = []; % Remove OU drone from the list

               shiftFlag = 0;

               for k = 1:length(user1PossibleConn) % LOOP: CHECK FOR ALL POSSIBLE CONNECTIONS

                   if shiftFlag == 0

                       curr = user1PossibleConn(k); % Collect current possible connection option

                       Flag1 = sum(ynm(:,curr))>=gammaMin-1; % Check if the current drone is not UU

                       Flag2 = sum(ynm(:,curr))<gammaMax; % Check if the current drone is not OU

                       Flag3 = xm(curr) >= UPPERTHRESHOLD; % Check if the drone is already deployed

                       if Flag1 && Flag2 && Flag3

                           ccc = zeros(1,m);

                           ccc(1,curr) = 1;

                           ynm(j,:) = ccc;

                           xm(curr) = 1;

                           xTemp = xTemp + 1;

                           shiftFlag = 1;

                       end

                   end

               end  

           end

       end

       %----------------------------------------------------------------

       totalConnections = sum(ynm(:,ouDrone1)); % Find total no. connected users to OU ith drone

       OverConnections = totalConnections - gammaMax; % Find over connections        

       if OverConnections > 0 % If still the ith drone is OU, simply remove extra users randomly

           nnDrone1 = find(ynm(:,ouDrone1) >= UPPERTHRESHOLD); % Find all connection to ith OU drone

           [~,Indx] = sort(sum(realYnm(nnDrone1,:)),'descend'); % sort users w.r.t. to their connection options

           SelectednnDrone1 = nnDrone1(Indx); % rearrange users order according to no. of connection options

           ynm(SelectednnDrone1(1:OverConnections),ouDrone1) = 0; % remove those extra users who would have multiple options

           xm = xm.*(sum(ynm)>0);

           ynm(:,xm <= LOWERTHRESHOLD) = 0;

       end

   end

end


%% Constraint 7: Repair coverage constraint

[~,constNum] = OnlyCheckConstraints(St_Data,ynm,xm); % Check if there are violations

if constNum(7) > 0

   for i = 1:n

       for j = 1:DroneLocs

           if ynm(i,j) > realYnm(i,j)

               currUserConOptions = find(realYnm(i,:) > 0);

               [~,indx] = sort(sum(ynm(:,currUserConOptions)),'ascend');

               for k = 1:length(currUserConOptions)

                   CurrDrone = currUserConOptions(indx(k));

                   ccc = zeros(1,m);

                   ccc(1,CurrDrone) = 1;

                   ynm(i,:) = ccc;

                   xm(CurrDrone) = 1;

               end

           end

       end

   end

end


%% Constraint 1: Connect all possible users

[~,constNum] = OnlyCheckConstraints(St_Data,ynm,xm); % Check if there are violations

if constNum(1) > 0

   unConnectedUsers = sum(ynm,2) < LOWERTHRESHOLD;

   IndexunConnectedUsers = find(unConnectedUsers >= UPPERTHRESHOLD);

   for i = 1:length(IndexunConnectedUsers)

       curr = IndexunConnectedUsers(i);

       user1PossibleConn = realYnm(curr,:) >= UPPERTHRESHOLD; % Find all possible connections for curr user

       UsersConnectedToThisDrone = sum(ynm(:,user1PossibleConn));

       [~,Sorteduser1PossibleConn] = sort(UsersConnectedToThisDrone,'descend');

       connectFlag = 0;

       for k = 1:length(Sorteduser1PossibleConn) % LOOP: CHECK FOR ALL POSSIBLE CONNECTIONS

           if connectFlag == 0

               currDrone = Sorteduser1PossibleConn(k); % Collect current possible connection option

               Flag1 = sum(ynm(:,currDrone))>=gammaMin-1; % Check if the current drone is not OU

                Flag2 = sum(ynm(:,currDrone))<gammaMax; % Check if the current drone is not OU

%                 Flag3 = xm(currDrone) >= UPPERTHRESHOLD; % Check if the drone is already deployed

                if Flag1 && Flag2

                   ccc = zeros(1,m);

                   ccc(1,currDrone) = 1;

                   ynm(curr,:) = ccc;

                   xm(currDrone) = 1;

                   connectFlag = 1;

                end

           end

       end        

   end

end


%% if still there are under-utilized drones, simply remove them and

% disconnect all users

DronesUtilization = sum(ynm);

UnderUtilizedDrones = DronesUtilization < gammaMin;

ynm(:,UnderUtilizedDrones) = 0; % If there are still UU drones, simply remove them

xm(UnderUtilizedDrones) = 0;


%% Remove all the drones with beta*n more users

BetaUsers = round(St_Data.beta*n);    

AdmittedUsers = sum(sum(ynm));

ExtraUsers =  AdmittedUsers - BetaUsers;


ConnectionsToEachDrone = sum(ynm);

[~,DroneIndx] = sort(ConnectionsToEachDrone,'ascend');

for i = 1:DroneLocs

   if ExtraUsers > 0

       ThisDrone = DroneIndx(i);

       if xm(ThisDrone) > 0

           if ExtraUsers >= ConnectionsToEachDrone(ThisDrone)

               ynm(:,ThisDrone) = 0;

               xm(ThisDrone) = 0;

               ExtraUsers = ExtraUsers - ConnectionsToEachDrone(ThisDrone);

           end

       end

   end

end


%% Connect all possible users

unConnectedUsers = sum(ynm,2) < LOWERTHRESHOLD;

IndexunConnectedUsers = find(unConnectedUsers >= UPPERTHRESHOLD);

for i = 1:length(IndexunConnectedUsers)

       curr = IndexunConnectedUsers(i);

       user1PossibleConn = find(realYnm(curr,:) >= UPPERTHRESHOLD); % Find all possible connections for curr user

       connectFlag = 0;

       for k = 1:length(user1PossibleConn) % LOOP: CHECK FOR ALL POSSIBLE CONNECTIONS

           if connectFlag == 0

               currDrone = user1PossibleConn(k); % Collect current possible connection option

               Flag1 = sum(ynm(:,currDrone))>=gammaMin-1; % Check if the current drone is not OU

               Flag2 = sum(ynm(:,currDrone))<gammaMax; % Check if the current drone is not OU

               Flag3 = xm(currDrone) >= UPPERTHRESHOLD; % Check if the drone is already deployed

                if Flag1 && Flag2 && Flag3

                   ccc = zeros(1,m);

                   ccc(1,currDrone) = 1;

                   ynm(curr,:) = ccc;

                   xm(currDrone) = 1;

                   connectFlag = 1;

                end

           end

       end

end


%% Remove all the drones with beta*n more users

BetaUsers = round(St_Data.beta*n);    

AdmittedUsers = sum(sum(ynm));

ExtraUsers =  AdmittedUsers - BetaUsers;


ConnectionsToEachDrone = sum(ynm);

[~,DroneIndx] = sort(ConnectionsToEachDrone,'ascend');

for i = 1:DroneLocs

   if ExtraUsers > 0

       ThisDrone = DroneIndx(i);

       if xm(ThisDrone) > 0

           if ExtraUsers >= ConnectionsToEachDrone(ThisDrone)

               ynm(:,ThisDrone) = 0;

               xm(ThisDrone) = 0;

               ExtraUsers = ExtraUsers - ConnectionsToEachDrone(ThisDrone);

           end

       end

   end

end



[ConstraintViolations,~] = OnlyCheckConstraints(St_Data,ynm,xm); % Check if there are violations

⛄ 运行结果

⛄ 参考文献

A. Ahmed, M. Naeem and A. Al-Dweik, "Joint Optimization of Sensors Association and UAVs Placement in IoT Applications With Practical Network Constraints," in IEEE Access, vol. 9, pp. 7674-7689, 2021, doi: 10.1109/ACCESS.2021.3049360.

⛳️ 代码获取关注我

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料



相关文章
|
2月前
|
安全
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
本文介绍了2023年高教社杯数学建模竞赛D题的圈养湖羊空间利用率问题,包括问题分析、数学模型建立和MATLAB代码实现,旨在优化养殖场的生产计划和空间利用效率。
123 6
【2023高教社杯】D题 圈养湖羊的空间利用率 问题分析、数学模型及MATLAB代码
|
2月前
|
存储 算法 搜索推荐
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
本文提供了2022年华为杯数学建模竞赛B题的详细方案和MATLAB代码实现,包括方形件组批优化问题和排样优化问题,以及相关数学模型的建立和求解方法。
95 3
【2022年华为杯数学建模】B题 方形件组批优化问题 方案及MATLAB代码实现
|
2月前
|
数据采集 存储 移动开发
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
本文介绍了2023年五一杯数学建模竞赛B题的解题方法,详细阐述了如何通过数学建模和MATLAB编程来分析快递需求、预测运输数量、优化运输成本,并估计固定和非固定需求,提供了完整的建模方案和代码实现。
71 0
【2023五一杯数学建模】 B题 快递需求分析问题 建模方案及MATLAB实现代码
|
5月前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
5月前
|
算法 调度
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
|
5月前
|
Serverless
基于Logistic函数的负荷需求响应(matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
|
5月前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
5月前
|
算法 调度
面向配电网韧性提升的移动储能预布局与动态调度策略(matlab代码)
面向配电网韧性提升的移动储能预布局与动态调度策略(matlab代码)
|
5月前
|
运维 算法
基于改进遗传算法的配电网故障定位(matlab代码)
基于改进遗传算法的配电网故障定位(matlab代码)

热门文章

最新文章

下一篇
无影云桌面