基于遗传算法求解多旅行商问题同一起点和终点付matlab代码

简介: 基于遗传算法求解多旅行商问题同一起点和终点付matlab代码

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

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

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

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

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

⛄ 内容介绍

旅行商问题是一个经典的NP完全问题,多人旅行商问题的求解则更具挑战性.以往对求解多人旅行商问题的研究局限于以所有成员路径总和最小为优化标准,而对以所有成员路径最大值最小为优化标准的另一类多人旅行商问题却未加注意.文章给出了这两类多人旅行商问题的形式化描述,探讨了利用遗传算法求解这两类多人旅行商问题的基本思想和具体方案,进行了仿真实验验证.仿真实验数据表明,这是一种高效而且适应性强的多入旅行商问题求解方法.

⛄ 部分代码

function varargout = mtspf_ga(xy,dmat,salesmen,min_tour,pop_size,num_iter,show_prog,show_res)

% MTSPF_GA Fixed Multiple Traveling Salesmen Problem (M-TSP) Genetic Algorithm (GA)

%   Finds a (near) optimal solution to a variation of the M-TSP by setting

%   up a GA to search for the shortest route (least distance needed for

%   each salesman to travel from the start location to individual cities

%   and back to the original starting place)

%

% Summary:

%     1. Each salesman starts at the first point, and ends at the first

%        point, but travels to a unique set of cities in between

%     2. Except for the first, each city is visited by exactly one salesman

%

% Note: The Fixed Start/End location is taken to be the first XY point

%

% Input:

%     XY (float) is an Nx2 matrix of city locations, where N is the number of cities

%     DMAT (float) is an NxN matrix of city-to-city distances or costs

%     SALESMEN (scalar integer) is the number of salesmen to visit the cities

%     MIN_TOUR (scalar integer) is the minimum tour length for any of the

%         salesmen, NOT including the start/end point

%     POP_SIZE (scalar integer) is the size of the population (should be divisible by 8)

%     NUM_ITER (scalar integer) is the number of desired iterations for the algorithm to run

%     SHOW_PROG (scalar logical) shows the GA progress if true

%     SHOW_RES (scalar logical) shows the GA results if true

%

% Output:

%     OPT_RTE (integer array) is the best route found by the algorithm

%     OPT_BRK (integer array) is the list of route break points (these specify the indices

%         into the route used to obtain the individual salesman routes)

%     MIN_DIST (scalar float) is the total distance traveled by the salesmen

%

% Route/Breakpoint Details:

%     If there are 10 cities and 3 salesmen, a possible route/break

%     combination might be: rte = [5 6 9 4 2 8 10 3 7], brks = [3 7]

%     Taken together, these represent the solution [1 5 6 9 1][1 4 2 8 1][1 10 3 7 1],

%     which designates the routes for the 3 salesmen as follows:

%         . Salesman 1 travels from city 1 to 5 to 6 to 9 and back to 1

%         . Salesman 2 travels from city 1 to 4 to 2 to 8 and back to 1

%         . Salesman 3 travels from city 1 to 10 to 3 to 7 and back to 1

%

% 2D Example:

%     n = 35;

%     xy = 10*rand(n,2);

%     salesmen = 5;

%     min_tour = 3;

%     pop_size = 80;

%     num_iter = 5e3;

%     a = meshgrid(1:n);

%     dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),n,n);

%     [opt_rte,opt_brk,min_dist] = mtspf_ga(xy,dmat,salesmen,min_tour, ...

%         pop_size,num_iter,1,1);

%

% 3D Example:

%     n = 35;

%     xyz = 10*rand(n,3);

%     salesmen = 5;

%     min_tour = 3;

%     pop_size = 80;

%     num_iter = 5e3;

%     a = meshgrid(1:n);

