Skip to main content

A Python package for TOPSIS multi-criteria decision analysis

Project description

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:

  1. Calculating the distance of each alternative from the ideal best and ideal worst solutions
  2. 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

  1. Normalization: Convert the decision matrix using vector normalization
  2. Weighted Normalization: Multiply normalized values by their weights
  3. Ideal Solutions: Determine ideal best (A+) and ideal worst (A-) solutions
  4. Distance Calculation: Calculate Euclidean distances from ideal solutions
  5. TOPSIS Score: Calculate relative closeness to ideal solution
  6. 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

Keywords

TOPSIS, MCDM, Multi-Criteria Decision Making, Decision Analysis, Optimization, Ranking, Python

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_saumil_102303862-1.0.2.tar.gz (8.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_saumil_102303862-1.0.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file topsis_saumil_102303862-1.0.2.tar.gz.

File metadata

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

File hashes

Hashes for topsis_saumil_102303862-1.0.2.tar.gz
Algorithm Hash digest
SHA256 93170196661c807e6ec4ebe686154cc38a954024dbb1a1af3f3b4b661bdb60f9
MD5 8f95ff54dfc561dbe41e8dce401836e3
BLAKE2b-256 01aa6819282b1dc276adbb394c47c04fff41d022acca73c5df40b5421ba994ba

See more details on using hashes here.

File details

Details for the file topsis_saumil_102303862-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for topsis_saumil_102303862-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 814c589b1841374790fb1df1ef2edcc6ad875a786facd7af9aa3bcd96e04db9a
MD5 df53f510b5ce96e35ab84e0f490ebf9b
BLAKE2b-256 805c1053189dcb1b8b74119fa6d40b2ad57e0943fd371f5ae86bd455a6c66d14

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