fshmily0711 发表于 2007-3-10 10:51

求遗传算法的工具箱的initializega函数

哪位仁兄有遗传算法的工具箱的initializega函数,能否共享一下?谢谢!!

[ 本帖最后由 eight 于 2007-9-1 16:58 编辑 ]

happy 发表于 2007-3-12 01:05

function = initializega(num, bounds, evalFN,evalOps,options)
% function =initializega(populationSize, variableBounds,evalFN,
%                           evalOps,options)
%    initializega creates a matrix of random numbers with
%    a number of rows equal to the populationSize and a number
%    columns equal to the number of rows in bounds plus 1 for
%    the f(x) value which is found by applying the evalFN.
%    This is used by the ga to create the population if it
%    is not supplied.
%
% pop            - the initial, evaluated, random population
% populatoinSize - the size of the population, i.e. the number to create
% variableBounds - a matrix which contains the bounds of each variable, i.e.
%                  
% evalFN         - the evaluation fn, usually the name of the .m file for
%                  evaluation
% evalOps      - any options to be passed to the eval function defaults []
% options      - options to the initialize function, ie.
%                   where eps is the epsilon value
%                  and the second option is 1 for float and 0 for binary,
%                  prec is the precision of the variables defaults

% Binary and Real-Valued Simulation Evolution for Matlab GAOT V2
% Copyright (C) 1998 C.R. Houck, J.A. Joines, M.G. Kay
%
% C.R. Houck, J.Joines, and M.Kay. A genetic algorithm for function
% optimization: A Matlab implementation. ACM Transactions on Mathmatical
% Software, Submitted 1996.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 1, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
% GNU General Public License for more details. A copy of the GNU
% General Public License can be obtained from the
% Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

if nargin<5
options=;
end
if nargin<4
evalOps=[];
end

if any(evalFN<48) %Not a .m file
if options(2)==1 %Float GA
    estr=['x=pop(i,1); pop(i,xZomeLength)=', evalFN ';'];
else %Binary GA
    estr=['x=b2f(pop(i,:),bounds,bits); pop(i,xZomeLength)=', evalFN ';'];
end
else %A .m file
if options(2)==1 %Float GA
    estr=['[ pop(i,:) pop(i,xZomeLength)]=' evalFN '(pop(i,:),);'];
else %Binary GA
    estr=['x=b2f(pop(i,:),bounds,bits);=' evalFN ...
        '(x,); pop(i,:)=;'];
    end
end


numVars   = size(bounds,1);                 %Number of variables
rng         = (bounds(:,2)-bounds(:,1))'; %The variable ranges'

if options(2)==1 %Float GA
xZomeLength = numVars+1;                 %Length of string is numVar + fit
pop         = zeros(num,xZomeLength);         %Allocate the new population
pop(:,1:numVars)=(ones(num,1)*rng).*(rand(num,numVars))+...
    (ones(num,1)*bounds(:,1)');
else %Binary GA
bits=calcbits(bounds,options(1));
xZomeLength = sum(bits)+1;                 %Length of string is numVar + fit
pop = round(rand(num,sum(bits)+1));
end

for i=1:num
eval(estr);
end

mcx8305 发表于 2007-8-31 09:09

谢谢happy教授!!巨大帮助!

sswwss 发表于 2009-6-3 10:07

非常感谢!
页: [1]
查看完整版本: 求遗传算法的工具箱的initializega函数