using GA including a hybrid function option
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-8-12
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)
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!