一、TSP简介

旅行商问题,即TSP问题(Traveling Salesman Problem)又译为旅行推销员问题、货郎担问题,是数学领域中著名问题之一。假设有一个旅行商人要拜访n个城市,他必须选择所要走的路径,路径的限制是每个城市只能拜访一次,而且最后要回到原来出发的城市。路径的选择目标是要求得的路径路程为所有路径之中的最小值。
TSP的数学模型

二、遗传算法简介

1 引言


2 遗传算法理论
2.1 遗传算法的生物学基础


2.2 遗传算法的理论基础




2.3 遗传算法的基本概念






2.4 标准的遗传算法


2.5 遗传算法的特点


2.6 遗传算法的改进方向

3 遗传算法流程



4 关键参数说明

三、部分源代码

function varargout = tsp_ga_gui(varargin)
% TSP_GA_GUI MATLAB code for tsp_ga_gui.fig
%      TSP_GA_GUI, by itself, creates a new TSP_GA_GUI or raises the existing
%      singleton*.
%
%      H = TSP_GA_GUI returns the handle to a new TSP_GA_GUI or the handle to
%      the existing singleton*.
%
%      TSP_GA_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TSP_GA_GUI.M with the given input arguments.
%
%      TSP_GA_GUI('Property','Value',...) creates a new TSP_GA_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before tsp_ga_gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to tsp_ga_gui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help tsp_ga_gui% Last Modified by GUIDE v2.5 25-Feb-2021 15:15:58% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @tsp_ga_gui_OpeningFcn, ...'gui_OutputFcn',  @tsp_ga_gui_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before tsp_ga_gui is made visible.
function tsp_ga_gui_OpeningFcn(hObject, eventdata, handles, varargin)
global hnds
global r nn dsm asz G
global startf% Choose default command line output for tsp_ga_gui
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes tsp_ga_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);hnds=handles;startf=false; % start flagasz=10; % area size   asx x asz
nn=str2num(get(handles.nn,'string')); % number of cities
ps=str2num(get(handles.ps,'string')); % population sizer=asz*rand(2,nn); % randomly distribute cities
% r(1,:) -x coordinaties of cities
% r(2,:) -y coordinaties of citiesdsm=zeros(nn,nn); % matrix of distancies
for n1=1:nn-1r1=r(:,n1);for n2=n1+1:nnr2=r(:,n2);dr=r1-r2;dr2=dr'*dr;drl=sqrt(dr2);dsm(n1,n2)=drl;dsm(n2,n1)=drl;end
end% start from random closed pathes:
G=zeros(ps,nn); % genes, G(i,:) - gene of i-path, G(i,:) is row-vector with cities number in the path
for psc=1:psG(psc,:)=randperm(nn);
endupdate_plots;% --- Outputs from this function are returned to the command line.
function varargout = tsp_ga_gui_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)% Get default command line output from handles structure
varargout{1} = handles.output;% --- Executes on button press in randomize.
function randomize_Callback(hObject, eventdata, handles)
global r nn dsm asznn=str2num(get(handles.nn,'string')); % number of citiesr=asz*rand(2,nn); % randomly distribute cities
% r(1,:) -x coordinaties of cities
% r(2,:) -y coordinaties of citiesdsm=zeros(nn,nn); % matrix of distancies
for n1=1:nn-1r1=r(:,n1);for n2=n1+1:nnr2=r(:,n2);dr=r1-r2;dr2=dr'*dr;drl=sqrt(dr2);dsm(n1,n2)=drl;dsm(n2,n1)=drl;end
endupdate_plots;% --- Executes on button press in circle.
function circle_Callback(hObject, eventdata, handles)
global r nn dsm asznn=str2num(get(handles.nn,'string')); % number of citiesr=zeros(2,nn);% circle
al1=linspace(0,2*pi,nn+1);
al=al1(1:end-1);
r(1,:)=0.5*asz+0.45*asz*cos(al);
r(2,:)=0.5*asz+0.45*asz*sin(al);% r(1,:) -x coordinaties of cities
% r(2,:) -y coordinaties of citiesdsm=zeros(nn,nn); % matrix of distancies
for n1=1:nn-1r1=r(:,n1);for n2=n1+1:nnr2=r(:,n2);dr=r1-r2;dr2=dr'*dr;drl=sqrt(dr2);dsm(n1,n2)=drl;dsm(n2,n1)=drl;end
endupdate_plots;function nn_Callback(hObject, eventdata, handles)
update_plots_nn_ps;% --- Executes during object creation, after setting all properties.
function nn_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
endfunction ps_Callback(hObject, eventdata, handles)
update_plots_nn_ps;% --- Executes during object creation, after setting all properties.
function ps_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ps (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');
end

四、运行结果


五、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.

【TSP】基于matlab GUI改进的遗传算法求解旅行商问题【含Matlab源码 926期】相关推荐

  1. 【图像处理】基于matlab GUI多功能图像处理系统【含Matlab源码 1876期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[图像处理]基于matlab GUI多功能图像处理系统[含Matlab源码 1876期] 点击上面蓝色字体,直接付费下载,即可. 获取代码 ...

  2. 【机械仿真】基于matlab GUI曲柄摇杆机构运动仿真【含Matlab源码 1608期】

    一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[机械仿真]基于matlab GUI曲柄摇杆机构运动仿真[含Matlab源码 1608期] 点击上面蓝色字体,直接付费下载,即可. 获取代码 ...

  3. 【光学】基于matlab GUI光栅条纹投影生成【含Matlab源码 2118期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[光学]基于matlab GUI光栅条纹投影生成[含Matlab源码 2118期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2 ...

  4. 【机械仿真】基于matlab GUI直齿圆柱齿轮应力计算【含Matlab源码 2077期】

    ⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[机械仿真]基于matlab GUI直齿圆柱齿轮应力计算[含Matlab源码 2077期] 点击上面蓝色字体,直接付费下载,即可. 获取代 ...

  5. 【天体学】基于matlab GUI太阳天顶角计算【含Matlab源码 2229期】

    一.⛄获取代码方式 获取代码方式1: 完整代码已上传我的资源:[天体学]基于matlab GUI太阳天顶角计算[含Matlab源码 2229期] 点击上面蓝色字体,直接付费下载,即可. 获取代码方式2 ...

  6. 【ACO TSP】基于matlab GUI蚁群算法求解旅行商问题【含Matlab源码 1032期】

    ⛄一.TSP简介 旅行商问题,即TSP问题(Traveling Salesman Problem)又译为旅行推销员问题.货郎担问题,是数学领域中著名问题之一.假设有一个旅行商人要拜访n个城市,他必须选 ...

  7. 【PSO TSP】基于matlab GUI粒子群算法求解旅行商问题【含Matlab源码 1334期】

    ⛄一.TSP简介 旅行商问题,即TSP问题(Traveling Salesman Problem)又译为旅行推销员问题.货郎担问题,是数学领域中著名问题之一.假设有一个旅行商人要拜访n个城市,他必须选 ...

  8. 【身份证识别】基于matlab GUI BP神经网络身份证识别【含Matlab源码 2239期】

    ⛄一.身份证号码识别简介 1 引言 当今是一个信息高度发达的时代,对于每个公民而言身份证那一连串的数字体现了个人信息的唯一性,出于保障公民合法权益和社会治安的考虑,越来越多的行业都开始建立自己的安全保 ...

  9. 【数学建模】基于matlab GUI平行停车模拟仿真【含Matlab源码 1877期】

    一.平行停车模拟仿真简介 近年来, 随着我国经济的快速发展, 机动车保有量也迅速增长.截至2012年底, 全国机动车保有量已达2.4亿辆, 城市"停车难"的问题日趋严重.统计结果表 ...

  10. 【语音去噪】基于matlab GUI IIR滤波器语音去噪【含Matlab源码 1864期】

    一.语音处理简介 语言是人们获得各类有效信息的主要途径, 而语音是语言的表现形式.语音在一定程度上可影响人们的生活, 因此, 语音信号的研究对科学领域和人们日常生活具有一定的研究价值和意义.噪声广泛存 ...

最新文章

  1. [BZOJ4756] [Usaco2017 Jan]Promotion Counting(线段树合并)
  2. 项目管理风险控制及注意事项
  3. termux配置python_termux python环境
  4. python简单可视化聊天界面_如何用Python制作可视化输入界面
  5. 递归与分治——子集问题
  6. 牛客 - 「火」皇家烈焰(线性dp)
  7. Apache Beam 剖析
  8. php 执行任务,php多进程执行任务的说明
  9. python是否安装numpy_python 怎么查看安装numpy的版本
  10. dell安装linux系统网卡,DELL 2850服务器Redhat Linux 9系统安装网卡驱动记
  11. 三调 图斑地类面积_国土三调APP-GIS,地理信息,综合管网,地下空间,给水排水,通信管网,燃气管网,智慧旅游,...
  12. 模2除法与二进制除法
  13. USB写保护的一些工具记录
  14. 发现Chrome小恐龙彩蛋的第n+1个使用者
  15. scikit-learn入门到精通(二):seting和estimator
  16. web前端能做到多少岁
  17. 瑞·达利欧的《原则》读后感
  18. android base64 编码 c# base64解码器,c#中base64编码解码
  19. C语言的if语句加减乘除
  20. 力扣 -- 551. 学生出勤记录 I 、 552. 学生出勤记录 II

热门文章

  1. C++ 日期 时间
  2. Day2:认识html
  3. ps 缩放 颜色分类 像素和分辨率学习笔记
  4. 190119每日一句
  5. Atitit 文档资料整理的规范流程与问题解决目录1. 减肥 11.1. 剥离非原创类文件 11.2. 去重 11.3. 转换格式 21.4. Topic主题剥离 22. 脱敏 2
  6. Atitit 获取SqlSessionFactory的三种方式 目录 第一节 DataSource 方式 1 第二节 读取sprbt Url方式 ByteArrayInputStream 1 第三节
  7. Atitit.spring体系结构大总结 1. Spel表达式解析 1 2. Srping mvc 1 3. Ioc 4 3.1. ApplicationContext在BeanFactory的基础
  8. Atitit 命令行执行springboot程序 目录 1.1. 执行spel表达式,调用app main,获取context 1 1.2. 直接在Application main函数内执行 1
  9. paip.提升性能----jvm参数调整.txt
  10. paip.python 执行shell 带空格命令行attilax总结