Skip to main content

TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) implementation for multi-criteria decision making

Project description

TOPSIS-Lavanya-102313066

PyPI version Python 3.7+ License: MIT

A Python package and Web Service for the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS).

๐Ÿ“‹ Table of Contents

๐Ÿง  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 matrix
  • Weights: 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 identifiers
  • weights (str or list): Comma-separated weights or list
  • impacts (str or list): Comma-separated impacts (+ or -) or list
  • output_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

๐Ÿ™ 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:

  1. Check the Complete Guide
  2. Review Quick Reference
  3. Check Troubleshooting
  4. Open an issue on GitHub

Happy TOPSIS Analysis! ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topsis_lavanya_102313066-1.0.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topsis_lavanya_102313066-1.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

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

Hashes for topsis_lavanya_102313066-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ba5c6dba87d85f993cc2596160a78f5e9958f0bc17bdba2f6686bb480e4f704c
MD5 0f1380d0313183240bdf1cfb1c39342e
BLAKE2b-256 d353fbef32cb38dbae4cd06712027eeaab9010dc2ecfbc391e1a7be1fdd83a9c

See more details on using hashes here.

File details

Details for the file topsis_lavanya_102313066-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for topsis_lavanya_102313066-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58827607aab34a5cf85286434008ce07626ee5cfbc34ed52cba80fea0f2cd621
MD5 3aed0a79ea2ad4a6cd49373c49f3fab4
BLAKE2b-256 44156100448a3195f2a42e34283fcbe52358b5a592197ff6758378bda51788e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page