gusucode.com > Toolbox_all_algorithms > Toolbox_all_algorithms/Optimization_toolbox.m
function varargout = Optimization_toolbox(varargin) %___________________________________________________________________% % Optimization toolbox version 1.0 % % % % Developed in MATLAB R2011b(7.13) % % % % Author and programmer: Seyedali Mirjalili % % % % e-Mail: ali.mirjalili@gmail.com % % seyedali.mirjalili@griffithuni.edu.au % %___________________________________________________________________% % % % You can simply define your cost function in a seperate file. % The default name of the objective function is CostFunction. % If you have a look at the CostFunction.m file, you may notice % that the cost function gets the variables in a vector ([x1 x2 ... xn]) and % returns the objective value. You can either write you objective function % in this file or create a new file and pass its name to the toolbox. % Remember to follow the same structure for input and output if you decided % to go for the second option. % % The lower bounds and upper bounds of variables should also be witten as % lb1,lb2,...,lbn and ub1,ub2,...,ubn % % If all of the variables have equal lower and/or upper bounds you can just % define lb and ub as two single number numbers: lb, ub % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Optimization_toolbox_OpeningFcn, ... 'gui_OutputFcn', @Optimization_toolbox_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 % End initialization code - DO NOT EDIT addpath('./GWO') addpath('./ALO') addpath('./MVO') addpath('./DA') addpath('./MFO') addpath('./SCA') addpath('./WOA') % --- Executes just before Optimization_toolbox is made visible. function Optimization_toolbox_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 Optimization_toolbox (see VARARGIN) % Choose default command line output for Optimization_toolbox handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes Optimization_toolbox wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Optimization_toolbox_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; labelStr = '<html><center><a href="">alimirjalili.com'; cbStr = 'web(''http://www.alimirjalili.com'');'; hButton = uicontrol('string',labelStr,'pos',[150,20,100,35],'callback',cbStr); labelStr = '<html><center><a href="">Find the papers'; cbStr = 'web(''http://alimirjalili.com/Publication.html'');'; hButton = uicontrol('string',labelStr,'pos',[50,20,100,35],'callback',cbStr); function WolfNo_Callback(hObject, eventdata, handles) % hObject handle to WolfNo (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 WolfNo as text % str2double(get(hObject,'String')) returns contents of WolfNo as a double % --- Executes during object creation, after setting all properties. function WolfNo_CreateFcn(hObject, eventdata, handles) % hObject handle to WolfNo (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 IterNo_Callback(hObject, eventdata, handles) % hObject handle to IterNo (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 IterNo as text % str2double(get(hObject,'String')) returns contents of IterNo as a double % --- Executes during object creation, after setting all properties. function IterNo_CreateFcn(hObject, eventdata, handles) % hObject handle to IterNo (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 LowerBound_Callback(hObject, eventdata, handles) % hObject handle to LowerBound (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 LowerBound as text % str2double(get(hObject,'String')) returns contents of LowerBound as a double % --- Executes during object creation, after setting all properties. function LowerBound_CreateFcn(hObject, eventdata, handles) % hObject handle to LowerBound (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 UpperBound_Callback(hObject, eventdata, handles) % hObject handle to UpperBound (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 UpperBound as text % str2double(get(hObject,'String')) returns contents of UpperBound as a double % --- Executes during object creation, after setting all properties. function UpperBound_CreateFcn(hObject, eventdata, handles) % hObject handle to UpperBound (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 Dim_Callback(hObject, eventdata, handles) % hObject handle to Dim (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 Dim as text % str2double(get(hObject,'String')) returns contents of Dim as a double % --- Executes during object creation, after setting all properties. function Dim_CreateFcn(hObject, eventdata, handles) % hObject handle to Dim (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 CostFunction_Callback(hObject, eventdata, handles) % hObject handle to CostFunction (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 CostFunction as text % str2double(get(hObject,'String')) returns contents of CostFunction as a double % --- Executes during object creation, after setting all properties. function CostFunction_CreateFcn(hObject, eventdata, handles) % hObject handle to CostFunction (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 edit7_Callback(hObject, eventdata, handles) % hObject handle to edit7 (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 edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) SearchAgents_no=str2num(get(handles.WolfNo,'String')); Max_iteration=str2num(get(handles.IterNo,'String')); lb=str2num(get(handles.LowerBound,'String')); ub=str2num(get(handles.UpperBound,'String')); dim=str2num(get(handles.Dim,'String')); fobj=str2func(get(handles.CostFunction,'String')); %cla(handles.axes2) reset(handles.axes2) box on index_selected = get(handles.listbox1,'Value'); if index_selected==1 [Best_score,Best_pos,cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); [Best_score,Best_pos,cg_curve]=ALO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); [Best_score,Best_pos,cg_curve]=MVO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); [Best_score,Best_pos,cg_curve]=MFO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); [Best_score,Best_pos,cg_curve]=SCA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); [Best_score,Best_pos,cg_curve]=WOA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==2 [Best_score,Best_pos,cg_curve]=GWO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==3 [Best_score,Best_pos,cg_curve]=ALO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==4 [Best_score,Best_pos,cg_curve]=MVO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==5 [Best_score,Best_pos,cg_curve]=DA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==6 [Best_score,Best_pos,cg_curve]=MFO(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==7 [Best_score,Best_pos,cg_curve]=SCA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); elseif index_selected==8 [Best_score,Best_pos,cg_curve]=WOA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj,handles); end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(handles.figure1) % --- Executes on button press in checkbox1. function checkbox1_Callback(hObject, eventdata, handles) % hObject handle to checkbox1 (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 checkbox1 function edit8_Callback(hObject, eventdata, handles) % hObject handle to edit8 (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 edit8 as text % str2double(get(hObject,'String')) returns contents of edit8 as a double % --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles) % hObject handle to edit8 (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 pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function edit9_Callback(hObject, eventdata, handles) % hObject handle to edit9 (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 edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double % --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (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 edit10_Callback(hObject, eventdata, handles) % hObject handle to edit10 (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 edit10 as text % str2double(get(hObject,'String')) returns contents of edit10 as a double % --- Executes during object creation, after setting all properties. function edit10_CreateFcn(hObject, eventdata, handles) % hObject handle to edit10 (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 selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox 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 pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) cla(handles.axes2) reset(handles.axes2) cla(handles.ax2,'reset'); box on