Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Optimization using Genetic Algorithm
Date: Mon, 7 Apr 2008 09:08:03 +0000 (UTC)
Organization: Pieper GmbH
Lines: 77
Message-ID: <ftco9j$c80$1@fred.mathworks.com>
References: <fsqc4b$hab$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1207559283 12544 172.30.248.37 (7 Apr 2008 09:08:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 7 Apr 2008 09:08:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 605234
Xref: news.mathworks.com comp.soft-sys.matlab:461462



You can represent the genome of an individual as a vector 
Individual = [a b c].
 
The fitness function is minimized and not maximized by ga
(). Therefore, you should implement your fitness function 
like this:

function Result = Fitness(Individual)

% Check inequality constraints
if (Individual(1) > 200) && (Individual(1) < 650) ...
&& (Individual(2) > 0.2) && (Individual(2) < 0.6) ...
&& (Individual(3) > 200) && (Individual(3) < 550)

 % Fitness value of a parameter combination that fulfills
 % the constraints.

 Result = -Individual ...
        * (11445.34 + [0.1133 -0.0183 -0.07788]';

else

 % Fitness function of a parameter combination that 
 % violates the constraints. It seems that the objective
 % function can't get negative or zero, so zeros is a
 % suitable upper bound for the fitness function.  
 Result = 0;

end;

end


You set the options of your GA in the following way:

PopulationSize = 100; % or any other number

NumberOfCrossOverIndividuals = 0.85 * PopulationSize;

NumberOfMutationIndividuals = 0.03 * PopulationSize;

NumberOfEliteIndividuals = PopulationSize ...
                         - NumberOfCrossOverIndividuals ...
                         - NumberOfMutationIndividuals;

Options = gaoptimset('CrossOverFraction', ...
                     0.85, ...
                     'EliteCount', ...
                     NumberOfEliteIndividuals, ...
                     'PopulationSize', ...
                     PopulationSize);


You run your GA in the following way:

[OptimaIndividual OptimalFitness] = ga(@Fitness, ...
                                       3, ...
                                       [], ...
                                       [], ...
                                       [], ...
                                       [], ...
                                       [], ...
                                       [], ...
                                       [], ...
                                       Options);


Note that cross over produces only one offspring individual 
for each set of parents. Mutation is not applied to 
offspring, but to individuals of the current generation. If 
you want to apply mutation to children generated by 
crossover, you have to implement your own cross over 
function.

I hope this helps you getting started.