Skip to main content

A Python package for implementing the TOPSIS method.

Project description

TOPSIS Implementation in Python

Introduction

This Python script implements the TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution) method for multi-criteria decision-making. It evaluates alternatives based on multiple criteria, considering their relative importance and impact.

Prerequisites Python 3.x

Libraries: pandas numpy

Install the required libraries using the following command: pip install pandas numpy

Files 102203527.py: The main Python script containing the TOPSIS implementation. Input File: A CSV file containing the decision matrix. Output File: A CSV file where the results will be saved.

Input File Format The input file must be a CSV file with the following format: First column: Names or identifiers of alternatives (e.g., A, B, C). Remaining columns: Criteria values (numerical).

Example Input File (data.csv):

Command-Line Usage The script requires four command-line arguments: python 102203527.py

Arguments: : Path to the input CSV file (e.g., data.csv). : Comma-separated weights for each criterion (e.g., 1,1,1,1). : Comma-separated impacts for each criterion (+ for beneficial, - for non-beneficial). : Path to the output CSV file (e.g., result.csv).

Example Command: python 102203527.py data.csv "1,1,1,1" "+,-,+,+" result.csv

Output File Format The output file will be a CSV file containing the input data with two additional columns: Topsis Score: The calculated score for each alternative. Rank: The rank of each alternative based on the TOPSIS score.

Example Output File Alternatives,Criterion1,Criterion2,Criterion3,Criterion4,Topsis Score,Rank A,20,300,50,0.5,0.78,2 B,25,250,60,0.7,0.85,1 C,30,200,70,0.4,0.63,3

Error Handling

Common Errors: Invalid Input File: Ensure the file exists and follows the correct format. Error: File '' not found.

Insufficient Columns: Ensure the file contains at least three columns (one for alternatives and two for criteria). Error: Input file must contain at least three columns. Mismatch in Weights or Impacts: Ensure the number of weights and impacts matches the number of criteria columns.

Error: Number of weights and impacts must match the number of criteria columns. Invalid Impacts: Ensure impacts are either + or -. Error: Impacts must be '+' or '-'.

Explanation of the TOPSIS Method

Input Normalization: Normalize the decision matrix using:

Weight Assignment: Multiply each normalized value by its respective weight.

Determine Ideal Best and Worst Values: For beneficial criteria (+), the ideal best is the maximum value, and the ideal worst is the minimum value. For non-beneficial criteria (-), the ideal best is the minimum value, and the ideal worst is the maximum value.

Calculate Distances: Compute the Euclidean distance from the ideal best and worst values.

Calculate TOPSIS Score: Compute the relative closeness to the ideal solution:

Ranking: Rank the alternatives based on their scores in descending order.

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-Akshita-102203527-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

Topsis_Akshita_102203527-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file Topsis-Akshita-102203527-0.1.0.tar.gz.

File metadata

File hashes

Hashes for Topsis-Akshita-102203527-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53afa2a405fa2e81783bf0f4fa983ef51ddd68bda665121d40e577111d8da210
MD5 d71a78664414f3973119c349c981323d
BLAKE2b-256 cf6b7dccdc85d5fbf6de8f3e7750a64f65075fe46f4cf1a7e218ebea7f3f4952

See more details on using hashes here.

File details

Details for the file Topsis_Akshita_102203527-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for Topsis_Akshita_102203527-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f51cbdc2409846d353911cb050e0970bfa054ecd40266f84a77e67d95d62d74
MD5 435571729f2b025f46e3b74809e2c104
BLAKE2b-256 1115d7740c83e62d67b550914f13c8e0889919edc33017d182310c700e00fa63

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