TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) command-line package by Krit Mukul (Roll 102303213).
Repository: https://github.com/KritMukul/TOPSIS
pip install Topsis-Krit-102303213git clone https://github.com/KritMukul/TOPSIS.git
cd TOPSIS
pip install -e .python -m topsis <InputDataFile> <Weights> <Impacts> <OutputResultFile>Or after installation:
topsis-cli data.csv "1,1,1,2" "+,+,-,+" output.csv- InputDataFile: CSV file with first column as identifier, remaining columns as numeric criteria
- Weights: Comma-separated numeric values (e.g.,
1,1,1,2) - Impacts: Comma-separated
+(beneficial) or-(cost) for each criterion (e.g.,+,+,-,+) - OutputResultFile: Path for result CSV with added
Topsis ScoreandRankcolumns
topsis-cli input.csv "1,1,1,1" "+,+,-,+" result.csvThis project implements the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method for multi-criteria decision making. The methodology is as follows:
-
Normalization: The decision matrix is normalized using vector normalization so that all criteria are dimensionless and comparable.
- Formula:
$r_{ij} = \frac{x_{ij}}{\sqrt{\sum x_{ij}^2}}$
- Formula:
-
Weighting: Each normalized criterion is multiplied by its assigned weight to reflect its importance.
- Formula:
$v_{ij} = w_j \times r_{ij}$
- Formula:
-
Ideal Best & Worst: For each criterion, determine the ideal best (maximum for beneficial, minimum for cost) and ideal worst (opposite).
- Beneficial (+): best = max, worst = min
- Cost (-): best = min, worst = max
-
Separation Measures: Calculate the Euclidean distance of each alternative from the ideal best and worst.
$S_i^+ = \sqrt{\sum (v_{ij} - v_j^+)^2}$ $S_i^- = \sqrt{\sum (v_{ij} - v_j^-)^2}$
-
TOPSIS Score: Compute the relative closeness to the ideal solution.
$C_i = \frac{S_i^-}{S_i^+ + S_i^-}$
- Ranking: Alternatives are ranked based on their TOPSIS scores (higher is better).
All these steps are implemented efficiently using NumPy and Pandas in topsis/core.py.
After running TOPSIS, the output CSV will look like this (see output.csv):
| Fund Name | P1 | P2 | P3 | P4 | P5 | Topsis Score | Rank |
|---|---|---|---|---|---|---|---|
| M1 | 0.67 | 0.45 | 6.5 | 42.6 | 12.56 | 0.215 | 8 |
| M2 | 0.60 | 0.36 | 3.6 | 53.3 | 14.47 | 0.468 | 4 |
| M3 | 0.82 | 0.67 | 3.8 | 63.1 | 17.10 | 0.861 | 1 |
| M4 | 0.60 | 0.36 | 3.5 | 69.2 | 18.42 | 0.589 | 3 |
| M5 | 0.76 | 0.58 | 4.8 | 43.0 | 12.29 | 0.451 | 5 |
| M6 | 0.69 | 0.48 | 6.6 | 48.7 | 14.12 | 0.327 | 7 |
| M7 | 0.79 | 0.62 | 4.8 | 59.2 | 16.35 | 0.695 | 2 |
| M8 | 0.84 | 0.71 | 6.5 | 34.5 | 10.64 | 0.414 | 6 |
Where:
- Topsis Score: The relative closeness to the ideal solution (0 to 1)
- Rank: 1 is best
The input data (see test-data.csv) should look like:
| Fund Name | P1 | P2 | P3 | P4 | P5 |
|---|---|---|---|---|---|
| M1 | 0.83 | 0.69 | 5.8 | 41.4 | 12.18 |
| M2 | 0.83 | 0.69 | 5.8 | 63.0 | 17.58 |
| M3 | 0.84 | 0.71 | 3.7 | 32.5 | 9.44 |
| M4 | 0.72 | 0.52 | 6.0 | 70.0 | 19.31 |
| M5 | 0.73 | 0.53 | 4.7 | 65.5 | 17.87 |
| M6 | 0.75 | 0.56 | 6.5 | 63.6 | 17.85 |
| M7 | 0.80 | 0.64 | 3.6 | 45.6 | 12.66 |
| M8 | 0.79 | 0.62 | 3.3 | 60.8 | 16.38 |
You can visualize the results using a bar plot of TOPSIS scores or ranks. Here is an example using matplotlib:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('output.csv')
plt.figure(figsize=(8,4))
plt.bar(df['Fund Name'], df['Topsis Score'], color='skyblue')
plt.xlabel('Alternative')
plt.ylabel('Topsis Score')
plt.title('TOPSIS Scores by Alternative')
plt.show()This will produce a graph showing the relative performance of each alternative. You can also plot the ranks for a clearer comparison.
CSV file with:
- Header row
- First column: Alternative names/IDs
- Remaining columns: Numeric criteria values (minimum 2 criteria required)
Input data with two additional columns:
- Topsis Score: Closeness coefficient (0-1)
- Rank: Rank based on score (1 = best)
python -m buildpython -m twine upload dist/*pip install Topsis-Krit-102303737
topsis-cli --helpMIT License - see LICENSE file
Krit Mukul - Roll No. 102303213


