MATLAB: How to define a constraint to the optimization problem

constraintintconmilpoptimization

Hi,
I am trying to write my optimization model by following the way of Factory, Warehouse, Sales Allocation Model: Solver-Based example. Unfortunately, I have this error:
% Unable to perform assignment because the size of the left side is 90-by-1 and the size of the right side is 5-by-3.
%
% Error in Constraint (line 28)
% xtemp(:,:,ii) = d_ik;
The optimization model:
This is the code I tried to write:
i = 5; k = 3; t = 6;
d_ik = [1,5,6; 3,6,3; 5,7,0; 6,3,9; 2,8,8];
TR_t = [1000, 1000, 1000, 1000, 1000, 1000];
X_ikt = zeros(i,k,t); % Allocate arrays
for ii = 1:i
for jj = 1:k
for kk = 1:t
obj(ii,jj,kk) = 1;
end
end
end
obj = X_ikt(:);
matwid = length(obj);
Aineq = spalloc(t,matwid,i*k*t);
bineq = zeros(t,1);
clearer1 = zeros(size(obj));
clearer12 = clearer1(:);
counter = 1;
for ii = 1:t
xtemp = clearer1;
xtemp(:,:,ii) = d_ik;
xtemp = sparse(xtemp(:)); % Convert to sparse
Aineq(counter,:) = xtemp'; % Fill in the row
bineq(counter) = TR(ii)';
counter = counter + 1;
end
intcon = t+1:length(obj);
lb = zeros(length(obj),1);
ub = Inf(length(obj),1);
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
[solution,fval,exitflag,output] = intlinprog(obj,intcon,Aineq,bineq,lb,ub,opts);
PS: I am intended to write my model like Factory, Warehouse, Sales Allocation Model: Solver-Based example to obtain computational efficiency for large scale models and to solve using different techniques such as Genetic Algorithm.

Best Answer

Aineq=kron(speye(t),d_ik(:).');
bineq=TR;
Note also that your call to intlinprog is the wrong syntax. You haven't specified the equality constraints (or indicated that there are none),
intlinprog(-obj,intcon,Aineq,bineq,[],[],lb,ub,opts)
Related Question