Topsis-Mahim-102303958 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- topsis_mahim_102303958-1.0.0/LICENSE.txt +11 -0
- topsis_mahim_102303958-1.0.0/PKG-INFO +16 -0
- topsis_mahim_102303958-1.0.0/README.md +64 -0
- topsis_mahim_102303958-1.0.0/Topsis_Mahim_102303958.egg-info/PKG-INFO +16 -0
- topsis_mahim_102303958-1.0.0/Topsis_Mahim_102303958.egg-info/SOURCES.txt +11 -0
- topsis_mahim_102303958-1.0.0/Topsis_Mahim_102303958.egg-info/dependency_links.txt +1 -0
- topsis_mahim_102303958-1.0.0/Topsis_Mahim_102303958.egg-info/entry_points.txt +2 -0
- topsis_mahim_102303958-1.0.0/Topsis_Mahim_102303958.egg-info/requires.txt +2 -0
- topsis_mahim_102303958-1.0.0/Topsis_Mahim_102303958.egg-info/top_level.txt +1 -0
- topsis_mahim_102303958-1.0.0/setup.cfg +4 -0
- topsis_mahim_102303958-1.0.0/setup.py +20 -0
- topsis_mahim_102303958-1.0.0/topsis_mahim_102303958/__init__.py +1 -0
- topsis_mahim_102303958-1.0.0/topsis_mahim_102303958/topsis.py +98 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
This project is developed for academic and educational purposes.
|
|
2
|
+
|
|
3
|
+
The source code may be used, modified, and shared strictly for learning,
|
|
4
|
+
assignment submission, and non-commercial use.
|
|
5
|
+
|
|
6
|
+
No warranty is provided. The author is not responsible for any misuse
|
|
7
|
+
or damage caused by this software.
|
|
8
|
+
|
|
9
|
+
Author: Mahim Katiyar
|
|
10
|
+
Roll Number: 102303958
|
|
11
|
+
Institution: Thapar Institute of Engineering and Technology
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Topsis-Mahim-102303958
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Implementation of TOPSIS method as a Python package
|
|
5
|
+
Author: Mahim
|
|
6
|
+
Author-email: mkatiyar_be23@thapar.edu
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Requires-Dist: pandas
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: requires-python
|
|
16
|
+
Dynamic: summary
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Topsis-Mahim-102303958
|
|
2
|
+
|
|
3
|
+
This package implements the **TOPSIS (Technique for Order Preference by Similarity to Ideal Solution)** method in Python.
|
|
4
|
+
It provides a command-line tool to rank alternatives based on multiple criteria, weights, and impacts.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
To install the package locally, go to the project directory and run:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install .
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
If installed from PyPI, use:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install Topsis-Mahim-102303958
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
The package provides a command-line tool named `topsis`.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
topsis <InputDataFile> <Weights> <Impacts> <OutputResultFileName>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Example
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
topsis data.csv "1,1,1,1,1" "+,+,-,+,-" output-result.csv
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Input File Requirements
|
|
41
|
+
|
|
42
|
+
- Input file must be in CSV or XLSX format.
|
|
43
|
+
- The file must contain at least three columns.
|
|
44
|
+
- The first column is treated as an identifier.
|
|
45
|
+
- All columns from the second to the last must contain numeric values only.
|
|
46
|
+
- Weights must be numeric and comma-separated.
|
|
47
|
+
- Impacts must be comma-separated and should be either `+` or `-`.
|
|
48
|
+
- The number of weights, impacts, and criteria must be the same.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Output
|
|
53
|
+
|
|
54
|
+
The output file contains two additional columns:
|
|
55
|
+
- **Topsis Score**
|
|
56
|
+
- **Rank** (Rank 1 indicates the best alternative)
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Author
|
|
61
|
+
|
|
62
|
+
Mahim Katiyar
|
|
63
|
+
Roll Number: 102303958
|
|
64
|
+
Email: mkatiyar_be23@thapar.edu
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Topsis-Mahim-102303958
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Implementation of TOPSIS method as a Python package
|
|
5
|
+
Author: Mahim
|
|
6
|
+
Author-email: mkatiyar_be23@thapar.edu
|
|
7
|
+
Requires-Python: >=3.7
|
|
8
|
+
License-File: LICENSE.txt
|
|
9
|
+
Requires-Dist: pandas
|
|
10
|
+
Requires-Dist: numpy
|
|
11
|
+
Dynamic: author
|
|
12
|
+
Dynamic: author-email
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
Dynamic: requires-dist
|
|
15
|
+
Dynamic: requires-python
|
|
16
|
+
Dynamic: summary
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
Topsis_Mahim_102303958.egg-info/PKG-INFO
|
|
5
|
+
Topsis_Mahim_102303958.egg-info/SOURCES.txt
|
|
6
|
+
Topsis_Mahim_102303958.egg-info/dependency_links.txt
|
|
7
|
+
Topsis_Mahim_102303958.egg-info/entry_points.txt
|
|
8
|
+
Topsis_Mahim_102303958.egg-info/requires.txt
|
|
9
|
+
Topsis_Mahim_102303958.egg-info/top_level.txt
|
|
10
|
+
topsis_mahim_102303958/__init__.py
|
|
11
|
+
topsis_mahim_102303958/topsis.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
topsis_mahim_102303958
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="Topsis-Mahim-102303958",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
author="Mahim",
|
|
7
|
+
author_email="mkatiyar_be23@thapar.edu",
|
|
8
|
+
description="Implementation of TOPSIS method as a Python package",
|
|
9
|
+
packages=find_packages(),
|
|
10
|
+
install_requires=[
|
|
11
|
+
"pandas",
|
|
12
|
+
"numpy"
|
|
13
|
+
],
|
|
14
|
+
entry_points={
|
|
15
|
+
"console_scripts": [
|
|
16
|
+
"topsis=topsis_mahim_102303958.topsis:main"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
python_requires=">=3.7",
|
|
20
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# TOPSIS package
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import pandas as pd
|
|
4
|
+
import numpy as np
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def validate_inputs():
|
|
8
|
+
|
|
9
|
+
if len(sys.argv) != 5:
|
|
10
|
+
print("Error: Incorrect number of parameters.")
|
|
11
|
+
print("Usage: python topsis.py <InputDataFile> <Weights> <Impacts> <OutputResultFileName>")
|
|
12
|
+
sys.exit(1)
|
|
13
|
+
|
|
14
|
+
input_file, weights_str, impacts_str, output_file = sys.argv[1:]
|
|
15
|
+
|
|
16
|
+
if not os.path.isfile(input_file):
|
|
17
|
+
print(f"Error: File '{input_file}' not found.")
|
|
18
|
+
sys.exit(1)
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
if input_file.endswith(".csv"):
|
|
22
|
+
df = pd.read_csv(input_file)
|
|
23
|
+
elif input_file.endswith(".xlsx"):
|
|
24
|
+
df = pd.read_excel(input_file)
|
|
25
|
+
else:
|
|
26
|
+
print("Error: Input file must be .csv or .xlsx")
|
|
27
|
+
sys.exit(1)
|
|
28
|
+
except:
|
|
29
|
+
print("Error: Unable to read input file.")
|
|
30
|
+
sys.exit(1)
|
|
31
|
+
|
|
32
|
+
if df.shape[1] < 3:
|
|
33
|
+
print("Error: Input file must contain at least 3 columns.")
|
|
34
|
+
sys.exit(1)
|
|
35
|
+
|
|
36
|
+
numeric_data = df.iloc[:, 1:].apply(pd.to_numeric, errors="coerce")
|
|
37
|
+
if numeric_data.isnull().values.any():
|
|
38
|
+
print("Error: From 2nd to last columns must contain numeric values only.")
|
|
39
|
+
sys.exit(1)
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
weights = [float(w) for w in weights_str.split(",")]
|
|
43
|
+
impacts = impacts_str.split(",")
|
|
44
|
+
except:
|
|
45
|
+
print("Error: Weights must be numeric and comma separated.")
|
|
46
|
+
sys.exit(1)
|
|
47
|
+
|
|
48
|
+
if not all(i in ["+", "-"] for i in impacts):
|
|
49
|
+
print("Error: Impacts must be either '+' or '-'.")
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
|
|
52
|
+
if len(weights) != df.shape[1] - 1 or len(impacts) != df.shape[1] - 1:
|
|
53
|
+
print("Error: Number of weights, impacts and criteria must be the same.")
|
|
54
|
+
sys.exit(1)
|
|
55
|
+
|
|
56
|
+
return df, weights, impacts, output_file
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def topsis_calculation(df, weights, impacts):
|
|
60
|
+
|
|
61
|
+
data = df.iloc[:, 1:].values.astype(float)
|
|
62
|
+
|
|
63
|
+
norm = data / np.sqrt((data ** 2).sum(axis=0))
|
|
64
|
+
weighted = norm * weights
|
|
65
|
+
|
|
66
|
+
best, worst = [], []
|
|
67
|
+
|
|
68
|
+
for i in range(len(impacts)):
|
|
69
|
+
if impacts[i] == "+":
|
|
70
|
+
best.append(weighted[:, i].max())
|
|
71
|
+
worst.append(weighted[:, i].min())
|
|
72
|
+
else:
|
|
73
|
+
best.append(weighted[:, i].min())
|
|
74
|
+
worst.append(weighted[:, i].max())
|
|
75
|
+
|
|
76
|
+
best = np.array(best)
|
|
77
|
+
worst = np.array(worst)
|
|
78
|
+
|
|
79
|
+
d_pos = np.sqrt(((weighted - best) ** 2).sum(axis=1))
|
|
80
|
+
d_neg = np.sqrt(((weighted - worst) ** 2).sum(axis=1))
|
|
81
|
+
|
|
82
|
+
return d_neg / (d_pos + d_neg)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def main():
|
|
86
|
+
|
|
87
|
+
df, weights, impacts, output_file = validate_inputs()
|
|
88
|
+
scores = topsis_calculation(df, weights, impacts)
|
|
89
|
+
|
|
90
|
+
df["Topsis Score"] = scores
|
|
91
|
+
df["Rank"] = df["Topsis Score"].rank(ascending=False, method="dense").astype(int)
|
|
92
|
+
|
|
93
|
+
df.to_csv(output_file, index=False)
|
|
94
|
+
print(f"TOPSIS analysis completed. Results saved in '{output_file}'.")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
main()
|