www.gusucode.com > 用蚁群算法解决TSP问题,其中有基本蚁群,蚁密系统,还有自己提出的改进算法,自带GUI界面 > 用蚁群算法解决TSP问题,其中有基本蚁群,蚁密系统,还有自己提出的改进算法,自带GUI界面/GUI/ACO.m

    function varargout = ACO(varargin)
% ACO M-file for ACO.fig
%      ACO, by itself, creates a new ACO or raises the existing
%      singleton*.
%
%      H = ACO returns the handle to a new ACO or the handle to
%      the existing singleton*.
%
%      ACO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ACO.M with the given input arguments.
%
%      ACO('Property','Value',...) creates a new ACO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ACO_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ACO_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 ACO

% Last Modified by GUIDE v2.5 21-Apr-2008 16:18:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ACO_OpeningFcn, ...
                   'gui_OutputFcn',  @ACO_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
function ACO_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 ACO (see VARARGIN)

% Choose default command line output for ACO
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = ACO_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;

%各TEXT和EDIT TEXT对象的回调函数,函数为空
function out_current_num_Callback(hObject, eventdata, handles)
% hObject    handle to out_current_num (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 out_current_num as text
%        str2double(get(hObject,'String')) returns contents of
%        out_current_num as a double
function out_current_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_current_num (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
function out_glob_num_Callback(hObject, eventdata, handles)
% hObject    handle to out_glob_num (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 out_glob_num as text
%        str2double(get(hObject,'String')) returns contents of out_glob_num
%        as a double
function out_glob_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_glob_num (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
function in_ant_num_Callback(hObject, eventdata, handles)
% hObject    handle to in_ant_num (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 in_ant_num as text
%        str2double(get(hObject,'String')) returns contents of in_ant_num as a double
function in_ant_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_ant_num (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
function text8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
function in_iter_num_Callback(hObject, eventdata, handles)
% hObject    handle to in_iter_num (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 in_iter_num as text
%        str2double(get(hObject,'String')) returns contents of in_iter_num
%        as a double
function in_iter_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_iter_num (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
function in_orig_pher_Callback(hObject, eventdata, handles)
% hObject    handle to in_orig_pher (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 in_orig_pher as text
%        str2double(get(hObject,'String')) returns contents of in_orig_pher
%        as a double
function in_orig_pher_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_orig_pher (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
function in_pher_evop_Callback(hObject, eventdata, handles)
% hObject    handle to in_pher_evop (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 in_pher_evop as text
%        str2double(get(hObject,'String')) returns contents of in_pher_evop
%        as a double
function in_pher_evop_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_pher_evop (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
function in_anti_num_Callback(hObject, eventdata, handles)
% hObject    handle to in_anti_num (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 in_anti_num as text
%        str2double(get(hObject,'String')) returns contents of in_anti_num
%        as a double
function in_anti_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_anti_num (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
function in_anti_iter_num_Callback(hObject, eventdata, handles)
% hObject    handle to in_anti_iter_num (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 in_anti_iter_num as text
%        str2double(get(hObject,'String')) returns contents of
%        in_anti_iter_num as a double
function in_anti_iter_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_anti_iter_num (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
function in_pher_eff_Callback(hObject, eventdata, handles)
% hObject    handle to in_pher_eff (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 in_pher_eff as text
%        str2double(get(hObject,'String')) returns contents of in_pher_eff
%        as a double
function in_pher_eff_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_pher_eff (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
function in_heu_eff_Callback(hObject, eventdata, handles)
% hObject    handle to in_heu_eff (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 in_heu_eff as text
%        str2double(get(hObject,'String')) returns contents of in_heu_eff
%        as a double
function in_heu_eff_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_heu_eff (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
function in_cand_len_Callback(hObject, eventdata, handles)
% hObject    handle to in_cand_len (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 in_cand_len as text
%        str2double(get(hObject,'String')) returns contents of in_cand_len
%        as a double
function in_cand_len_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_cand_len (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
function in_local_update_Callback(hObject, eventdata, handles)
% hObject    handle to in_local_update (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 in_local_update as text
%        str2double(get(hObject,'String')) returns contents of
%        in_local_update as a double
function in_local_update_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_local_update (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
function in_peso_para_Callback(hObject, eventdata, handles)
% hObject    handle to in_peso_para (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 in_peso_para as text
%        str2double(get(hObject,'String')) returns contents of in_peso_para
%        as a double
function in_peso_para_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_peso_para (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
function in_localsearch_num_Callback(hObject, eventdata, handles)
% hObject    handle to in_localsearch_num (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 in_localsearch_num as text
%        str2double(get(hObject,'String')) returns contents of
%        in_localsearch_num as a double
function in_localsearch_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_localsearch_num (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
function in_prob1_Callback(hObject, eventdata, handles)
% hObject    handle to in_prob1 (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 in_prob1 as text
%        str2double(get(hObject,'String')) returns contents of in_prob1 as
%        a double
function in_prob1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_prob1 (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
function in_num1_Callback(hObject, eventdata, handles)
% hObject    handle to in_num1 (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 in_num1 as text
%        str2double(get(hObject,'String')) returns contents of in_num1 as a double
function in_num1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_num1 (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
function in_prob2_Callback(hObject, eventdata, handles)
% hObject    handle to in_prob2 (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 in_prob2 as text
%        str2double(get(hObject,'String')) returns contents of in_prob2 as
%        a double
function in_prob2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_prob2 (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
function in_num2_Callback(hObject, eventdata, handles)
% hObject    handle to in_num2 (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 in_num2 as text
%        str2double(get(hObject,'String')) returns contents of in_num2 as a
%        double
function in_num2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_num2 (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
function in_prob3_Callback(hObject, eventdata, handles)
% hObject    handle to in_prob3 (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 in_prob3 as text
%        str2double(get(hObject,'String')) returns contents of in_prob3 as a double
function in_prob3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_prob3 (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
function in_num3_Callback(hObject, eventdata, handles)
% hObject    handle to in_num3 (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 in_num3 as text
%        str2double(get(hObject,'String')) returns contents of in_num3 as a
%        double
function in_num3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_num3 (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
function in_instance_Callback(hObject, eventdata, handles)
% hObject    handle to in_instance (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns in_instance contents as cell array
%        contents{get(hObject,'Value')} returns selected item from
%        in_instance
function in_instance_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_instance (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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
function in_algorithm_Callback(hObject, eventdata, handles)
% hObject    handle to in_algorithm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns in_algorithm contents as cell array
%        contents{get(hObject,'Value')} returns selected item from
%        in_algorithm
function in_algorithm_CreateFcn(hObject, eventdata, handles)
% hObject    handle to in_algorithm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu 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
function out_city_num_Callback(hObject, eventdata, handles)
% hObject    handle to out_city_num (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 out_city_num as text
%        str2double(get(hObject,'String')) returns contents of out_city_num
%        as a double
function out_city_num_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_city_num (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
function out_tour_length_Callback(hObject, eventdata, handles)
% hObject    handle to out_tour_length (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 out_tour_length as text
%        str2double(get(hObject,'String')) returns contents of
%        out_tour_length as a double
function out_tour_length_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_tour_length (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
function out_time1_Callback(hObject, eventdata, handles)
% hObject    handle to out_time1 (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 out_time1 as text
%        str2double(get(hObject,'String')) returns contents of out_time1 as a double
function out_time1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_time1 (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
function out_time2_Callback(hObject, eventdata, handles)
% hObject    handle to out_time2 (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 out_time2 as text
%        str2double(get(hObject,'String')) returns contents of out_time2 as a double
function out_time2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_time2 (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
function out_tour_Callback(hObject, eventdata, handles)
% hObject    handle to out_tour (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 out_tour as text
%        str2double(get(hObject,'String')) returns contents of out_tour as a double
function out_tour_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_tour (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
function out_status_Callback(hObject, eventdata, handles)
% hObject    handle to out_status (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 out_status as text
%        str2double(get(hObject,'String')) returns contents of out_status
%        as a double
function out_status_CreateFcn(hObject, eventdata, handles)
% hObject    handle to out_status (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
function detail_Callback(hObject, eventdata, handles)
% hObject    handle to detail (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of detail

%四个按钮的回调函数
function run_Callback(hObject, eventdata, handles)
% hObject    handle to run (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(findobj('tag','out_status'),'string','正在运行,请稍等...');
detail_pro=get(findobj('tag','detail'),'Value');
%读取算法类型
algorithm_type = get(findobj('tag','in_algorithm'),'Value');
%读取城市数据
city_instance = get(findobj('tag','in_instance'),'Value');
switch city_instance
    case 1
        data=load('ulysses16.txt');
    case 2
        data=load('ulysses22.txt');
    case 3
        data=load('oliver30.txt');
    case 4
        data=load('att48.txt');
    case 5
        data=load('eil51.txt');
    case 6
        data=load('eil76.txt');
    case 7
        data=load('eil101.txt');
    case 8
        data=load('ch130.txt');
    case 9
        data=load('ch150.txt');
    case 10
        data=load('rat195.txt');
    case 11
        data=load('tsp225.txt');
end
X=data(:,2);
Y=data(:,3);
%计算城市之间的距离和最近邻列表
cand_length = str2double(get(findobj('tag','in_cand_len'),'string'));
if cand_length==0
   [dist,city_num]=dist_cand(X,Y);
else
   [dist,city_num,cand_list]=dist_cand(X,Y,cand_length);
end
set(findobj('tag','out_city_num'),'string',num2str(city_num));
%获取蚂蚁数、算法迭代次数、初始信息素、信息素蒸发速率、信息素系数、启发式信息素系数
ant_num=str2double(get(findobj('tag','in_ant_num'),'string'));
iter_num=str2double(get(findobj('tag','in_iter_num'),'string'));
tau=str2double(get(findobj('tag','in_orig_pher'),'string'));
pher_evap_rate=str2double(get(findobj('tag','in_pher_evop'),'string'));
pher_effe_rate=str2double(get(findobj('tag','in_pher_eff'),'string'));
heur_effe_rate=str2double(get(findobj('tag','in_heu_eff'),'string'));
%获取各算法的其它参数
switch algorithm_type
    case 4
         psi=str2double(get(findobj('tag','in_local_update'),'string'));
         para_q=str2double(get(findobj('tag','in_peso_para'),'string'));
    case 5
         psi=str2double(get(findobj('tag','in_local_update'),'string'));
         para_q=str2double(get(findobj('tag','in_peso_para'),'string'));
         local_iter_num = str2double(get(findobj('tag','in_localsearch_num'),'string'));
    case 6
        % psi=str2double(get(findobj('tag','in_local_update'),'string'));
        % para_q=str2double(get(findobj('tag','in_peso_para'),'string'));
         anti_num=str2double(get(findobj('tag','in_anti_num'),'string'));
         anti_iter=str2double(get(findobj('tag','in_anti_iter_num'),'string'));
         imu_num=str2double(get(findobj('tag','in_localsearch_num'),'string'));
         pc=str2double(get(findobj('tag','in_prob1'),'string'));
         uc=str2double(get(findobj('tag','in_num1'),'string'));
         ps=str2double(get(findobj('tag','in_prob2'),'string'));
         us=str2double(get(findobj('tag','in_num2'),'string'));
         pi=str2double(get(findobj('tag','in_prob3'),'string'));
         ui=str2double(get(findobj('tag','in_num3'),'string'));
end
%初始化信息素
if algorithm_type==6                 %利用人工免疫算法的初步解进行信息素初始化
    set(findobj('tag','out_status'),'string','正在执行人工免疫算法部分...');
    AIA=AIA_algorithm(anti_iter,city_num,dist,X,Y,pc,uc,ps,us,pi,ui);
    pher=(ones(city_num)-eye(city_num))*tau;
    for i=1:anti_num
        for j=1:city_num
            pres=AIA(i).tour(j);
            next=AIA(i).tour(j+1);
            pher(pres,next)=pher(pres,next)+tau*0.2;
            pher(next,pres)=pher(pres,next);
        end
    end
else
    pher=(ones(city_num)-eye(city_num))*tau;
end
%计算信息数与启发式信息联合矩阵
choice_info=calc_info(pher_effe_rate,heur_effe_rate,pher,dist);
%启动计时器
set(findobj('tag','out_status'),'string','正在运行,请稍等...');
tic;
%构建路径
for order=1:iter_num
    %清除蚂蚁记录
    ant = clear_fisttour(ant_num,city_num);
    switch algorithm_type
        case {1,2,3,6}                  %蚁圈系统、蚁密系统、蚁量系统和混合算法均采用共同的构建方法,算法采用并行构建方式
            for step = 2:city_num
                for i = 1:ant_num
                    pres_city = ant(i).tour(step-1);
                    if cand_length==0
                        next_city=as_next_tour(city_num,choice_info,pres_city,ant(i));    
                    else
                        next_city=as_cand_next_tour(cand_list,cand_length,city_num,pres_city,choice_info,ant(i));
                    end
                    %将下一访问城市添加到路径和记录表中
                    ant(i).tour(step)=next_city;                  
                    ant(i).visited(next_city)=1; 
                end
            end
        case {4,5}                     %蚁群算法和3-opt蚁群算法路径构建
            for step = 2:city_num
                for i=1:ant_num
                    pres_city = ant(i).tour(step-1);
                    rand_q=rand;
                    if cand_length==0                            
                        if rand_q<=para_q
                            next_city=acs_next_tour(pres_city,city_num,choice_info,ant(i));
                        else
                            next_city=as_next_tour(city_num,choice_info,pres_city,ant(i));
                        end
                    else                                            %使用候选列表
                        if rand_q<=para_q
                            next_city=acs_next_tour(pres_city,city_num,choice_info,ant(i));
                            %next_city=acs_cand_next_tour(pres_city,city_num,choice_info,cand_length,cand_list,ant(i));
                        else
                            next_city=as_cand_next_tour(cand_list,cand_length,city_num,pres_city,choice_info,ant(i));
                        end
                    end
                    %将下一访问城市添加到路径和记录表中
                    ant(i).tour(step)=next_city;                  
                    ant(i).visited(next_city)=1;                   
                    %局部信息素更新并更新信息素与启发式信息联合矩阵
                    pher(pres_city,next_city)=(1-psi)*pher(pres_city,next_city)+psi*tau;
                    pher(next_city,pres_city)=pher(pres_city,next_city);    
                    choice_info(pres_city,next_city)=pher(pres_city,next_city)*(1/dist(pres_city,next_city))^heur_effe_rate;
                    choice_info(next_city,pres_city)=choice_info(pres_city,next_city);
                end
            end
    end
    %引入3-opt局部搜索
    if algorithm_type == 5
        for i=1:ant_num
            ant(i).tour=local_search(city_num,dist,ant(i).tour,local_iter_num);
        end
    end
    %计算每一只蚂蚁的路径长度和当前迭代最优路径
    [iter_best,ant]=tourlength_iterbest(ant_num,city_num,dist,ant);
    %求得迭代至今最优路径
    if order==1
        glob_best.tour=iter_best.tour;
        glob_best.length=iter_best.length;
        glob_best.found=1;
        glob_best.time=toc;
    elseif   iter_best.length<glob_best.length
        glob_best.tour=iter_best.tour;
        glob_best.length=iter_best.length;
        glob_best.found=order;
        glob_best.time=toc;
    end
    %人工免疫和蚂蚁算法融合,加入免疫局部优化
    if algorithm_type == 6
        for i=1:imu_num
            vairiation_tour=immune_operator(city_num,glob_best.tour(1:city_num),pc,uc,ps,us,pi,ui);
            vairiation_tour=[vairiation_tour vairiation_tour(1)];
            vairiation_length=0;
            for j=1:city_num
                vairiation_length=vairiation_length+dist(vairiation_tour(j),vairiation_tour(j+1));
            end
            if  vairiation_length<glob_best.length
                glob_best.tour=vairiation_tour;
                glob_best.length=vairiation_length;
                glob_best.found=order;
                glob_best.time=toc;
            end
        end
    end
    %进行信息素更新,其中蚁群系统只在最优路径上进行信息素更新
    switch algorithm_type
        case 1
            pher=as_pher_update(pher_evap_rate,city_num,ant_num,dist,'ant_quantity',pher,ant);
            choice_info=calc_info(pher_effe_rate,heur_effe_rate,pher,dist);
        case 2
            pher=as_pher_update(pher_evap_rate,city_num,ant_num,dist,'ant_density',pher,ant);
            choice_info=calc_info(pher_effe_rate,heur_effe_rate,pher,dist);
        case {3,6}
            pher=as_pher_update(pher_evap_rate,city_num,ant_num,dist,'ant_cycle',pher,ant);
            choice_info=calc_info(pher_effe_rate,heur_effe_rate,pher,dist);
        case {4,5}
            pher=acs_glob_pher_update(glob_best,pher_evap_rate,city_num,pher); 
            %choice_info=calc_info(pher_effe_rate,heur_effe_rate,pher,dist);
    end
    %在坐标轴上显示路径构建过程
    if detail_pro==1
        axes(handles.axes1)                   %当前迭代最优路径
        for i=1:city_num+1
            m=iter_best.tour(i);
            p(i)=X(m);q(i)=Y(m);
        end
        tu(1)=scatter(X,Y,'.');set(handles.axes1,'box','on');hold on;
        tu(2)=plot(p,q);set(handles.axes1,'box','on');hold off;
        axes(handles.axes2)                   %至今迭代最优路径
        for i=1:city_num+1
            m=glob_best.tour(i);
            p(i)=X(m);q(i)=Y(m);
        end
        tu(3)=scatter(X,Y,'.');set(handles.axes2,'box','on');hold on;
        tu(4)=plot(p,q);set(handles.axes2,'box','on');hold off;
        %保存图形句柄
        set(hObject,'userdata',tu);
    end
    %输出迭代至今程序状态信息
    set(findobj('tag','out_current_num'),'string',num2str(order));
    set(findobj('tag','out_glob_num'),'string',num2str(glob_best.found));
    set(findobj('tag','out_tour_length'),'string',num2str(glob_best.length));    
    set(findobj('tag','out_time1'),'string',num2str(glob_best.time));
    set(findobj('tag','out_time2'),'string',num2str(toc));
end
%将路径输出
if detail_pro==0
    axes(handles.axes2)                   %至今迭代最优路径
    for i=1:city_num+1
        m=glob_best.tour(i);
        p(i)=X(m);q(i)=Y(m);
    end
    tu(3)=scatter(X,Y,'.');set(handles.axes2,'box','on');hold on;
    tu(4)=plot(p,q);set(handles.axes2,'box','on');hold off;
    tu(1)=tu(3);tu(2)=tu(4);
    %保存图形句柄
    set(hObject,'userdata',tu);
end
string_tour=num2str(glob_best.tour(1));
for i=1:city_num
    string_tour=[string_tour '->' num2str(glob_best.tour(i+1))];
end
set(findobj('tag','out_tour'),'string',string_tour);
set(findobj('tag','out_status'),'string','运行完成!');
function clear_input_Callback(hObject, eventdata, handles)
% hObject    handle to clear_input (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% --- Executes on button press in clear_output.
set(findobj('tag','in_ant_num'),'string','');
set(findobj('tag','in_iter_num'),'string','');
set(findobj('tag','in_orig_pher'),'string','');
set(findobj('tag','in_pher_evop'),'string','');
set(findobj('tag','in_anti_num'),'string','');
set(findobj('tag','in_anti_iter_num'),'string','');
set(findobj('tag','in_pher_eff'),'string','');
set(findobj('tag','in_heu_eff'),'string','');
set(findobj('tag','in_cand_len'),'string','');
set(findobj('tag','in_local_update'),'string','');
set(findobj('tag','in_peso_para'),'string','');
set(findobj('tag','in_localsearch_num'),'string','');
set(findobj('tag','in_prob1'),'string','');
set(findobj('tag','in_num1'),'string','');
set(findobj('tag','in_prob2'),'string','');
set(findobj('tag','in_num2'),'string','');
set(findobj('tag','in_prob3'),'string','');
set(findobj('tag','in_num3'),'string','');
function clear_output_Callback(hObject, eventdata, handles)
% hObject    handle to clear_output (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(findobj('tag','out_city_num'),'string','');
set(findobj('tag','out_tour_length'),'string','');
set(findobj('tag','out_time1'),'string','');
set(findobj('tag','out_time2'),'string','');
set(findobj('tag','out_tour'),'string','');
set(findobj('tag','out_status'),'string','');
set(findobj('tag','out_current_num'),'string','');
set(findobj('tag','out_glob_num'),'string','');
tu=get(findobj('tag','run'),'userdata');
delete(tu);
function quit_Callback(hObject, eventdata, handles)
% hObject    handle to quit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
exit_button=questdlg('确定要退出当前程序?','ExitProgram','是','否','否');
switch exit_button
    case '是'
        delete(gcf);
    case '否'
        return
end