ddv.m
来自「一些用matlab编写的经典遗传算法算例。可以用于解决许多优化问题」· M 代码 · 共 54 行
M
54 行
function d = ddv(varargin)
% DDV - Constructor for the class ddv, a sub class of the gen class.
% The constructor can be called in two ways:
%
% ddv('name',value_1,value_2,etc..) where 'name' is a string identifying
% the variable and value_1, value_2 etc. are the possible values that
% the discrete variable can assume.
%
% ddv('name',[value_1 value_2 etc..]) here 'name' is as before but
% the possible values are suppplied in a vector.
%
% There is no need for supplpiyng the coding bits since this is
% determined by the possible values that the variable can assume.
%
% Calling the constructor without any argument creates an "empty" variable.
%
% See also CDV,CHROM,UI_GEN,UI_CHROM
switch nargin
case 0
pointer=0;
d=struct('ddv_val',[]);
d = class(d,'ddv',gen);
case 1
if isa(varargin{1},'ddv')
d=varargin{1};
else
error('wrong argument')
end
case 2
if ~isa(varargin{1},'char')
error('You must specify the the id as the first argument')
else
for k=1:length(varargin{2})
ddv_val(k)=varargin{2}(k);
end
d=struct('ddv_val',ddv_val);
d=class(d,'ddv',gen(varargin{1},nextpow2(ddv_val)));
end
otherwise
if ~isa(varargin{1},'char')
error('You must specify the the id as the first argument')
else
for k=2:nargin
ddv_val(k-1)=varargin{k};
end
d=struct('ddv_val',ddv_val);
d=class(d,'ddv',gen(varargin{1},nextpow2(ddv_val)));
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?