Skip to main content

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

Project description

TOPSIS Implementation

TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) is a multi-criteria decision-making algorithm that ranks alternatives based on their closeness to an ideal solution.

Installation

pip install topsis-vidyt-102303747

Usage

Command Line

python -m topsis_package <InputDataFile> <Weights> <Impacts> <OutputResultFile>

Arguments:

  • InputDataFile: CSV or XLSX file with data (first column: identifiers, rest: numeric criteria)
  • Weights: Comma-separated numeric weights (e.g., "0.2,0.2,0.2,0.2,0.2")
  • Impacts: Comma-separated impacts: '+' for benefit, '-' for cost (e.g., "+,+,+,-,+")
  • OutputResultFile: Output CSV file name

Example:

python -m topsis_package data.xlsx "0.2,0.2,0.2,0.2,0.2" "+,+,+,+,+" output.csv

Python Code

import numpy as np
from topsis_package import topsis

# Data: 8 alternatives, 5 criteria
data = np.array([
    [0.67, 0.45, 6.5, 42.0, 12.56],
    [0.60, 0.36, 3.3, 53.3, 14.47],
    [0.82, 0.67, 3.6, 38.0, 17.1],
    [0.60, 0.36, 3.5, 60.9, 18.42],
    [0.76, 0.58, 4.8, 43.0, 12.29],
    [0.69, 0.48, 6.6, 48.7, 14.12],
    [0.79, 0.62, 4.8, 59.2, 16.35],
    [0.84, 0.71, 6.5, 34.5, 10.64],
])

weights = [0.2, 0.2, 0.2, 0.2, 0.2]
impacts = ["+", "+", "+", "+", "+"]

result = topsis(data, weights, impacts)
print("Scores:", result.scores)
print("Ranks:", result.ranks)

Input File Format

CSV Example (data.csv):

Fund_Name,P1,P2,P3,P4,P5
M1,0.67,0.45,6.5,42.0,12.56
M2,0.60,0.36,3.3,53.3,14.47
M3,0.82,0.67,3.6,38.0,17.1

XLSX Example:

Same structure, saved as .xlsx file.

Output Format

Output CSV includes original columns plus:

  • Topsis Score: Closeness coefficient (0 to 1, higher is better)
  • Rank: 1-based ranking (1 is best)

Example Output (output.csv):

Fund_Name,P1,P2,P3,P4,P5,Topsis Score,Rank
M1,0.67,0.45,6.5,42.0,12.56,0.650000,2
M2,0.60,0.36,3.3,53.3,14.47,0.480000,5
M3,0.82,0.67,3.6,38.0,17.1,0.720000,1

Validation Rules

The program validates:

  • ✓ Correct number of CLI arguments
  • ✓ Weights are numeric and comma-separated
  • ✓ Impacts are '+' or '-' only
  • ✓ Input file exists (File not found handling)
  • ✓ Input file has ≥3 columns (ID + ≥2 criteria)
  • ✓ All criteria columns contain numeric values only
  • ✓ Number of weights = number of impacts = number of criteria columns
  • ✓ Input file has at least one data row

TOPSIS Algorithm Steps

  1. Normalize the decision matrix using vector normalization
  2. Weight each normalized column
  3. Determine ideal best and worst based on impact type (+ or -)
  4. Calculate distances from each alternative to ideal best/worst
  5. Compute closeness coefficient = distance_to_worst / (distance_to_best + distance_to_worst)
  6. Rank alternatives by descending score (1 = best)

Error Handling

The program provides clear error messages:

Error: Input file not found
Error: Weights must be numeric and separated by commas
Error: Impacts must be either '+' or '-' and separated by commas
Error: Number of weights, impacts, and criteria columns must match
Error: Non-numeric value found in row X (criteria columns must be numeric)

Requirements

  • Python ≥ 3.7
  • numpy
  • pandas
  • openpyxl (for XLSX support)

License

MIT License

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_vidyt_102303747-1.0.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

topsis_vidyt_102303747-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file topsis_vidyt_102303747-1.0.0.tar.gz.

File metadata

  • Download URL: topsis_vidyt_102303747-1.0.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for topsis_vidyt_102303747-1.0.0.tar.gz
Algorithm Hash digest
SHA256 21e1af41d29c2baf2b6ff74632bbae762f1c567a135402459c05e8aa003f287d
MD5 e8d1398ce52e385fe876342396e344ac
BLAKE2b-256 dc6f5b48ebbd7995d91a178e2085ee566f151fc5236b763666b7b3593d39db12

See more details on using hashes here.

File details

Details for the file topsis_vidyt_102303747-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for topsis_vidyt_102303747-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9723c9a86f4e2eea4b27eaad62da9bbb2327b70ac731c5c22732993621bf83d
MD5 637e2fb9425a05f13cb93dba06a67712
BLAKE2b-256 f4a994da2ece249ff6eeb351cd624b4bec6230b01d3460d0550ab65a035492e5

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