Skip to main content

A Python implementation of the TOPSIS decision-making method

Project description

TOPSIS Program

What is this program?

This Python program helps in decision-making by ranking different options based on multiple criteria. It uses a method called TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) to calculate a score for each option and rank them from best to worst.

What does it do?

The program takes data about different options, with several criteria for each option, and ranks them. You can specify the importance of each criterion (called weights) and whether you want the criteria to be a benefit (+) or a cost (-). After running the program, it gives you a rank for each option based on the calculations.

How does it work?

  1. Input File: You provide a file that lists the options and their values for each criterion.
  2. Weights: You specify how important each criterion is.
  3. Impacts: You specify if the criterion is a benefit (like higher values are better) or a cost (like lower values are better).
  4. Output File: The program calculates a score for each option, adds the rank, and saves the results to a new file.

Requirements

Make sure you have Python installed, and you will need to install a library called pandas to read and write the data files. You can install it by running:

pip install pandas
1. Prepare the Files
Input File: This is a CSV file with the data you want to process. It must have at least three columns: the first one for the name of the options (e.g., M1, M2, M3), and the others for the values of different criteria.

Example of Input Data (101556-data.csv):

Object	Criterion1	Criterion2	Criterion3
M1	100	200	300
M2	150	250	350
M3	120	220	330
Weights and Impacts: These are provided as comma-separated values. The weights tell you how important each criterion is, and the impacts tell you if a higher value is better (use +) or if a lower value is better (use -).
2. Running the Program
Run the program from the command line by typing:

bash
Copy
Edit
python <YourFileName.py> <InputDataFile> <Weights> <Impacts> <ResultFileName>
<YourFileName.py>: The name of your Python program (e.g., 101556.py).
<InputDataFile>: The input data file (e.g., 101556-data.csv).
<Weights>: The importance of each criterion (e.g., "1,1,1,2").
<Impacts>: Whether each criterion is a benefit (+) or a cost (-) (e.g., "+,+,-,+").
<ResultFileName>: The name of the output file where the results will be saved (e.g., 101556-result.csv).
Example Command:
bash
Copy
Edit
python 101556.py 101556-data.csv "1,1,1,2" "+,+,-,+" 101556-result.csv
This will read the 101556-data.csv, calculate the Topsis scores, and save the result in 101556-result.csv.

What Does the Program Do?
Read Data: The program reads the input file and checks if it has at least 3 columns.
Normalize: It normalizes the values so that they can be compared fairly.
Apply Weights: It multiplies the values by the specified weights.
Ideal Solutions: The program identifies the best (ideal) and worst (negative-ideal) solutions.
Calculate Scores: It calculates a score for each option based on how close it is to the ideal solution.
Rank: It ranks the options based on the scores.
Error Handling
The program checks for:

Correct number of inputs (file names, weights, impacts).
If the file exists.
If the input data file has valid numbers and enough columns.
If the number of weights and impacts matches the number of criteria.
If the impacts are valid (either + or -).
Example of Output
After running the program, it will produce an output file that looks like this:

Object	Criterion1	Criterion2	Criterion3	Topsis Score	Rank
M1	100	200	300	0.75	1
M2	150	250	350	0.80	2
M3	120	220	330	0.70	3
The Topsis Score tells you how good each option is, and the Rank shows the best to worst alternatives.

Contributing
Feel free to make improvements or fix bugs by forking the repository and submitting a pull request.

License
This project is open source under the MIT License.

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_krishna-1.0.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

topsis_krishna-1.0.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file topsis_krishna-1.0.1.tar.gz.

File metadata

  • Download URL: topsis_krishna-1.0.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for topsis_krishna-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d2a3dc47c13b0c8ae3e5781afab9796a666307b4bdf554214d85cbc00309a3b6
MD5 1f68b508f4a987892fc54ebe2e735595
BLAKE2b-256 eecabedeaec1d06beeb7a02e1bec6c514991daf974ff94795dfad9e9fd3c6a3a

See more details on using hashes here.

File details

Details for the file topsis_krishna-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: topsis_krishna-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for topsis_krishna-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf334b6c5fe6168ef02304dc1f47504463f3a91634b310444b4b02dc2cbb02c8
MD5 5321f7a3fac22d0a078169183961b596
BLAKE2b-256 5b0fbefd6546cd5a3f414396e8776585aa635924acd97edbfa0ead5f8add8955

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