using GA including a hybrid function option
3 views (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Star Strider
on 12 Aug 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)
w=ga(fun,4,A,b,[],[],[],ub,[],opt);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
format shortE % <— ADDED
w
sumni=n1+n2+n3+n4
sumresult=w(1)+w(2)+w(3)+w(4)
.
2 Comments
More Answers (0)
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!