chrom.m
来自「一些用matlab编写的经典遗传算法算例。可以用于解决许多优化问题」· M 代码 · 共 49 行
M
49 行
function c = chrom(varargin)
% CHROM - Constructor for the chromosome class
% This is the corner stone data type that the genetic tools operate on.
% It has four fields that contains all necsessary data.
% ____________________
% | -------- -------- |
% || NAME ||FITNESS ||
% | -------- -------- |
% | -------- -------- |
% || CDVS || DDVS ||
% | -------- -------- |
% |____________________|
%
% A chromosome is created by calling the constructor.
% c=chrom('name',cdvs,ddvs) or c=chrom
% In the first case a chromosome is created with the properties
% supplied in the function call. cdvs and ddvs are the continuous-
% and discrete design variables repsectively. The 'name' is a
% string that identifies a chromosome. This to allow multiple
% species in a population. Note that the FITNESS is never set. It
% is always initialized to an empty matrix. Calling the
% constructor without any arguments creates an "empty" chromosome.
% See also CDV,DDV,UI_GEN,UI_CHROM
switch nargin
case 0
c=struct('name','','cdvs',cdv,'ddvs',ddv,'fitness',[],'id','');
c = class(c,'chrom');
case 1
if isa(varargin{1},'chrom')
c=varargin{1};
else
error('wrong argument')
end
case 3
c=struct('name',varargin{1},'cdvs',varargin{2},'ddvs', ...
varargin{3},'fitness',[],'id','');
c=class(c,'chrom');
otherwise
error('Wrong number of arguments')
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?