using GA including a hybrid function option

5 visualizaciones (últimos 30 días)
shirin mhd
shirin mhd el 12 de Ag. de 2022
Comentada: Star Strider el 16 de Ag. de 2022
Hi everyone
I have a problem related to how to use options in GA .
I want to use a hybrid function like fmincon.
n1=1;
n2=5;
n3=7;
n4=466352414.326725;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=[-1 -1 -1 -1;...
1 1 1 1;...
-1 0 0 0;...
0 -1 0 0;...
0 0 -1 0;...
0 0 0 -1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=[0,4.8e8,0,0,0,0];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ub=[n1,n2,n3,n4];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fun=@(t) ((5*t(1)^2)-(10*(t(1))))+...
((0.4*(t(2))^2)-(4*(t(2))))+...
((0.408163265306122*(t(3))^2)-(5.71428571428571*(t(3))))+...
((1.3170965284189E-07*(t(4))^2)-(122.8462291859*(t(4))));
rng default
opt=optimoptions(@ga,'HybridFcn',fmincon),
w=ga(fun,4,A,b,[],[],[],[],ub);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
w
sumni=n1+n2+n3+n4
sumresult=w(1)+w(2)+w(3)+w(4)
but the result is this:
Not enough input arguments.
Error in fmincon (line 218)
X, A, B, Aeq, Beq, LB, UB);
Error in plotttt (line 22)
opt=optimoptions(@ga,'HybridFcn',fmincon),
how should I write option to get a result?

Respuesta aceptada

Star Strider
Star Strider el 12 de Ag. de 2022
In the optimoptions call, the 'HybridFcn' name-value pair must have a function handle to they hybrid function as its value.
It is also necessary to specify the arguments correctly, and to include ‘opt’ as the last argument.
Then, it works —
n1=1;
n2=5;
n3=7;
n4=466352414.326725;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
A=[-1 -1 -1 -1;...
1 1 1 1;...
-1 0 0 0;...
0 -1 0 0;...
0 0 -1 0;...
0 0 0 -1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=[0,4.8e8,0,0,0,0];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ub=[n1,n2,n3,n4];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fun=@(t) ((5*t(1)^2)-(10*(t(1))))+...
((0.4*(t(2))^2)-(4*(t(2))))+...
((0.408163265306122*(t(3))^2)-(5.71428571428571*(t(3))))+...
((1.3170965284189E-07*(t(4))^2)-(122.8462291859*(t(4))));
rng default
opt=optimoptions(@ga,'HybridFcn',@fmincon)
opt =
ga options: Set properties: HybridFcn: @fmincon Default properties: ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FunctionTolerance: 1.0000e-06 InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
w=ga(fun,4,A,b,[],[],[],ub,[],opt);
Optimization terminated: average change in the fitness value less than options.FunctionTolerance.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
format shortE % <— ADDED
w
w = 1×4
1.0e+00 * 9.9998e-01 5.0000e+00 6.9999e+00 4.6635e+08
sumni=n1+n2+n3+n4
sumni =
4.6635e+08
sumresult=w(1)+w(2)+w(3)+w(4)
sumresult =
4.6635e+08
.
  2 comentarios
shirin mhd
shirin mhd el 16 de Ag. de 2022
Thanks a lot
Star Strider
Star Strider el 16 de Ag. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by