Note: This article mainly refers to “Matlab Mathematical Modeling Algorithm Examples and Analysis”, and some pictures are from WIKI

The article is divided into two parts:

The first part briefly describes the basic steps and ideas of ahp in a popular way

2. The second part introduces the application of analytic hierarchy process in the mathematical modeling of our team. In some places, we did some unrigorous reasoning, such as the consistency test

Part I:

Analytic Hierarchy Process (AHP) is a simple method to make decisions on some complicated and fuzzy problems, which is especially suitable for those problems that are difficult to complete quantitative analysis. It is a simple, flexible and practical multi-criteria decision-making method proposed by American operational research professor T. L. Saaty in the early 1970s.

In the systematic analysis of social, economic and scientific management problems, people often face a complex system which is composed of many interrelated and restricting factors and often lacks quantitative data. Analytic hierarchy process (AHP) provides a new, simple and practical modeling method for decision making and sorting of this kind of problems.

By using analytic hierarchy process (AHP) modeling, the following four steps can be generally carried out: (I) establishing hierarchical structure model; (ii) Construct all judgment matrices in each level; (iii) Hierarchical single ordering and consistency test; (iv) Hierarchical total ordering and consistency test. \

 

Of the four steps, the first two are the easiest to understand, while the last two take a little time to understand

 

Let’s start with the hierarchy model

Analytic hierarchy process (AHP) is a mathematical method that is used to select the best among the candidates according to a variety of criteria, or factors

\

The top layer is our target, such as selecting leader, job and tourist destination

The middle layer is the factor or criterion to judge the merits of the candidate

When choosing a job: development prospects, salary, working environment, etc

When choosing a leader: age, experience, education background, charm

 

After stratification, in order to select the best candidate

Assign a value of 1.000 to the target layer

This value is then used as a weight to assign to different factors, and the weight of the corresponding factor represents the importance of the factor in the whole selection process

Then, for the candidate scheme, each criterion assigns its weight value to all candidate schemes, and each scheme obtains the weight value, which comes from the sum of the weight values of different factors

 

Figure below :(alternative1)0.333=0.250/4(criterion1)+0.250/4(criterion2)+0.250/4(criterion3)+0.250/4(criterion4)

Finally, the sum of weight values of each scheme is still 1

\

For example, when choosing a job, the proportion of salary is 0.8, and there are candidates for job 1,2 and 3. If job 1 is the highest, job 2 is second, and job 3 is the worst, then the value of 0.8 can be divided among job 1,2,3,\ according to 0.4,0.3, 0.1

Isn’t it a simple weighted scoring process? Why do we need hierarchical analysis. There are two key questions:

How much weight should be assigned to each criterion (factor)

2. How much weight should each candidate plan get under each factor

 

Here we enter the second step of analytic hierarchy process, which is also an essence of analytic hierarchy process (constructing comparison matrix) :

 

First, solve the first question: how much weight should be assigned to each criterion?

If it is difficult to assign weight to each factor directly, it is relatively easy to compare the importance of different factors in pairs

\

 

Now fill in the position of row I and column J of the matrix with the value aij obtained by comparing the different factors in pairs, and the so-called comparison matrix is constructed. The diagonal lines are all 1, because it is self to self ratio

This matrix is easy to get, how do we get the weight assignment from this matrix

Here comes a more advanced concept, reciprocal matrices and consistency matrices

First, the definition of reciprocal matrix is:

 

The matrices we have constructed so far are clearly reciprocal matrices

 

The definition of consistency matrix is:


Here, the matrix we constructed does not necessarily meet the consistency. For example, factor 1: Factor 2= 4:1 Factor 2: Factor 3=2:1 Factor 1: Factor 3=6:1 (if consistency is satisfied, it should be 8:1). It is because it is difficult to determine the proportion distribution of each factor that we make pairwise comparison. If consistency can be guaranteed in the judgment, weight distribution is directly given

 

When it comes to the crucial part, the consistency matrix has a property that allows you to calculate the ratio of different factors

 

\

Here w is the weight we want to know, so by finding the eigenvector corresponding to the largest eigenvalue of the comparison matrix, we can get the weight of different factors, normalization (each weight divided by the weight sum as its own value, the final sum is 1) is more convenient to use. (In fact, I wrote this blog because I read the book of dai Dai and finally understood it, so I wanted to record it.)

 

