【无人机通信】无人机飞行基站构建5G网络【含Matlab源码 3293期】

在这里插入图片描述

⛄一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【无人机通信】无人机飞行基站构建5G网络【含Matlab源码 3293期】
点击上面蓝色字体,直接付费下载,即可。

获取代码方式2:
付费专栏Matlab信号处理(初级版)

备注:
点击上面蓝色字体付费专栏Matlab信号处理(初级版),扫描上面二维码,付费29.9元订阅海神之光博客付费专栏Matlab信号处理(初级版),凭支付凭证,私信博主,可免费获得1份本博客上传CSDN资源代码(有效期为订阅日起,三天内有效);
点击CSDN资源下载链接:1份本博客上传CSDN资源代码

⛄二、部分源代码

function [p,L] = tspsearch(X,m)
%TSPSEARCH Heuristic method for Traveling Salesman Problem (TSP).
% [P,L] = TSPSEARCH(X,M) gives a tour P of length L. X is either a
% coordinate matrix of size Nx2 or Nx3 or a symmetric distance matrix.
% Euclidian distances are used in the coordinate case. M is an integer
% in the range 1 to N. Default is M = 1.
%
% METHOD
% M nearest neighbour tours are generated from randomly selected starting
% points. Each tour is improved by 2-opt heuristics (pairwise exchange of
% edges) and the best result is selected.
%
% EXAMPLES
%
% X = rand(100,2);
% [p,L] = tspsearch(X,100);
% tspplot(p,X)
%
% % Optimal tour length 1620
% X = load(‘hex162.dat’);
% [p,L] = tspsearch(X,10);
% tspplot(p,X)
%
% % Optimal tour length 4860
% X = load(‘hex486.dat’);
% [p,L] = tspsearch(X);
% tspplot(p,X)
% Author: Jonas Lundgren splinefit@gmail.com 2012
% Check first argument
[n,dim] = size(X);
if dim == 2 || dim == 3
% X is a coordinate matrix, compute euclidian distances
D = distmat(X);
elseif n == dim && min(X(😃) >= 0 && isequal(X,X’)
% X is a distance matrix
D = X;
else
mess = ‘First argument must be Nx2, Nx3 or symmetric and nonnegative.’;
error(‘tspsearch:first’,mess)
end
% Check second argument
if nargin < 2 || isempty(m)
m = 1;
elseif ~isscalar(m) || m < 1 || m > n || fix(m) < m
mess = ‘M must be an integer in the range 1 to %d.’;
error(‘tspsearch:second’,mess,n)
end
% Starting points for nearest neighbour tours
s = randperm(n);
Lmin = inf;
for k = 1:m
% Nearest neighbour tour
p = greedy(s(k),D);
% Improve tour by 2-opt heuristics
[p,L] = exchange2(p,D);
% Keep best tour
if L < Lmin
Lmin = L;
pmin = p;
end
end
% Output
p = double(pmin);
L = Lmin;
%--------------------------------------------------------------------------
function D = distmat(X)
%DISTMAT Compute euclidian distance matrix from coordinates
[n,dim] = size(X);
D = zeros(n);
for j = 1:n
for k = 1:dim
v = X(:,k) - X(j,k);
D(:,j) = D(:,j) + v.*v;
end
end
D = sqrt(D);
%--------------------------------------------------------------------------
function p = greedy(s,D)
%GREEDY Travel to nearest neighbour, starting with node s.
n = size(D,1);
p = zeros(1,n,‘uint16’);
p(1) = s;
for k = 2:n
D(s,:) = inf;
[~,s] = min(D(:,s));
p(k) = s;
end
%--------------------------------------------------------------------------
function [p,L] = exchange2(p,D)
%EXCHANGE2 Improve tour p by 2-opt heuristics (pairwise exchange of edges).
% The basic operation is to exchange the edge pair (ab,cd) with the pair
% (ac,bd). The algoritm examines all possible edge pairs in the tour and
% applies the best exchange. This procedure continues as long as the
% tour length decreases. The resulting tour is called 2-optimal.
n = numel§;
% Tour length
L = D(p(n),p(1));
for j = 2:n
L = L + D(p(j-1),p(j));
end
zmin = -L;
% Iterate until the tour is 2-optimal
while zmin/L < -1e-6
zmin = 0;
i = 0;
b = p(n);
% Loop over all edge pairs (ab,cd)
while i < n-2
a = b;
i = i+1;
b = p(i);
Dab = D(a,b);
j = i+1;
d = p(j);
while j < n
c = d;
j = j+1;
d = p(j);
% Tour length diff z
% Note: a == d will occur and give z = 0
z = (D(a,c) - D(c,d)) + D(b,d) - Dab;
% Keep best exchange
if z < zmin
zmin = z;
imin = i;
jmin = j;
end
end
end
% Apply exchange
if zmin < 0
p(imin:jmin-1) = p(jmin-1👎imin);
L = L + zmin;
end
end

⛄三、运行结果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

⛄四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,2015.
[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,2020.
[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,2018.

3 备注
简介此部分摘自互联网,仅供参考,若侵权,联系删除

  • 14
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab领域

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值