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.4.tar.gz (3.8 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.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: topsis_arnav_102203979-1.4.tar.gz
  • Upload date:
  • Size: 3.8 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.4.tar.gz
Algorithm Hash digest
SHA256 4e1ca929bbffbe3a7044feee613abc9cea83b8ae27f9d26dc3242e2faa0ae2ee
MD5 c079e0563c67e231a4065608c40db8ed
BLAKE2b-256 45a4a64836a1b87023a9de13f10096dd7dd99289ce2fe74a6e583610e095e4dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for topsis_arnav_102203979-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7ababb8309082e5865ea25f3433637b97b0d05bd2b1a5574e80640fecb329b2a
MD5 517ff2a30c3594a64e4a73f8963eb698
BLAKE2b-256 ee9fa5291f6e5e30bf352eb9ec1ffbe367cef9d6e9e467abbd3330b1a3f1f3a2

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