Here’s a little bit of linear algebra:

The n-order matrix has n eigenvalues, and each eigenvalue corresponds to an n-dimensional eigencolumn vector. The calculation method of eigenvalues and eigenvectors is omitted here. Anyway, the program in the book is directly obtained by eiG function of MATLAB

 

Remember, the comparison matrix we give is generally not consistent, but we still treat it as a consistent matrix, and we can also get a set of weights, but whether this set of weights is acceptable or not needs further consideration

For example, when judging the importance of factors 1,2, and 3, there may be some differences, but they should not be too big. 1 is more important than 2, 2 is more important than 3, and 1 is more important than 3, which is obviously not acceptable

 

So the consistency test is introduced:

The conformance test is carried out by calculating the conformance ratio CR

          

When 10. 0 < CR, the consistency of the judgment matrix is considered acceptable; otherwise, the judgment matrix should be modified appropriately.

 

The value of CI is calculated by the judgment matrix, and the value of RI is obtained by looking up the table. The specific calculation formula is omitted here. The key is to understand why consistency test is required

 

 

Then we solve the second question: how much weight should each candidate get for each factor

 

Here, different candidate schemes need to be compared under different factors. The specific comparison method is still to use comparison matrix, but the comparison matrix in the previous criterion layer compares factors. Here, it compares the advantages and disadvantages of candidate schemes under a certain factor, and n comparison matrices need to be constructed for n factors

For example, under the factors of working environment, the comparison between job 1 and job 2 is: 4:2, job 2 and job 3=2:1 job 1: job 3=6: 1. In this way, a matrix can be constructed and a weight can be calculated by using the previous consistency matrix method. Then the weight of the corresponding factor (here is the work environment) can be assigned to different candidates or people according to this weight ratio.

 

Same thing for all other factors

 

 

At this point both problems have been solved

Finally, by summing up the weights obtained by each candidate and person from different factors, the weights of different candidates for the target layer can be obtained, and then the pros and cons can be selected according to the size of the values


Summary of the first part:

* * * * through the basic understanding of the analytic hierarchy process (ahp), it is not difficult to find that the analytic hierarchy process has carried on the processing process of people’s thinking, put forward a set of system method, to analyze the problem of scientific management and decision provides a convincing basis, but the obvious disadvantage is that the entire analysis process seems to be dependent on the person’s subjective judgment thinking, then is not an objective, Two to two to compare all artificial completion, or very energy – consuming, especially when there are more candidates.



The second part of the article:

Analytic hierarchy process (also may have been used in this way, but the reference books did not say so, foreign language papers did not look carefully) to solve the problem of optimal coach selection

 

Objective: To select the best coach

 

Criteria: Career winning percentage of the team

Career team wins

Length of Education (years)

Career team awards (converted into scores)

  

Candidate: Lots of coaches

 

The comparison matrix of criterion layer is easy to construct, and the comparison matrix of 4*4 can be obtained by 6 pairwise comparisons

 

The problem is how to obtain the comparison matrix of candidate layer. If there are 4000 coaches, the comparison will be 4000*3999 times. There is no need to make artificial comparison here, but to introduce quantitative data and use program control to make comparison


The win rate factor is used to construct the matrix in pairs, and the length of time factor is used to do the comparison


Here are two more things to note:

1. The dimensionality and nature of data under different factors are different, so it may not be appropriate to directly use data as a ratio to allocate. For example, the closer the winning rate is to 1, the more difficult it is. In modeling, we combine power and logarithmic functions.


2. The matrix obtained by comparing quantitative data here obviously meets the consistency requirements, and there is no need for consistency test (it is not easy to do this, RI is needed to calculate CR value, and only 9 RI values are given in the table, 4000 RI is needed to calculate 4000 coaches).


To sum up, the analytic hierarchy Process (AHP) has been applied in combination of qualitative and quantitative methods, as well as the comparison of multiple candidate schemes (in fact, it is only using program control data for comparison, our level is limited, and it is not easy to successfully apply this method).


Unfortunately, the flash drive of the code written during the competition was lost accidentally, so there is no way to share the code. The code in the book can only be posted here. This code is used to modify the game model. Once you understand the code below, it should be easy to write programs that meet your needs.

 

