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

📄 gs_ls_chga.asv

📁 基于灰色系统方法的离散多目标优化设计程序
💻 ASV
📖 第 1 页 / 共 2 页
字号:
clear
%clc
global f1 f0 fe kg kexample nn kdegree kgnumber nn0;
global GreyEntropy;
%global pop cros_ratio muta_ratio emig_ratio emig_pop tmax gk hk n con_rule ux us flag_x dis_date float_date float_date;% 在GREY_OPT 中使用的参数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
%fprintf('\n\t欢迎使用灰熵_灰色混合离散变量-混沌遗传复合优化算法软件GS_LS_ChGA1.0!\n')
%fprintf('\t\t设计:湖南文理学院机械工程系 罗佑新\n')
%fprintf('\t\t资助课题:湖南省科技厅计划项目资助\n')
%fprintf('\t\t版权所有,非法复制传播必究。2007/08于常德\n')
%Gs_LS-ChGA1.0采用动态惩罚因子。
%  适应数学模型:    min f(x)   (x为n维,x=[x离散,x连续])
%              s.t. gi(x)<=0  (i=1,2,……,gk);
%                   hj(x)==0  (j=1,2,……,hk). 

fprintf('\n\t程序已经开始运行!\n\n');
%pause
ttime0=cputime;  
%%%%%%%%%%%%%initiation%%%%%%%%%%%%%%%%%%%%%%%%%%%
nn=1; %赋值nn=1使f0初始化。
kg=1;% 用关联度计算,而kg=3 用f(x)单目标计算。否则另用程序opt_fminimax即kg=2,用fminimax计算
kdegree=2;
% kdegree=1 % absolute degree of grey incidence%%%%%%%%%%%%%%%%%
% kdegree=2 % Deng Type degree of grey incidencer%(有待改进)
% kdegree=3 % relative degree of grey incidenc(与其它例题相比例2最快)
% kdegree=4 % compositive  degree of grey incidenc
% kdegree=5 % improved relative degree of grey incidenc
% kdegree=6 %improved absolue degree of grey incidenc
% kdegree=7 % improved  compositive  degree of grey incidenc
% kdegree=8 %B type degree of grey incidenc
% kdegree=9 %C type degree of grey incidenc(效果不佳)
kexample=7;%kexample=1;第一个例题,其余类推;
GreyEntropy=2;%GreyEntropy=1,使用灰熵计算;GreyEntropy=0;不使用灰熵计算;GreyEntropy=2 优度计算。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     %+++++++++++++++++算法控制参数初始化++++++++++++++++++++%
pop=100;           % 请确定群体规模pop值,建议取>=50
cros_ratio=0.7;    % 请确定交叉概率,一般取0.25~0.8
muta_ratio=0.08;   % 请确定变异概率,一般取0.1~0.02
emig_ratio=0.1;      % 请确定移民比例,群体规模取100~50时建议取取0.05~0.3;不采用混沌移民时取0。
emig_pop=500;       % 请确定移民总规模,建议取>=500,不采用混沌移民时取0。
tmax=1000;          % 请确定最大遗传代数,建议取>=500
con_rule=1;        % 算法收敛准则选则标志,取1时:进化到既定最大代数tmax时收敛,建议取1
                   %                       取0时:100代内最优染色体保持不变时收敛 。
nn0=floor(tmax/3); % 
nn0=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%n=5;         % 请确定设计变量维数
%gk=6;        % 请确定不等式约束数,无不等式约束问题时取0
%hk=0;        % 请确定等式约束数,无等式约束问题时取0
%ux=[78,33,27,27,27];  % 请确定设计变量取值范围下限,用逗号分隔
%us=[102,45,45,45,45];    % 请确定设计变量取值范围上限,用逗号分隔
%-------混合离散变量参数初始化说明:
%flag_x=[0,0,0,0,0]; % 变量类型标识数组,依次取:连续变量取0,整型变量取1,不等距离散变量取2。
%dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
                      % dis_date为不等距离散变量取值范围矩阵;列数为不等距离散变量取值的最大个数,
                      % 小于最大个数的后面补0;行数为不等距离散变量个数。无不等距离散变量时取空。
%float_date=[10,10,10,10,10];     % 连续变量精确到小数位数组,按连续变量的先后顺序依次确定。无连续变量时取空。

if kexample==1, %%%%%%%%%%%%%%%%%% the first example(good)%%%%%%%%%%%%%%%%%%%%%%%%
    n=5;gk=6;hk=0;
    ux=[78,33,27,27,27]; us=[102,45,45,45,45];
    flag_x=[0,0,0,0,0];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
    float_date=[2,2,2,2,2]; %各连续变量均取2位小数。
 elseif kexample==2    %%%%%%%%%%%%%%%%%%%% the second example (not find)%%%%%%%%%%%%%%%%
   n=6;gk=16;hk=0;
   ux=[10,17,0.2,17,10,13]; us=[20,130,0.8,30,15,20];
   flag_x=[1,1,2,0,1,1];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
    float_date=[2,2,2,2,2,2]; %各连续变量均取2位小数。
 elseif kexample==3 
    n=7;gk=10;hk=0;
    ux=[2.6,0.3,17,7.3,7.3,2.9,5]; us=[3.6,1.0,28,8.3,8.3,3.9,5.5];
    flag_x=[0,0,0,0,0,0,0];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
    float_date=[2,2,2,2,2,2,2]; %各连续变量均取2位小数。
elseif kexample==4
    n=3;gk=6;hk=0;
    ux=[3,18,4]; us=[7,100,10];
    flag_x=[0,1,1];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
    float_date=[2,2,2]; %各连续变量均取2位小数。
elseif kexample==5
    n=4;gk=2;hk=0;
    ux=[10,10,0.9,0.9]; us=[80,50,5,5];
    flag_x=[0,0,0,0];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
    float_date=[2,2,2,2]; %各连续变量均取2位小数。
elseif kexample==6
    n=5;gk=14;hk=0;
    ux=[0.6,0.6,0.6,0.6,0.6]; us=[2.4,2.4,2.4,2.4,2.4];
    flag_x=[0,0,0,0,0];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,5,6,8,10,12,16,20,25,32,40,50];
    float_date=[2,2,2,2,2];
else %kexample==7
   n=3;gk=10;hk=0;
    ux=[2.5,30,3]; us=[9.5,90,30];
    flag_x=[2,1,2];
    dis_date=[0.2,0.25,0.3,0.4,0.5,0.6,0.8,1,1.25,1.5,2,2.5,3,4,4.5,5,5.5,6,6.5,7,9,10,11,12,14,16,20,25,32,40,50;
              2,3,4,5,6,7,8,8.5,9,9.5,10,11,12,13,13.5,14,14.5,15,16,17,18,19,20,22,25,28,30,32,40,45,50];
    float_date=[2,2,2]; 
 end
%%%%%%%%
  %+++++++++++++++++优化问题参考最优解++++++++++++++++++++%  
    fristx=zeros(1,n);%初始化
    %如无参考最优解,置fristx为空即:fristx=[].
   %fristx=[799.6127,350.3652,5.0210,5.8796];
   fristx=[];
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   %%%%%%%%%%%%%%%%%%%%%%%end initiation%%%%%%%%%%%%%%%%%%%%%%
 % emigrant_or_not 确定是否采用混沌移民的标志,采用时取1,否则取0
  if emig_ratio+emig_pop==0
    emigrant_or_not=0;
  else
    emigrant_or_not=1;
  end
  %res_flg确定有无约束条件的标记,约束优化问题取1,无约束取0
  if gk+hk==0
    res_flg=0;
  else
    res_flg=1;
  end
     %+++++++++++++++++随机生成初始群体xpop++++++++++++++++++%
xpop=zeros(pop,n);
for i=1:pop
    for  j=1:n
        fun=unifrnd(0,1);
        xpop(i,j)=ux(j)+(us(j)-ux(j))*fun;
    end
    xpop(i,:)=discrete(xpop(i,:),n,flag_x,dis_date,float_date); %离散化处理
end
     %++++计算初始群体中目标函数或惩罚函数的最大值cmax+++++++%
if res_flg>0
    for i=1:pop
        xfen(i)=fenelize(xpop(i,:),gk,hk,1,tmax);
    end
    cmax=max(xfen);
else
    for i=1:pop
        fyy0(i)=objfunction(xpop(i,:));
    end
    cmax=max(fyy0);
end
      %++++++++++选出初始群体的最优染色体fristx+++++++++++++%
change=zeros(1,n);
if res_flg
    for i=1:pop-1  %冒泡法把染色体按排惩罚函数升序
        for j=1:(pop-i)
            if xfen(j)>xfen(j+1)
                change(1,:)=xpop(j,:);
                xpop(j,:)=xpop(j+1,:);
                xpop(j+1,:)=change(1,:);
            end
        end
    end
    %if fristx==[]
       fristx(1,:)=xpop(1,:); % 取惩罚函数值最小者为最优染色体
       %else
      % xpop(pop,:)=fristx;
      %end
else
    for i=1:pop-1   %冒泡法把染色体按目标函数排序
        for j=1:(pop-i)
            if fyy0(j)>fyy0(j+1)
                change(1,:)=xpop(j,:);
                xpop(j,:)=xpop(j+1,:);
                xpop(j+1,:)=change(1,:);
            end
        end
    end
    if fristx==[]
           fristx(1,:)=xpop(1,:);  % 取目标函数值最小者为最优染色体
    else
          xpop(pop,:)=fristx(1,:);
    end
end
            %+++++++++++++++开始ChGA算法主循环++++++++++++++++++++++%
        selecx=zeros(pop,n);
        crosx=zeros(pop,n);
        mutax=zeros(pop,n);
        emigx=zeros(pop,n);
        fcmax=0.0;
        fxk=zeros(1,n);
        xk=zeros(1,n);   %混沌变量数组初始化 
        objoptmal=zeros(1,tmax);   %每代最优目标函数值数组
        con_flag=0;  %收敛标志
      %  h = waitbar(0,'程序正在为您寻优...');
  for tpop=1:tmax 
      % waitbar(tpop/tmax);
      selecx=selection(xpop,pop,res_flg,gk,hk,n,cmax,tpop,tmax);                       %选择
      crosx=crossover(selecx,cros_ratio,pop,n,res_flg,gk,hk,cmax,tpop,tmax,flag_x,dis_date,float_date);           %交叉
      mutax=mutation(crosx,muta_ratio,tpop,n,pop,us,ux,tmax,res_flg,gk,hk,cmax,emigrant_or_not,flag_x,dis_date,float_date);       %变异
      if emigrant_or_not>0 ; %判断是否采用混沌移民
          [emigx,fxk]=emigrant(us,ux,xk,emig_pop,emig_ratio,n,pop,res_flg,gk,hk,cmax,tpop,tmax,flag_x,dis_date,float_date);%移民
           xk=fxk;   %混沌变量数组更新
      else
          emig_ratio=0.0;
          emigx=[];
      end
      xpop=combination(mutax,emigx,fristx,pop,res_flg,gk,hk,cmax,emig_ratio,n,tpop,tmax);   %重组
      %pause
      [fristx,fcmax,objopt,xpop]=frist(xpop,tpop,res_flg,pop,gk,hk,cmax,n,tmax);   %对xpop评价并输出3个参数

⌨️ 快捷键说明

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