이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
why ga become infeasible after increasing the size of variables
조회 수: 1 (최근 30일)
이전 댓글 표시
BOWEN LI
2019년 9월 2일
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!
댓글 수: 12
BOWEN LI
2019년 9월 2일
Hi, there's actually no error messages, but the exitflag is -2 which is No feasible point found. And the fval changes dramatically when i increase the number of variables.
Walter Roberson
2019년 9월 2일
I don't think we have enough information about your setup. As outside observers, we have no reason to know that any feasible point truly exists.
BOWEN LI
2019년 9월 2일
Hi I'm sorry that my variables are setup in a relativley comlplicated way, but if you don't mind, is it possible for me to post my code here? The setup may seem complicated but the mechanisms of it is straight forward. Thanks so much for this!
totalcost912019 is my function file
thesis_code2 is the ga file.
revconstr is the unlinear constraint file
I have set up the paremeters to those which yield the infeasible outcome.
Walter Roberson
2019년 9월 2일
Look at your code for constructing A4:
A4=[];
for t=1:N
for i=1:N
for j= i+1:N
A_temp=zeros(1,(N^2+N^3));
if A_temp((i+1+(t-1)*N):(j+(t-1)*N))==1
A_temp(((N^2)+(t-1)*(N^2)+(i-1)*N+j))=1;
else
A_temp(((N^2)+(t-1)*(N^2)+(i-1)*N+j))=0;
end
A4=[A4;A_temp];
end
end
end
You zero out all of A_temp every j iteration, so any changes to A_temp are going to be lost between rounds. Therefore A_temp(whatever) cannot == 1 in any position, so you never assign 1 to any A_temp position. Therefore the A4 that you build is going to be all 0. You are building N^3 rows of zeros to put on the non-linear constraints. That is not illegal, but it is a waste.
BOWEN LI
2019년 9월 5일
Sorry for the late reply. Thank you for pointing out this mistake, i did not notice this one. Thank you!
Walter Roberson
2019년 9월 5일
편집: Walter Roberson
2019년 9월 5일
Note that this does not explain why the constraints cannot be met.
When looked at the other linear constraints, it looked to me as if they could not be met, that they were internally inconsistent. However, I was not able to prove that in the time I spent.
BOWEN LI
2019년 9월 6일
Hi, I just found out that my answer is complex numbers which means that maybe there are negative numbers when i calculate by using "sqrt" in my function file. But i have some problem to found out where or which step that the problem occurs.
Walter Roberson
2019년 9월 7일
I just had another glance at your code and noticed the section
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/8)*(1+sij(:,:,t-1).*r2).^t);
cc(t)=(y(:,1,t)-y(:,1,t-1)).'*d*k;%construction cost
end
%end
hb1(t)=sum(2*(1-yi(1,:,t))*d./vb)+sum((1-yi(1,:,t))*td)*ubc; %bus headway
hb2(t)=sum(sum((1-yi(:,:,t)).*qij(:,:,t)));
You are using the value of t after the end of the immediately proceeding for t=1:N loop. MATLAB does define a meaning for that: after a for loop, the loop index is left as the last value it was assigned in the loop. For example,
for K = 1 : 10
K = 11;
end
Here, K is initialized to 1 and the K=11 assignment is done. But for keeps internal track of the value of the loop variable and knows that it just did 1, and increments that internal counter to 2, finds that the 2 is within range, and assigns that 2 to K, making K=2, overwriting the K=11 value. Then when K=2, the loop assigns K=11 . But for is keeping track internally, increments its internal counter to 3, finds that 3 is in range, and assigns that 3 to K, making K=3, overwriting the K=11 that was just done. And so on. Eventually the internal counter is incremented to 10, and that is found to be within range, and K=10 is done. Then the loop body does K=11 because of the assignment there. The internal counter that was 10 is then incremented, and 11 is found to be outside of the loop bounds, and so the value of K is not updated, leaving the in-loop assignment K=11 as the current value of K.
So it is all well defined in MATLAB, but most people do not understand the details, and it is not a good idea to count on the details being clear to the readers (and to you, the author of the code.)
This matters because your %end is commented out, so the for t loop has not ended there. Your code continues on to
hb1(t)=sum(2*(1-yi(1,:,t))*d./vb)+sum((1-yi(1,:,t))*td)*ubc; %bus headway
hb2(t)=sum(sum((1-yi(:,:,t)).*qij(:,:,t)));
% hb(t)=2*sqrt(hb1(t)+hb2(t));
for t=1:N %bus headway requirement
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)))
else
hb(t)=cb/max(max(qij(:,:,t)));
end
end
You are still inside the for t loop, and you start another for t loop. The effects are defined in MATLAB -- as far as MATLAB is concerned this is just like the K=11 case that I had in my example, where you are assigning something to the loop variable inside the loop. Because of the internal track it is keeping of each loop counter, MATLAB is able to handle the outer for t loop, but by now everyone is confused over what is supposed to be happening.
Then after the inner for t loop you continue to
hr1(t)=((2*yi(1,:,t)*d)/vr)+sum(sum((0.1+yi(1,:,t))*td))*nc*uc;
hr2(t)=sum(sum((0.1+y(:,:,t)).*qij(:,:,t)));
As described above, t will have been left the last value assigned by the inner for t=1:N loop, so t will equal N at that point, making those two lines equivalent to
hr1(N)=((2*yi(1,:,N)*d)/vr)+sum(sum((0.1+yi(1,:,N))*td))*nc*uc;
hr2(N)=sum(sum((0.1+y(:,:,N)).*qij(:,:,N)));
but is that really what you want there? Or do you want the t to be the t related to the outer for t loop?
BOWEN LI
2019년 9월 7일
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.
hb1(t)=sum(2*(1-yi(1,:,t))*d./vb)+sum((1-yi(1,:,t))*td)*ubc; %bus headway
hb2(t)=sum(sum((1-yi(:,:,t)).*qij(:,:,t)));
hb(t)=2*sqrt(hb1(t)+hb2(t));
%for t=1:N %bus headway requirement
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));
%for t=1:N %rail headway requirement
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
hb1(t)=sum(2*(1-yi(1,:,t))*d./vb)+sum((1-yi(1,:,t))*td)*ubc; %bus headway
hb2(t)=sum(sum((1-yi(:,:,t)).*qij(:,:,t)));
hb(t)=2*sqrt(hb1(t)+hb2(t));
%for t=1:N %bus headway requirement
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));
%for t=1:N %rail headway requirement
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.
Thank you as always for your answer!
Walter Roberson
2019년 9월 7일
Could you post your complete adjusted totalcost file?
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
2019년 9월 7일
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!
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)