📄 sga_main.asv
字号:
function varargout = SGA_main(varargin)
%global fitFunc bounds;
% /*==================================================================================================
% Simple Genetic Algorithm Program for Matlab 7.x
% ====================================================================================================
%File description:
% SGA_main M-file for SGA_main.fig
% SGA_main, by itself, creates a new SGA_main or raises the existing
% singleton*.
%
% H = SGA_main returns the handle to a new SGA_main or the handle to
% the existing singleton*.
%Input:
% options(1)-- fitFunc is fitness function
% options(2)-- popSize is the size of population
% options(1)-- lChrom is the length of chromosome
% options(1)-- pCross is crossover probolitity
% options(1)-- pMutation is mutation probolitity
% options(1)-- maxGen is the max generation of population
% options(1)-- maxRuns is rhe max running times
%Output:
% maxfitness_selection-- is max fitness value from selection operator
% minfitness_selection-- is min fitness value from selection operator
% meanfitness_selection-- is mean fitness value from selection operator
% the_best_chrom-- is the best chrom from selection operator
%
% Copyright By Jiang Quansheng,2006-3-7.
% Last Modified by GUIDE v2.5 20-Mar-2006 21:24:20
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SGA_main_OpeningFcn, ...
'gui_OutputFcn', @SGA_main_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
%set(gco,'menubar','figure');
% --- Executes just before SGA_main is made visible.
function SGA_main_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 SGA_main (see VARARGIN)
% Choose default command line output for SGA_main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SGA_main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SGA_main_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;
function func_Callback(hObject, eventdata, handles)
% hObject handle to func (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 func as text
% str2double(get(hObject,'String')) returns contents of func as a double
% --- Executes during object creation, after setting all properties.
function func_CreateFcn(hObject, eventdata, handles)
% hObject handle to func (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function lchrom_Callback(hObject, eventdata, handles)
% hObject handle to lchrom (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%lChrom=str2Num(get(handles.lchrom,'string'));
% Hints: get(hObject,'String') returns contents of lchrom as text
% str2double(get(hObject,'String')) returns contents of lchrom as a double
% --- Executes during object creation, after setting all properties.
function lchrom_CreateFcn(hObject, eventdata, handles)
% hObject handle to lchrom (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function pmutation_Callback(hObject, eventdata, handles)
% hObject handle to pmutation (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% pMutation=str2Num(get(handles.pmutation,'string'));
% Hints: get(hObject,'String') returns contents of pmutation as text
% str2double(get(hObject,'String')) returns contents of pmutation as a double
% --- Executes during object creation, after setting all properties.
function pmutation_CreateFcn(hObject, eventdata, handles)
% hObject handle to pmutation (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function maxruns_Callback(hObject, eventdata, handles)
% hObject handle to maxruns (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% maxRuns=str2Num(get(handles.maxruns,'string'));
% Hints: get(hObject,'String') returns contents of maxruns as text
% str2double(get(hObject,'String')) returns contents of maxruns as a double
% --- Executes during object creation, after setting all properties.
function maxruns_CreateFcn(hObject, eventdata, handles)
% hObject handle to maxruns (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function popsize_Callback(hObject, eventdata, handles)
% hObject handle to popsize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% val = str2int(get(gcbo,'Value'));
% Hints: get(hObject,'String') returns contents of popsize as text
% str2double(get(hObject,'String')) returns contents of popsize as a double
% popSize=str2Num(get(handles.popsize,'string'));
% --- Executes during object creation, after setting all properties.
function popsize_CreateFcn(hObject, eventdata, handles)
% hObject handle to popsize (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function pcross_Callback(hObject, eventdata, handles)
% hObject handle to pcross (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% pCross=str2Num(get(handles.pcross,'string'));
% Hints: get(hObject,'String') returns contents of pcross as text
% str2double(get(hObject,'String')) returns contents of pcross as a double
% --- Executes during object creation, after setting all properties.
function pcross_CreateFcn(hObject, eventdata, handles)
% hObject handle to pcross (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -