📄 multiinitializega.m
字号:
function [pop] = multiinitializega(num, varOps, evalFN, evalOps, options)% function [pop]=multiinitializega(populationSize, variableOps, evalFN,% evalOps, options)% multiinitializega 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 % populationSize - the size of the population, i.e., the number to create% varOps - a matrix which contains the bounds and type of each% variable, i.e.% [type1 var1_low var1_high; type2 var2_low var2_high; ....]% Types are defined as follows:% 1 - binary variable (boundaries should be 0 and 1)% 2 - independent integer% 3 - dependent integer (representing a real-life number,% not a set of options)% 4 - floating point variable% evalFN - the name of the evaluation .m function, as a string % evalOps - options to pass to the evaluation function ([NULL])% options - options to the initialize function, i.e.,% [prec] prec is the precision of the variables% defaults [1e-6]% 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.%% Modified by Kerry W. Lothrop <kerry@lothrop.de> to work with more% complex objective functions enabling design vectors containing% binary digits, dependent integers, independent integers and floating% point numbers% University of Colorado, 2002%% Lothrop, K.W.: Conceptual Design Optimization of a Cis-Lunar% Transportation Architecture Using Genetic Algorithms, Universit鋞% Stuttgart, University of Colorado, 2003%% 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=[1e-6];endif nargin<4 evalOps=[];endtypes = varOps(:,1);numVars = size(types, 1);numVars1 = numVars + 1;% initialize with zerospop = zeros(num, numVars1);% prepare objective function callfor individual = 1:num % number of individuals for variable = 1:numVars % number of variables in a chromosome switch types(variable) case 1 % binary pop(individual, variable) = round(rand); case {2, 3} % integer (dependency is irrelevant during initialization) pop(individual, variable) = floor(rand * ... (varOps(variable, 3) - varOps(variable, 2) + 1)) + ... varOps(variable, 2); case 4 % float pop(individual, variable) = (rand * ... (varOps(variable, 3) - varOps(variable, 2))) + ... varOps(variable, 2); end end pop(individual, numVars1) = feval(evalFN, pop(individual,1:numVars), [0 evalOps]);end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -