⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mfile_isa.m

📁 模拟退火算法在共模电流能量搜索过程中的应用
💻 M
字号:
function [N,Se,Minenergy_final,Pd_final] = mfile_isa(StartT,Annealco,Step1,Step2)
% MFILE_ISA implement the inproved simulated annealing(ISA)
% the number of input variable is three:[N,Se,Varefinal]
% N--the number of annealing process
% Se--the current state which is accepted when every annealing process is endof 
% Minenergy_final--the last minimum energy 
% Pd_final--the last delay time of compensating circuit
% the number of output variable is four:(T,a,Step1,Step2)
% StartT--the initial temperature
% Annealco--the coefficient of annealing functions
% Step1--the annealing number when annealing process is ended  
% Step2--the sampling number when sampling process is ended

%---------initialization process------------------------------------------
 
x0=0;     % initial resolution
x1=x0;    % current resolution
n=160;    % range of resolution only for 'msimmodel' system
T=StartT; % starting temperature
a=Annealco;    % the coefficient of annealing process
T=T/a;

%---------initial state ---------------------------------------------------
% obtain the value of objective funtion according the initial
% resolution,and this is the current resolution and current state.
PD=x1;      % current resolution is the delay time of compensating circuit           
n1=n/2+fix(x1/1.5e-7); % convert to digital variable
sim('msimmodel');
data=load('EMI.mat');
dis1=data.ans;
dis=dis1(2,1:2500); % the number of CM current is 2500
vare1=dis*dis';  % energy of CM noise 
        
%---------simulated annealing parameters-----------------------------------
N=0;  % number of annealing
p=0;  % number of annealing at the condition of optimal resolution is 
      % invariable in annealing process
k=0;  % number of sampling
q=0;  % number of sampling at the condition of current state is 
      % invariable in sampling process
minenergy_s=vare1; % minimum ennergy at the process of annealing
pd_s=x1; % delay time when minimum energy appear at the process of annealing
minenergy_a=vare1  % minimum ennergy at the process of sampling
pd_a=x1; % delay time when minimum energy appear at the process of sampling
i=0;  % sum of sampling

%--------------starting the annealing--------------------------------------

if p<=Step2
    N=N+1;        % number of annealing
    T=a*T;        % annealing function
  
    while q<Step1  % sampling process starting
        r(i)=rand(1);
        x2=x1+1.5e-7*fix(10*(r(i)-0.5));%step change range is 0~10 deta(t)
        n2=n/2+fix(x2/1.5e-7);   % generate new resolution randomly
        
        if n2>=160
            n2=160;
        elseif n2<=1
            n2=1;
        end        % judge whether reaolution is out of range
        
        PD=x2;
        sim('msimmodel');%
        data=load('EMI.mat');
        dis1=data.ans;
        dis=dis1(2,1:num1);
        vare2=dis*dis';  % generate new state
                
        if(vare2-vare1)<0
            n1=n2;
            x1=(n1-n/2)*1.5e-7;
            vare1=vare2;
            q=0;
        elseif exp((vare1-vare2)/T)>0.5
            n1=n2;
            x1=(n1-n/2)*1.5e-7;
            vare1=vare2;
            q=0;
        else 
            q=q+1;
        end % judge whether new state is accepted
        
        if(minenergy_s>vare1)
            minenergy_s=vare1;
            pd_s=x1;
        end % reserve middle optimal resolution at the process of sampling
        
        i=i+1;
        k=k+1;
        ret(k,N)=vare1;% current minenergy for every sampling process 
    end  %end of sampling process
    
    k=0;
    q=0;% reinitialize the sampling process
    se(N,:)=x1;   % last current resolution evergy annealing process 
    
    if minenergy_a>minenergy_s
        minenergy_a=minenergy_s;
        pd_a=pd_s;
        p=0;
    else 
        p=p+1;
    end % reserve middle optimal resolution at the process of annealing
   
end   %end of annealing process
%----------ending the annealing----------------------------------------

%----------output the result------------------------------------------
Minenergy_final=minenergy_a;
Pd_final=pd_a;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -