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:
pandasnumpy
You can install the necessary libraries using:
pip install pandas numpy
Functionality
The program performs the following tasks:
- Input Validation: It validates the input CSV file, the weights, and the impacts.
- Normalization: It normalizes the decision matrix using vector normalization.
- Weighted Normalization: Each attribute of the normalized decision matrix is multiplied by its corresponding weight.
- Ideal and Negative Ideal Solutions: It computes the ideal and negative ideal solutions based on the given impacts (
+for beneficial,-for non-beneficial). - Distance Calculation: The program calculates the distance of each alternative from the ideal and negative ideal solutions.
- TOPSIS Score Calculation: A score is computed for each alternative, which indicates its closeness to the ideal solution.
- Ranking: The alternatives are ranked based on their scores, with the best alternative ranked 1.
- 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:
- Read data from
data.csv - Use weights
0.4, 0.3, 0.3for the criteria - Apply impacts
+, -, +to the criteria - 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
FileNotFoundErroris 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
ValueErrorwill 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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0d5b65b77ac289fc8b222ae4c89e9254327bf6117e4edd4afe077ecb6bc1470
|
|
| MD5 |
3c9477b6b7a9e8a78ddf310706964ee4
|
|
| BLAKE2b-256 |
c8ec9a8bc4c07c1920b6e234197cc767f6b36dcb630a48969c7186ddba549952
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1f402c90e0bff62829aa793dd14891d4588fbeda22b1a41ca7d9644f6bc30be
|
|
| MD5 |
55dc4e25ec1508f59b9934a675d64f68
|
|
| BLAKE2b-256 |
74f98a66af0df74604c9937c4c3a9705ed9c44da3e04f83f8e4b7cc111b8778d
|