In this article, we are going to solve a practical example step-by-step using the Analytic Hierarchy Process (AHP). Before we proceed, let us provide an introduction to AHP and explain why it is necessary.

**Introduction to Analytic Hierarchy Process (AHP)**

Multi-criteria decision making (MCDM) is a decision-making approach that allows experts to take into account multiple criteria when making decisions. Analytic Hierarchy Process (AHP) is a popular MCDM technique that helps decision-makers to evaluate and prioritize alternatives based on a set of criteria.

MCDM can be categorized into two main groups, namely multi-objective decision making (MODM) and multi-attribute decision making (MADM). MODM is a category of MCDM that aims to minimize or maximize multiple objectives or criteria simultaneously. It is characterized by the presence of an objective function for each criterion. The criteria can be either in the form of maximization for positive criteria or minimization for negative criteria. However, MODM can be computationally expensive and often requires heuristic algorithms to solve. Generally, MODM applies to quantitative variables, but qualitative variables can be transformed into quantitative variables and still be used in MODM.

On the other hand, MADM methods like AHP, ANP, TOPSIS, etc. aim to address the limitations of MODM. MADM is a category of MCDM that deals with the evaluation of alternatives based on a set of attributes or criteria. The attributes or criteria can be at different levels, such as criteria, alternatives, or any finer level. Sub-criteria can also be included, although the model does not necessarily require sub-criteria for each criterion.

To illustrate the above concepts, consider an example of each category. For MODM, consider minimizing a two-objective function, and for MADM, consider a model with three levels of criteria, sub-criteria, and alternatives.

### Design AHP questionnaire

In this second part of the AHP tutorial, the focus is on designing a questionnaire to evaluate the pairwise comparisons of criteria and alternatives. A hierarchical structure is used to form the pairwise comparison matrices for both the criteria and alternatives. Since all the criteria are connected to the goal, a pairwise comparison matrix for it is created. Similarly, pairwise comparison matrices are created for the alternatives corresponding to each criterion. A sample of the pairwise comparison matrices is presented, and each cell is filled based on a linguistic scale, such as the Likert scale, which ranges from 1 to 5 or 1 to 10. Experts are asked to assign the appropriate value to each question based on their preference, with the numerical value matched to a linguistic variable. For criteria, experts are asked to compare the preference between two options and indicate the degree of relative preference. For alternatives, the experts are asked to indicate which option is preferred more in terms of a criterion and the degree of relative preference. Once the questionnaire is completed and the expert’s answers are obtained, the pairwise matrices are filled in. It is important to ensure that the answers meet the consistency rate before calculating the weights of the matrices. Aggregating the questionnaires into one is required to solve the AHP problem. The geometric mean is the most popular method used for aggregating the questionnaires, where the nth root is taken after multiplying the values.

### Calculate AHP weights

In this third part of the AHP tutorial, Ishmael from dataharnessing.com explains how to calculate the weights and inconsistency rate for a single matrix. These calculations can be repeated for each matrix in the analysis or for aggregated matrices from multiple experts. To calculate the weights, one needs to find \lambda_{max}, which is the maximum eigenvalue obtained by setting the determinant of det(A-\lambda*I)=0. This value is then used to solve for the weights by plugging it into the previous equation and multiplying it by the vector W, (A-\lambda_{max}*I)W=0. To convert the weights to a contracted scale between 0 and 1, normalization can be done by dividing each weight by the sum of all weights.

Calculating the inconsistency rate involves determining the inconsistency index, which depends on the number of attributes being compared. For example, in the matrix provided, there are 4 attributes. The inconsistency index is divided by the inconsistency ratio, which is a predetermined value for a given number of attributes, to determine the inconsistency rate. In this case, the inconsistency ratio is 0.9, which can be found in a table provided.

[matlab]

function [W, IR] = WtIR(A)

%% Find weights

Lambda_max = max(eig(A));

W = null(A- Lambda_max * eye(size(A)));

W_normalized = W./sum(W);&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/code&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;

%% inconsistency rate

RI = [0.00, 0.00, 0.58, 0.90, 1.12, 1.24, 1.32, 1.41, 1.45, 1.49, 1.51, 1.54, 1.56, 1.58, 1.59, 1.61];

II = (Lambda_max-size(A, 1))/(size(A, 1) – 1);

IR = II/RI(size(A, 1));

if IR &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt; 0.1

disp(‘The imported pairwise comparison matrix is consistent’)

else

disp(‘The imported pairwise comparison matrix is inconsistent, and questions should answer again.’)

end

end

[/matlab]

Click here to download the AHP codes in matlab

The calculations for weights and inconsistency rate can be performed using MATLAB software. A function has been created that combines the calculation of both inconsistency rate and weights in a single code. However, the word “function” should be excluded from the first line of the code when you run it in MATLAB to yield both results.

**Multiplying decision matrices**

Once the weights of the pairwise comparison matrices have been calculated, they are organized into decision matrices for each level. In our previous example, the decision matrix for alternatives is a 3 by 4 matrix where each column represents the weights of the alternatives for a specific criterion. It is important to note that the decision matrix for criteria is a 4 by 1 vector because there is only one pairwise comparison matrix at this level.

To determine the final aggregated weights of alternatives in the Analytic Hierarchy Process, the decision matrices need to be multiplied from the bottom to the top of the hierarchy. This requires multiplying the decision matrix of alternatives by the criteria vector, which yields a 3×1 vector. It is necessary to normalize these weights if they have not already been normalized.

In the next video we introduce software and online resources that you can easily run your AHP projects benefiting from machine learning techniques.

## مریم بخارائیان

## محمد رضایی

## نعیمه

## محمد رضایی