📄 hea.m
字号:
if (isempty(n)) set(hObject,'String','10')endguidata(hObject, handles); % --- Executes during object creation, after setting all properties.function edit7_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 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)name=str2num(get(handles.edit1,'String'));Size=str2num(get(handles.edit2,'String')); %setup population size i.e. 50 or 100if isempty(Size) Size=100;endG=str2num(get(handles.edit3,'String')); %setup generation i.e. 100,200,...,1000if isempty(G) G=100;endCodel=str2num(get(handles.edit4,'String')); %setup code length i.e. 20,32if isempty(Codel) Codel=12;endumax=str2num(get(handles.edit5,'String')); %setup up bound i.e. 1000000if isempty(umax) umax=10^6;endumin=str2num(get(handles.edit6,'String')); %setup low bound i.e. 1000000if isempty(umin) umin=-10^6;endn=str2num(get(handles.edit7,'String')); %setup numbers of variables i.e. if your equation with 2 variables then%input with 2.mm=cell(1,n);mmb=cell(1,n);Q=cell(1,5); % setup 5 closed cell for store Q{1,1};Q{1,2};Q{1,3};Q{1,4};Q{1,5} five matrix, every rows in matrix %standard as indiviudal solutions of all variables. Q{1,1}=round(4*rand(Size,n*Codel));% Generate a random matrix with numbers 1's,2's,3's,4's,5's. EX=round(4*rand(Size,n*Codel)); for k=1:1:G % start to looping Generations time(k)=k; % counting looping times % Generate a random matrix have same size of Q{1,1}, and adding it at begining %of program looping. for i=1:1:Size % from matrix Q{1,1} to generate Q{1,2},Q{1,3},Q{1,4},Q{1,5} for j=1:1:n*Codel if Q{1,1}(i,j)==0 Q{1,2}(i,j)=1;Q{1,3}(i,j)=2;Q{1,4}(i,j)=3;Q{1,5}(i,j)=4; elseif Q{1,1}(i,j)==1 Q{1,2}(i,j)=2;Q{1,3}(i,j)=3;Q{1,4}(i,j)=4;Q{1,5}(i,j)=0; elseif Q{1,1}(i,j)==2 Q{1,2}(i,j)=3;Q{1,3}(i,j)=4;Q{1,4}(i,j)=0;Q{1,5}(i,j)=1; elseif Q{1,1}(i,j)==3 Q{1,2}(i,j)=4;Q{1,3}(i,j)=0;Q{1,4}(i,j)=1;Q{1,5}(i,j)=2; elseif Q{1,1}(i,j)==4 Q{1,2}(i,j)=0;Q{1,3}(i,j)=1;Q{1,4}(i,j)=2;Q{1,5}(i,j)=3; end if EX(i,j)==0 Q{1,6}(i,j)=1;Q{1,7}(i,j)=2;Q{1,8}(i,j)=3;Q{1,9}(i,j)=4; elseif EX(i,j)==1 Q{1,6}(i,j)=2;Q{1,7}(i,j)=3;Q{1,8}(i,j)=4;Q{1,9}(i,j)=0; elseif EX(i,j)==2 Q{1,6}(i,j)=3;Q{1,7}(i,j)=4;Q{1,8}(i,j)=0;Q{1,9}(i,j)=1; elseif EX(i,j)==3 Q{1,6}(i,j)=4;Q{1,7}(i,j)=0;Q{1,8}(i,j)=1;Q{1,9}(i,j)=2; elseif EX(i,j)==4 Q{1,6}(i,j)=0;Q{1,7}(i,j)=1;Q{1,8}(i,j)=2;Q{1,9}(i,j)=3; end end end E=[Q{1,1};Q{1,2};Q{1,3};Q{1,4};Q{1,5};Q{1,6};Q{1,7};Q{1,8};Q{1,9};EX];% Let E equal to combination of 6 Matrix. for s=1:1:10*Size % Evaluate the objective function value and ranking from best individual to worst one. m=E(s,:); for v=1:1:n y(v)=0; mm{1,v}=m(Codel*(v-1)+1:1:v*Codel); for i=1:1:Codel y(v)=y(v)+mm{1,v}(i)*5^(Codel-i); end x(v)=(umax-umin)*y(v)/(5^Codel)+umin; r(1,v)=x(v); end F(s)=name(r); end Ji=1./F;% setp up inverse measure for plot image using BestJ(k)=max(Ji); fi=F; [Oderfi,Indexfi]=sort(fi); [Oderfi1,Indexfi1]=sort(fi,'descend'); Bestfitness=Oderfi(1); for i=1:1:Size TempE(i,:)=E(Indexfi(i),:); TempE1(i,:)=E(Indexfi1(i),:); end BestS=TempE(1,:); bfi(k)=Bestfitness; BS(k,:)=BestS; for i=1:1:Size-4 for j=1:1:n*Codel if TempE(i,j)==TempE(i+1,j) && TempE(i,j)~=4 TempE(i+1,j)=TempE(i+1,j)+1; elseif TempE(i,j)==TempE(i+1,j) && TempE(i,j)==4 TempE(i+1,j)=0; elseif TempE(i,j)==TempE(i+2,j) && TempE(i,j)~=4 TempE(i+2,j)=TempE(i+2,j)+1; elseif TempE(i,j)==TempE(i+2,j) && TempE(i,j)==4 TempE(i+2,j)=0; elseif TempE(i,j)==TempE(i+3,j) && TempE(i,j)~=4 TempE(i+3,j)=TempE(i+3,j)+1; elseif TempE(i,j)==TempE(i+3,j) && TempE(i,j)==4 TempE(i+3,j)=0; elseif TempE(i,j)==TempE(i+4,j) && TempE(i,j)~=4 TempE(i+4,j)=TempE(i+4,j)+1; elseif TempE(i,j)==TempE(i+4,j) && TempE(i,j)==4 TempE(i+4,j)=0; end if TempE1(i,j)==TempE1(i+1,j) && TempE1(i,j)~=4 TempE1(i+1,j)=TempE1(i+1,j)+1; elseif TempE1(i,j)==TempE1(i+1,j) && TempE1(i,j)==4 TempE1(i+1,j)=0; elseif TempE1(i,j)==TempE1(i+2,j) && TempE1(i,j)~=4 TempE1(i+2,j)=TempE1(i+2,j)+1; elseif TempE1(i,j)==TempE1(i+2,j) && TempE1(i,j)==4 TempE1(i+1,j)=0; elseif TempE1(i,j)==TempE1(i+3,j) && TempE1(i,j)~=4 TempE1(i+3,j)=TempE1(i+3,j)+1; elseif TempE1(i,j)==TempE1(i+3,j) && TempE1(i,j)==4 TempE1(i+3,j)=0; elseif TempE1(i,j)==TempE1(i+4,j) && TempE1(i,j)~=4 TempE1(i+4,j)=TempE1(i+4,j)+1; elseif TempE1(i,j)==TempE1(i+4,j) && TempE1(i,j)==4 TempE1(i+4,j)=0; end end end for i=1:1:Size-1 for j=1:1:n*Codel if TempE1(1,j)==TempE(i+1,j) TempE(i+1,j)=TempE(1,j); end if TempE(1,j)==TempE1(i+1,j) TempE1(i+1,j)=TempE1(1,j); end end end Q{1,1}=TempE; EX=TempE1; for v=1:1:n yb(v)=0; mmb{1,v}=BestS(Codel*(v-1)+1:1:v*Codel); for i=1:1:Codel yb(v)=yb(v)+mmb{1,v}(i)*5^(Codel-i); end variables(v)=(umax-umin)*yb(v)/(5^Codel)+umin; end figure(1); subplot(2,1,1); set(gcf,'CurrentAxes',gca) plot(time,BestJ); xlabel('Times');ylabel('BestJ'); subplot(2,1,2); set(gcf,'CurrentAxes',gca) plot(time,bfi) xlabel('Times');ylabel('Best optimization value');end% Bestfitness = num2str(Bestfitness);variables=num2str(variables);set(handles.edit8,'String',Bestfitness);set(handles.edit9,'String',variables);guidata(hObject, handles); function edit8_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 edit8_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 edit9_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 edit9_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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -