TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) implementation for multi-criteria decision making
Project description
TOPSIS-Lavanya-102313066
A Python package and Web Service for the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS).
๐ Table of Contents
- About TOPSIS
- System Flowchart
- Installation
- Usage (CLI & Python)
- Web Application
- Mathematics Behind TOPSIS
- Project Structure
- License
- Author
๐ง About TOPSIS
TOPSIS is a multi-criteria decision analysis method. It is based on the concept that the chosen alternative should have the shortest geometric distance from the positive ideal solution (PIS) and the longest geometric distance from the negative ideal solution (NIS).
This project provides a complete suite to perform TOPSIS analysis:
- Command Line Tool: For quick, local analysis
- Python Package: Installable via PyPI, usable in your Python scripts
- Web Service: Cloud-based interface with drag-and-drop, email integration, and real-time results
PyPI Link: https://pypi.org/project/Topsis-Lavanya-102313066/
๐ System Flowchart
User Input (Data, Weights, Impacts)
โ
File Upload (CSV/Excel/JSON)
โ
Data Normalization
โ
Apply Weights
โ
Find Ideal Solutions
โ
Calculate Separations
โ
Calculate Scores & Ranks
โ
Display Results + Email
๐ฆ Installation
Install the package directly from PyPI:
pip install Topsis-Lavanya-102313066
๐ป Usage
1. Command Line Interface (CLI)
Calculate TOPSIS scores directly from your terminal.
Syntax:
topsis-cli <InputDataFile> <Weights> <Impacts> <ResultFileName>
Example:
topsis-cli data.csv "1,1,1,2" "+,+,+,-" result.csv
Inputs:
InputDataFile: CSV file containing the data matrixWeights: Comma-separated weights (e.g., 1,1,1,2)Impacts: Comma-separated impacts (+ for beneficial, - for non-beneficial)ResultFileName: Path to save the output file
Output:
Alternative,Storage,RAM,Price,Battery,Topsis Score,Rank
M5,512,16,50000,7000,0.8954,1
M2,512,12,40000,6000,0.7823,2
M1,256,8,30000,5000,0.5621,3
2. Python Library
Import the package in your Python scripts.
from topsis_lavanya_102313066 import topsis
# topsis(input_file, weights, impacts, output_file)
result = topsis("data.csv", "1,1,1,2", "+,+,+,-", "output.csv")
print(result)
Parameters:
input_file(str): Path to CSV file with first column as identifiersweights(str or list): Comma-separated weights or listimpacts(str or list): Comma-separated impacts (+ or -) or listoutput_file(str, optional): Output file path
Returns:
pd.DataFrame: Results with Topsis Score and Rank columns
๐ Web Application
A live web service provides a graphical user interface for TOPSIS analysis.
Features:
- โ Drag & Drop Interface: Upload .csv, .xlsx, .xls, or .json files
- โ Multi-Format Support: Automatic format detection
- โ Real-Time Validation: Instant feedback on inputs
- โ Email Integration: Results delivered to your inbox
- โ CSV Download: Download results instantly
- โ Professional UI: Modern dark theme with cyan accents
Local Access:
cd web_service
pip install -r requirements.txt
python app.py
Then visit: http://localhost:5000
๐งฎ Mathematics Behind TOPSIS
The TOPSIS process involves the following steps:
Step 1: Normalize the Decision Matrix
$$r_{ij} = \frac{x_{ij}}{\sqrt{\sum_{i=1}^{m} x_{ij}^2}}$$
Step 2: Calculate Weighted Normalized Decision Matrix
$$v_{ij} = w_j \times r_{ij}$$
Step 3: Determine Ideal Solutions
- Ideal Best (V+): $v_j^+ = \max(v_{ij})$ if impact is (+), $\min(v_{ij})$ if (-)
- Ideal Worst (V-): $v_j^- = \min(v_{ij})$ if impact is (+), $\max(v_{ij})$ if (-)
Step 4: Calculate Separation Measures
$$S_i^+ = \sqrt{\sum_{j=1}^{n} (v_{ij} - v_j^+)^2}$$ $$S_i^- = \sqrt{\sum_{j=1}^{n} (v_{ij} - v_j^-)^2}$$
Step 5: Calculate Performance Score
$$P_i = \frac{S_i^-}{S_i^+ + S_i^-}$$
Score range: 0 to 1 (higher is better)
Step 6: Rank Alternatives
Sort by performance score in descending order (highest score = Rank 1)
๐ Project Structure
Topsis-Lavanya-102313066/
โโโ topsis_package/ # PyPI Package Source
โ โโโ topsis_lavanya_102313066/
โ โ โโโ __init__.py
โ โ โโโ topsis.py # Core algorithm
โ โ โโโ cli.py # Command-line interface
โ โโโ setup.py # Package configuration
โ โโโ README.md # Package documentation
โ โโโ LICENSE # MIT License
โ โโโ MANIFEST.in
โ
โโโ web_service/ # Web Service
โ โโโ app.py # Flask Application
โ โโโ requirements.txt # Dependencies
โ โโโ templates/ # HTML Templates
โ โ โโโ index.html # Web UI
โ โโโ uploads/ # Temporary file storage
โ โโโ .env # Configuration
โ โโโ .env.example # Configuration template
โ โโโ README.md # Web service documentation
โ
โโโ topsis.py # Standalone CLI program
โโโ data.csv # Sample dataset
โโโ test_all.py # Test suite
โโโ README.md # Main documentation
โโโ COMPLETE_GUIDE.md # Comprehensive guide
โโโ DEPLOYMENT_GUIDE.md # Deployment instructions
โโโ QUICK_REFERENCE.md # Quick commands
โโโ LICENSE # MIT License
๐ Example Use Case
Mobile Phone Selection
Data (data.csv):
Mobile,Storage,RAM,Price,Battery
M1,256,8,30000,5000
M2,512,12,40000,6000
M3,128,4,15000,3000
M4,256,6,25000,4500
M5,512,16,50000,7000
Analysis:
topsis-cli data.csv "1,1,1,2" "+,+,-,+" result.csv
Results (result.csv):
Mobile,Storage,RAM,Price,Battery,Topsis Score,Rank
M5,512,16,50000,7000,0.8954,1
M2,512,12,40000,6000,0.7823,2
M1,256,8,30000,5000,0.5621,3
M4,256,6,25000,4500,0.3847,4
M3,128,4,15000,3000,0.1892,5
Interpretation: M5 is the best phone based on the criteria with weight emphasis on battery life.
โจ Features
- โ Complete TOPSIS algorithm implementation
- โ Command-line interface
- โ Python library for integration
- โ Web-based user interface
- โ Multi-file format support (CSV, Excel, JSON)
- โ Email result delivery
- โ Input validation and error handling
- โ Comprehensive documentation
- โ Production-ready code
๐ง Requirements
- Python 3.7 or higher
- pandas >= 1.0.0
- numpy >= 1.18.0
- Flask >= 2.3.3 (for web service)
- openpyxl >= 3.1.5 (for Excel support)
- python-dotenv >= 1.0.0 (for configuration)
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐จโ๐ป Author
Lavanya Garg
- Roll Number: 102313066
- Institution: Thapar Institute of Engineering and Technology
- Email: lgarg_be23@thapar.edu
- GitHub: https://github.com/lavanya-garg
๐ Acknowledgments
- TOPSIS methodology based on Hwang & Yoon (1981)
- Inspired by real-world multi-criteria decision-making problems
- Built with Python, Flask, and modern web technologies
๐ Support
For issues, questions, or suggestions:
- Check the Complete Guide
- Review Quick Reference
- Check Troubleshooting
- Open an issue on GitHub
Happy TOPSIS Analysis! ๐
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_lavanya_102313066-1.0.1.tar.gz.
File metadata
- Download URL: topsis_lavanya_102313066-1.0.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba5c6dba87d85f993cc2596160a78f5e9958f0bc17bdba2f6686bb480e4f704c
|
|
| MD5 |
0f1380d0313183240bdf1cfb1c39342e
|
|
| BLAKE2b-256 |
d353fbef32cb38dbae4cd06712027eeaab9010dc2ecfbc391e1a7be1fdd83a9c
|
File details
Details for the file topsis_lavanya_102313066-1.0.1-py3-none-any.whl.
File metadata
- Download URL: topsis_lavanya_102313066-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58827607aab34a5cf85286434008ce07626ee5cfbc34ed52cba80fea0f2cd621
|
|
| MD5 |
3aed0a79ea2ad4a6cd49373c49f3fab4
|
|
| BLAKE2b-256 |
44156100448a3195f2a42e34283fcbe52358b5a592197ff6758378bda51788e0
|