How to execute GA properly?

Hello, I am trying to use the Genetic algorithm from the Optimization toolbox. I receive following error for both my code and for example code called Run ga from a File included in the Matlab help.
Here is the error:
Undefined function 'ga' for input arguments of type 'optim.options.GaOptions'.
Error in go_ga (line 43)
[x,fval,exitflag,output,population,scores] = ga(@get_fitness_v1,nvars,[],[],[],[],LB,UB,[],options);
Here is part of my code:
% GA SETTINGS AND EXECUTION
options = optimoptions('ga','PopulationSize', PopulationSize,...
'InitialPopulationMatrix', InitialPopulation,...
'MaxGenerations',MaxGenerations);
[x,fval,exitflag,output,population,scores] = ga(@get_fitness_v1,nvars,[],[],[],[],LB,UB,[],options);
out = [x,fval,exitflag,output,population,scores];
Thank you in advance. Best regards JC

5 Comments

Jan - which version of MATLAB are you using? Or, from the command line type
>> doc ga
to see what is the function signature for ga.
Also, which example are you running - one from the web or one from your version of the toolbox?
Hi Geoff,
I am using Matlab R2016b. I have already read the documentation, but there must be something that I overlooked.
The example "Run ga from a File" from Matlab documentation which has the same error is following:
options = optimoptions('ga','MaxGenerations',300,'Display','none');
rng default % for reproducibility
record=[];
for n=0:.05:1
options = optimoptions(options,'CrossoverFraction',n);
[x,fval]=ga(@rastriginsfcn,2,[],[],[],[],[],[],[],options);
record = [record; fval];
end
Thank you for kind help.
JC
Jan - as per Walter's answer, ga is part of the Global Optimization Toolbox. Do you have this? From the command line, what does
which ga -all
return?
Ok, now i understand, here is the reason:
>> which ga -all
C:\Program Files\MATLAB\R2016b\toolbox\globaloptim\globaloptim\ga.m % Has no license available
I thought that I have full school Matlab license :-(, but reality is in another place.
Thank you very much.
JC
The Student Suite does not include Global Optimization Toolbox; that has to be added on.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 11 Mar 2017
ga is not part of the Optimization Toolbox: it is part of the Global Optimization Toolbox.

Asked:

on 11 Mar 2017

Commented:

on 11 Mar 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!