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

topsis <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:

topsis 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.1.tar.gz (19.9 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.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: topsis_vidyt_102303747-1.0.1.tar.gz
  • Upload date:
  • Size: 19.9 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.1.tar.gz
Algorithm Hash digest
SHA256 6d3d103f51d7f7400096dd2f05c8b8cb45d57a2a73c5f1e81fa583328cf47416
MD5 f423d8fbcf1d6ba6f52d420a5cb4bf7e
BLAKE2b-256 f0a58aa3b18c9f096ecaca16275bb4f22faee9f786f9dfc058f9a46eeb3208b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for topsis_vidyt_102303747-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8ad5563e0edae02a4b09d973439d2ee9368216e5ee5fec9ee98ac34cce219d46
MD5 2793a78146ab9eab19090c668d3f5756
BLAKE2b-256 8047e1a37562f882808ebefb3e3ebb642ca56f69e7890455b4077553dabfdd2f

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