How can I define a constraint to my optimization problem?
Mostrar comentarios más antiguos
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.
2 comentarios
OK, well you need to tell us which information in the error message contradicts what you intended to happen? If you didn't intend the left hand side xtemp(:,:,ii) at line 22 to be 90x1 then what did you intend? Similarly if you didn't intend the right hand side d_ik to be 5x3 what did you intend for that?
Alperen BAL
el 3 de Dic. de 2018
Respuesta aceptada
Más respuestas (1)
Alan Weiss
el 4 de Dic. de 2018
0 votos
Perhaps you would find it easier to follow the problem-based version of the example. It is indeed difficult to get the constraint matrices straight using the solver-based approach.
If you eventually have to convert the problem to a solver-based approach, you can first write the model in the problem-based approach and then convert it using prob2struct.
Alan Weiss
MATLAB mathematical toolbox documentation
1 comentario
Alperen BAL
el 4 de Dic. de 2018
Categorías
Más información sobre Problem-Based Optimization Setup en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!