Article From:

      AHP(Analytic hierarchy process (AHP)

  The Analytic Hierarchy Process (AHP) was developed by American operations researchers in the mid-1970s.Thomas Sethi(TLsaaty)Formally put forward.It is a qualitative and quantitative, systematic and hierarchical analysis method.Because it’s dealing with complexity.Policy decisionThe practicability and validity of the issue soon gained worldwide attention.Its application has spread all over the economy.planandAdministrationenergy policyAnd distribution,behavioral science、Military command, transportation, agriculture, education, personnel, medical and environmental fields.


Basic steps of analytic hierarchy process

1、The hierarchical structure model is established.On the basis of in-depth analysis of practical problems, the relevant factors are categorized according to different attributes.From top to bottomIt is divided into several levels. The factors at the same level are subordinate to the factors at the upper level or have an impact on the factors at the upper level, and at the same time dominate the factors at the lower level or are affected by the factors at the lower level.The top level is the target level, usually with only one factor. The bottom level is usually the scheme or object level. There can be one or more levels in the middle, usually the criteria or indicators level.When there are too many criteria (e.g. more than 9 criteria), the sub-criteria layer should be further decomposed.

2、A paired comparison matrix is constructed.Starting from Level 2 of the Hierarchical Model, for the same level of factors that are subordinate to (or influence) each factor at the upper level, usePaired comparison methodA pair comparison matrix is constructed on the scale of 1-9, up to the lowest level.

3、Calculate the weight vector and do consistency test.For each pairwise comparison matrix, the maximum eigenvalues and corresponding eigenvectors are computed, and consistency tests are performed using consistency index, random consistency index and consistency ratio.If the test passes, the eigenvector (normalized) is the weight vector: if it fails, it needs to be reconstructed into a paired comparison matrix.

4、The combination weight vectors were calculated and the consistency test was performed.The combination weight vectors of the lowest level are calculated, and the combination consistency test is made according to the formula. If the test passes, the decision can be made according to the results expressed by the combination weight vectors. Otherwise, it is necessary to reconsider the model or reconstruct those pairwise comparison matrices with larger consistency ratio.



Establishing Hierarchical Structure Model

Example–Model of Selecting Cadres

   Three candidates for cadres123,According to the five criteria of selecting cadres: morality, talent, seniority, age and mass relations, the following hierarchical analysis model is formed: assuming three candidates for cadres12y 3,According to the five criteria of selecting cadres: moral character, ability, seniority, age and mass relations, the following hierarchical analysis model is formed.




Construct a pairwise comparison matrix

Quantitative relativity is used when comparing the importance of the first element with that of the first element.weightjTo describe.If there are n elements in the comparison, thenA=(a_{ij})_{n\times n}It is called pairwise comparison matrix.

  In pairwise comparison matrixjAccording to Satty’s proposal, we can assign the values according to the following scales.jTake the value between 1-9 and its reciprocal.

  • j = 1,Element I and element J are of the same importance to the factors at the upper level.
  • j = 3,Element I is slightly more important than element J.
  • j = 5,Element I is more important than element J.
  • j = 7,Element I is much more important than element J.
  • j = 9,Element I is more important than element J.
  • j = 2 n,n=1,2,3,4,The importance of elements I and j lies somewhere between a j = 2 n − 1and a j = 2 n + 1Between;
  • a_{ij}=\frac{1}{n},n=1,2,…,9,if and only ifi = n

  The characteristics of pairwise comparison matrix:a_{ij}>0,a_{ij}=1,a_{ij}=\frac{1}{a_{ji}}(Note: When I = j,j = 1

  Five conditions for selecting cadres: morality1,Can2,Seniority3,Age4,one’s relations with the masses5A decision maker used pairwise comparison method and obtained pairwise comparison matrix as follows:

  \begin{pmatrix}1&2&7&5&5\\\frac{1}{2}&1&4&3&3\\\frac{1}{7}&\frac{1}{4}&1&\frac{1}{2}&\frac{1 }{3}\\\frac{1}{5}&\frac{1}{3}&2&1&1\\\frac{1}{5}&\frac{1}{3}&3&1&1\end{pmatrix}                14 = 5The ratio of moral character to age importance is 5, that is, the decision maker thinks moral character is more important than age.


Consistency check

Theoretical analysis shows that if A is a completely consistent paired comparison matrix, there should be

  a_{ij}a_{jk}=a_{ik},1\le i,j,k\le n.

  But in fact, it is impossible to satisfy many of the above equations when constructing pairwise comparison matrices.Therefore, it is necessary to have some consistency in paired comparison matrices, that is to say, a certain degree of inconsistency can be allowed in paired comparison matrices.

  From the analysis, it can be seen that the maximum eigenvalue of the absolute value of a completely consistent pairwise comparison matrix is equal to the dimension of the matrix.The consistency requirement of pairwise comparison matrix is transformed into requirement: the maximum eigenvalue of absolute value is not different from the dimension of the matrix.

  The steps for checking the consistency of pairwise comparison matrix A are as follows:

  • Calculate the index CI to measure the degree of inconsistency of a paired comparison matrix A (n> first-order square matrix):


  RIIt is obtained that for a fixed n, a pairwise comparison matrix A is randomly constructed, in which a pairwise comparison matrix A is constructed.jIt’s from 1,2,… 9,1/2,1/3,… 1/9 randomly selected. Such A is inconsistent. Sufficiently large samples are taken to obtain the average of the maximum eigenvalue of A.







  • The standard RI: RI, which checks the consistency of the pairwise comparison matrix A, is called the average random consistency index. It is only related to the order n of the matrix (generally no more than 9).
  • The random consistency ratio CR of paired comparison matrix A is calculated according to the following formula:

     CR=\frac{CI}{RI} 。

  • The judgment method is as follows: when CR< 0.1, the consistency of the paired comparison matrix A is satisfactory, or the degree of the inconsistency is acceptable; otherwise, the paired comparison matrix A is adjusted until the satisfactory consistency is achieved.

  Example matrix




  Eigenvector: 0.47439499 0.26228108 0.0544921 0.098533570.11029827 (add equal to 1)

       The algorithm first adds columns to the array – – – 2.04285714, 3.91666667, 17, 10.5, 10.333333]

  Then a new matrix is obtained by dividing the result of waiting by the original matrix.


  Then add the rows of the matrix until – —[2.37197494 1.31140538 0.2724605 0.49266783 0.55149136]

   The above eigenvectors are obtained by normalizing (the results above are divided by the order).It was found that morality had the greatest impact.



  AW = The eigenvector * the original matrix (at the beginning), and then get the sum of each line – – – 2.42456102 1.34394248 0.27386595 0.50012206 0.55461416]

  So we can get (AW / order * eigenvector)5.07293180152562


  Calculated obtained\lambda_{max}(A)=5.073,CI=\frac{\lambda_{max}(A)-5}{5-1}=0.018,Check RI=1.12,


  This shows that A is not a uniform matrix, but A has satisfactory consistency and the degree of inconsistency of A is acceptable.


