MATLAB® Programs for Evolutionary Algorithms
F.1.1 Using the Genetic Algorithm Toolbox
The toolbox provides the function ga() to implement the genetic algorithm at the command line or in M-files to minimize an objective function. The general form of the function ga() is
x = ga(fitness_function, no_variables, options) [x, fval, reason, output, population, scores] = ga(…)
where fitness_function, no_variables and options are the input arguments. For standard optimization algorithms, fitness_function is known as the objective function. The objective function is written as an M-file and used as a function handle input argument in the ga() function. no_variables is the number of independent variables of the fitness function, and options is the set of parameters of the genetic algorithm defined with gaoptimset.
After running the algorithms for the maximum number of generations, ga(…) returns x, fval, reason, output, population and scores. x is the final solution, fval is the final value of the fitness function at x, reason is a string containing the reason for termination of the algorithm, output is a structure that contains the following fields:
randstate – the state of the MATLAB® random number generator
randnstate – the state of the MATLAB® normal random number generator
generations – the number of generations computed
funccount – the number of evaluations of the fitness function
message – the reason the algorithm terminated (same as reason).
ga(…) also returns a population ...