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

📄 set.m

📁 一些用matlab编写的经典遗传算法算例。可以用于解决许多优化问题
💻 M
字号:
function c = set(chr,varargin)
% SET - Acces to the fields in the chromosome class
% Any number of valid properties can be set with one function
% call.  The syntax for calling the function is:
% set(chromosome,'property',value,'property',value,etc..).  The
% properties are:
%
% 'name' - the name of the variable
% 'fitness' - the value of the variable
% 'cdvs' - number of coding bits
% 'ddvs' - a vector containing the binary "dna"
%
% to list the valid properties for a certain object use set(chromosome)

tst=nargin;
if tst==1
  fprintf('Valid properties:\nname \nfitness \ncdvs\nddvs\nid\n')
  else
    if ~or(or(tst==3,tst==5),tst==7)
      error('wrong number of arguments')
  else
    for k=1:2:tst-1
      switch varargin{k}
       case 'name'
	chr.name=varargin{k+1};
       case 'fitness'
	chr.fitness=varargin{k+1};
       case 'cdvs'
	chr.cdvs=varargin{k+1};
       case 'ddvs'
	chr.ddvs=varargin{k+1};
       case 'id'
	chr.id=varargin{k+1};
       otherwise
	error('Unknown method')
      end
    end
    c=chr;
    end
end






⌨️ 快捷键说明

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