Skip to main content

Python implementation of the TOPSIS method for multi-criteria decision analysis

Project description

TOPSIS Algorithm - Ranking Made Simple

Welcome to this Python implementation of TOPSIS (Technique for Order Preference by Similarity to Ideal Solution), a method used to rank alternatives based on a set of decision-making criteria. This project aims to simplify complex decision-making processes by using mathematical formulas to calculate the best options.

How Does It Work?

Imagine you are comparing different models of smartphones based on various features like price, storage, camera quality, and design. Instead of relying on your gut feeling, TOPSIS normalizes the data, assigns weights to each feature (e.g., you care more about camera quality than looks), and then calculates the distance between each model and an ideal solution. The closer a model is to the "best-case scenario," the better its rank.

What You Will Need

To get started, you will need:

  • Python 3.7+ (preferably)
  • Pandas for data handling
  • NumPy for numerical calculations

To install the dependencies, just run:

pip install pandas numpy

How to Run the Script

Command-Line Execution

Here is the command you will use to run the script:

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

Where:

  • <inputFileName> is your CSV file that holds the data. It should have one column for alternatives and the rest for decision-making criteria (e.g., price, storage, camera).
  • <Weights> is a comma-separated string that specifies the importance (weight) of each criterion.
  • <Impacts> is another comma-separated string, indicating whether a criterion is beneficial (+) or non-beneficial (-).
  • <resultFileName> is where you want to save the output, containing the scores and ranks.

Example

Let us say we have a CSV file named input_data.csv and we want to weigh the features as 20%, 30%, 30%, and 20%, respectively, with the first three being beneficial and the last one (Looks) being non-beneficial.

Run:

topsis input_data.csv "0.2,0.3,0.3,0.2" "+,+,+,-" result.csv

This command will process the data, calculate the scores, and save the results in a file called result.csv.

Input File Structure

The CSV file should look like this:

Model Price Storage Camera Looks
M1 250 16 12 5
M2 200 16 8 3
M3 300 32 16 4
M4 275 32 8 4
M5 225 16 16 2

Here, each row represents a different alternative (e.g., smartphone model) and each column represents a decision-making criterion.

Output Format

After running the script, the output will look like this:

Model Price Storage Camera Looks Score Rank
M1 250 16 12 5 0.4459 4
M2 200 16 8 3 0.3700 5
M3 300 32 16 4 0.6299 1
M4 275 32 8 4 0.4936 2
M5 225 16 16 2 0.4758 3

The Score is a measure of how close each alternative is to the ideal solution, and the Rank shows the order of preference, with 1 being the best choice.

Handling Errors

The script takes care of common mistakes:

  • If your input file does not exist, it will raise a FileNotFoundError.
  • If you mismatch the number of weights and impacts, or if you provide incorrect impacts (e.g., using anything other than + or -), you will get a ValueError.

License

This project is licensed under the MIT License. Feel free to use, modify, or contribute!

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_arnav_102203979-1.5.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

topsis_arnav_102203979-1.5-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file topsis_arnav_102203979-1.5.tar.gz.

File metadata

  • Download URL: topsis_arnav_102203979-1.5.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.1

File hashes

Hashes for topsis_arnav_102203979-1.5.tar.gz
Algorithm Hash digest
SHA256 058e414d9b597171111456fae5dda6bc2d619fd3532a182001dca753f70d13fa
MD5 d3b38adf3b5ea0680b4548f745476427
BLAKE2b-256 fac616690469a433f3acd44761ed3769d974e732bc09c1a65b9b5b1c4dc86663

See more details on using hashes here.

File details

Details for the file topsis_arnav_102203979-1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for topsis_arnav_102203979-1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3de4be50e3557b21decffb222445a790d93efe5044de29d0c7aa4aee338fefcc
MD5 1b60cf25b86f4342bd18bd080d7c3740
BLAKE2b-256 b645046082fed5b946590fd2ec47e5e7773fc1912f5905d2f39d62ecd254d0b6

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