失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 【TSP】基于matlab GUI遗传算法求解旅行商问题【含Matlab源码 899期】

【TSP】基于matlab GUI遗传算法求解旅行商问题【含Matlab源码 899期】

时间:2019-03-07 11:32:20

相关推荐

【TSP】基于matlab GUI遗传算法求解旅行商问题【含Matlab源码 899期】

一、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 = gaGui(varargin)% GAGUI M-file for gaGui.fig%GAGUI, by itself, creates a new GAGUI or raises the existing%singleton*.%%H = GAGUI returns the handle to a new GAGUI or the handle to%the existing singleton*.%%GAGUI('CALLBACK',hObject,eventData,handles,...) calls the local%function named CALLBACK in GAGUI.M with the given input arguments.%%GAGUI('Property','Value',...) creates a new GAGUI or raises the%existing singleton*. Starting from the left, property value pairs are%applied to the GUI before gaGui_OpeningFunction gets called. An%unrecognized property name or invalid value makes property application%stop. All inputs are passed to gaGui_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% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @gaGui_OpeningFcn, ...'gui_OutputFcn', @gaGui_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 gaGui is made visible.function gaGui_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to gaGui (see VARARGIN)% Choose default command line output for gaGuihandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes gaGui wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = gaGui_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 structurevarargout{1} = handles.output;function EditCityNumber_Callback(hObject, eventdata, handles)% hObject handle to EditCityNumber (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of EditCityNumber as text% str2double(get(hObject,'String')) returns contents of EditCityNumber as a double% --- Executes during object creation, after setting all properties.function EditCityNumber_CreateFcn(hObject, eventdata, handles)% hObject handle to EditCityNumber (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 edit3_Callback(hObject, eventdata, handles)% hObject handle to edit3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit3 as text% str2double(get(hObject,'String')) returns contents of edit3 as a double% --- Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject handle to edit3 (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 editInitialGroup_Callback(hObject, eventdata, handles)% hObject handle to editInitialGroup (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of editInitialGroup as text% str2double(get(hObject,'String')) returns contents of editInitialGroup as a double% --- Executes during object creation, after setting all properties.function editInitialGroup_CreateFcn(hObject, eventdata, handles)% hObject handle to editInitialGroup (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 EditCrossOver_Callback(hObject, eventdata, handles)% hObject handle to EditCrossOver (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of EditCrossOver as text% str2double(get(hObject,'String')) returns contents of EditCrossOver as a double% --- Executes during object creation, after setting all properties.function EditCrossOver_CreateFcn(hObject, eventdata, handles)% hObject handle to EditCrossOver (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 edit6_Callback(hObject, eventdata, handles)% hObject handle to edit6 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of edit6 as text% str2double(get(hObject,'String')) returns contents of edit6 as a double% --- Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject handle to edit6 (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% --- Executes on button press in GenerateInitialCitiesButton.function GenerateInitialCitiesButton_Callback(hObject, eventdata, handles)% hObject handle to GenerateInitialCitiesButton (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)str1=char(get(handles.EditCityNumber,'string'));global NN=str2num(str1);%生成随即城市global cities;if(~isempty(cities))cla;endcities=round(100*rand(N,2));axes(handles.CityMap);for k=1:Nif(k~=1)hold onendplot(cities(k,1),cities(k,2),'bo');end

四、运行结果

五、matlab版本及参考文献

1 matlab版本

a

2 参考文献

[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,.

[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,.

如果觉得《【TSP】基于matlab GUI遗传算法求解旅行商问题【含Matlab源码 899期】》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。