# TOPSIS implementation in Python

Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) CHING-LAI Hwang and Yoon introduced TOPSIS in 1981 in their Multiple Criteria Decision Making (MCDM) and Multiple Criteria Decision Analysis (MCDA) methods [1]. TOPSIS strives to minimize the distance between the positive ideal solution and the chosen alternative, as well as to maximize the distance between the negative ideal solution and the chosen alternative. [2]. TOPSIS, in a nutshell, aids researchers to rank alternative items by identifying some criteria. We present alternative information and the criteria for each in the following decision matrix:

It is possible that some criteria are more effective than others. Therefore, some weights are given to their importance. It is required that the summation of n weights equals one.

Jahanshahloo et al, (2006), explained the TOPSIS in six main phases as follows:

## 1) Normalized Decision Matrix

It is the first phase of TOPSIS to normalize the process. Researchers have proposed different types of normalization. In this section, we identify the most commonly used normalization methods. The criterion or attribute is divided into two categories, cost and benefit. There are two formulas for normalizing the decision matrix for each normalization method: one for benefit criteria and one for cost criteria. According to Vafaei et al (2018), some of these normalization methods include:

All of the above normalization methods were coded in Normalization.py. Also, there is another related file called Normalized_Decision_Matrix.py, implementing the normalization method on the decision matrix. Now we have anormalized decision matrix as follows:

## 2) Weighted Normalized Decision Matrix

The Weighted Normalized Decision Matrix is calculated by multiplying the normalized decision matrix by the weights.

This multiplication is performed in the Weighted_Normalized_Decision_Matrix.py file. Now, we have a weighted normalized decision matrix as follows:

## 3) Ideal Solutions

As was mentioned, TOPSIS strives to minimize the distance between the positive ideal solution and the chosen alternative, as well as to maximize the distance between the negative ideal solution and the chosen alternative. But what are the positive and negative ideal solutions?

If our attribute or criterion is profit-based, positive ideal solution (PIS) and negative ideal solution (NIS) are:

If our attribute or criterion is cost-based, positive ideal solution (PIS) and negative ideal solution (NIS) are:

In our code, ideal solutions are calculated in Ideal_Solution.py.

- Separation measures It is necessary to introduce a measure that can measure how far alternatives are from the ideal solutions. Our measure comprise two main sections: The separation of each alternative from the PIS is calculated as follows:

Also, the separation of each alternative from the NIS is calculated as follows:

- Closeness to the Ideal Solution Now that the distance between ideal solutions and alternatives has been calculated, we rank our alternatives according to how close they are to ideal solutions. The distance measure is calculated by the following formula:

It is clear that :

## 6) Ranking

Now, alternatives are ranked in decreasing order based on closeness to the ideal solution. Both of (5) and (6) are calculated in Distance_Between_Ideal_and_Alternatives.py.

## 7) TOPSIS

In this section, all of the previous .py files are employed and utilized in an integrated way.