《蚁群算法原理及其应用》(段海滨)附录Matlab源程序

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%       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;

你可能感兴趣的:(蚁群算法)