function varargout = yichuan1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @yichuan1_OpeningFcn, ...
'gui_OutputFcn', @yichuan1_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
% --- Executes just before yichuan1 is made visible.
function yichuan1_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 yichuan1 (see VARARGIN)
% Choose default command line output for yichuan1
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes yichuan1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = yichuan1_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global d;
d(1)=str2double(get(handles.edit1,'String'));
d(2)=str2double(get(handles.edit2,'String'));
d(3)=str2double(get(handles.edit3,'String'));
d(4)=str2double(get(handles.edit4,'String'));
d(5)=str2double(get(handles.edit5,'String'));
d(6)=str2double(get(handles.edit6,'String'));
d(7)=str2double(get(handles.edit7,'String'));
d(8)=str2double(get(handles.edit8,'String'));
d(9)=str2double(get(handles.edit9,'String'));
d(10)=str2double(get(handles.edit10,'String'));
d=sort(d);
axes(handles.axes1)
for i=1:11
for j=1:11
gx((i-1)*11+j)=j-1;
gy((i-1)*11+j)=11-i;
end
end
for i=1:10
for j=1:10
gbh((i-1)*10+j,:)=[(i-1)*11+j,(i-1)*11+j+1,i*11+j+1,i*11+j];
end
end
hold on
for i=1:length(d)
fill(gx(gbh(d(i)+1,:)),gy(gbh(d(i)+1,:)),'b')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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
function edit6_Callback(hObject, eventdata, handles)
function edit6_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit7_Callback(hObject, eventdata, handles)
function edit7_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit8_Callback(hObject, eventdata, handles)
function edit8_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit9_Callback(hObject, eventdata, handles)
function edit9_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit10_Callback(hObject, eventdata, handles)
function edit10_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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)
global d;
G=2000;
popsize=50;
poplength=18;
pc=1;
pm=1;
pop=yichuaninitialize(popsize,poplength);
for i=1:G
pop=yichuancrossover(pop,poplength,pc);
pop=yichuanmuate(pop,pm);
pop=yichuanroulette(pop,popsize,poplength);
end
[a,b]=sort(pop(:,poplength+1));
bestroad=pop(b(popsize),:);
t=0;
for i=1:poplength
if(bestroad(i)~=0)
t=t+1;
end
end
disp(bestroad(1:t))
disp(t)
set(handles.edit11,'String',bestroad(1:t));
set(handles.edit12,'String',t);
axes(handles.axes2);
cla reset
axes(handles.axes2)
for i=1:11
for j=1:11
gx((i-1)*11+j)=j-1;
gy((i-1)*11+j)=11-i;
end
end
for i=1:10
for j=1:10
gbh((i-1)*10+j,:)=[(i-1)*11+j,(i-1)*11+j+1,i*11+j+1,i*11+j];
end
end
hold on
for i=1:length(d)
fill(gx(gbh(d(i)+1,:)),gy(gbh(d(i)+1,:)),'b')
end
for i=1:100
plot(gx(gbh(i,1:2)),gy(gbh(i,1:2)))
plot(gx(gbh(i,2:3)),gy(gbh(i,2:3)))
plot(gx(gbh(i,3:4)),gy(gbh(i,3:4)))
plot(gx(gbh(i,4:1)),gy(gbh(i,4:1)))
text(sum(gx(gbh(i,:)))/4,sum(gy(gbh(i,:)))/4,...
num2str(i-1),'Color','White','Fontsize',10)%序号尺寸
end
for i=1:t
ljx(i)=sum(gx(gbh((bestroad(i)+1),:)))/4;
ljy(i)=sum(gy(gbh((bestroad(i)+1),:)))/4;
end
ljx=[0.5 ljx];
ljy=[9.5 ljy];
% plot(ljx,ljy,'linewidth',3)
for i=1:length(ljx)-1
plot(ljx(i:i+1),ljy(i:i+1),'linewidth',3)%线宽
pause(0.2)
end
function edit11_Callback(hObject, eventdata, handles)
function edit11_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit12_Callback(hObject, eventdata, handles)
function edit12_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
评论3