Blending Problem / Weighted Average
3 次查看(过去 30 天)
显示 更早的评论
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
2016-2-28
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(:))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genomics and Next Generation Sequencing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!