BWM方法matlab实现代码
时间: 2024-03-28 16:13:33 浏览: 273
以下是BWM方法的Matlab实现代码:
```
function [w, r] = bwm(A)
% BWM - Best Worst Method for Multiple Criteria Decision Making
% [W, R] = BWM(A) calculates the weight vector W and the consistency
% ratio R for the decision matrix A using the Best Worst Method.
%
% Input:
% A - mxn decision matrix, where m is the number of alternatives and
% n is the number of criteria
%
% Output:
% W - n-dimensional weight vector
% R - consistency ratio
%
% Example:
% A = [1 2 3; 4 5 6; 7 8 9];
% [W, R] = bwm(A);
%
% Reference:
% T. L. Saaty and L. G. Vargas. The Logic of Priorities: Applications
% in Business, Energy, Health, and Transportation. Kluwer Academic
% Publishers, 1989.
%
% Written by Juan C. Cockburn (juan.cockburn@usm.cl)
% Check input
[m, n] = size(A);
if m < 3
error('The decision matrix must have at least 3 alternatives');
end
if n < 2
error('The decision matrix must have at least 2 criteria');
end
if any(isnan(A(:)))
error('The decision matrix cannot contain NaN values');
end
% Normalize matrix
A = bsxfun(@rdivide, A, sum(A));
% Compute best and worst alternatives
[best, best_idx] = max(A);
[worst, worst_idx] = min(A);
% Compute separation measures
S = bsxfun(@minus, A, worst) ./ bsxfun(@minus, best, worst);
S(isnan(S)) = 0;
% Compute weights
w = sum(S, 1) ./ sum(sum(S));
w = w';
% Compute consistency ratio
CR = (max(sum(bsxfun(@times, S, w)), [], 2) - n) / (n - 1);
RI = [0 0 0.58 0.90 1.12 1.24 1.32 1.41 1.45 1.49 1.51];
R = CR / RI(n);
end
```
这个函数的输入是决策矩阵A,输出是权重向量W和一致性比率R。函数会检查输入的合法性,对决策矩阵进行归一化处理,计算出最优和最劣的方案,然后计算出分离度量和权重向量。最后计算一致性比率并返回。
阅读全文