%     dmat = reshape(sqrt(sum((xyz(a,:)-xyz(a',:)).^2,2)),n,n);

%     [opt_rte,opt_brk,min_dist] = mtspf_ga(xyz,dmat,salesmen,min_tour, ...

%         pop_size,num_iter,1,1);

%

% See also: mtsp_ga, mtspo_ga, mtspof_ga, mtspofs_ga, mtspv_ga, distmat



% Process Inputs and Initialize Defaults

nargs = 8;

for k = nargin:nargs-1

   switch k

       case 0

           xy = 10*rand(40,2);

       case 1

           N = size(xy,1);

           a = meshgrid(1:N);

           dmat = reshape(sqrt(sum((xy(a,:)-xy(a',:)).^2,2)),N,N);

       case 2

           salesmen = 5;

       case 3

           min_tour = 2;

       case 4

           pop_size = 80;

       case 5

           num_iter = 5e3;

       case 6

           show_prog = 1;

       case 7

           show_res = 1;

       otherwise

   end

⛄ 运行结果

⛄ 参考文献

[1]葛春志, 汪亚东, 王荣鑫,等. 基于遗传算法的旅行商问题多量值最优化求解研究[J]. 黑龙江大学自然科学学报, 2013(5):8.

[2]吴云, 姜麟, 刘强. 基于并行遗传算法多旅行商问题的求解[J]. 微型电脑应用, 2011(7):4.

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


相关文章
|
机器学习/深度学习 网络安全 算法框架/工具
在本地利用服务器显卡跑代码
在本地利用服务器显卡跑代码
1648 0
|
存储 缓存 监控
一文读懂分布式架构知识体系(内含超全核心知识大图)
7月9日 19:00-21:30 阿里云开发者社区首场“Offer 5000”直播开启!15位团队技术大牛在线招人,更有《阿里云技术面试红宝书》助你拿下Offer!马上投递简历:https://developer.aliyun.com/special/offerday01
20040 0
|
7月前
|
缓存 JavaScript PHP
斩获开发者口碑!SnowAdmin:基于 Vue3 的高颜值后台管理系统,3 步极速上手!
SnowAdmin 是一款基于 Vue3/TypeScript/Arco Design 的开源后台管理框架,以“清新优雅、开箱即用”为核心设计理念。提供角色权限精细化管理、多主题与暗黑模式切换、动态路由与页面缓存等功能,支持代码规范自动化校验及丰富组件库。通过模块化设计与前沿技术栈(Vite5/Pinia),显著提升开发效率,适合团队协作与长期维护。项目地址:[GitHub](https://github.com/WANG-Fan0912/SnowAdmin)。
1049 5
|
存储 人工智能 数据库
面向医疗场景的大模型 RAG 检索增强解决方案
本方案为您介绍,如何使用人工智能平台 PAI 构建面向医疗场景的大模型 RAG 检索增强解决方案。
|
存储 JSON API
作为开发者,我如何提高任务型大模型应用的响应性能
本文基于实际场景,分享了作为开发者提高大模型响应性能的四个实用方法。
2558 58
|
10月前
|
机器学习/深度学习 人工智能 API
上新!支持100万Tokens上下文的Qwen2.5-1M 开源模型来了
上新!支持100万Tokens上下文的Qwen2.5-1M 开源模型来了
|
11月前
|
缓存 算法 物联网
【论文专辑】2024年大模型推理优化论文精选第六期
本文整理了 OSDI 2024 和 SOSP 2024 中与大语言模型(LLM)推理优化相关的10篇论文,涵盖 Parrot、ServerlessLLM、dLoRA 等系统,提出的技术如 Chunked Prefill、Prefix-Caching、P/D分离等已被 vLLM 和 TensorRT-LLM 等主流推理引擎采用。这些研究解决了 LLM 推理中的冷启动延迟、资源分配、KV 缓存管理等问题,提升了推理性能和资源利用率。CodeFuse推理优化项目地址https://github.com/codefuse-ai/EasyDeploy
1395 2
|
JavaScript Java CDN
vue3完整教程从入门到精通(新人必学1,vue3快速上手)
本文提供了Vue 3从入门到精通的完整教程,涵盖了创建Vue应用、通过CDN使用Vue、定义网站以及使用ES模块构建版本的步骤和示例代码。
10756 1
vue3完整教程从入门到精通(新人必学1,vue3快速上手)
|
算法 决策智能
基于遗传算法解决TSP问题(Matlab代码实现)
基于遗传算法解决TSP问题(Matlab代码实现)
668 0