Topsis-HarshTanwar-102303812 1.0.0
A Python package to implement TOPSIS

# 102303812-topsis

A Python package to implement **TOPSIS** (Technique for Order of Preference by Similarity to Ideal Solution) for multi-criteria decision analysis.

**Author:** Harsh Tanwar  
**Roll No:** 102303812  
**Email:** htanwar_be23@thapar.edu  

**Repository:** [Assignment1-Topsis](https://github.com/htan11/course-materials/tree/main/UCS654/Assignment1-Topsis)

---

## What is TOPSIS?

TOPSIS ranks alternatives by comparing each to an *ideal positive* and *ideal negative* solution. Alternatives closer to the ideal positive and farther from the ideal negative get higher scores and better ranks. The method uses vector normalization, weighted criteria, and Euclidean distances to compute a performance score for each alternative.

---

## Requirements

- Python 3.6+
- **pandas** â€“ data handling
- **numpy** â€“ numerical operations

Install dependencies:

```bash
pip install pandas numpy
```

---

## Installation

### From PyPI (if published)

```bash
pip install 102303812-topsis
```

### From source (clone or download the repo)

```bash
git clone https://github.com/htan11/course-materials.git
cd course-materials/UCS654/Assignment1-Topsis
pip install .
```

Or, in the folder containing `setup.py`:

```bash
pip install .
```

---

## Usage

### Command line

```bash
topsis <InputDataFile> <Weights> <Impacts> <OutputResultFileName>
```

**Example (with 5 criteria):**

```bash
topsis data.csv "1,1,1,1,1" "+,+,-,+,-" result.csv
```

### As a Python module

(Because the package name contains a hyphen, use `importlib` to import.)

```python
import importlib
topsis = getattr(importlib.import_module("102303812-topsis"), "topsis")

topsis("data.csv", "1,1,1,1,1", "+,+,-,+,-", "result.csv")
```

---

## Parameters

| Parameter | Description |
|-----------|-------------|
| **InputDataFile** | Path to a CSV file: first column = alternative names, remaining columns = numeric criterion values. Must have a header row. |
| **Weights** | Comma-separated weights for each criterion (e.g. `"1,1,1,2,1"`). Number of values must match number of criteria. |
| **Impacts** | Comma-separated impacts: `+` for beneficial (higher is better), `-` for non-beneficial (lower is better). Same count as criteria. |
| **OutputResultFileName** | Path for the output CSV. Contains original columns plus **Topsis Score** and **Rank**. |

- Beneficial (`+`): e.g. Quality, Customer Rating â€” higher value is better.  
- Non-beneficial (`-`): e.g. Price, Delivery Time â€” lower value is better.

---

## Input file format

CSV with a header; first column = alternative names, rest = numeric only.

**Example (`data.csv`):**

| Product | Quality | Price | Features | Customer Rating | Delivery Time |
|---------|---------|-------|----------|-----------------|---------------|
| A1      | 8.5     | 450   | 7.2      | 4.3             | 3             |
| A2      | 7.8     | 380   | 8.1      | 4.5             | 5             |
| ...     | ...     | ...   | ...      | ...             | ...           |

- Column 1: labels (not used in math).  
- Columns 2â€“6: criteria. Weights and impacts must be given for each of these in order.

---

## Example with this dataset

For 5 criteria (Quality, Price, Features, Customer Rating, Delivery Time):

- **Weights:** `"1,1,1,1,1"` (equal weight).  
- **Impacts:** `"+,+,-,+,-"` (Quality +, Price +, Features -, Customer Rating +, Delivery Time -).

Run:

```bash
topsis data.csv "1,1,1,1,1" "+,+,-,+,-" result.csv
```

Output CSV will have all input columns plus:

- **Topsis Score** â€“ higher is better.  
- **Rank** â€“ 1 = best alternative.

---

## Output

The result file contains:

- All original columns.  
- **Topsis Score** â€“ performance score in [0, 1].  
- **Rank** â€“ integer rank (1 = best).

Example message: `Result file 'result.csv' created successfully.`

---

## Project structure

```
assignment1_DS-main/
â”œâ”€â”€ README.md
â”œâ”€â”€ setup.py
â”œâ”€â”€ data.csv              # Sample input
â”œâ”€â”€ 102303812-topsis/
â”‚   â”œâ”€â”€ __init__.py
â”‚   â””â”€â”€ topsis.py         # TOPSIS implementation
â””â”€â”€ LICENSE
```

---

## License

MIT License. See [LICENSE](LICENSE) for details.