Hierarchical Total Sorting and Decision Making



Now to solve the problem of Example 2 completely, three candidates are needed.1 , 2 , 3Choose a candidate who is best suited to the above five conditions in general.In this regard, for the three candidatesy = 1 , 2 , 3Compare their moral character separately1 ),Can2 ),Seniority3 ),Age4 ),one’s relations with the masses5 )

  Comparing the virtues of the three candidates in pairs first, we have to compare them in pairs.


  After calculation,1Weight vector

  ω x 1 ( Y ) = (0.082,0.236,0.682) z


  so1The degree of inconsistency is acceptable.ω x 1 ( Y )It can be seen intuitively as the candidates’moral scores.

  Similarly, the talent, seniority, age and mass relations of the three candidates are compared in pairs.

  B_2=\begin{pmatrix}1&2&5\\\frac{1}{2}&1&2\\\frac{1}{5}&\frac{1}{2}&1\end{pmatrix}   B_3=\begin{pmatrix}1&1&3\\1&1&3\\\frac{1}{3}&\frac{1}{3}&1\end{pmatrix}

  B_4=\begin{pmatrix}1&3&4\\\frac{1}{3}&1&1\\\frac{1}{4}&1&1\end{pmatrix}         B5=

  Five eigenvectors can be obtained


  And then pass

     First person: (0.08 199023*0.47439499 (The initial eigenvector) +0.59488796*0.26228108 +0.42857143*0.0544921 +0.63274854*0.09853357 +0.34595035*0.11029827 ) = Total score

    The latter two are similar.

 Finally gotThe first person got 0.31878206

       The second person got 0.23919592.

       The third person gets 0.44202202

   So No. 3 is the first candidate.




