using GA including a hybrid function option
조회 수: 2 (최근 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!