# why ga become infeasible after increasing the size of variables

1 view (last 30 days)
BOWEN LI on 2 Sep 2019
Commented: BOWEN LI on 7 Sep 2019
Hi, I am trying to use ga to solve a mixed integer optimization problem. I have a problem that ga became infeasible after i enlarged the size of my varibles. For example, if the number of varibles are 80 or 150, ga runs very good. But when it comes to 252 variables, ga immediately becomes infeasible.In my problem, i set my number of variables to "N" which can be changed before the optimization.
Thank you!

BOWEN LI on 7 Sep 2019
Hi Walter, thank you so much and I carefully read your answer. Thanks for your example and I figured out what your example says. Actually i want all "t" that changes simultaneously from 1:N.
for this part I try to define qij and cc(t) which i will use in my function.
if t==1
qij(:,:,t)=qij0;
yi(:,:,t)=zeros(N);
sij(:,:,t)=zeros(N);
cc(t)=y(:,1,t).'*d*k;
else
qij(:,:,t)=(qij(:,:,t-1).*((1+r1).^t)).*((1/(2*N))*(1+sij(:,:,t-1).*r2).^t);
cc(t)=(y(:,1,t)-y(:,1,t-1)).'*d*k;%construction cost
end
for this part I'm trying to set the rule for hb(t), as you see in the "if else" statement.
hb2(t)=sum(sum((1-yi(:,:,t)).*qij(:,:,t)));
hb(t)=2*sqrt(hb1(t)+hb2(t));
if hb(t)==2*sqrt(hb1(t)+hb2(t))>=0.02
hb(t)=2*sqrt(hb1(t)+hb2(t));
else
hb(t)=0.02;
end
if hb(t)==2*sqrt(hb1(t)+hb2(t))>=nc*ct/max(max(qij(:,:,t)))
hb(t)=cb/max(max(qij(:,:,t)));
end
for this part I'm trying to set the rule for hr(t), as you see in the "if else" statement.
hr1(t)=((2*yi(1,:,t)*d)/vr)+sum(sum((0.1+yi(1,:,t))*td))*nc*uc;
hr2(t)=sum(sum((0.1+yi(:,:,t)).*qij(:,:,t)));
hr(t)=2*sqrt(hr1(t)/hr2(t));
if hr(t)==hr1(t)+hr2(t)>=0.02 %hours
hr(t)=2*sqrt(hr1(t)/hr2(t));
else
hr(t)=0.02;
end
if hr(t)==hr1(t)+hr2(t)>=nc*ct/max(max(qij(:,:,t)))
hr(t)=cb/max(max(qij(:,:,t)));
end
And this part is my equations about time (t), and my objective function is f(t) which is the sum of all previous equations.
cu(t)=sum(sum(qij(:,:,t).*(1-yi(:,:,t))))*(hb(t)/2)*(u/4)+sum(sum(qij(:,:,t).*yi(:,:,t)))*(hr(t)/2)*(u/4); %user wait cost
ci1(t)=((diag((1-yi(:,:,t))*qij(:,:,t))).'*(d+td))*(u/vb);
ci2(t)=((diag(yi(:,:,t)*qij(:,:,t))).'*(d+td)).*(u+vb);
ci(t)=ci1(t)+ci2(t);
rb(t)=2*(1-yi(1,:,t))*d/vb+2*sum((1-yi(1,:,t))*td);%bus round trip time
rr(t)=2*((yi(1,:,t)*d)/vr)+sum((yi(1,:,t))*td); %rail round trip time
cv1(t)=(rb(t)/hb(t))*ubc;
cv2(t)=(rr(t)/hr(t))*nc*uc;%vehicle operating speed
cv(t)=cv1(t)+cv2(t);
cm(t)=(yi(1,:,t)*d)*L;%maintenance cost
f(t)=cu(t)+ci(t)+cv(t)+cm(t)+cc(t);
lastly, i sum up all time periods of f(t) as
f = sum(f)*((1+rs)^-N);
I did confuse about how to use the "for loop" in my function structure. My objective function is f(t) which is about time (t) from 1 to N. And f(t) is composed by cu(t),ci(t),cv(t),cm(t), and cc(t). Before just add them up, I set some rules for some terms like hb(t), hr(t) which are used inside of the equations. So generally "t" i supposed to make it change simultaneously for each equation with respect to "t". So i changed my code that seperates these part from each other by set "for" loop for each of these parts as:
for t=1:N
if t==1
qij(:,:,t)=qij0;
yi(:,:,t)=zeros(N);
sij(:,:,t)=zeros(N);
cc(t)=y(:,1,t).'*d*k;
else
qij(:,:,t)=(qij(:,:,t-1).*((1+r1).^t)).*((1/(2*N))*(1+sij(:,:,t-1).*r2).^t);
cc(t)=(y(:,1,t)-y(:,1,t-1)).'*d*k;%construction cost
end
end
for t=1:N
hb2(t)=sum(sum((1-yi(:,:,t)).*qij(:,:,t)));
hb(t)=2*sqrt(hb1(t)+hb2(t));
if hb(t)==2*sqrt(hb1(t)+hb2(t))>=0.02
hb(t)=2*sqrt(hb1(t)+hb2(t));
else
hb(t)=0.02;
end
if hb(t)==2*sqrt(hb1(t)+hb2(t))>=nc*ct/max(max(qij(:,:,t)))
hb(t)=cb/max(max(qij(:,:,t)));
end
end
for t=1:N
hr1(t)=((2*yi(1,:,t)*d)/vr)+sum(sum((0.1+yi(1,:,t))*td))*nc*uc;
hr2(t)=sum(sum((0.1+yi(:,:,t)).*qij(:,:,t)));
hr(t)=2*sqrt(hr1(t)/hr2(t));
if hr(t)==hr1(t)+hr2(t)>=0.02 %hours
hr(t)=2*sqrt(hr1(t)/hr2(t));
else
hr(t)=0.02;
end
if hr(t)==hr1(t)+hr2(t)>=nc*ct/max(max(qij(:,:,t)))
hr(t)=cb/max(max(qij(:,:,t)));
end
end
for t=1:N
cu(t)=sum(sum(qij(:,:,t).*(1-yi(:,:,t))))*(hb(t)/2)*(u/4)+sum(sum(qij(:,:,t).*yi(:,:,t)))*(hr(t)/2)*(u/4); %user wait cost
ci1(t)=((diag((1-yi(:,:,t))*qij(:,:,t))).'*(d+td))*(u/vb);
ci2(t)=((diag(yi(:,:,t)*qij(:,:,t))).'*(d+td)).*(u+vb);
ci(t)=ci1(t)+ci2(t);
rb(t)=2*(1-yi(1,:,t))*d/vb+2*sum((1-yi(1,:,t))*td);%bus round trip time
rr(t)=2*((yi(1,:,t)*d)/vr)+sum((yi(1,:,t))*td); %rail round trip time
cv1(t)=(rb(t)/hb(t))*ubc;
cv2(t)=(rr(t)/hr(t))*nc*uc;%vehicle operating speed
cv(t)=cv1(t)+cv2(t);
cm(t)=(yi(1,:,t)*d)*L;%maintenance cost
f(t)=cu(t)+ci(t)+cv(t)+cm(t)+cc(t);
end
f = sum(f)*((1+rs)^-N);
but i still got the similar result, infeasible solutions and complex fval number.
Walter Roberson on 7 Sep 2019
My testing before strongly suggested that your linear constraints cannot be met, so it would not matter what your function calculated (provided the result was not infinite or nan) and you would still get told it was infeasible.
BOWEN LI on 7 Sep 2019
Sure no problem. totalcost912019.m is the adjusted file.
I put my constraints in the thesis_code2 file.
My linear constriants basically says that:
A1: yi(: , :, t) - yi(:, :, t-1) >= 0 (t=2:N)
A1sub: sij(: , :, t) - sij(:, :, t-1) >= 0 (t=2:N)
A2: for each sij(:, :, t) matrix, the upper and lower half that symmetry to the diagonal are same
A3: negative of A2
A4: for each time period(t), if yi to yj are all "1", then sij is 1, 0 otherwise.
Since the constraints are created based on the paper I referenced which has A1 but not A2 A3 and A4. And based on my x outcome, at least A1 is met. However, A2 - A4, especially A4, should be met in my problem.
Thank you!