Use Matlab to implement the AHP algorithm

Source: Internet
Author: User

Clc, clear
Fidbench fopen('txt3.txt ', 'R ');
N1 = 6; n2 = 3;
A = [];
For I = 1: n1
Tmp = str2num (fgetl (fid ));
A = [a; tmp]; % read criterion layer Judgment Matrix
End

For I = 1: n1
Str1 = char (['B', int2str (I), '= [];']);
Str2 = char (['B', int2str (I), '= [B', int2str (I), '; tmp];']);
Eval (str1 );
For j = 1: n2
Tmp = str2num (fgetl (fid ));
Eval (str2); % judgment matrix of the read solution Layer
End
End

Ri = [0.58, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45,]; % consistency indicator
[X, y] = eig ();
Lamda = max (diag (y ));
Num = find (diag (y) = lamda );
W0 = x (:, num)/sum (x (:, num); % w0 indicates that the feature vector is divided by the algebraic sum of the feature vector, indicating that the Hierarchical Single sorting

Cr0 = (lamda-n1)/(n1-1)/ri (n1) % indicates the consistency test of the criterion layer Judgment Matrix
For I = 1: n1
[X, y] = eig (eval (char (['B', int2str (I)]);
Lamda = max (diag (y ));
Num = find (diag (y) = lamda );
W1 (:, I) = x (:, num)/sum (x (:, num); % indicates the ranking of each judgment matrix in the solution layer, the hierarchical total sorting matrix equals to the criterion layer level single sorting multiplied by the scheme previous Hierarchical Single sorting
Cr1 (I) = (lamda-n2)/(n2-1)/ri (n2); % indicates the consistency test of each judgment matrix in the scheme Layer
End
Cr0, cr1, ts = w1 * w0, cr = cr1 * w0 % print out consistency test criteria and overall hierarchy sorting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.