Problems with GA function (global optimization toolbox)

I am trying to execute the global optimization toolbox function ga, but my FITNESSFUNCTION has another non-parameterized values. Specifically I want to call another function with multiple parameters inside the calling of ga function :
FITNESSFUNCTION = @(x1,x2,x3) mod_sol(x1, x2, x3, DSSCircuit, DSSText, canb(1), cand(1), i, s1);
[x_sol, f_sol] = ga(FITNESSFUNCTION,3, [], [], [], [],lb, ub, [], [], opts);
the parameters to be optmized are x1, x2 and x3, but I need doing some other calculus with the variables DSSCircuit, DSSText, canb(1), cand(1), i et s1 in order to evaluate the fitness function

6 comentarios

What difficulty are you encountering? That syntax looks appropriate.
Jose Vivas
Jose Vivas el 27 de En. de 2016
Editada: Walter Roberson el 27 de En. de 2016
There is the error
Error in balvolag_v1>@(x1,x2,x3)mod_sol(x1,x2,x3,DSSCircuit,DSSText,canb(1),cand(1),i,s1) (line 58)
fitness = @(x1,x2,x3) mod_sol(x1, x2, x3, DSSCircuit, DSSText, canb(1), cand(1), i, s1)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 359)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in balvolag_v1 (line 59)
[x_sol, f_sol] = ga(fitness,3, [], [], [], [],lb, ub, [], [], opts);
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
Thanks
jgg
jgg el 27 de En. de 2016
It looks like there's a problem in your mod_sol function, specifically with balvolag_v1 which you haven't included.
Not quite, balvolag_v1 appears to be the name of the file that contains the calls the user shows.
The problem is something to do with mod_sol, such as if mod_sol cannot be found, or one of the named variables does not exist at the time the anonymous function is created.
Jose Vivas
Jose Vivas el 28 de En. de 2016
Editada: Jose Vivas el 28 de En. de 2016
I Finally found the error, on the handler definition, it must be
FITNESSFUNCTION = @(x) mod_sol(x1, x2, x3, DSSCircuit, DSSText, canb(1), cand(1), i, s1);
instead
FITNESSFUNCTION = @(x1,x2,x3) mod_sol(x1, x2, x3, DSSCircuit, DSSText, canb(1), cand(1), i, s1);
thanks a lot to jgg and Walter Roberson by your suggestions
More likely you would need
FITNESSFUNCTION = @(x) mod_sol(x(1), x(2), x(3), DSSCircuit, DSSText, canb(1), cand(1), i, s1);

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Preguntada:

el 27 de En. de 2016

Comentada:

el 28 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by