Skip to main content

No project description provided

Project description


TOPSIS Method Implementation

This Python program implements the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method, which is used for multi-criteria decision analysis. It helps in evaluating and ranking alternatives based on several criteria and weights.

Requirements

  • Python 3.x
  • Required libraries:
    • pandas
    • numpy

You can install the necessary libraries using:

pip install pandas numpy

Functionality

The program performs the following tasks:

  1. Input Validation: It validates the input CSV file, the weights, and the impacts.
  2. Normalization: It normalizes the decision matrix using vector normalization.
  3. Weighted Normalization: Each attribute of the normalized decision matrix is multiplied by its corresponding weight.
  4. Ideal and Negative Ideal Solutions: It computes the ideal and negative ideal solutions based on the given impacts (+ for beneficial, - for non-beneficial).
  5. Distance Calculation: The program calculates the distance of each alternative from the ideal and negative ideal solutions.
  6. TOPSIS Score Calculation: A score is computed for each alternative, which indicates its closeness to the ideal solution.
  7. Ranking: The alternatives are ranked based on their scores, with the best alternative ranked 1.
  8. Output: The results (scores and rankings) are saved in a CSV file.

Usage

Command-Line Usage

The program is run through the command line with the following parameters:

topsis <inputFileName> <Weights> <Impacts> <resultFileName>

Parameters

  • <inputFileName>: Path to the input CSV file containing the decision matrix. The first column should contain the alternatives, and the subsequent columns should contain the criteria.
  • <Weights>: Comma-separated list of weights for each criterion (e.g., 0.25,0.35,0.4).
  • <Impacts>: Comma-separated list of impacts for each criterion (either + for beneficial or - for non-beneficial, e.g., +, -, +).
  • <resultFileName>: Path to the output CSV file where the results will be saved. This file will contain the score and rank for each alternative.

Example

python topsis.py data.csv "0.4,0.3,0.3" "+,-,+" result.csv

This will:

  1. Read data from data.csv
  2. Use weights 0.4, 0.3, 0.3 for the criteria
  3. Apply impacts +, -, + to the criteria
  4. Save the results (including the calculated scores and ranks) to result.csv

Input File Format

The input CSV file should have the following format:

Alternative Criterion 1 Criterion 2 Criterion 3
A1 3.5 2.1 8.4
A2 4.2 1.9 7.5
A3 5.1 2.8 6.2
  • The first column should contain the names of the alternatives.
  • The remaining columns should contain the values of the criteria for each alternative.

Output File Format

The output CSV file will contain the following columns:

Alternative Criterion 1 Criterion 2 Criterion 3 Score Rank
A1 3.5 2.1 8.4 0.825 1
A2 4.2 1.9 7.5 0.713 2
A3 5.1 2.8 6.2 0.665 3
  • Score: The computed score indicating the proximity to the ideal solution.
  • Rank: The rank based on the score.

Error Handling

  • File Not Found: If the input file does not exist, a FileNotFoundError is raised.
  • Invalid Weights or Impacts: If the number of weights does not match the number of impacts, or if the impacts contain invalid values, a ValueError will be raised.
  • General Errors: Any other issues during execution will be caught and displayed as an error message.

License

This program is open-source and released under the MIT License. Feel free to use and modify it for your needs.


Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topsis_102217126-1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

topsis_102217126-1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file topsis_102217126-1.0.tar.gz.

File metadata

  • Download URL: topsis_102217126-1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for topsis_102217126-1.0.tar.gz
Algorithm Hash digest
SHA256 b0d5b65b77ac289fc8b222ae4c89e9254327bf6117e4edd4afe077ecb6bc1470
MD5 3c9477b6b7a9e8a78ddf310706964ee4
BLAKE2b-256 c8ec9a8bc4c07c1920b6e234197cc767f6b36dcb630a48969c7186ddba549952

See more details on using hashes here.

File details

Details for the file topsis_102217126-1.0-py3-none-any.whl.

File metadata

  • Download URL: topsis_102217126-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for topsis_102217126-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1f402c90e0bff62829aa793dd14891d4588fbeda22b1a41ca7d9644f6bc30be
MD5 55dc4e25ec1508f59b9934a675d64f68
BLAKE2b-256 74f98a66af0df74604c9937c4c3a9705ed9c44da3e04f83f8e4b7cc111b8778d

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