MATLAB Answers

0

Blending Problem / Weighted Average

Ron 님이 질문을 제출함. 27 Feb 2016
최근 활동 Ron 님이 댓글을 추가함. 1 Mar 2016
I have a blending problems where I have a selection of containers, each with a weight and a specific attribute. I have to combine the containers so that the weight is between a lower and upper value and that the weighted average of the attribute is between a lower and upper value. My objective is to minimize the containers that need to be opened.
The attribute in the first row of Att applies to all the containers in the first row of W and similarly for the rest of the rows.
W=[1,1,4,5;3,9,10,4;1,7,1,8]
Att=[4;1;3]
I have set up the A matrix so far as the top two rows being the W.*Att and the bottom two rows being the W matrices. The first and third rows are negative to account for greater than the lower attribute and weight constraints.
[m,n]=size(W);
W_column=W(:);
Att_column=repmat(Att,n,1);
A=[-W_column.*Att_column,W_column.*Att_column,-W_column,W_column]';
My problem is formulating the attribute weighted average in the "A" matrix for the intlinprog solver. In general it should be W1*Att1*X1+W2*Att2*X2.../sum(W) to get the weighted average. The X would either be a 1 if the container would be used and a 0 if not used. I cannot figure out how to do the sum(W) piece in a matrix format. Thank you for any help provided!

  댓글 수: 0

로그인 to comment.

답변 수: 1

Image Analyst 님의 답변 28 Feb 2016

Try this:
W=[1, 1, 4, 5;
3, 9, 10, 4;
1, 7, 1, 8]
Att=[4;1;3]
X = [1;1;1]
[rows, columns] = size(W);
Att_column = repmat(Att, 1, columns);
A = W .* Att_column
% Now sum across columns, multiply by X,
% and divide by the sum of all W elements.
A= sum(A, 2) .* X / sum(W(:))

  댓글 수: 1

I think your matrix multiplication is a little more elegant than mine, and is a good idea. The idea in the example is that I have 12 binary variable (all the elements in W) that have to be chosen to meet the specifications of a blend. Some of them will not be chosen, which would removed their weights from the sum((W) portion. X should really be a 12,1 vector, using the optimization functions.

로그인 to comment.



Translated by