mixed integer program trouble defining proper objective function
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello guys I'm new in matlab and I am working on writing a mixed linear integer program that solves for x(binary matrix) 181x80 and y (integer matrix with upper bounds determined by a previous function) 181x80.
Since I've been working on it I've realized that intlinprog has to have the decision variables written as a single vector so I combined x and y to form z.
My issue is that the objective function is Max = x.*y.*Price(third matrix of same size) of the same sixe. When I try to run it, I get the error that I should only need x integer variables. So it looks like I am not writing the objective function properly to also show that y are integer variables as well and need to be solved for the model.
Here is some of my code. Also It is messy and not very efficient so any pointers there will be appreciated.
x=ones(181,80);
y=Pdist;
x2=cat(3,x,y);
z=reshape(x2,1,[]);
revenue= x.*y.*Pricematrix;
for ii=1:181
for jj=1:80
revenue=x.*y.*Pricematrix;
end
end
cleary=zeros(181,80);
clearz=zeros(181,80);
lbx=zeros(181,80);
lby=zeros(181,80);
lb=[lbx(:);lby(:)]';
uby=ones(181,80);
ubz=Pdist;
ub=cat(3,uby,ubz)
ubv=reshape(ub,1,[]);
Aeq = spalloc(181,80,1); % nPeriods*nGens inequalities
counter = 1;
for ii = 1:181;
temp = cleary;
temp(ii) = 1;
addrow = temp(:)';
Aeq(:)= sparse(addrow);
counter = counter + 1;
end
beq = ones(181,1);
f=-revenue(:);
intcon=length(z);
options=optimoptions('intlinprog','display','final');
[z,fval,eflag,output]=intlinprog(f,intcon,[],[],Aeq,beq,lb,ubv,options);
There are other constraints that I need to add but I do not understand why it does not recognize that it needs coefficients for x and y variables not just x. I should have 181x80x2 total variables but it thinks I only have 181x80 variables.
댓글 수: 0
채택된 답변
John D'Errico
2016년 5월 5일
편집: John D'Errico
2016년 5월 5일
If x and y are both variables to be estimated, then exactly how is the objective x.*y a LINEAR problem? Must be the new math. That seems to me to be nonlinear. :)
You need to use a tool that can handle a nonlinear objective, subject to the appropriate constraints. That is not intlinprog. (nor would fmincon suffice.)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Programming and Mixed-Integer Linear Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!