function varargout = spinwithGA(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @spinwithGA_OpeningFcn, ...
'gui_OutputFcn', @spinwithGA_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 spinwithGA_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
function varargout = spinwithGA_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
n=str2double(get(handles.edit1,'String'))
N=n*n;
pool=zeros(n,N);
Y=zeros(1,2*n);%ظرف نگهداري انرژي ها%%%%%%%%%%%%%
K=str2double(get(handles.edit2,'String'))
H=str2double(get(handles.edit3,'String'))
b=1;%شمارنده حلقه%%%%%%%%%%%%%%%%%
tempmin=0;
ARmin(b)=0;%آرايه شامل انرژي هاي مينيمم%%%%%%%%%%%%%
br=1;%شمارنده براي خروج از حلقه%%%%%%%%%%%%
mr=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[pool]=createpool(n,N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while(1)
if(tempmin==ARmin(b))
br=br+1;
mr=mr+1;
else
br=0;
end
tempmin=ARmin(b);
b=b+1;
%%%%%%%%%%%%%%%%%کراس%%%%%%%%%%%%%%%%%%
[pool]=crossover1(n,N,pool);
%%%%%%%%%%%%%%%%%%%%انجام محاسبات%%%%%%%%%%%%%%%
for i=1:n+n
[Y(i)]=gacompute1(n,H,K,pool(i,1:N));
end
%%%%%%%%%%%%%%%%%پيدا کردن n مينيمم و حذف بقيه کروموزم ها%%%%%%%%%%%%%%%
[ARmin(b),pool]=findmins(n,N,Y,pool);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if br==str2double(get(handles.edit5,'String'))
break;
end
end
axes(handles.axes1)
plot(ARmin);
grid on;
min=ARmin(1);
for i=1:b
if ARmin(i)<min
min=ARmin(i);
end
end
min
% set(handles.text11,'String','Down')
set(handles.text9,'String',min)
axes(handles.axes1)
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
function edit4_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit5_Callback(hObject, eventdata, handles)
function edit5_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end