Code: (corresponding to the Leader selection in part 1 of the article) :

 

clc,clear fid=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); % reading scheme layer of judgment matrix end end ri = [,0,0.58 0, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45]. % consistency index [x,y]=eig(a); % MATLAB eig(a) returns the eigenvalues and eigenvectors of the matrix, where x is the n eigenvectors of the matrix A, y is the n eigenvalues of the matrix A lamda= Max (diag(y)); Lamda num=find(diag(y)==lamda); diag(y)==lamda; W0 =x(:,num)/sum(x(:,num)); % x(:num) is the column of eigenvectors corresponding to the maximum eigenvalue. The normalized n weight values calculated by the criterion layer in W0 cr0=(lamda-N1)/(N1-1)/ri(n1) for I =1: N1% cycle n dimensions. For each dimension, Eig (eval(char(['b',int2str(I)]))); lamda=max(diag(y)); num=find(diag(y)==lamda); w1(:,i)=x(:,num)/sum(x(:,num)); cr1(i)=(lamda-n2)/(n2-1)/ri(n2); end cr1, ts=w1*w0, cr=cr1*w0Copy the code

 

The content in TXt3.txt is the 6 x 6 comparison matrix of the first 6 code of conduct layer, and the last 18 lines are the 3 x 3 comparison matrix of each of the 6 codes.

1 1 1 4 1 1/2 1 1 2 4 1 1/2 1 1/2 1 5 3 1/2 1/4 1/4 1/5 1 1/3 1/3 3 1 1 1 2 2 3 3 1 1/4 1/2 4 1 3 2 1/3 1 1 1 1/4 1/5 4 1 1/2 5 2 1 1 3 1/3 1/3 1 1/7 3 7 1 1 1/3 5 3 1 7 1/5 1/7 1 1 7 1 7 1/7 1/7 1 7 9 1/7 1 1 1/9 1 1Copy the code

Again a section of JAVA code, convenient JAVA children’s shoes reference, this part only shows how to use JAVA code to calculate the criteria layer comparison matrix.

 

import org.apache.commons.math3.linear.*; public class MatrixTester { public static void main(String[] args) { // Create a real matrix with two rows and three columns, using a factory // method that selects the implementation class for us. double[][] matrixData = { {1d, 1d, 1d, 4d, 1d, 1d/2d}, {1d, 1d, 2d, 4d, 1d, 1d/2d}, {1d, 1d/2d, 1d, 5d, 3d, 1d/2d }, {1d/4d, 1d/4d, 1d/5d, 1d, 1d/3d, 1d/3d }, {1d, 1d, 1d/3d, 3d, 1d, 1d }, {2d, 2d, 2d, 3d, 3d, 1d }, }; RealMatrix m = MatrixUtils.createRealMatrix(matrixData); // One more with three rows, two columns, this time instantiating the // RealMatrix implementation class directly. double[][] matrixData2 = {{1d, 2d}, {2d, 5d}, {1d, 7d}}; RealMatrix n = new Array2DRowRealMatrix(matrixData2); // Note: The constructor copies the input double[][] array in both cases. // Now multiply m by n // RealMatrix p = m.multiply(n);  // System.out.println(p.getRowDimension()); // 2 // System.out.println(p.getColumnDimension()); // 2 // // // Invert p, using LU decomposition // RealMatrix pInverse = new LUDecomposition(p).getSolver().getInverse(); RealMatrix D = new EigenDecomposition(m).getD(); RealMatrix V = new EigenDecomposition(m).getV(); for(int i=0; i<D.getRowDimension(); i++) { System.out.println(D.getRowMatrix(i)); } for(int i=0; i<V.getRowDimension(); i++) { System.out.println(V.getRowMatrix(i)); } // double maxLamda; int columIndexForMaxLamda=0; MaxLamda = D.g etEntry (0, 0); for(int i =0, j=0; i<D.getRowDimension()&&j<D.getColumnDimension(); i++,j=i) { double lamda = D.getEntry(i,j); if(maxLamda<lamda) { maxLamda=lamda; columIndexForMaxLamda = j; } System.out.println(lamda); } // The output is not normalized w1, w2, w3, w4, w5, w6, system.out.println (v.getColumnmatrix (columIndexForMaxLamda)); }}Copy the code