A Python package to implement the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method for multi-criteria decision-making problems.
- Rank alternatives based on multiple criteria.
 - Handle positive and negative impacts of criteria.
 - Simple to use with CSV input/output.
 - Fully customizable weights and impacts.
 
Install the package directly from PyPI:
pip install Topsis-Vansh-102203021The package can be used through the command line or imported into a Python script.
The basic syntax for using the package via the command line:
python -m topsis <input_file> <weights> <impacts> <output_file>input_file: CSV file containing the decision matrix.weights: Comma-separated values representing the importance of each criterion (e.g.,1,1,2,3).impacts: Comma-separated values representing the impact of each criterion (+for positive,-for negative).output_file: Name of the CSV file where the results will be saved.
python -m topsis data.csv "1,1,2,3" "+,+,-,+" result.csvThe input file must be a CSV file with the following structure:
| Alternatives | Criterion 1 | Criterion 2 | Criterion 3 | Criterion 4 | 
|---|---|---|---|---|
| A1 | 250 | 16 | 12 | 5 | 
| A2 | 200 | 18 | 8 | 3 | 
| A3 | 300 | 14 | 16 | 7 | 
| A4 | 275 | 17 | 10 | 4 | 
- The first column contains alternative names (e.g., A1, A2, etc.).
 - From the second column onwards, numeric values for each criterion are provided.
 
The output file will include the input data along with two additional columns:
| Alternatives | Criterion 1 | Criterion 2 | Criterion 3 | Criterion 4 | Topsis Score | Rank | 
|---|---|---|---|---|---|---|
| A1 | 250 | 16 | 12 | 5 | 0.65 | 2 | 
| A2 | 200 | 18 | 8 | 3 | 0.45 | 4 | 
| A3 | 300 | 14 | 16 | 7 | 0.78 | 1 | 
| A4 | 275 | 17 | 10 | 4 | 0.52 | 3 | 
You can also import and use the package in your Python scripts:
from topsis_vansh_102203021 import topsis
topsis(
    input_file="data.csv",
    weights="1,1,2,3",
    impacts="+,+,-,+",
    output_file="result.csv"
)The package includes robust error handling to ensure correct inputs:
- 
File Not Found:
- If the input file does not exist, an appropriate error message is shown.
 
 - 
Invalid Parameters:
- The number of weights, impacts, and criteria must match.
 
 - 
Non-Numeric Values:
- From the second column onwards, only numeric values are allowed.
 
 - 
Invalid Impacts:
- Impacts must be either 
+or-. 
 - Impacts must be either 
 - 
Minimum Column Requirement:
- The input file must have at least three columns.
 
 
You can test the package using the following example files:
| Alternatives | Criterion 1 | Criterion 2 | Criterion 3 | Criterion 4 | 
|---|---|---|---|---|
| A1 | 250 | 16 | 12 | 5 | 
| A2 | 200 | 18 | 8 | 3 | 
| A3 | 300 | 14 | 16 | 7 | 
| A4 | 275 | 17 | 10 | 4 | 
| Alternatives | Criterion 1 | Criterion 2 | Criterion 3 | Criterion 4 | Topsis Score | Rank | 
|---|---|---|---|---|---|---|
| A1 | 250 | 16 | 12 | 5 | 0.65 | 2 | 
| A2 | 200 | 18 | 8 | 3 | 0.45 | 4 | 
| A3 | 300 | 14 | 16 | 7 | 0.78 | 1 | 
| A4 | 275 | 17 | 10 | 4 | 0.52 | 3 | 
Developed by Vansh Kansal (Roll Number: 102203021).
For any questions or feedback, please contact vanshkansal5@gmail.com.