Topsis-Chahat-102303831 1.0.2__py3-none-any.whl

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/__init__.py ADDED
File without changes
topsis/topsis.py ADDED
@@ -0,0 +1,85 @@
1
+ import sys
2
+ import pandas as pd
3
+ import numpy as np
4
+ import os
5
+
6
+ def main():
7
+ if len(sys.argv) != 5:
8
+ print("Usage: python topsis.py <InputFile> <Weights> <Impacts> <OutputFile>")
9
+ sys.exit(1)
10
+
11
+ input_file = sys.argv[1]
12
+ weights = sys.argv[2]
13
+ impacts = sys.argv[3]
14
+ output_file = sys.argv[4]
15
+
16
+ if not os.path.exists(input_file):
17
+ print("Error: Input file not found")
18
+ sys.exit(1)
19
+
20
+ try:
21
+ if input_file.endswith('.xlsx'):
22
+ data = pd.read_excel(input_file)
23
+ else:
24
+ data = pd.read_csv(input_file)
25
+ except:
26
+ print("Error: Unable to read input file")
27
+ sys.exit(1)
28
+
29
+ if data.shape[1] < 3:
30
+ print("Error: Input file must contain at least 3 columns")
31
+ sys.exit(1)
32
+
33
+ try:
34
+ weights = list(map(float, weights.split(',')))
35
+ impacts = impacts.split(',')
36
+ except:
37
+ print("Error: Weights and impacts must be comma separated")
38
+ sys.exit(1)
39
+
40
+ if len(weights) != len(impacts) or len(weights) != data.shape[1] - 1:
41
+ print("Error: Number of weights, impacts and columns must be same")
42
+ sys.exit(1)
43
+
44
+ for i in impacts:
45
+ if i not in ['+', '-']:
46
+ print("Error: Impacts must be + or -")
47
+ sys.exit(1)
48
+
49
+ try:
50
+ matrix = data.iloc[:, 1:].astype(float)
51
+ except:
52
+ print("Error: Non-numeric values found")
53
+ sys.exit(1)
54
+
55
+ norm = np.sqrt((matrix ** 2).sum())
56
+ normalized = matrix / norm
57
+ weighted = normalized * weights
58
+
59
+ ideal_best = []
60
+ ideal_worst = []
61
+
62
+ for i in range(len(impacts)):
63
+ if impacts[i] == '+':
64
+ ideal_best.append(weighted.iloc[:, i].max())
65
+ ideal_worst.append(weighted.iloc[:, i].min())
66
+ else:
67
+ ideal_best.append(weighted.iloc[:, i].min())
68
+ ideal_worst.append(weighted.iloc[:, i].max())
69
+
70
+ ideal_best = np.array(ideal_best)
71
+ ideal_worst = np.array(ideal_worst)
72
+
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
+ score = dist_worst / (dist_best + dist_worst)
77
+
78
+ data['Topsis Score'] = score
79
+ data['Rank'] = data['Topsis Score'].rank(ascending=False).astype(int)
80
+
81
+ data.to_csv(output_file, index=False)
82
+ print("TOPSIS completed successfully!")
83
+
84
+ if __name__ == "__main__":
85
+ main()
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: Topsis-Chahat-102303831
3
+ Version: 1.0.2
4
+ Summary: A Python package implementing TOPSIS for MCDM problems
5
+ Author: Chahat
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Operating System :: OS Independent
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: pandas
11
+ Requires-Dist: numpy
12
+ Requires-Dist: openpyxl
13
+ Dynamic: author
14
+ Dynamic: classifier
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: requires-dist
18
+ Dynamic: summary
19
+
20
+ \## Project Description
21
+
22
+
23
+
24
+ Topsis-Chahat-102303831
25
+
26
+
27
+
28
+ For: Project-1 (UCS633)
29
+
30
+ Submitted by: Chahat
31
+
32
+ Roll No: 102303831
33
+
34
+
35
+
36
+ Topsis-Chahat-102303831 is a Python package for solving Multiple Criteria Decision Making (MCDM) problems using the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS).
37
+
38
+ The package ranks alternatives based on their distance from the ideal best and ideal worst solutions.
39
+
40
+
41
+
42
+ ---
43
+
44
+
45
+
46
+ Installation:
47
+
48
+
49
+
50
+ Install the package using pip:
51
+
52
+
53
+
54
+ pip install Topsis-Chahat-102303831
55
+
56
+
57
+
58
+ ---
59
+
60
+
61
+
62
+ Usage
63
+
64
+
65
+
66
+ Provide the input file name, followed by the weights vector, impacts vector, and the output file name.
67
+
68
+
69
+
70
+ topsis data.xlsx "1,1,1,1,1" "+,+,+,+,+" output.csv
71
+
72
+
73
+
74
+ Vectors can also be entered without double quotes:
75
+
76
+
77
+
78
+ topsis data.xlsx 1,1,1,1,1 +,+,+,+,+ output.csv
79
+
80
+
81
+
82
+ If the vectors contain spaces, they must be enclosed in double quotes.
83
+
84
+
85
+
86
+ To view help:
87
+
88
+
89
+
90
+ topsis /h
91
+
92
+
93
+
94
+ ---
95
+
96
+
97
+
98
+ Example
99
+
100
+
101
+
102
+ Input File (data.xlsx)
103
+
104
+
105
+
106
+ | Fund Name | P1 | P2 | P3 | P4 | P5 |
107
+
108
+ |---------- |----- |-----|---- |----- |------|
109
+
110
+ | M1 | 0.62 | 0.38| 7.0 | 42.6 | 12.65|
111
+
112
+ | M2 | 0.79 | 0.62| 4.8 | 65.5 | 17.93|
113
+
114
+ | M3 | 0.75 | 0.56| 4.6 | 63.7 | 17.40|
115
+
116
+ | M4 | 0.78 | 0.61| 4.9 | 66.3 | 18.15|
117
+
118
+ | M5 | 0.61 | 0.37| 6.4 | 32.3 | 9.92 |
119
+
120
+ | M6 | 0.78 | 0.61| 4.2 | 45.4 | 12.75|
121
+
122
+ | M7 | 0.90 | 0.81| 3.5 | 63.3 | 17.13|
123
+
124
+ | M8 | 0.63 | 0.40| 4.1 | 61.7 | 16.71|
125
+
126
+
127
+
128
+ Weights vector = \[ 1 , 1 , 1 , 1 , 1 ]
129
+
130
+ Impacts vector = \[ + , + , + , + , + ]
131
+
132
+
133
+
134
+ ---
135
+
136
+
137
+
138
+ Input Command
139
+
140
+
141
+
142
+ topsis data.xlsx "1,1,1,1,1" "+,+,+,+,+" output.csv
143
+
144
+
145
+
146
+ ---
147
+
148
+
149
+
150
+ Output (output.csv)
151
+
152
+
153
+
154
+ | Fund Name | P1 | P2 | P3 | P4 | P5 | Topsis Score | Rank |
155
+
156
+ |---------- |---- -|----- |---- |----- |------ |--------------|------|
157
+
158
+ | M1 | 0.84 | 0.71 | 6.7 | 42.1 | 12.59 | 0.563692 | 3 |
159
+
160
+ | M2 | 0.91 | 0.83 | 7.0 | 31.7 | 10.11 | 0.513032 | 4 |
161
+
162
+ | M3 | 0.79 | 0.62 | 4.8 | 46.7 | 13.23 | 0.439177 | 6 |
163
+
164
+ | M4 | 0.78 | 0.61 | 6.4 | 42.4 | 12.55 | 0.491956 | 5 |
165
+
166
+ | M5 | 0.94 | 0.88 | 3.6 | 62.2 | 16.91 | 0.641886 | 2 |
167
+
168
+ | M6 | 0.88 | 0.77 | 6.5 | 51.5 | 14.91 | 0.738148 | 1 |
169
+
170
+ | M7 | 0.66 | 0.44 | 5.3 | 48.9 | 13.83 | 0.407390 | 8 |
171
+
172
+ | M8 | 0.93 | 0.86 | 3.4 | 37.0 | 10.55 | 0.408499 | 7 |
173
+
174
+
175
+
176
+ ---
177
+
178
+
179
+
180
+
181
+
182
+ Notes
183
+
184
+
185
+
186
+ \- The first column represents the alternatives and is not used in calculations.
187
+
188
+ \- All criteria columns must contain numeric values only.
189
+
190
+ \- The number of weights, impacts, and criteria columns must be equal.
191
+
192
+ \- The input file must contain at least three columns.
193
+
194
+
195
+
196
+ ---
197
+
198
+
199
+
200
+ License
201
+
202
+
203
+
204
+ MIT
205
+
206
+
207
+
@@ -0,0 +1,7 @@
1
+ topsis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ topsis/topsis.py,sha256=uFZrp2qhTLqwh0F6g919FuM2UBYUnSnOXX6zD_46or4,2461
3
+ topsis_chahat_102303831-1.0.2.dist-info/METADATA,sha256=KaAP_319ZoI7V_BOy3XPC1ZZ9_r3gYzk3h6yA-8-YzQ,3403
4
+ topsis_chahat_102303831-1.0.2.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
5
+ topsis_chahat_102303831-1.0.2.dist-info/entry_points.txt,sha256=ldifNxmg9cP1nDdmg-jd2eI_t1XqNUX68-eaf3vZr1A,46
6
+ topsis_chahat_102303831-1.0.2.dist-info/top_level.txt,sha256=ol7AZ-3jpBeKNxw8WZBbIF4dSQOBGkuzmZDZaufWR4Q,7
7
+ topsis_chahat_102303831-1.0.2.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ topsis = topsis.topsis:main