Skip to main content

A Python package for TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) analysis.

Project description

TOPSIS Implementation in Python

Author: Sanyam Wadhwa

Roll Number: 102303059

Class: 3C12

Introduction

This project implements TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) as a Python package for multi-criteria decision analysis.

What is TOPSIS?

TOPSIS is a multi-criteria decision analysis method that ranks alternatives by measuring their geometric distance from ideal solutions. The best alternative has the shortest distance from the ideal best and the farthest distance from the ideal worst.

Methodology

Algorithm Steps:

  1. Normalize Decision Matrix
    • r_ij = x_ij / √(Σ x_ij²)
  2. Calculate Weighted Normalized Matrix
    • v_ij = w_j × r_ij
  3. Determine Ideal Solutions
    • Ideal Best (A⁺): Max for beneficial (+), Min for non-beneficial (-)
    • Ideal Worst (A⁻): Min for beneficial (+), Max for non-beneficial (-)
  4. Calculate Separation Measures
    • S_i⁺ = √(Σ (v_ij - v_j⁺)²) [Distance from ideal best]
    • S_i⁻ = √(Σ (v_ij - v_j⁻)²) [Distance from ideal worst]
  5. Calculate TOPSIS Score
    • P_i = S_i⁻ / (S_i⁺ + S_i⁻) [Range: 0 to 1]
  6. Rank Alternatives
    • Higher score = Better rank (Rank 1 is best)

Installation

pip install pandas numpy

Usage

As a Library

import pandas as pd
from Topsis_Sanyam_102303059.topsis import topsis

df = pd.read_csv('data.csv')
weights = [1,1,1,2,1]
impacts = ['+','+','-','+','+']
result = topsis(df, weights, impacts)
print(result)

As a Command-Line Tool

python topsis.py <InputFile> <Weights> <Impacts> <OutputFile>

Example:

python topsis.py data.csv "1,1,1,2,1" "+,+,-,+,+" result.csv

Input Format

  • CSV Structure:
    • First column: Alternative names/IDs
    • Remaining columns: Numerical criteria values

Sample (data.csv):

Model,Price,Storage,Camera,Looks,Performance
M1,250,16,12,5,5
M2,200,16,8,3,3
M3,300,32,16,4,4
M4,275,32,8,4,4
M5,225,16,16,2,2

Output Format

Original columns + Topsis Score + Rank

Sample (result.csv):

Model,Price,Storage,Camera,Looks,Performance,Topsis Score,Rank
M3,300,32,16,4,4,0.6891,1
M4,275,32,8,4,4,0.6234,2
M1,250,16,12,5,5,0.5345,3
M5,225,16,16,2,2,0.4789,4
M2,200,16,8,3,3,0.4523,5

Error Handling

The program validates:

  • Parameter Count: Exactly 4 arguments required
  • File Existence
  • Column Count: Minimum 3 columns required
  • Numeric Values: Columns 2+ must be numeric
  • Impact Validation: Only '+' or '-' allowed
  • Parameter Matching: Weights, impacts, and criteria count must match

Example Demonstration

Test Case: Mobile Phone Selection

python topsis.py data.csv "1,1,1,1,1" "-,+,+,+,+" result.csv

Applications

  • Product selection and comparison
  • Supplier evaluation
  • Project prioritization
  • Investment decision making
  • Technology selection
  • Performance evaluation

File Structure

Topsis_Sanyam_102303059/
│
├── Topsis_Sanyam_102303059/
│   ├── __init__.py
│   └── topsis.py
├── README.md
├── setup.py
├── pyproject.toml
└── LICENSE

Quick Start

# 1. Install dependencies
pip install pandas numpy

# 2. Use as a library or run as a script

References

  • Hwang, C.L.; Yoon, K. (1981). Multiple Attribute Decision Making
  • Yoon, K. (1987). A reconciliation among discrete compromise situations

Developed by: Sanyam Wadhwa (102303059) - Class 3C12

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_sanyam_102303059-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

topsis_sanyam_102303059-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file topsis_sanyam_102303059-1.0.1.tar.gz.

File metadata

  • Download URL: topsis_sanyam_102303059-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for topsis_sanyam_102303059-1.0.1.tar.gz
Algorithm Hash digest
SHA256 67c2f2d57dca152d391670e93a4f3eb86b0015d1d2f50168531db13ac09c26e2
MD5 18f35cc7520248e3876a697b8e1921d8
BLAKE2b-256 cea08e8dbf82e9aa8273bcfb6ea64e9980a6ebfc21f19a9eed629bb27c841844

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for topsis_sanyam_102303059-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f86f869e26177f2a9d1bceefee11e9501b18758d02985e0470e30df0a4ab724d
MD5 cb49a1461f1f42b7fd58b92d47e5ab79
BLAKE2b-256 29892701be91c8aa6232413ffdecf6b4fd269d77a4cebf0f7ce1ddfa236a9d25

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