Topsis-Rakshita-102303498 1.0.0__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 +1 -0
- topsis/topsis.py +68 -0
- topsis_rakshita_102303498-1.0.0.dist-info/METADATA +23 -0
- topsis_rakshita_102303498-1.0.0.dist-info/RECORD +7 -0
- topsis_rakshita_102303498-1.0.0.dist-info/WHEEL +5 -0
- topsis_rakshita_102303498-1.0.0.dist-info/entry_points.txt +2 -0
- topsis_rakshita_102303498-1.0.0.dist-info/top_level.txt +1 -0
topsis/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .topsis import topsis
|
topsis/topsis.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
import numpy as np
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def topsis(input_file, weights, impacts, output_file):
|
|
7
|
+
data = pd.read_csv(input_file)
|
|
8
|
+
|
|
9
|
+
if len(weights) != len(impacts) or len(weights) != data.shape[1] - 1:
|
|
10
|
+
raise ValueError("Number of weights, impacts and criteria must match")
|
|
11
|
+
|
|
12
|
+
matrix = data.iloc[:, 1:].values.astype(float)
|
|
13
|
+
|
|
14
|
+
# Step 1: Normalize
|
|
15
|
+
norm = np.sqrt((matrix ** 2).sum(axis=0))
|
|
16
|
+
matrix = matrix / norm
|
|
17
|
+
|
|
18
|
+
# Step 2: Apply weights
|
|
19
|
+
matrix = matrix * weights
|
|
20
|
+
|
|
21
|
+
# Step 3: Ideal best and worst
|
|
22
|
+
ideal_best = []
|
|
23
|
+
ideal_worst = []
|
|
24
|
+
|
|
25
|
+
for i in range(len(impacts)):
|
|
26
|
+
if impacts[i] == '+':
|
|
27
|
+
ideal_best.append(matrix[:, i].max())
|
|
28
|
+
ideal_worst.append(matrix[:, i].min())
|
|
29
|
+
else:
|
|
30
|
+
ideal_best.append(matrix[:, i].min())
|
|
31
|
+
ideal_worst.append(matrix[:, i].max())
|
|
32
|
+
|
|
33
|
+
ideal_best = np.array(ideal_best)
|
|
34
|
+
ideal_worst = np.array(ideal_worst)
|
|
35
|
+
|
|
36
|
+
# Step 4: Distances
|
|
37
|
+
dist_best = np.sqrt(((matrix - ideal_best) ** 2).sum(axis=1))
|
|
38
|
+
dist_worst = np.sqrt(((matrix - ideal_worst) ** 2).sum(axis=1))
|
|
39
|
+
|
|
40
|
+
# Step 5: Score
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
score = dist_worst / (dist_best + dist_worst)
|
|
44
|
+
|
|
45
|
+
data["Topsis Score"] = score
|
|
46
|
+
data["Rank"] = pd.Series(score).rank(ascending=False).astype(int)
|
|
47
|
+
|
|
48
|
+
data.to_csv(output_file, index=False)
|
|
49
|
+
print("Output file created:", output_file)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def main():
|
|
55
|
+
if len(sys.argv) != 5:
|
|
56
|
+
print("Usage: topsis <input_file> <weights> <impacts> <output_file>")
|
|
57
|
+
sys.exit(1)
|
|
58
|
+
|
|
59
|
+
input_file = sys.argv[1]
|
|
60
|
+
weights = list(map(float, sys.argv[2].split(",")))
|
|
61
|
+
impacts = sys.argv[3].split(",")
|
|
62
|
+
output_file = sys.argv[4]
|
|
63
|
+
|
|
64
|
+
topsis(input_file, weights, impacts, output_file)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
if __name__ == "__main__":
|
|
68
|
+
main()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Topsis-Rakshita-102303498
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: TOPSIS implementation for MCDM problems
|
|
5
|
+
Author: Rakshita Garg
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: numpy
|
|
8
|
+
Requires-Dist: pandas
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: description
|
|
11
|
+
Dynamic: description-content-type
|
|
12
|
+
Dynamic: requires-dist
|
|
13
|
+
Dynamic: summary
|
|
14
|
+
|
|
15
|
+
# Topsis-Rakshita-102303498
|
|
16
|
+
|
|
17
|
+
A Python package to implement the TOPSIS method for Multiple Criteria Decision Making (MCDM).
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
pip install Topsis-Rakshita-102303498
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
topsis input.csv "1,1,1,1" "+,+,-,+" output.csv
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
topsis/__init__.py,sha256=ySjTkNVa20OI1QFkLvToedIHgoOwlWAQvHCbV2Rg1E0,27
|
|
2
|
+
topsis/topsis.py,sha256=VfiblWOjF_Y2t0xkPlbHvCPscpcfLUu6Jr0hMlwu3AA,1760
|
|
3
|
+
topsis_rakshita_102303498-1.0.0.dist-info/METADATA,sha256=U1O5ZxrZY9tc7SGrvxP878dJGoTbPcrR48Nf9Wnq6c0,571
|
|
4
|
+
topsis_rakshita_102303498-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
+
topsis_rakshita_102303498-1.0.0.dist-info/entry_points.txt,sha256=ldifNxmg9cP1nDdmg-jd2eI_t1XqNUX68-eaf3vZr1A,46
|
|
6
|
+
topsis_rakshita_102303498-1.0.0.dist-info/top_level.txt,sha256=ol7AZ-3jpBeKNxw8WZBbIF4dSQOBGkuzmZDZaufWR4Q,7
|
|
7
|
+
topsis_rakshita_102303498-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
topsis
|