Examples of Application of Analytic Hierarchy Process


For example, when someone is going to buy a refrigerator, he knows about six different types of refrigerators on the market. When deciding which style to buy, he often does not directly compare the refrigerator as a whole, because there are many incomparable factors, but chooses some intermediate indicators to examine.For example, refrigerator capacity, refrigeration level, price, model, power consumption, external reputation, after-sales service, etc.Then consider the advantages and disadvantages of different types of refrigerators under the above intermediate standards.With the help of this sort, the final purchase decision is made.In decision-making, because the ranking of six refrigerators for each intermediate standard is generally inconsistent, the decision maker first estimates the importance of the seven standards, gives a ranking, and then finds out the ranking weight of six refrigerators for each standard, and finally synthesizes these information and data.The ranking weight for the total objective of buying refrigerators is obtained.With this weight vector, decision-making is easy.

Application Program of Analytic Hierarchy Process

  When using AHP method to make decision, the following four steps are needed:

  1、Establishing hierarchical structure of the system;

  2、Construct two-to-two comparison judgment matrix; (positive and reciprocal matrices)

  3、For a certain criterion, the weight of each candidate element is calculated.

  4、Calculate the ranking weight of the current layer elements about the total objective.

  5、Conduct consistency test.

 Appendix sample code (python)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

RI_dict = {1: 0, 2: 0, 3: 0.58, 4: 0.90, 5: 1.12, 6: 1.24, 7: 1.32, 8: 1.41, 9: 1.45}

def get_w(array):
    row = array.shape[0]  # Calculated order
    a_axis_0_sum = array.sum(axis=0)
    # print(a_axis_0_sum)
    b = array / a_axis_0_sum  # New matrix B
    # print(b)
    b_axis_0_sum = b.sum(axis=0)
    b_axis_1_sum = b.sum(axis=1)  # Eigenvector of each row
    # print(b_axis_1_sum)
    w = b_axis_1_sum / row  # Normalization (eigenvector)
    nw = w * row
    AW = (w * array).sum(axis=1)
    # print(AW)
    max_max = sum(AW / (row * w))
    # print(max_max)
    CI = (max_max - row) / (row - 1)
    CR = CI / RI_dict[row]
    if CR < 0.1:
        # print(round(CR, 3))
        # print('Meeting consistency "
        # print(np.max(w))
        # print(sorted(w,reverse=True))
        # print(max_max)
        # print('Eigenvector:% s'%w)
        return w
        print(round(CR, 3))
        print('If the consistency is not satisfied, please amend it.')

def main(array):
    if type(array) is np.ndarray:
        return get_w(array)
        print('Please enter numpy object.')

if __name__ == '__main__':
    # Because of the local problem, I wrote the matrix as one line.
    e = np.array([[1, 2, 7, 5, 5], [1 / 2, 1, 4, 3, 3], [1 / 7, 1 / 4, 1, 1 / 2, 1 / 3], [1 / 5, 1 / 3, 2, 1, 1], [1 / 5, 1 / 3, 3, 1, 1]])
    a = np.array([[1, 1 / 3, 1 / 8], [3, 1, 1 / 3], [8, 3, 1]])
    b = np.array([[1, 2, 5], [1 / 2, 1, 2], [1 / 5, 1 / 2, 1]])
    c = np.array([[1, 1, 3], [1, 1, 3], [1 / 3, 1 / 3, 1]])
    d = np.array([[1, 3, 4], [1 / 3, 1, 1], [1 / 4, 1, 1]])
    f = np.array([[1, 4, 1 / 2], [1 / 4, 1, 1 / 4], [2, 4, 1]])
    e = main(e)
    a = main(a)
    b = main(b)
    c = main(c)
    d = main(d)
    f = main(f)
        res = np.array([a, b, c, d, f])
        ret = (np.transpose(res) * e).sum(axis=1)
    except TypeError:
        print('The data is incorrect and may not be consistent. Please modify it.')


Leave a Reply

Your email address will not be published. Required fields are marked *