%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Function: Open and import file of city coordinates in TSP %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[fname,pname,filterindex]=uigetfile('*.*','All Files (*.*)');
set(handles.text_filename,'String',filename);
fid=fopen(filename,'r');
if fid==-1
warndlg('Can not open the file','WARN');
fclose(fid);
end
[citymat,COUNT]=fscanf(fid,' %g');
cN=COUNT/3;
set(handles.edit_citysum,'String',cN);
fclose(fid);
aN=str2double(get(handles.edit_antsum,'String'));
ncmax=str2double(get(handles.edit_ncmax,'String'));
for nc=1:ncmax
for k=1:aN
g(nc,k)=fix((aN-1)*rand(1))+1;
end
end
% Basic Ant Colony Algorithm for TSP
global citymat;
global cN; % city number
global g
aN=str2double(get(handles.edit_antsum,'String')); % Set ant number by using Matlab GUI
initao=str2double(get(handles.edit_tao,'String'));
alpha=str2double(get(handles.edit_alpha,'String'));
beta=str2double(get(handles.edit_beta,'String'));
Q=str2double(get(handles.edit_q,'String'));
rou=str2double(get(handles.edit_rou,'String'));
ncmax=str2double(get(handles.edit_ncmax,'String'));
%
% 原文中以上参数是通过作者自建的GUI界面读入的
% 为便于调用,可把程序改为Matlab的M函数文件,以上参数作为函数的输入
%
% function bestroute = fun_basic_TSP(aN,initao,alpha,beta,Q,rou,ncmax)
%