My gamultobj nonlinear constraints are being ignored

1 vue (au cours des 30 derniers jours)
Edson Francisconi Perdoná Júnior
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!

Réponses (2)

Stephan
Stephan le 29 Juil 2019
Modifié(e) : Stephan le 29 Juil 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 commentaires
Edson Francisconi Perdoná Júnior
Modifié(e) : Edson Francisconi Perdoná Júnior le 30 Juil 2019
Done that! Worked for most part, now it is getting respected almost always, but for some reason I keep getting once in a while, a positive value for one of the constraints. I will put all codes, and some examples where the values of x(1)~(7) makes one of the constraints been violated.
Fitness Function
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;
Constraint Function
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
Execution Function
options = optimoptions('gamultiobj');
options = optimoptions(options,'PopulationSize', 1000);
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)
Code for constraint test
y = 2.*x(1).^2 + 3.*x(2).^4 + x(3) + 4.*x(4).^2 + 5.*x(5) - 127
z = 7.*x(1) + 3.*x(2) + 10.*x(3).^2 + x(4) - x(5) - 282
w = 23.*x(1) + x(2).^2 + 6.*x(6).^2 - 8.*x(7) - 196
t = 4.*x(1).^2 + x(2).^2 - 3.*x(1).*x(2) + 2.*x(3).^2 + 5.*x(6) - 11.*x(7)
Results where it was breached:
x = 2.2614 1.9463 0.0968 4.3256 -0.2430 1.0790 1.5070
fval = 682.8752 [c1 is violated]
x = 1.7837 2.0548 0.4340 4.1565 -0.4758 0.7983 1.5416
fval = 687.5698 [c1 is violated]
x = 2.2541 1.9418 0.2085 4.3758 -0.5223 1.1186 1.5233
fval = 681.6373 [c1 is violated]
I got mostly c(1) being violated, but I remember in some example c3 being violated too.
Thank you for your time and patience.
Stephan
Stephan le 30 Juil 2019
Modifié(e) : Stephan le 30 Juil 2019
The fitness function you provide does not appear to have to be optimized by gamultiobj, but by ga.

Connectez-vous pour commenter.


Alex Sha
Alex Sha le 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

Community Treasure Hunt

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

Start Hunting!

Translated by