Passing additional inputs to gamultiobj

I'm running the genetic algorithm function gamultiobj with the option "UseParallel" enabled. However I need to pass additional inputs other than the current population in the algorithm to the objective fitness function.
I've been unable to find any documentation on how to do this for the objective fitness function. Because I'm running parallel I'm also unable to use global variables to pass the inputs.
I'm thus wondering if there's a way to do this that doesn't involve saving external files and then reading them in the objective fitness function.
Here's the code (cut to barebones):
FitnessFunction = @evaluate_objective;
options = optimoptions(@gamultiobj,'PopulationSize',15,'MaxGenerations',15,'UseParallel',true);
[x,Fval,exitFlag,Output] = gamultiobj(FitnessFunction,V,A, ...
b,Aeq,beq,min_range,max_range,options);

 Respuesta aceptada

michio
michio el 24 de Sept. de 2016
Editada: michio el 24 de Sept. de 2016
You can take advantage of properties of anonymous functions to define values for additional inputs.
Suppose you have another function otherFunction that accepts additional parameters, you can define the objective fitness function FitnessFunction as follows;
FitnessFunction = @(x) otherFunction(x, parameter1, parameter2, parameter3);
[x,Fval,exitFlag,Output] = gamultiobj(FitnessFunction,V,A, ...
b,Aeq,beq,min_range,max_range,options);
FitnessFunction above accepts a variable x only. Note that those additional parameters should be defined before defining FitnessFunction.

3 comentarios

Emil Nielsen
Emil Nielsen el 24 de Sept. de 2016
It worked just as you said. Really easy solution.
Thanks!
michio
michio el 25 de Sept. de 2016
Anytime;)
Alan Weiss
Alan Weiss el 26 de Sept. de 2016
Emil, I wonder if you can help me make this information more readily apparent. How did you search for ways of passing extra parameters? Did you search in Google, or look through the Global Optimization Toolbox documentation, or ask friends, or what? If you searched for a particular phrase, what was that phrase?
FYI, I put a link on the Define Objective Function page (Passing Extra Parameters).
Thanks in advance,
Alan Weiss
MATLAB mathematical toolbox documentation

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 24 de Sept. de 2016

Comentada:

el 26 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by