# the GA shows the problem with "Failure in initial user-supplied nonlinear constraint function evaluation. "

23 views (last 30 days)
Nathan Yang on 7 Oct 2019
Answered: Alan Weiss on 7 Oct 2019
Hi guys I'm trying use GA as my solver to solve a nonlinear inter problem. However I met a issue below,
Once I remove my nonlinear constraint, run the code again, there was another issue
I don't understand why GA cannot have equality constraints and interger at the same time. So I want to know what is the problem of my code , Thanks
Here is my code: nonlinear constraints
function ceq= mycon_try1(x)
%% first day,year
for i = 0:23
ceq(1+8*i) =x(1+19*i)-(2.5)*(x(2307)+1)*(x(9+19*i)-x(10+19*i)) ;
ceq(2+8*i) =x(2+19*i)-(1.667)*(x(2308)+1)*(x(9+19*i)-x(12+19*i)) ;
ceq(3+8*i) =x(3+19*i)-(5)*(x(2309)+1)*(x(9+19*i)-x(13+19*i)) ;
ceq(4+8*i) =x(4+19*i)-(5)*(x(2310)+1)*(x(10+19*i)-x(11+19*i)) ;
ceq(5+8*i) =x(5+19*i)-(2.5)*(x(2311)+1)*(x(10+19*i)-x(12+19*i)) ;
ceq(6+8*i) =x(6+19*i)-(3.3)*(x(2312)+0)*(x(10+19*i)-x(14+19*i)) ;
ceq(7+8*i) =x(7+19*i)-(5)*(x(2313)+1)*(x(11+19*i)-x(13+19*i)) ;
ceq(8+8*i) =x(8+19*i)-(3.3)*(x(2314)+0)*(x(12+19*i)-x(14+19*i)) ;
end
for j = 0:23
ceq(193+8*j) =x(461+19*j)-(2.5)*(x(2307)+1)*(x(469+19*j)-x(470+19*j)) ;
ceq(194+8*j) =x(462+19*j)-(1.667)*(x(2308)+1)*(x(469+19*j)-x(472+19*j)) ;
ceq(195+8*j) =x(463+19*j)-(5)*(x(2309)+1)*(x(469+19*j)-x(473+19*j)) ;
ceq(196+8*j) =x(464+19*j)-(5)*(x(2310)+1)*(x(470+19*j)-x(471+19*j)) ;
ceq(197+8*j) =x(465+19*j)-(2.5)*(x(2311)+1)*(x(470+19*j)-x(472+19*j)) ;
ceq(198+8*j) =x(466+19*j)-(3.3)*(x(2312)+0)*(x(470+19*j)-x(474+19*j)) ;
ceq(199+8*j) =x(467+19*j)-(5)*(x(2313)+1)*(x(471+19*j)-x(473+19*j)) ;
ceq(200+8*j) =x(468+19*j)-(3.3)*(x(2314)+0)*(x(472+19*j)-x(474+19*j)) ;
end
for k = 0:23
ceq(385+8*k) =x(921+19*k)-(2.5)*(x(2307)+1)*(x(929+19*k)-x(930+19*k)) ;
ceq(386+8*k) =x(922+19*k)-(1.667)*(x(2308)+1)*(x(929+19*k)-x(932+19*k)) ;
ceq(387+8*k) =x(923+19*k)-(5)*(x(2309)+1)*(x(929+19*k)-x(933+19*k)) ;
ceq(388+8*k) =x(924+19*k)-(5)*(x(2310)+1)*(x(930+19*k)-x(931+19*k)) ;
ceq(389+8*k) =x(925+19*k)-(2.5)*(x(2311)+1)*(x(930+19*k)-x(932+19*k)) ;
ceq(390+8*k) =x(926+19*k)-(3.3)*(x(2312)+0)*(x(930+19*k)-x(934+19*k)) ;
ceq(391+8*k) =x(927+19*k)-(5)*(x(2313)+1)*(x(931+19*k)-x(933+19*k)) ;
ceq(392+8*k) =x(928+19*k)-(3.3)*(x(2314)+0)*(x(932+19*k)-x(934+19*k)) ;
end
for l = 0:23
ceq(577+8*l) =x(1381+19*l)-(2.5)*(x(2307)+1)*(x(1389+19*l)-x(1390+19*l)) ;
ceq(578+8*l) =x(1382+19*l)-(1.667)*(x(2308)+1)*(x(1389+19*l)-x(1392+19*l)) ;
ceq(579+8*l) =x(1383+19*l)-(5)*(x(2309)+1)*(x(1389+19*l)-x(1393+19*l)) ;
ceq(580+8*l) =x(1384+19*l)-(5)*(x(2310)+1)*(x(1390+19*l)-x(1391+19*l)) ;
ceq(581+8*l) =x(1385+19*l)-(2.5)*(x(2311)+1)*(x(1390+19*l)-x(1392+19*l)) ;
ceq(582+8*l) =x(1386+19*l)-(3.3)*(x(2312)+0)*(x(1390+19*l)-x(1394+19*l)) ;
ceq(583+8*l) =x(1387+19*l)-(5)*(x(2313)+1)*(x(1391+19*l)-x(1393+19*l)) ;
ceq(584+8*l) =x(1388+19*l)-(3.3)*(x(2314)+0)*(x(1392+19*l)-x(1394+19*l)) ;
end
for m = 0:23
ceq(769+8*m) =x(1841+19*m)-(2.5)*(x(2307)+1)*(x(1849+19*m)-x(1850+19*m)) ;
ceq(770+8*m) =x(1842+19*m)-(1.667)*(x(2308)+1)*(x(1849+19*m)-x(1852+19*m)) ;
ceq(771+8*m) =x(1843+19*m)-(5)*(x(2309)+1)*(x(1849+19*m)-x(1853+19*m)) ;
ceq(772+8*m) =x(1844+19*m)-(5)*(x(2310)+1)*(x(1850+19*m)-x(1851+19*m)) ;
ceq(773+8*m) =x(1845+19*m)-(2.5)*(x(2311)+1)*(x(1850+19*m)-x(1852+19*m)) ;
ceq(774+8*m) =x(1846+19*m)-(3.3)*(x(2312)+0)*(x(1850+19*m)-x(1854+19*m)) ;
ceq(775+8*m) =x(1847+19*m)-(5)*(x(2313)+1)*(x(1851+19*m)-x(1853+19*m)) ;
ceq(776+8*m) =x(1848+19*m)-(3.3)*(x(2314)+0)*(x(1852+19*m)-x(1854+19*m)) ;
end
main code as shown here:
A_total = [Aa_1;Aa_2];
B_1 = [100;100;100;100;100;0;100;0]; B1 = repmat(B_1,24*5*2,1);
B2 = [repmat(Pg_max1,24*5,1);repmat(Pg_max2,24*5,1);repmat(Pg_max3,24*5,1)]; B3 = zeros(12,1);
B4 = zeros(120,1); B5 = B4; B6 = zeros(4,1);
B7 = zeros(120,1); B8 = zeros(120,1);
%B_total = [B1;B2;B3;B4;B5;B6;B7;B8];
B_total = [B1];
fun = @myfun_try2;
nonlcon = @mycon_try1;
Intcon = [457:460 917:920 1377:1380 1837:1840 2297:2314];
[x,fval] = ga(fun,2314,A_total,B_total,Aeq_total,beq_total,lb_total,ub_total,nonlcon,Intcon);

Alan Weiss on 7 Oct 2019
Please read the documentation on Mixed Integer Optimization. The solver truly does not accept equality constraints along with integer constraints, though you will find some potential workarounds in that documentation.
For your particular equality constraints, which seem at first glance to be quadratic, you might be able to solve for some variables in terms of other variables outside of your setup, then reduce the number of problem variables and try without imposing the constraints in ga. But I am not sure how feasible this is.
Alan Weiss
MATLAB mathematical toolbox documentation