Skip to main content

A Python package to implement TOPSIS

Project description

102303812-topsis

A Python package to implement TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) for multi-criteria decision analysis.

Author: Harsh Tanwar
Roll No: 102303812
Email: htanwar_be23@thapar.edu

Repository: Assignment1-Topsis


What is TOPSIS?

TOPSIS ranks alternatives by comparing each to an ideal positive and ideal negative solution. Alternatives closer to the ideal positive and farther from the ideal negative get higher scores and better ranks. The method uses vector normalization, weighted criteria, and Euclidean distances to compute a performance score for each alternative.


Requirements

  • Python 3.6+
  • pandas – data handling
  • numpy – numerical operations

Install dependencies:

pip install pandas numpy

Installation

From PyPI (if published)

pip install 102303812-topsis

From source (clone or download the repo)

git clone https://github.com/htan11/course-materials.git
cd course-materials/UCS654/Assignment1-Topsis
pip install .

Or, in the folder containing setup.py:

pip install .

Usage

Command line

topsis <InputDataFile> <Weights> <Impacts> <OutputResultFileName>

Example (with 5 criteria):

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

As a Python module

(Because the package name contains a hyphen, use importlib to import.)

import importlib
topsis = getattr(importlib.import_module("102303812-topsis"), "topsis")

topsis("data.csv", "1,1,1,1,1", "+,+,-,+,-", "result.csv")

Parameters

Parameter Description
InputDataFile Path to a CSV file: first column = alternative names, remaining columns = numeric criterion values. Must have a header row.
Weights Comma-separated weights for each criterion (e.g. "1,1,1,2,1"). Number of values must match number of criteria.
Impacts Comma-separated impacts: + for beneficial (higher is better), - for non-beneficial (lower is better). Same count as criteria.
OutputResultFileName Path for the output CSV. Contains original columns plus Topsis Score and Rank.
  • Beneficial (+): e.g. Quality, Customer Rating — higher value is better.
  • Non-beneficial (-): e.g. Price, Delivery Time — lower value is better.

Input file format

CSV with a header; first column = alternative names, rest = numeric only.

Example (data.csv):

Product Quality Price Features Customer Rating Delivery Time
A1 8.5 450 7.2 4.3 3
A2 7.8 380 8.1 4.5 5
... ... ... ... ... ...
  • Column 1: labels (not used in math).
  • Columns 2–6: criteria. Weights and impacts must be given for each of these in order.

Example with this dataset

For 5 criteria (Quality, Price, Features, Customer Rating, Delivery Time):

  • Weights: "1,1,1,1,1" (equal weight).
  • Impacts: "+,+,-,+,-" (Quality +, Price +, Features -, Customer Rating +, Delivery Time -).

Run:

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

Output CSV will have all input columns plus:

  • Topsis Score – higher is better.
  • Rank – 1 = best alternative.

Output

The result file contains:

  • All original columns.
  • Topsis Score – performance score in [0, 1].
  • Rank – integer rank (1 = best).

Example message: Result file 'result.csv' created successfully.


Project structure

assignment1_DS-main/
├── README.md
├── setup.py
├── data.csv              # Sample input
├── 102303812-topsis/
│   ├── __init__.py
│   └── topsis.py         # TOPSIS implementation
└── LICENSE

License

MIT License. See LICENSE for details.

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_harshtanwar_102303812-1.0.0.tar.gz (6.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_harshtanwar_102303812-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for topsis_harshtanwar_102303812-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fe02e35c738498846baeeaa875f0f883ca36f9856ed502c4cdf68c8a59ddad34
MD5 6af9f7e8bf18d3342a6c99dd6ed4533c
BLAKE2b-256 736657005a5c5a9a573618e02e43dc9161fa0af08e64f0db0e7718bf106bb3c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for topsis_harshtanwar_102303812-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c03359a196b148dc227c829b8d962831e3896535a0774223eda225c7f0a15bb0
MD5 690bb1dea1647a6bee6ac0b52938cef9
BLAKE2b-256 9809ec31083dd7b564d8f4c1076a4b70c1ecf646ce3ea965741f911140fea10d

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