My gamultobj nonlinear constraints are being ignored
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello! I have been trying to solve a university problem with MATlab, the problem is a gamultobj with nonlinear constraints, but i dont really know how to proceed. If I have just made a mistake, just a link to a guide would be welcomed!
function y = myFit(x)
y = x(1).^2 + 5.*x(2).^2 + x(3).^4 + 3.*x(4).^2 + 10.*x(5).^6 + 7.*x(6).^2 + x(7).^4 - 20.*x(1) - 120.*x(2) - 4.*x(6).*x(7) - 66.*x(4) - 10.*x(6) - 8.*x(7) + 1183;
function[c,ceq] = myCon(x)
c(1) = 2.*x(1).^2 + 3.*x(2).^4 + x(3) + 4.*x(4).^2 + 5.*x(5) - 127 <= 0;
c(2) = 7.*x(1) + 3.*x(2) + 10.*x(3).^2 + x(4) - x(5) - 282 <= 0;
c(3) = 23.*x(1) + x(2).^2 + 6.*x(6).^2 - 8.*x(7) - 196 <= 0;
c(4) = 4.*x(1).^2 + x(2).^2 - 3.*x(1).*x(2) + 2.*x(3).^2 + 5.*x(6) - 11.*x(7) <= 0;
ceq = [];
end
%% Start with the default options
options = optimoptions('gamultiobj');
%% Modify options setting
options = optimoptions(options,'PopulationSize', 500);
options = optimoptions(options,'SelectionFcn', { @selectiontournament 4 });
lb = [-10, -10, -10, -10, -10, -10, -10];
ub = [10, 10, 10, 10, 10, 10, 10];
[x,fval] = gamultiobj(@myFit,7,[],[],[],[],lb,ub,@myCon)
Then I have made a little function just to test the constraints. And it turned out, constraints are not being respected, at least the results I got made me believe in it. (The results for x(1~7) are for just one result from the code above, but I tested nearly 20 times I think).
x(1) = 9.7397;
x(2) = 9.9999;
x(3) = 4.1734;
x(4) = 9.9986;
x(5) = 0.1580;
x(6) = 1.3022;
x(7) = 1.5499;
y(1) = 2.*x(1).^2 + 3.*x(2).^4 + x(3) + 4.*x(4).^2 + 5.*x(5) - 127
y(2) = 7.*x(1) + 3.*x(2) + 10.*x(3).^2 + x(4) - x(5) - 282
y(3) = 23.*x(1) + x(2).^2 + 6.*x(6).^2 - 8.*x(7) - 196
y(4) = 4.*x(1).^2 + x(2).^2 - 3.*x(1).*x(2) + 2.*x(3).^2 + 5.*x(6) - 11.*x(7)
Am I doing something wrong? Thank you!
0 Kommentare
Antworten (2)
Stephan
am 29 Jul. 2019
Bearbeitet: Stephan
am 29 Jul. 2019
Get rid of the <= operators, they make the result of myCon a logical zero vector, which brings trouble. Use this instead, to calculate the correct constraints:
function[c,ceq] = myCon(x)
c(1) = 2.*x(1).^2 + 3.*x(2).^4 + x(3) + 4.*x(4).^2 + 5.*x(5) - 127;
c(2) = 7.*x(1) + 3.*x(2) + 10.*x(3).^2 + x(4) - x(5) - 282;
c(3) = 23.*x(1) + x(2).^2 + 6.*x(6).^2 - 8.*x(7) - 196;
c(4) = 4.*x(1).^2 + x(2).^2 - 3.*x(1).*x(2) + 2.*x(3).^2 + 5.*x(6) - 11.*x(7);
ceq = [];
end
2 Kommentare
Edson Francisconi Perdoná Júnior
am 30 Jul. 2019
Bearbeitet: Edson Francisconi Perdoná Júnior
am 30 Jul. 2019
Alex Sha
am 11 Sep. 2019
The global solution:
Objective Function (Min.): 680.630057374403
x1: 2.33049949480739
x2: 1.95137240931401
x3: -0.477541007554087
x4: 4.36572610028707
x5: -0.624486992651187
x6: 1.03813112439475
x7: 1.59422682441138
Constrained Functions:
1: 2*x1^2 + 3*x2^4 + x3 + 4*x4^2 + 5*x5 - 127-0 = -2.8421709430404E-14
2: 7*x1 + 3*x2 + 10*x3^2 + x4 - x5 - 282-0 = -252.56171907651
3: 23*x1 + x2^2 + 6*x6^2 - 8*x7 - 196-0 = -144.878174546266
4: 4*x1^2 + x2^2 - 3*x1*x2 + 2*x3^2 + 5*x6 - 11*x7-0 = -4.61852778244065E-14
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with Problem-Based Optimization and Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!