A Python package for implementing the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS). This is a multi-criteria decision analysis method that helps in ranking alternatives based on multiple criteria.
Install the package using pip:
pip install topsis-102203427You can run the TOPSIS method directly from the command line.
topsis <input_file> <weights> <impacts> <output_file>-
<input_file>: Path to the input CSV file containing the data.- The first column should contain the names of the alternatives.
- The remaining columns should contain numerical values for the criteria.
-
<weights>: A comma-separated string of weights for each criterion (e.g.,"1,1,1,1"). -
<impacts>: A comma-separated string of impacts (+for positive,-for negative) corresponding to each criterion (e.g.,"+,+,-,+"). -
<output_file>: Path to save the resulting output file, which will include the computed scores and ranks.
| Alternative | Criterion1 | Criterion2 | Criterion3 | Criterion4 |
|---|---|---|---|---|
| Alt1 | 250 | 16 | 12 | 5 |
| Alt2 | 200 | 32 | 8 | 3 |
| Alt3 | 300 | 24 | 10 | 4 |
| Alt4 | 275 | 20 | 11 | 4.5 |
| Alt5 | 225 | 28 | 9 | 4 |
topsis input.csv "1,1,1,1" "+,+,-,+" output.csv| Alternative | Criterion1 | Criterion2 | Criterion3 | Criterion4 | Score | Rank |
|---|---|---|---|---|---|---|
| Alt1 | 250 | 16 | 12 | 5 | 0.8729 | 1 |
| Alt2 | 200 | 32 | 8 | 3 | 0.3243 | 4 |
| Alt3 | 300 | 24 | 10 | 4 | 0.2985 | 5 |
| Alt4 | 275 | 20 | 11 | 4.5 | 0.7315 | 3 |
| Alt5 | 225 | 28 | 9 | 4 | 0.4532 | 2 |
You can also use the package programmatically in Python.
from topsis_package.main import topsis
topsis("input.csv", "1,1,1,1", "+,+,-,+", "output.csv")- Python >= 3.7
- pandas
- numpy
-
Normalize the Decision Matrix
Convert each criterion to a unit vector. -
Calculate the Weighted Normalized Decision Matrix
Multiply each normalized value by its weight. -
Determine the Ideal Best and Worst Solutions
- For positive impacts: Max value.
- For negative impacts: Min value.
-
Calculate Separation Measures
- Distance from the ideal best.
- Distance from the ideal worst.
-
Compute Relative Closeness to the Ideal Solution
Rank the alternatives based on their closeness.
This project is licensed under the MIT License. See the LICENSE file for details.
Aditya Raj Singh
Email: aditya003rs@gmail.com