GA for Mixed-Integer Nonlinear Programing

Dear all,
I am having a problem with solving a MINLP with GA solver. It keeps having the message of "Constraint function must return real value". I have double checked all the constraints and they should be fine. But this message still appeared. May I ask whether Matlab 2018b can show the contraint that has a problem? I would really appreciate your help.
Thank you so much,
Kind Regards,
Hoang Trinh,

8 comentarios

Ameer Hamza
Ameer Hamza el 28 de Abr. de 2020
Can you share the code for the optimization problem? Alternatively, you can add a breakpoint inside nonlcon and find out if there is some issue with return values.
Dear Ameer Hamza,
Yeah, I also think there is something wrong in the nonlcon constraints. But I do not know how to detect it. Here is the code of my nonlcon constraints:
function [c ceq] = nlcon(x)
tol = 1e-3 ;
c(1) = x(32) - 500*x(1)*6.5/(500*6.5 + x(1)) - tol ;
c(2) = x(33) - 50*(0.06*x(2) - 1)*(1 - exp(-1095)) - 520*(10950^0.8)*(1 - 0.008*x(2))*(0.8 + 1.2*exp(-0.005*x(32)))/(10950^0.8 + 0.15*x(32)) - tol ;
c(3) = x(34)^2 - (x(1) - 41 - x(34))*(400*x(24))/x(5) - tol ;
c(4) = 1000*x(44) - x(9)*x(10)*x(11)*x(12) - tol ;
c(5) = x(51) - 0.6*(x(9)^2*x(10)*x(11) + 2000*x(50))/1000 - tol ;
c(6) = x(52) - 1/1000*(600*x(44)*x(45) + 720*x(50)*(2*x(45)-x(9))/x(45)) - tol ;
c(7) = x(53) - 1/1000000*(300*x(44)*x(45)*(x(9)-x(12)*x(45)) + 360*x(50)*(2*x(45)-x(9))^2/x(45)) - tol ;
c(8) = x(54) - 1/1000*(3600*x(44)*x(45)/11 + 120*x(50)*(12*x(45) - 11*x(9))/x(45)) - tol ;
c(9) = x(55) - 1/1000000*(9000*x(44)*x(45)*(x(9) - 6/11*x(12)*x(45))/55 + 660*x(50)*(2*x(45)-x(9))^2/x(45)) - tol ;
c(10) = x(56) - 1/1000000*(800*x(45)*x(50)*(1 - 0.5*x(12)*x(57)) + 960*x(50)*(1 - (x(9)-x(45))/x(45)/x(57))*(0.5*x(12)*x(57)*x(45) - x(9) + x(45))) - tol ;
c(11) = x(57)*(x(57) + 200*x(50)/1000/x(44)/x(45)) - 1200*x(50)*(x(9)-x(45))/1000/x(44)/x(45)^2 - tol ;
c(12) = 1000*x(58) - 7*(7*6.5*(0.03*x(1) + 5.7) + 30*(x(9)/1000)^2*(3.5 - x(1)/1000)) - tol ;
c(13) = x(59) - 0.05*x(9)*x(58) - tol ;
c(14) = -x(32) + 500*x(1)*6.5/(500*6.5 + x(1)) - tol ;
c(15) = -x(33) + 50*(0.06*x(2) - 1)*(1 - exp(-1095)) + 520*(10950^0.8)*(1 - 0.008*x(2))*(0.8 + 1.2*exp(-0.005*x(32)))/(10950^0.8 + 0.15*x(32)) - tol ;
c(16) = -x(34)^2 + (x(1) - 41 - x(34))*(400*x(24))/x(5) - tol ;
c(17) = -1000*x(44) + x(9)*x(10)*x(11)*x(12) - tol ;
c(18) = -x(51) + 0.6*(x(9)^2*x(10)*x(11) + 2000*x(50))/1000 - tol ;
c(19) = -x(52) + 1/1000*(600*x(44)*x(45) + 720*x(50)*(2*x(45) - x(9))/x(45)) - tol ;
c(20) = -x(53) + 1/1000000*(300*x(44)*x(45)*(x(9)-x(12)*x(45)) + 360*x(50)*(2*x(45)-x(9))^2/x(45)) - tol ;
c(21) = -x(54) + 1/1000*(18000/55*x(44)*x(45) + 120*x(50)*(12*x(45) - 11*x(9))/x(45)) - tol ;
c(22) = -x(55) + 1/1000000*(9000/55*x(44)*x(45)*(x(9) - 6/11*x(12)*x(45)) + 660*x(50)*(2*x(45)-x(9))^2/x(45) ) - tol ;
c(23) = -x(56) + 1/1000000*(800*x(45)*x(50)*(1 - 0.5*x(12)*x(57)) + 960*x(50)*(1 - (x(9)-x(45))/x(45)/x(57))*(0.5*x(12)*x(57)*x(45) - x(9) + x(45))) - tol ;
c(24) = -x(57)*(x(57) + 200*x(50)/(1000*x(44)*x(45))) + 1200*x(50)*(x(9)-x(45))/1000/x(44)/x(45)^2 - tol ;
c(25) = -1000*x(58) + 7*(7*6.5*(0.03*x(1) + 5.7) + 30*(x(9)/1000)^2*(3.5-x(1)/1000)) - tol ;
c(26) = -x(59) + 0.05*x(9)*x(58) - tol ;
c(27) = x(22)/(2*x(2)*x(3)*x(4)*(x(1) - 41)) - 0.36 ;
c(28) = -x(22) + 36/125*(x(2))^0.5*x(1)^2/(x(1) - 41) ;
c(29) = x(23)/(2*x(2)*x(3)*x(4)*(x(1) - 41)) - 0.36 ;
c(30) = -1/2500*x(23)*(x(1) - 41)*(1 - x(23)/(4*x(2)*x(3)*(x(1) - 41))) + 1/10*(0.03*x(1) + 5.7)*(6.5/2 * + x(9)/2000)*(7 - 0.7*x(9)/1000)^2/6.5 ;
c(31) = -x(23) + 36/125*(x(2))^0.5*x(1)^2/(x(1) - 41) ;
c(32) = x(23)/(x(1) - 41) - 4/5*x(2)*x(3)*x(4) ;
c(33) = x(24)/(2*x(2)*x(3)*x(4)*(x(1) - 41)) - 0.36 ;
c(34) = -1/2500*x(24)*(x(1) - 41)*(1 - x(24)/(4*x(2)*x(3)*(x(1) - 41))) + 9/64*(0.03*x(1) + 5.7)*(7 - 0.7*x(9)/1000)^2 ;
c(35) = -x(24) + 36/125*(x(2))^0.5*x(1)^2/(x(1) - 41) ;
c(36) = x(24)/(x(1) - 41) - 4/5*x(2)*x(3)*x(4) ;
c(37) = x(25)/(2*x(2)*x(3)*x(4)*(x(1) - 41)) - 0.36 ;
c(38) = -1/2500*x(25)*(x(1) - 41)*(1 - x(25)/(4*x(2)*x(3)*(x(1) - 41))) + 1/20*(0.03*x(1) + 5.7)*(7 - 0.7*x(9)/1000)^2 ;
c(39) = -x(25) + 36/125*(x(2))^0.5*x(1)^2/(x(1) - 41) ;
c(40) = x(25)/(x(1) - 41) - 4/5*x(2)*x(3)*x(4) ;
c(41) = x(26)/(2*x(2)*x(3)*x(4)*(x(1) - 53)) - 0.36 ;
c(42) = -1/2500*x(26)*(x(1) - 53)*(1 - x(26)/(4*x(2)*x(3)*(x(1) - 53))) + 9/128*(0.03*x(1) + 5.7)*(7/2 * + x(9)/2000)*(6.5 - 0.7*x(9)/1000)^2/(7/4 * + x(9)/2000) ;
c(43) = -x(26) + 36/125*(x(2)^0.5)*x(1)^2/(x(1) - 53) ;
c(44) = x(26)/(x(1) - 53) - 4/5*x(2)*x(3)*x(4) ;
c(45) = x(27)/(2*x(2)*x(3)*x(4)*(x(1) - 53)) - 0.36 ;
c(46) = -1/2500*x(27)*(x(1) - 53)*(1 - x(27)/(4*x(2)*x(3)*(x(1) - 53))) + 1/10*(0.03*x(1) + 5.7)*(7/2 * + x(9)/2000)*(6.5 - 0.7*x(9)/1000)^2/7 ;
c(47) = -x(27) + 36/125*(x(2)^0.5)*x(1)^2/(x(1) - 53) ;
c(48) = x(27)/(x(1) - 53) - 4/5*x(2)*x(3)*x(4) ;
c(49) = -1/2500*x(28)*(x(1) - 53)*(1 - x(28)/(4*x(2)*x(3)*(x(1) - 53))) + 9/64*7*(0.03*x(1) + 5.7)*(6.5 - 0.7*x(9)/1000)^2/6.5 ;
c(50) = -x(28) + 36/125*(x(2))^0.5*x(1)^2/(x(1) - 41) ;
c(51) = x(28)/(x(1) - 53) - 4/5*x(2)*x(3)*x(4) ;
c(52) = x(29)/(2*x(2)*x(3)*x(4)*(x(1) - 53)) - 0.36 ;
c(53) = -1/2500*x(29)*(x(1) - 53)*(1 - x(29)/(4*x(2)*x(3)*(x(1) - 53))) + 1/40*7*(0.03*x(1) + 5.7)*(6.5 - 0.7*x(9)/1000)^2/(7-6.5/2) ;
c(54) = -x(29) + 36/125*(x(2)^0.5)*x(1)^2/(x(1) - 53) ;
c(55) = x(29)/(x(1) - 53) - 4/5*x(2)*x(3)*x(4) ;
c(56) = 0.25*(0.03*x(1) + 5.7)*(7 + x(9)/1000)*(6.5 + x(9)/1000) - 119/500000*(x(1) - 47)*(2*x(9) + x(1) - 47)*(x(2))^0.5/(1 + 125*(7 - 0.7*x(9)/1000)^2/8/(7 + x(9)/1000)/(x(1) - 47)) ;
c(57) = 0.25*(0.03*x(1) + 5.7)*(7 + x(9)/1000)*(6.5 + x(9)/1000) - 119/500000*(x(1) - 47)*(2*x(9) + x(1) - 47)*(x(2))^0.5/(1 + 125*(6.5 - 0.7*x(9)/1000)^2/8/(6.5 + x(9)/1000)/(x(1) - 47)) ;
c(58) = 27/400*(6.5 + x(9)/1000)*(7 - 0.7*x(9)/1000)^2 - 50 ;
c(59) = 1/160*(0.03*x(1) + 5.7)*(6.5 + x(9)/1000)*(7 - 0.7*x(9)/1000)^2 - 160 ;
c(60) = 27/400*(6.5 + x(9)/1000)*(7 - 0.7*x(9)/1000)^2 - x(40) ;
c(61) = 1/160*(0.03*x(1) + 5.7)*(6.5 + x(9)/1000)*(7 - 0.7*x(9)/1000)^2 - x(40) ;
c(62) = x(40) - 27/400*(6.5 + x(9)/1000)*(7 - 0.7*x(9)/1000)^2 - 160*(1-x(14)) ;
c(63) = x(40) - 1/160*(0.03*x(1) + 5.7)*(6.5 + x(9)/1000)*(7 - 0.7*x(9)/1000)^2 - 160*(1-x(15)) ;
c(64) = 0.5*7*(0.03*x(1) + 5.7)*(6.5 + x(9)/1000) - 119/500000*(x(1) - 47)*(3*x(9) + 2*x(1) - 94)*(x(2))^0.5/(1 + 250*x(40)*(3*x(9) + 2*x(1) - 94)/7/(0.03*x(1) + 5.7)/(6.5 + x(9)/1000)/(x(9) + x(1) - 47)/(x(1) - 47)) ;
c(65) = 0.5*7*(0.03*x(1) + 5.7)*(6.5 + x(9)/1000) - 119/500000*(x(1) - 47)*(3*x(9) + 2*x(1) - 94)*(x(2))^0.5/(1 + 125/8*(6.5 - 0.7*x(9)/1000)^2*(3*x(9) + 2*x(1) - 94)/(6.5 + x(9)/1000)/(2*x(9) + x(1) - 47)/(x(1) - 47)) ;
c(66) = 27/400*(7 + x(9)/1000)*(6.5 - 0.7*x(9)/1000)^2 - 50 ;
c(67) = 1/160*(0.03*x(1) + 5.7)*(7 + x(9)/1000)*(6.5 - 0.7*x(9)/1000)^2 - 160 ;
c(68) = 27/400*(7 + x(9)/1000)*(6.5 - 0.7*x(9)/1000)^2 - x(41) ;
c(69) = 1/160*(0.03*x(1) + 5.7)*(7 + x(9)/1000)*(6.5 - 0.7*x(9)/1000)^2 - x(41) ;
c(70) = x(41) - 27/400*(7 + x(9)/1000)*(6.5 - 0.7*x(9)/1000)^2 - 160*(1-x(16)) ;
c(71) = x(41) - 1/160*(0.03*x(1) + 5.7)*(7 + x(9)/1000)*(6.5 - 0.7*x(9)/1000)^2 - 160*(1-x(17)) ;
c(72) = 0.5*6.5*(0.03*x(1) + 5.7)*(7 + x(9)/1000) - 119/500000*(x(1) - 47)*(3*x(9) + 2*x(1) - 94)*(x(2))^0.5/(1 + 125/8*(7 - 0.7*x(9)/1000)^2*(3*x(9) + 2*x(1) - 94)/(7 + x(9)/1000)/(2*x(9) + x(1) - 47)/(x(1) - 47)) ;
c(73) = 0.5*6.5*(0.03*x(1) + 5.7)*(7 + x(9)/1000) - 119/500000*(x(1) - 47)*(3*x(9) + 2*x(1) - 94)*(x(2))^0.5/(1 + 250*(3*x(9) + 2*x(1) - 94)*x(41)/6.5/(0.03*x(1) + 5.7)/(7 + x(9)/1000)/(x(9) + x(1) - 47)/(x(1) - 47)) ;
c(74) = 27/200*6.5*(7 - 0.7*x(9)/1000)^2 - 95 ;
c(75) = 1/80*6.5*(0.03*x(1) + 5.7)*(7 - 0.7*x(9)/1000)^2 - 305 ;
c(76) = 27/200*6.5*(7 - 0.7*x(9)/1000)^2 - x(42) ;
c(77) = 1/80*6.5*(0.03*x(1) + 5.7)*(7 - 0.7*x(9)/1000)^2 - x(42) ;
c(78) = x(42) - 27/200*6.5*(7 - 0.7*x(9)/1000)^2 - 305*(1-x(18)) ;
c(79) = x(42) - 1/80*6.5*(0.03*x(1) + 5.7)*(7 - 0.7*x(9)/1000)^2 - 305*(1-x(19)) ;
c(80) = 27/200*7*(6.5 - 0.7*x(9)/1000)^2 - 95 ;
c(81) = 1/80*7*(0.03*x(1) + 5.7)*(6.5 - 0.7*x(9)/1000)^2 - 305 ;
c(82) = 27/200*7*(6.5 - 0.7*x(9)/1000)^2 - x(43) ;
c(83) = 1/80*7*(0.03*x(1) + 5.7)*(6.5 - 0.7*x(9)/1000)^2 - x(43) ;
c(84) = x(43) - 27/200*7*(6.5 - 0.7*x(9)/1000)^2 - 305*(1-x(20)) ;
c(85) = x(43) - 1/80*7*(0.03*x(1) + 5.7)*(6.5 - 0.7*x(9)/1000)^2 - 305*(1-x(21)) ;
c(86) = 7*6.5*(0.03*x(1) + 5.7) - 119/125000*(x(1) - 47)*(x(9) + x(1) - 47)*(x(2))^0.5/(1 + 500*x(42)/7/6.5/(0.03*x(1) + 5.7)/(x(1) - 47)) ;
c(87) = 7*6.5*(0.03*x(1) + 5.7) - 119/125000*(x(1) - 47)*(x(9) + x(1) - 47)*(x(2))^0.5/(1 + 500*x(43)/7/6.5/(0.03*x(1) + 5.7)/(x(1) - 47)) ;
c(88) = -(0.025*x(1) + 3.1)*(7 - 0.7*x(9)/1000)^2 + 1/750*x(1)^2*(x(2)^0.5 - 1/60*x(24)*x(33)/(20*x(1) + x(24) - 820)) ;
c(89) = log((1/6000*6.5*x(34)^3 + 0.1*x(24)*6.5*(x(1) - 41-x(34) )^2/x(5))/(1 - (1 - 4*x(34)^3/x(1)^3 - 2400*x(24)*(x(1) - 41-x(34))^2/x(5)/x(1)^3)*(1/750*x(1)^2*(x(2)^0.5 - (1/60*x(24)*x(33))/(20*x(1) + x(24) - 820))/(0.025*x(1) + 3.1)/(7 - 0.7/1000*x(9))^2)^2)) - 50 ;
c(90) = log(1/24000*6.5*x(1)^3) - 50 ;
c(91) = x(35) - log((1/6000*6.5*x(34)^3 + 0.1*x(24)*6.5*(x(1) - 41-x(34) )^2/x(5))/(1 - (1 - 4*x(34)^3/x(1)^3 -2400*x(24)*(x(1) - 41-x(34))^2/x(5)/x(1)^3)*(1/750*x(1)^2*(x(2)^0.5 - (1/60*x(24)*x(33))/(20*x(1) + x(24) - 820))/(0.025*x(1) + 3.1)/(7 - 0.7/1000*x(9))^2)^2)) ;
c(92) = x(35) - log(1/24000*6.5*x(1)^3) ;
c(93) = -x(35) + log((1/6000*6.5*x(34)^3 + 0.1*x(24)*6.5*(x(1) - 41 - x(34))^2/x(5))/(1 - (1 - 4*x(34)^3/x(1)^3 - 2400*x(24)*(x(1) - 41 - x(34))^2/x(5)/x(1)^3)*(1/750*x(1)^2*(x(2)^0.5 - 1/60*x(24)*x(33)/(20*x(1) + x(24) - 820))/(0.025*x(1) + 3.1)/(7 - 0.7/1000*x(9))^2)^2)) - 50*(1 - x(30)) ;
c(94) = -x(35) + log(1/24000*6.5*x(1)^3) - 50*(1-x(31)) ;
c(95) = -(0.025*x(1) + 3.1)*(7 - 0.7/1000*x(9))^2 + 4/5625*x(1)^2*(x(2)^0.5 - (1/60*x(24)*x(33))/(20*x(1) + x(24) - 820)) ;
c(96) = log((1/6000*6.5*x(34)^3 + 0.1*x(24)*6.5*(x(1) - 41 - x(34))^2/x(5))/(1 - (1 - 4*x(34)^3/x(1)^3 - 2400*x(24)*(x(1) - 41- x(34))^2/x(5)/x(1)^3)*(4/5625*x(1)^2*(x(2)^0.5 - (1/60*x(24)*x(33))/(20*x(1) + x(24) - 820))/(0.025*x(1) + 3.1)/(7 - 0.7/1000*x(9))^2)^2)) - 50 ;
c(97) = x(36) - log((1/6000*6.5*x(34)^3 + 0.1*x(24)*6.5*(x(1) - 41 - x(34))^2/x(5))/(1 - (1 - 4*x(34)^3/x(1)^3 - 2400*x(24)*(x(1) - 41- x(34))^2/x(5)/x(1)^3)*(4/5625*x(1)^2*(x(2)^0.5 - (1/60*x(24)*x(33))/(20*x(1) + x(24) - 820))/(0.025*x(1) + 3.1)/(7 - 0.7/1000*x(9))^2)^2)) ;
c(98) = x(36) - log(1/24000*6.5*x(1)^3) ;
c(99) = -x(36) + log((1/6000*6.5*x(34)^3 + 0.1*x(24)*6.5*(x(1) - 41 - x(34))^2/x(5))/(1 - (1 - 4*x(34)^3/x(1)^3 - 2400*x(24)*(x(1) - 41- x(34))^2/x(5)/x(1)^3)*(4/5625*x(1)^2*(x(2)^0.5 - (1/60*x(24)*x(33))/(20*x(1) + x(24) - 820))/(0.025*x(1) + 3.1)/(7 - 0.7/1000*x(9))^2)^2)) - 50*(1 - x(37)) ;
c(100) = -x(36) + log(1/24000*6.5*x(1)^3) - 50*(1-x(38)) ;
c(101) = log(546875/96*6.5) + log(1 + 2*(0.025*x(1) + 2.2)/(0.025*x(1) + 3.1)) + log(0.025*x(1) + 3.1) + 3*log(7 - 0.7*x(9)/1000) - log(x(5)) - log(exp(x(35)) + exp(x(36))) - log(4) ;
c(102) = log(546875/96*6.5) + log(1 + 2*(0.025*x(1) + 2.2)/(0.025*x(1) + 3.1)) + log(0.025*x(1) + 3.1) + 4*log(7 - 0.7*x(9)/1000) - log(x(5)) - log(exp(x(35)) + exp(x(36))) - log(25) ;
c(103) = 1/80*7*(0.03*x(1) + 5.7)*(6.5 - 0.7*x(9)/1000)^2 - x(59) ;
c(104) = 1/80*6.5*(0.03*x(1) + 5.7)*(7 - 0.7*x(9)/1000)^2 - x(59) ;
c(105) = 1000*x(58) - x(59)*(x(52)-x(51))/x(53) - x(51) ;
c(106) = 1000*x(58) - x(59)*(x(54)-x(52))/(x(55)-x(53)) - (x(55)*x(52)-x(53)*x(54))/(x(55)-x(53)) ;
c(107) = -1000*x(58) - x(59)*x(54)/(x(56)-x(55)) + x(56)*x(54)/(x(56)-x(55)) ;
c(108) = 0.01*x(9)^2 - 4*x(50) ;
c(109) = -0.04*x(9)^2 + 4*x(50) ;
c(110) = 3300000/x(10)/(x(9) - 78) - x(64) ;
c(111) = 7*(3500 - x(1)) - 3300000*(x(63) + 1)/x(10)/(x(9) - 78) ;
c(112) = x(28)/(2*x(2)*x(3)*x(4)*(x(1) - 53)) - 0.36 ;
c(113) = x(22)/(x(1) - 41) - 4/5*x(2)*x(3)*x(4) ;
c(114) = -1/2500*x(22)*(x(1) - 41)*(1 - x(22)/(4*x(2)*x(3)*(x(1) - 41))) + 9/128*(0.03*x(1) + 5.7)*(6.5/2 + x(9)/2000)*(7 - 0.7*x(9)/1000)^2/(6.5/4 + x(9)/2000) ;
ceq = [];
end
Could you please help me to tackle this error?
Really thank you so much,
Walter Roberson
Walter Roberson el 29 de Abr. de 2020
You have problems if some of your variables such as x(5) or x(44) or x(45) can be 0, or your x(32) can be sufficiently negative, or if your x(2) can be negative, or your x(1) can be 53, or any of several combinations of values could just happen to cause a division by 0.
It would be easier to debug if we had the rest of your code.
Hoang Trinh
Hoang Trinh el 29 de Abr. de 2020
Editada: Walter Roberson el 29 de Abr. de 2020
Thank you a lot for your response. Yes, I will copy all of my code here.
This is my main code:
% Main code for optimization
fun = @myFitness;
nvars = 82;
lb = [ 200 32 0.67 0.67 30100 348.6 0 0 450 32 0.67 0.67 348.6 0 0 0 0 0 0 0 0 366.7 366.7 366.7 366.7 366.7 366.7 366.7 366.7 0 0 100 100 10 5 5 0 0 0 2 2 2 2 2 50 0 0 0 16 200 5 5 5 5 5 5 0 5 5 20 20 20 2 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ] ;
ub = [ 1100 65 0.85 0.85 37400 739.2 0 0 1000 65 0.85 0.85 739.2 1 1 1 1 1 1 1 1 1833.33 1833.33 1833.33 1833.33 1833.33 1833.33 1833.33 1833.33 1 1 1100 1200 1100 50 50 1 1 0 400 400 400 400 50 1000 1 1 0 40 1260 10000 10000 1000 10000 1000 1000 1 10000 1000 300 300 300 500 600 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ] ;
% Nonlinear constraints
nonlcon = @nlcon;
% Linear constraints
A = zeros([71 82]) ;
A(1,2) = -1;
A(2,3) = -1;
A(3,4) = -1;
A(4,5) = -1;
A(5,6) = -1;
A(8,2) = 1 ;
A(9,3) = 1 ;
A(10,4) = 1 ;
A(11,5) = 1 ;
A(12,6) = 1 ;
A(13,10) = 1 ;
A(14,11) = 1 ;
A(15,12) = 1 ;
A(16,13) = 1 ;
A(17,10) = -1;
A(18,11) = -1;
A(19,12) = -1;
A(20,13) = -1;
A(45,9) = -1;
A(46,9) = 1 ;
A(49,9) = 1 ;
A(50,9) = -1 ;
A(47,1) = 1;
A(48,1) = -1;
A(52,1) = 21/8 ;
A(53,1) = 21/8 ;
A(54,1) = 21/8 ;
A(55,1) = 21/8 ;
A(56,1) = 21/8 ;
A(57,1) = 21/8 ;
A(58,1) = 21/8 ;
A(59,1) = 21/8 ;
A(60,1) = 5 ;
A(61,2) = 1 ;
A(62,1) = -1 ;
A(61,10) = -1 ;
A(62,9) = -7.5;
A(66,9) = -1;
A(68,9) = -0.6;
A(71,9) = 0.6;
A(29,14) = 1 ;
A(30,14) = -1 ;
A(29,15) = 1 ;
A(30,15) = -1 ;
A(31,16) = 1 ;
A(32,16) = -1 ;
A(31,17) = 1 ;
A(32,17) = -1 ;
A(33,18) = 1 ;
A(34,18) = -1 ;
A(33,19) = 1 ;
A(34,19) = -1 ;
A(35,20) = 1 ;
A(36,20) = -1 ;
A(35,21) = 1 ;
A(36,21) = -1 ;
A(52,22) = -1 ;
A(53,23) = -1 ;
A(54,24) = -1 ;
A(55,25) = -1 ;
A(56,26) = -1 ;
A(57,27) = -1 ;
A(58,28) = -1 ;
A(59,29) = -1 ;
A(60,24) = -1 ;
A(37,30) = 1 ;
A(38,30) = -1 ;
A(37,31) = 1 ;
A(38,31) = -1 ;
A(39,37) = 1 ;
A(40,37) = -1 ;
A(39,38) = 1 ;
A(40,38) = -1 ;
A(41,46) = 1 ;
A(42,46) = -1 ;
A(41,47) = 1 ;
A(42,47) = -1 ;
A(45,45) = 1 ;
A(46,45) = -1 ;
A(45,49) = 0.5;
A(46,49) = -0.5 ;
A(63,49) = 1.5 ;
A(65,49) = -1.5 ;
A(66,49) = 2 ;
A(67,49) = -15 ;
A(70,49) = 15 ;
A(64,46) = 20 ;
A(65,47) = 36 ;
A(23,49) = 1 ;
A(24,49) = -1 ;
A(25,50) = 1 ;
A(26,50) = -1 ;
A(1,65) = 32 ;
A(1,66) = 40 ;
A(1,67) = 50 ;
A(1,68) = 65 ;
A(2,65) = 0.85 ;
A(2,66) = 0.85 ;
A(2,67) = 0.85 ;
A(2,68) = 0.805 ;
A(3,65) = 0.826 ;
A(3,66) = 0.77 ;
A(3,67) = 0.7 ;
A(3,68) = 0.67 ;
A(4,65) = 30100 ;
A(4,66) = 32800 ;
A(4,67) = 34800 ;
A(4,68) = 37400 ;
A(5,65) = 348.6 ;
A(5,66) = 405 ;
A(5,67) = 513 ;
A(5,68) = 739.2 ;
A(6,65) = 1 ;
A(6,66) = 1 ;
A(6,67) = 1 ;
A(6,68) = 1 ;
A(7,65) = -1 ;
A(7,66) = -1 ;
A(7,67) = -1 ;
A(7,68) = -1 ;
A(8,65) = -32 ;
A(8,66) = -40 ;
A(8,67) = -50 ;
A(8,68) = -65 ;
A(9,65) = -0.85 ;
A(9,66) = -0.85 ;
A(9,67) = -0.85 ;
A(9,68) = -0.805 ;
A(10,65) = -0.826 ;
A(10,66) = -0.77 ;
A(10,67) = -0.7 ;
A(10,68) = -0.67 ;
A(11,65) = -30100 ;
A(11,66) = -32800 ;
A(11,67) = -34800 ;
A(11,68) = -37400 ;
A(12,65) = -348.6 ;
A(12,66) = -405 ;
A(12,67) = -513 ;
A(12,68) = -739.2 ;
A(13,69) = -32 ;
A(13,70) = -40 ;
A(13,71) = -50 ;
A(13,72) = -65 ;
A(14,69) = -0.85 ;
A(14,70) = -0.85 ;
A(14,71) = -0.85 ;
A(14,72) = -0.805 ;
A(15,69) = -0.826 ;
A(15,70) = -0.77 ;
A(15,71) = -0.7 ;
A(15,72) = -0.67 ;
A(16,69) = -348.6 ;
A(16,70) = -405 ;
A(16,71) = -513 ;
A(16,72) = -739.2 ;
A(17,69) = 32 ;
A(17,70) = 40 ;
A(17,71) = 50 ;
A(17,72) = 65 ;
A(18,69) = 0.85 ;
A(18,70) = 0.85 ;
A(18,71) = 0.85 ;
A(18,72) = 0.805 ;
A(19,69) = 0.826 ;
A(19,70) = 0.77 ;
A(19,71) = 0.7 ;
A(19,72) = 0.67 ;
A(20,69) = 348.6 ;
A(20,70) = 405 ;
A(20,71) = 513 ;
A(20,72) = 739.2 ;
A(21,69) = 1;
A(21,70) = 1;
A(21,71) = 1;
A(21,72) = 1;
A(22,69) = -1;
A(22,70) = -1;
A(22,71) = -1;
A(22,72) = -1;
A(23,73) = -16 ;
A(23,74) = -20 ;
A(23,75) = -24 ;
A(23,76) = -28 ;
A(23,77) = -32 ;
A(23,78) = -36 ;
A(23,79) = -40 ;
A(24,73) = 16 ;
A(24,74) = 20 ;
A(24,75) = 24 ;
A(24,76) = 28 ;
A(24,77) = 32 ;
A(24,78) = 36 ;
A(24,79) = 40 ;
A(25,73) = -200 ;
A(25,74) = -310 ;
A(25,75) = -450 ;
A(25,76) = -620 ;
A(25,77) = -800 ;
A(25,78) = -1020 ;
A(25,79) = -1260 ;
A(26,73) = 200 ;
A(26,74) = 310 ;
A(26,75) = 450 ;
A(26,76) = 620 ;
A(26,77) = 800 ;
A(26,78) = 1020 ;
A(26,79) = 1260 ;
A(27,73) = 1;
A(27,74) = 1;
A(27,75) = 1;
A(27,76) = 1;
A(27,77) = 1;
A(27,78) = 1 ;
A(27,79) = 1 ;
A(28,73) = -1;
A(28,74) = -1;
A(28,75) = -1;
A(28,76) = -1;
A(28,77) = -1;
A(28,78) = -1 ;
A(28,79) = -1 ;
A(43,80) = 1 ;
A(43,81) = 1 ;
A(43,82) = 1 ;
A(44,80) = -1 ;
A(44,81) = -1 ;
A(44,82) = -1 ;
A(69,80) = 150 ;
A(70,81) = 450 ;
A(71,82) = 450 ;
A(67,64) = 1 ;
A(68,64) = 1 ;
A(69,64) = -1 ;
A(70,64) = -1 ;
A(71,64) = -1 ;
A(63,62) = -1 ;
A(64,62) = 1 ;
A(65,62) = 1 ;
A(66,62) = 1 ;
A(47,60) = -5 ;
A(48,60) = 5 ;
A(49,61) = -5 ;
A(50,61) = 5 ;
b = [ 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 -45 45 0 0 0 0 0 0 0 0 0 0 0 0 0 205 0 -3500 0 60 36 -90 0 0 -150 450 450 ]' ;
IntCon = [1 2 5 9 10 14 15 16 17 18 19 20 21 30 31 37 38 46 47 49 50 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82] ;
opts = optimoptions('ga', ...
'PopulationSize', 1000, ...
'MaxGenerations', 500, ...
'EliteCount', 10, ...
'FunctionTolerance', 1e-8, ...
'PlotFcn', @gaplotbestf);
[x fval] = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon);
And this is my Fitness function:
function y = myFitness(x)
y = 1/1000*7*(x(6)*x(1)*(7*3 + x(9)/1000)*(6.5*3 + x(9)/1000)/1000 + 40.251660/1000*((x(26)*(x(9)/1000 + 0.5*7) + 0.5*x(27)*7 + (3 - 1)*(0.5*6.5*x(28) + 7*x(29) - 0.5*6.5*x(29)))*(6.5*3 + x(9)/1000)+ (x(22)*(x9/1000 + 0.5*6.5) + 0.5*x(23)*6.5 + 0.5*6.5*(3 - 1)*(x(24) + x(25)))*(7*3 + x(9)/1000)) + x(13)*(3 + 1)*(3 + 1)*(3.5 - x(1)/1000)*(x(9)/1000)^2 + 161.006640/1000*(3 + 1)*(3 + 1)*x(50)) + 17.7107304/1000000*(3 + 1)*(3 + 1)*(x(63) + 1)*(x(9) - 51) ;
end
Thank you so much,
Walter Roberson
Walter Roberson el 29 de Abr. de 2020
Your x(53), x(55), and x(56) all become 5. That gives you division by 0 in entries 106 and 107 of your nonlinear constraints, where you divide by the difference between some of those.
You need to add constraints to ensure relative order of those and that they are never equal.
Hoang Trinh
Hoang Trinh el 29 de Abr. de 2020
Editada: Walter Roberson el 29 de Abr. de 2020
Thank you so much for your help,
I have added four linear constraints for x55, x53, and x56 as follows:
% Main code for optimization
fun = @myFitness;
nvars = 82;
lb = [ 200 32 0.67 0.67 30100 348.6 0 0 450 32 0.67 0.67 348.6 0 0 0 0 0 0 0 0 366.7 366.7 366.7 366.7 366.7 366.7 366.7 366.7 0 0 100 100 10 5 5 0 0 0 2 2 2 2 2 50 0 0 0 16 200 5 5 5 5 5 5 0 5 5 20 20 20 2 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ] ;
ub = [ 1100 65 0.85 0.85 37400 739.2 0 0 1000 65 0.85 0.85 739.2 1 1 1 1 1 1 1 1 1833.33 1833.33 1833.33 1833.33 1833.33 1833.33 1833.33 1833.33 1 1 1100 1200 1100 50 50 1 1 0 400 400 400 400 50 1000 1 1 0 40 1260 10000 10000 1000 10000 1000 1000 1 10000 1000 300 300 300 500 600 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ] ;
% Nonlinear constraints
nonlcon = @nlcon;
% Linear constraints
A = zeros([74 82]) ;
A(1,2) = -1;
A(2,3) = -1;
A(3,4) = -1;
A(4,5) = -1;
A(5,6) = -1;
A(8,2) = 1 ;
A(9,3) = 1 ;
A(10,4) = 1 ;
A(11,5) = 1 ;
A(12,6) = 1 ;
A(13,10) = 1 ;
A(14,11) = 1 ;
A(15,12) = 1 ;
A(16,13) = 1 ;
A(17,10) = -1;
A(18,11) = -1;
A(19,12) = -1;
A(20,13) = -1;
A(45,9) = -1;
A(46,9) = 1 ;
A(49,9) = 1 ;
A(50,9) = -1 ;
A(47,1) = 1;
A(48,1) = -1;
A(52,1) = 21/8 ;
A(53,1) = 21/8 ;
A(54,1) = 21/8 ;
A(55,1) = 21/8 ;
A(56,1) = 21/8 ;
A(57,1) = 21/8 ;
A(58,1) = 21/8 ;
A(59,1) = 21/8 ;
A(60,1) = 5 ;
A(61,2) = 1 ;
A(62,1) = -1 ;
A(61,10) = -1 ;
A(62,9) = -7.5;
A(66,9) = -1;
A(68,9) = -0.6;
A(71,9) = 0.6;
A(29,14) = 1 ;
A(30,14) = -1 ;
A(29,15) = 1 ;
A(30,15) = -1 ;
A(31,16) = 1 ;
A(32,16) = -1 ;
A(31,17) = 1 ;
A(32,17) = -1 ;
A(33,18) = 1 ;
A(34,18) = -1 ;
A(33,19) = 1 ;
A(34,19) = -1 ;
A(35,20) = 1 ;
A(36,20) = -1 ;
A(35,21) = 1 ;
A(36,21) = -1 ;
A(52,22) = -1 ;
A(53,23) = -1 ;
A(54,24) = -1 ;
A(55,25) = -1 ;
A(56,26) = -1 ;
A(57,27) = -1 ;
A(58,28) = -1 ;
A(59,29) = -1 ;
A(60,24) = -1 ;
A(37,30) = 1 ;
A(38,30) = -1 ;
A(37,31) = 1 ;
A(38,31) = -1 ;
A(39,37) = 1 ;
A(40,37) = -1 ;
A(39,38) = 1 ;
A(40,38) = -1 ;
A(41,46) = 1 ;
A(42,46) = -1 ;
A(41,47) = 1 ;
A(42,47) = -1 ;
A(45,45) = 1 ;
A(46,45) = -1 ;
A(45,49) = 0.5;
A(46,49) = -0.5 ;
A(63,49) = 1.5 ;
A(65,49) = -1.5 ;
A(66,49) = 2 ;
A(67,49) = -15 ;
A(70,49) = 15 ;
A(64,46) = 20 ;
A(65,47) = 36 ;
A(23,49) = 1 ;
A(24,49) = -1 ;
A(25,50) = 1 ;
A(26,50) = -1 ;
A(1,65) = 32 ;
A(1,66) = 40 ;
A(1,67) = 50 ;
A(1,68) = 65 ;
A(2,65) = 0.85 ;
A(2,66) = 0.85 ;
A(2,67) = 0.85 ;
A(2,68) = 0.805 ;
A(3,65) = 0.826 ;
A(3,66) = 0.77 ;
A(3,67) = 0.7 ;
A(3,68) = 0.67 ;
A(4,65) = 30100 ;
A(4,66) = 32800 ;
A(4,67) = 34800 ;
A(4,68) = 37400 ;
A(5,65) = 348.6 ;
A(5,66) = 405 ;
A(5,67) = 513 ;
A(5,68) = 739.2 ;
A(6,65) = 1 ;
A(6,66) = 1 ;
A(6,67) = 1 ;
A(6,68) = 1 ;
A(7,65) = -1 ;
A(7,66) = -1 ;
A(7,67) = -1 ;
A(7,68) = -1 ;
A(8,65) = -32 ;
A(8,66) = -40 ;
A(8,67) = -50 ;
A(8,68) = -65 ;
A(9,65) = -0.85 ;
A(9,66) = -0.85 ;
A(9,67) = -0.85 ;
A(9,68) = -0.805 ;
A(10,65) = -0.826 ;
A(10,66) = -0.77 ;
A(10,67) = -0.7 ;
A(10,68) = -0.67 ;
A(11,65) = -30100 ;
A(11,66) = -32800 ;
A(11,67) = -34800 ;
A(11,68) = -37400 ;
A(12,65) = -348.6 ;
A(12,66) = -405 ;
A(12,67) = -513 ;
A(12,68) = -739.2 ;
A(13,69) = -32 ;
A(13,70) = -40 ;
A(13,71) = -50 ;
A(13,72) = -65 ;
A(14,69) = -0.85 ;
A(14,70) = -0.85 ;
A(14,71) = -0.85 ;
A(14,72) = -0.805 ;
A(15,69) = -0.826 ;
A(15,70) = -0.77 ;
A(15,71) = -0.7 ;
A(15,72) = -0.67 ;
A(16,69) = -348.6 ;
A(16,70) = -405 ;
A(16,71) = -513 ;
A(16,72) = -739.2 ;
A(17,69) = 32 ;
A(17,70) = 40 ;
A(17,71) = 50 ;
A(17,72) = 65 ;
A(18,69) = 0.85 ;
A(18,70) = 0.85 ;
A(18,71) = 0.85 ;
A(18,72) = 0.805 ;
A(19,69) = 0.826 ;
A(19,70) = 0.77 ;
A(19,71) = 0.7 ;
A(19,72) = 0.67 ;
A(20,69) = 348.6 ;
A(20,70) = 405 ;
A(20,71) = 513 ;
A(20,72) = 739.2 ;
A(21,69) = 1;
A(21,70) = 1;
A(21,71) = 1;
A(21,72) = 1;
A(22,69) = -1;
A(22,70) = -1;
A(22,71) = -1;
A(22,72) = -1;
A(23,73) = -16 ;
A(23,74) = -20 ;
A(23,75) = -24 ;
A(23,76) = -28 ;
A(23,77) = -32 ;
A(23,78) = -36 ;
A(23,79) = -40 ;
A(24,73) = 16 ;
A(24,74) = 20 ;
A(24,75) = 24 ;
A(24,76) = 28 ;
A(24,77) = 32 ;
A(24,78) = 36 ;
A(24,79) = 40 ;
A(25,73) = -200 ;
A(25,74) = -310 ;
A(25,75) = -450 ;
A(25,76) = -620 ;
A(25,77) = -800 ;
A(25,78) = -1020 ;
A(25,79) = -1260 ;
A(26,73) = 200 ;
A(26,74) = 310 ;
A(26,75) = 450 ;
A(26,76) = 620 ;
A(26,77) = 800 ;
A(26,78) = 1020 ;
A(26,79) = 1260 ;
A(27,73) = 1;
A(27,74) = 1;
A(27,75) = 1;
A(27,76) = 1;
A(27,77) = 1;
A(27,78) = 1 ;
A(27,79) = 1 ;
A(28,73) = -1;
A(28,74) = -1;
A(28,75) = -1;
A(28,76) = -1;
A(28,77) = -1;
A(28,78) = -1 ;
A(28,79) = -1 ;
A(43,80) = 1 ;
A(43,81) = 1 ;
A(43,82) = 1 ;
A(44,80) = -1 ;
A(44,81) = -1 ;
A(44,82) = -1 ;
A(69,80) = 150 ;
A(70,81) = 450 ;
A(71,82) = 450 ;
A(67,64) = 1 ;
A(68,64) = 1 ;
A(69,64) = -1 ;
A(70,64) = -1 ;
A(71,64) = -1 ;
A(63,62) = -1 ;
A(64,62) = 1 ;
A(65,62) = 1 ;
A(66,62) = 1 ;
A(47,60) = -5 ;
A(48,60) = 5 ;
A(49,61) = -5 ;
A(50,61) = 5 ;
A(51,55) = 1;
A(51,53) = -1;
A(72,55) = 1;
A(72,53) = -1;
A(73,55) = 1;
A(73,56) = -1;
A(74,55) = -1;
A(74,56) = 1;
b = [ 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 -45 45 0 0 0 0 0 0 0 0 0 0 0 0 0 205 0 -3500 0 60 36 -90 0 0 -150 450 450 0 0 0 ]' ;
IntCon = [1 2 5 9 10 14 15 16 17 18 19 20 21 30 31 37 38 46 47 49 50 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82] ;
opts = optimoptions('ga', ...
'PopulationSize', 1000, ...
'MaxGenerations', 500, ...
'EliteCount', 10, ...
'FunctionTolerance', 1e-8, ...
'PlotFcn', @gaplotbestf);
[x fval] = ga(fun,nvars,A,b,[],[],lb,ub,nonlcon,IntCon);
But it still resulted in an error message. :(
Kind Regards,
A(51,55) = 1;
A(51,53) = -1;
That expresses that (1) * x(55) + (-1) * x(53) <= b(51) . b(51) is 0, so you are expressing that x(55)-x(53) <= 0, which is to say that x(55) <= x(53) . But that still allows them to be equal, and when they are equal, you get the division by 0.
Linear constraints are A*x' <= b not A*x' < b.
If you want < then you need to make b(51) negative, even if it is only -realmin()
Hoang Trinh
Hoang Trinh el 30 de Abr. de 2020
I have made some changes like this:
A(51,55) = 1;
A(51,53) = -1;
A(72,56) = 1;
A(72,55) = -1;
with
b(51) = 0.1 ;
b(72) = 0.1 ;
So now, x(55) - x(53) <= 0.1 ; and x(56) - x(55) <= 0.1;
Still, the error has not been fixed. :(

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Preguntada:

el 28 de Abr. de 2020

Comentada:

el 30 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by