Topsis-Saumil-102303862
A Python package implementing TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) for multi-criteria decision analysis (MCDM).
What is TOPSIS?
TOPSIS is a multi-criteria decision-making method that helps rank alternatives based on multiple criteria. It works by:
- Calculating the distance of each alternative from the ideal best and ideal worst solutions
- Ranking alternatives based on their relative closeness to the ideal solution
Installation
pip install Topsis-Saumil-102303862
Usage
Command Line Interface
After installation, you can use TOPSIS directly from the command line:
topsis <InputDataFile> <Weights> <Impacts> <OutputResultFileName>
Parameters
- InputDataFile: CSV file with the first column as object/alternative names and remaining columns as criteria
- Weights: Comma-separated weights for each criterion (e.g., "1,1,2,1")
- Impacts: Comma-separated impacts for each criterion, either '+' (benefit) or '-' (cost) (e.g., "+,+,-,+")
- OutputResultFileName: Name of the output CSV file with TOPSIS scores and ranks
Example
Input File (data.csv)
Fund Name,P1,P2,P3,P4,P5
M1,0.67,0.45,6.5,42.6,12.56
M2,0.60,0.36,3.6,53.3,14.47
M3,0.82,0.67,3.8,63.1,17.10
M4,0.60,0.36,3.5,69.2,18.42
M5,0.76,0.58,4.8,43.0,12.29
M6,0.69,0.48,6.6,48.7,14.12
M7,0.79,0.62,4.8,59.2,16.35
M8,0.84,0.71,6.5,34.5,10.64
Command
topsis data.csv "1,1,1,1,1" "+,+,-,+,+" result.csv
Output File (result.csv)
The output will include the original data plus two additional columns:
- Topsis Score: A score between 0-100 indicating closeness to the ideal solution
- Rank: Ranking based on TOPSIS score (1 = best)
Fund Name,P1,P2,P3,P4,P5,Topsis Score,Rank
M1,0.67,0.45,6.5,42.6,12.56,21.52,8
M2,0.60,0.36,3.6,53.3,14.47,46.80,4
M3,0.82,0.67,3.8,63.1,17.10,86.15,1
M4,0.60,0.36,3.5,69.2,18.42,58.85,3
M5,0.76,0.58,4.8,43.0,12.29,45.08,5
M6,0.69,0.48,6.6,48.7,14.12,32.66,7
M7,0.79,0.62,4.8,59.2,16.35,69.55,2
M8,0.84,0.71,6.5,34.5,10.64,41.42,6
Using in Python Code
You can also use the TOPSIS package programmatically:
from topsis.topsis import topsis
import pandas as pd
# Your data as a list of lists (excluding the first column with names)
matrix = [
[0.67, 0.45, 6.5, 42.6, 12.56],
[0.60, 0.36, 3.6, 53.3, 14.47],
[0.82, 0.67, 3.8, 63.1, 17.10],
]
weights = [1, 1, 1, 1, 1]
impacts = ["+", "+", "-", "+", "+"]
scores, ranks = topsis(matrix, weights, impacts)
print("Scores:", scores)
print("Ranks:", ranks)
Input Validation
The package performs comprehensive input validation:
✅ Checks for correct number of command-line parameters
✅ Validates file existence
✅ Ensures minimum 3 columns (1 name + 2 criteria)
✅ Verifies all criteria values are numeric
✅ Confirms weights and impacts count matches criteria count
✅ Validates impacts are only '+' or '-'
✅ Ensures comma-separated format for weights and impacts
Error Messages
The package provides clear, actionable error messages:
# Wrong number of parameters
Error: Incorrect number of parameters.
Usage : topsis <InputFile> <Weights> <Impacts> <OutputFile>
# File not found
Error: Input file 'data.csv' not found.
# Non-numeric value
Error: Non-numeric value 'abc' in row 2, column 3.
# Mismatched weights
Error: Number of weights (3) does not match criteria columns (5).
# Invalid impact
Error: Invalid impact '0'. Must be '+' or '-'.
Algorithm Steps
- Normalization: Convert the decision matrix using vector normalization
- Weighted Normalization: Multiply normalized values by their weights
- Ideal Solutions: Determine ideal best (A+) and ideal worst (A-) solutions
- Distance Calculation: Calculate Euclidean distances from ideal solutions
- TOPSIS Score: Calculate relative closeness to ideal solution
- Ranking: Rank alternatives based on TOPSIS scores
Requirements
- Python >= 3.7
- pandas >= 1.0.0
License
MIT License
Author
Saumil Makkar
Email: saumilmakkar@example.com
GitHub: https://github.com/SaumilMakkar/UCS654
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Issues
If you encounter any problems, please file an issue at: https://github.com/SaumilMakkar/UCS654/issues
Changelog
Version 1.0.0 (2024)
- Initial release
- Command-line interface
- Comprehensive input validation
- Clear error messages
- Support for any number of criteria
- Handles both benefit (+) and cost (-) criteria
References
- Hwang, C.L.; Yoon, K. (1981). Multiple Attribute Decision Making: Methods and Applications. New York: Springer-Verlag.
- Yoon, K. (1987). "A reconciliation among discrete compromise situations". Journal of the Operational Research Society. 38 (3): 277–286.
- Original Implementation: https://github.com/SaumilMakkar/UCS654/blob/main/Assignment3/Assignment3UCS654.ipynb
Keywords
TOPSIS, MCDM, Multi-Criteria Decision Making, Decision Analysis, Optimization, Ranking, Python
Metadata
Release files for Topsis-Saumil-102303862 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| topsis_saumil_102303862-1.0.2.tar.gz | 8.1 kB | Without provenance | Details for topsis_saumil_102303862-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| topsis_saumil_102303862-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for topsis_saumil_102303862-1.0.2-py3-none-any.whl |
Total release size: 16.3 kB
Release files / topsis_saumil_102303862-1.0.2.tar.gz
| Download URL | topsis_saumil_102303862-1.0.2.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
93170196661c807e6ec4ebe686154cc38a954024dbb1a1af3f3b4b661bdb60f9
|
|
BLAKE2b-256 checksum How to use checksums |
01aa6819282b1dc276adbb394c47c04fff41d022acca73c5df40b5421ba994ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / topsis_saumil_102303862-1.0.2-py3-none-any.whl
| Download URL | topsis_saumil_102303862-1.0.2-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
814c589b1841374790fb1df1ef2edcc6ad875a786facd7af9aa3bcd96e04db9a
|
|
BLAKE2b-256 checksum How to use checksums |
805c1053189dcb1b8b74119fa6d40b2ad57e0943fd371f5ae86bd455a6c66d14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for Topsis-Saumil-102303862 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.