A Python implementation of the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method.
Project description
Topsis-Sparsh_Gupta-102317228
A Python implementation of the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method for multi-criteria decision making.
📌 What is TOPSIS?
TOPSIS is a Multi-Criteria Decision Making (MCDM) technique used to rank alternatives based on:
- Distance from the Ideal Best solution
- Distance from the Ideal Worst solution
The best alternative is:
- Closest to the Ideal Best
- Farthest from the Ideal Worst
⚙️ Mathematical Steps
- Normalize the decision matrix
- Multiply by weights
- Determine Ideal Best and Ideal Worst
- Compute Euclidean distances
- Calculate relative closeness score
- Rank alternatives
📊 Algorithm Flow (Mermaid Diagram)
flowchart TD
A[Start] --> B[Read Input File]
B --> C[Validate Data]
C --> D[Normalize Matrix]
D --> E[Apply Weights]
E --> F[Find Ideal Best & Worst]
F --> G[Compute Distances]
G --> H[Calculate TOPSIS Score]
H --> I[Rank Alternatives]
I --> J[Save Output File]
J --> K[End]
📥 Installation
Install from PyPI:
pip install Topsis-Sparsh Gupta-102317228
Or install locally:
pip install .
🚀 Usage (Command Line)
topsis <InputFile> <Weights> <Impacts> <OutputFile>
Example
topsis data.xlsx "1,1,1,2" "+,+,-,+" result.csv
📄 Input Format
The input file must:
- Contain at least 3 columns
- First column: Identifier (Name/ID)
- Remaining columns: Numeric values only
- Weights must be comma-separated
- Impacts must be '+' or '-'
Example Input
| Fund | P1 | P2 | P3 | P4 |
|---|---|---|---|---|
| M1 | 0.67 | 0.45 | 5.6 | 12.56 |
| M2 | 0.6 | 0.36 | 3.5 | 14.47 |
📤 Output Format
The output file contains:
- Original data
- Topsis Score column
- Rank column
Higher score = Better rank
🧮 Mathematical Formula
Normalization
[ R_{ij} = \frac{x_{ij}}{\sqrt{\sum x_{ij}^2}} ]
Weighted Matrix
[ V_{ij} = w_j \cdot R_{ij} ]
Distance Measures
[ S_i^+ = \sqrt{\sum (V_{ij} - A_j^+)^2} ]
[ S_i^- = \sqrt{\sum (V_{ij} - A_j^-)^2} ]
Topsis Score
[ C_i = \frac{S_i^-}{S_i^+ + S_i^-} ]
🛑 Error Handling
The program checks for:
- File not found
- Incorrect number of parameters
- Less than 3 columns
- Non-numeric values
- Mismatch in weights and impacts
- Invalid impacts
🧠 Requirements
- Python 3.7+
- numpy
- pandas
- openpyxl
👤 Author
Sparsh Gupta
102317228
📜 License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file topsis_sparsh_gupta_102317228-1.0.0.tar.gz.
File metadata
- Download URL: topsis_sparsh_gupta_102317228-1.0.0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38bd5c636292700f8f908c2e68f7b13ec07980702a4dd23c396a3c2b2f1d6beb
|
|
| MD5 |
da9e99be72775f17d6be47017de476c5
|
|
| BLAKE2b-256 |
7119f8facd43a212bab5c5b1c2f99c14ca6d363ab0a6b60fd15629feacaf1f32
|
File details
Details for the file topsis_sparsh_gupta_102317228-1.0.0-py3-none-any.whl.
File metadata
- Download URL: topsis_sparsh_gupta_102317228-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63533de1c025def0faa9b570f4e766326087f4cdaba39be0e6fb47c39843470b
|
|
| MD5 |
9022a30b28d75699c112db53a1f479a2
|
|
| BLAKE2b-256 |
c32c9f99f16b1c6d12e48867171a6046d4172921e0c46f10a6a66f541fbd1e1f
|