Topsis-Anahat-102313058 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_anahat_102313058-1.0.0/PKG-INFO +10 -0
- topsis_anahat_102313058-1.0.0/README.md +10 -0
- topsis_anahat_102313058-1.0.0/Topsis_Anahat_102313058.egg-info/PKG-INFO +10 -0
- topsis_anahat_102313058-1.0.0/Topsis_Anahat_102313058.egg-info/SOURCES.txt +10 -0
- topsis_anahat_102313058-1.0.0/Topsis_Anahat_102313058.egg-info/dependency_links.txt +1 -0
- topsis_anahat_102313058-1.0.0/Topsis_Anahat_102313058.egg-info/entry_points.txt +2 -0
- topsis_anahat_102313058-1.0.0/Topsis_Anahat_102313058.egg-info/requires.txt +2 -0
- topsis_anahat_102313058-1.0.0/Topsis_Anahat_102313058.egg-info/top_level.txt +1 -0
- topsis_anahat_102313058-1.0.0/setup.cfg +4 -0
- topsis_anahat_102313058-1.0.0/setup.py +15 -0
- topsis_anahat_102313058-1.0.0/topsis-anahat-102313058/__init__.py +0 -0
- topsis_anahat_102313058-1.0.0/topsis-anahat-102313058/topsis.py +88 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
Topsis_Anahat_102313058.egg-info/PKG-INFO
|
|
4
|
+
Topsis_Anahat_102313058.egg-info/SOURCES.txt
|
|
5
|
+
Topsis_Anahat_102313058.egg-info/dependency_links.txt
|
|
6
|
+
Topsis_Anahat_102313058.egg-info/entry_points.txt
|
|
7
|
+
Topsis_Anahat_102313058.egg-info/requires.txt
|
|
8
|
+
Topsis_Anahat_102313058.egg-info/top_level.txt
|
|
9
|
+
topsis-anahat-102313058/__init__.py
|
|
10
|
+
topsis-anahat-102313058/topsis.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
topsis-anahat-102313058
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="Topsis-Anahat-102313058",
|
|
5
|
+
version="1.0.0",
|
|
6
|
+
author="Anahat",
|
|
7
|
+
description="TOPSIS implementation using Python",
|
|
8
|
+
packages=find_packages(),
|
|
9
|
+
install_requires=["pandas", "numpy"],
|
|
10
|
+
entry_points={
|
|
11
|
+
'console_scripts': [
|
|
12
|
+
'topsis=topsis_anahat_102313058.topsis:topsis'
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
def error(msg):
|
|
6
|
+
print(f"Error: {msg}")
|
|
7
|
+
sys.exit(1)
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
# Correct number of parameters
|
|
11
|
+
if len(sys.argv) != 5:
|
|
12
|
+
error("Incorrect number of parameters.\nUsage: python topsis.py <InputFile> <Weights> <Impacts> <OutputFile>")
|
|
13
|
+
|
|
14
|
+
input_file = sys.argv[1]
|
|
15
|
+
weights = sys.argv[2]
|
|
16
|
+
impacts = sys.argv[3]
|
|
17
|
+
output_file = sys.argv[4]
|
|
18
|
+
|
|
19
|
+
#Message for wrong inputs
|
|
20
|
+
#File Handling
|
|
21
|
+
try:
|
|
22
|
+
data = pd.read_csv(input_file)
|
|
23
|
+
except FileNotFoundError:
|
|
24
|
+
error("Input file not found.")
|
|
25
|
+
|
|
26
|
+
if data.shape[1] < 3:
|
|
27
|
+
error("Input file must contain three or more columns.")
|
|
28
|
+
|
|
29
|
+
#Numeric Validation
|
|
30
|
+
try:
|
|
31
|
+
matrix = data.iloc[:, 1:].astype(float)
|
|
32
|
+
except ValueError:
|
|
33
|
+
error("From 2nd to last columns must contain numeric values only.")
|
|
34
|
+
|
|
35
|
+
#Weights & Impacts
|
|
36
|
+
try:
|
|
37
|
+
weights = list(map(float, weights.split(',')))
|
|
38
|
+
except:
|
|
39
|
+
error("Weights must be numeric and separated by commas.")
|
|
40
|
+
|
|
41
|
+
impacts = impacts.split(',')
|
|
42
|
+
|
|
43
|
+
if len(weights) != matrix.shape[1] or len(impacts) != matrix.shape[1]:
|
|
44
|
+
error("Number of weights, impacts, and criteria columns must be equal.")
|
|
45
|
+
|
|
46
|
+
for i in impacts:
|
|
47
|
+
if i not in ['+', '-']:
|
|
48
|
+
error("Impacts must be either '+' or '-'.")
|
|
49
|
+
|
|
50
|
+
# TOPSIS Steps
|
|
51
|
+
# Step 1: Normalize
|
|
52
|
+
norm = matrix / np.sqrt((matrix ** 2).sum())
|
|
53
|
+
|
|
54
|
+
# Step 2: Weighting
|
|
55
|
+
weighted = norm * weights
|
|
56
|
+
|
|
57
|
+
# Step 3: Ideal best & worst
|
|
58
|
+
ideal_best = []
|
|
59
|
+
ideal_worst = []
|
|
60
|
+
|
|
61
|
+
for i in range(len(impacts)):
|
|
62
|
+
if impacts[i] == '+':
|
|
63
|
+
ideal_best.append(weighted.iloc[:, i].max())
|
|
64
|
+
ideal_worst.append(weighted.iloc[:, i].min())
|
|
65
|
+
else:
|
|
66
|
+
ideal_best.append(weighted.iloc[:, i].min())
|
|
67
|
+
ideal_worst.append(weighted.iloc[:, i].max())
|
|
68
|
+
|
|
69
|
+
ideal_best = np.array(ideal_best)
|
|
70
|
+
ideal_worst = np.array(ideal_worst)
|
|
71
|
+
|
|
72
|
+
# Step 4: Distance
|
|
73
|
+
dist_best = np.sqrt(((weighted - ideal_best) ** 2).sum(axis=1))
|
|
74
|
+
dist_worst = np.sqrt(((weighted - ideal_worst) ** 2).sum(axis=1))
|
|
75
|
+
|
|
76
|
+
# Step 5: Score
|
|
77
|
+
score = dist_worst / (dist_best + dist_worst)
|
|
78
|
+
|
|
79
|
+
# Step 6: Rank
|
|
80
|
+
data['Topsis Score'] = score
|
|
81
|
+
data['Rank'] = data['Topsis Score'].rank(ascending=False, method='dense').astype(int)
|
|
82
|
+
|
|
83
|
+
# Output
|
|
84
|
+
data.to_csv(output_file, index=False)
|
|
85
|
+
print(f"TOPSIS result saved to {output_file}")
|
|
86
|
+
|
|
87
|
+
if __name__ == "__main__":
|
|
88
|
+
main()
|