MATLAB Answers

Blending Problem / Weighted Average

조회 수: 6(최근 30일)
Ron
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

댓글을 달려면 로그인하십시오.

답변(1개)

Image Analyst
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

Ron
Ron 1 Mar 2016
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.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by