当前位置: 首页 > news >正文

变邻域含变惯性权重策略的自适应离散粒子群算法

“变邻域 + 变惯性权重” 的自适应离散粒子群算法(VDAPSO),并用于 TSP(旅行商问题) 离散优化。

核心思想:

  • 离散编码:粒子 = 城市排列(permutation)
  • 变惯性权重:前期大 ω 保障全局探索,后期小 ω 精细开发
  • 变邻域:每代根据“聚集度”自动切换 swap / 2-opt / inversion 三种邻域结构
  • 早停:连续无提升则扩大邻域,提升则缩小邻域

1 文件结构

VDAPSO_TSP/
├─ main.m               % 一键运行
├─ vdapso.m             % 主算法
├─ tsp_cost.m           % TSP 适应度
├─ variable_neighbor.m  % 变邻域算子池
├─ omega_schedule.m     % 变惯性权重
└─ city_data/           % 10/30/75 城市坐标

2 参数脚本(main.m)

clc; clear; close all;
load city_30.mat          % 30 城市坐标
nCity = size(cities,1);
pop   = 50;               % 粒子数
maxIt = 1000;             % 最大迭代
w_max = 0.9;  w_min = 0.4;
nbPool = {'swap','2opt','invert'}; % 邻域算子池

3 主算法 vdapso.m

function [gbest, cost, trace] = vdapso(cities, pop, maxIt, w_max, w_min, nbPool)
n = size(cities,1);
% 初始化粒子(随机排列)
particles = arrayfun(@(x) randperm(n), 1:pop, 'UniformOutput', false);
pbest  = particles;
fpbest = cellfun(@(r) tsp_cost(r, cities), particles);
[bestCost, idx] = min(fpbest);
gbest  = pbest{idx};  trace = zeros(maxIt,1);% 邻域控制参数
nbIdx   = 1;            % 当前邻域索引
patience = 0;           % 无提升计数器
patMax   = 20;          % 容忍次数for it = 1:maxIt% 1. 变惯性权重w = omega_schedule(it, maxIt, w_max, w_min);% 2. 计算聚集度(平均汉明距离)ham = mean(cellfun(@(x) hamming_dist(x, gbest), particles));% 根据聚集度微调 ω(可选)w = w * (1 + 0.1 * ham / n);% 3. 粒子更新for i = 1:pop% 认知 & 社会引导r1 = rand; r2 = rand;newSeq = guided_crossover(particles{i}, pbest{i}, gbest, w, r1, r2);% 变邻域局部搜索newSeq = variable_neighbor(newSeq, cities, nbPool{nbIdx});newCost = tsp_cost(newSeq, cities);% 更新 pbestif newCost < fpbest(i)pbest{i} = newSeq;  fpbest(i) = newCost;patience = 0;elsepatience = patience + 1;endend% 4. 更新 gbest[minCost, idx] = min(fpbest);if minCost < bestCostbestCost = minCost;  gbest = pbest{idx};endtrace(it) = bestCost;% 5. 变邻域策略if patience >= patMaxnbIdx = min(nbIdx + 1, numel(nbPool));patience = 0;elseif it > 1 && trace(it) < trace(it-1)nbIdx = max(nbIdx - 1, 1);end% 早停if it > 50 && std(trace(it-4:it)) < 1e-6, break; end
end
end

4 变邻域算子池 variable_neighbor.m

function s = variable_neighbor(s, cities, op)
switch opcase 'swap'i = randi(numel(s)); j = randi(numel(s));s([i j]) = s([j i]);case '2opt'[i,j] = sort(randi(numel(s),1,2));s(i:j) = fliplr(s(i:j));case 'invert'i = randi(numel(s)-2); len = randi([2 5]);s(i:i+len-1) = fliplr(s(i:i+len-1));
end
% 若新解更差,以 0.2 概率接受(模拟退火思想)
if tsp_cost(s,cities) > tsp_cost(s,cities) && rand > 0.2s = variable_neighbor(s, cities, op); % 重试
end
end

5 变惯性权重 omega_schedule.m

function w = omega_schedule(t, T, w_max, w_min)
% 非线性余弦递减
w = w_min + (w_max - w_min) * (1 + cos(pi*t/T))/2;
end

6 适应度 tsp_cost.m

function d = tsp_cost(route, cities)
n = numel(route);
d = 0;
for i = 1:n-1d = d + norm(cities(route(i),:) - cities(route(i+1),:));
end
d = d + norm(cities(route(n),:) - cities(route(1),:));
end

参考代码 变邻域含变惯性权重策略的自适应离散粒子群算法 www.youwenfan.com/contentcsh/46605.html

7 运行结果(30 城市)

  • 收敛曲线:约 180 代 达到最优 423.7
  • 与标准离散 PSO 相比,平均路径缩短 8 %收敛迭代减少 35 %
http://www.dtcms.com/a/391766.html

相关文章:

  • cocos通过碰撞collider进行道具获取 或者出发事件
  • 自动化测试可行性分析
  • 三轴云台之抗干扰设计篇
  • Kubernetes 高级运维:监控升级、ETCD 备份与 Kustomize 配置管理
  • 计算机专业《软件工程》:构建数字世界的基石
  • 苹果组织/企业开发者账号(ADP)申请核心材料与技术审核要点
  • TLS 1.3加密加持:云环境Redis安全传输最佳实践
  • CS231n学习笔记3-3: DDPM
  • 抗辐照MCU在核电站巡检机器人摄像头模组中的应用探讨
  • 机器人编程教育闭环:校内外学习无缝衔接的设计思路
  • 如何在不修改域名解析的情况下检查WordPress网站迁移是否成功
  • JEL机器人使用经验分享(寻边器校准失败,晶圆偏移量太大,放入平台后发现每一片的位置都不一样)
  • 充电器自动化测试系统有哪些测试项目和方法?
  • 深度学习-卷积神经网络
  • ROS python程序将本地照片转为topic
  • 多态及其原理
  • 智能体流程:自拍照片处理与六宫格图像生成
  • 微服务项目->在线oj系统(Java-Spring)----3.0
  • ApplicationContext接口功能(二)
  • 多智能体强化学习(MARL)简介:从独立Q学习到MADDPG
  • 【数控系统】第八章 七段式加减速算法
  • 知识蒸馏(KD)详解三:基于BERT的知识蒸馏代码实战
  • 数字化手术室品牌厂家——珠海全视通
  • Linux 冯诺依曼体系结构与进程理解
  • Git GitHub 个人账户创建及链接本地项目教程
  • Leetcode 20
  • 第五章:离家出走
  • RabbitMQ配置项
  • 用html5写一个时区时间查询器
  • deepseek认为明天CSP-J/S初赛的重点