mixed integer program trouble defining proper objective function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
John D'Errico
le 5 Mai 2016
Modifié(e) : John D'Errico
le 5 Mai 2016
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.)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!