Skip to main content

A Python implementation of the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method.

Project description

Topsis-Sparsh_Gupta-102317228

A Python implementation of the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method for multi-criteria decision making.


📌 What is TOPSIS?

TOPSIS is a Multi-Criteria Decision Making (MCDM) technique used to rank alternatives based on:

  • Distance from the Ideal Best solution
  • Distance from the Ideal Worst solution

The best alternative is:

  • Closest to the Ideal Best
  • Farthest from the Ideal Worst

⚙️ Mathematical Steps

  1. Normalize the decision matrix
  2. Multiply by weights
  3. Determine Ideal Best and Ideal Worst
  4. Compute Euclidean distances
  5. Calculate relative closeness score
  6. Rank alternatives

📊 Algorithm Flow (Mermaid Diagram)

flowchart TD
    A[Start] --> B[Read Input File]
    B --> C[Validate Data]
    C --> D[Normalize Matrix]
    D --> E[Apply Weights]
    E --> F[Find Ideal Best & Worst]
    F --> G[Compute Distances]
    G --> H[Calculate TOPSIS Score]
    H --> I[Rank Alternatives]
    I --> J[Save Output File]
    J --> K[End]

📥 Installation

Install from PyPI:

pip install Topsis-Sparsh Gupta-102317228

Or install locally:

pip install .

🚀 Usage (Command Line)

topsis <InputFile> <Weights> <Impacts> <OutputFile>

Example

topsis data.xlsx "1,1,1,2" "+,+,-,+" result.csv

📄 Input Format

The input file must:

  • Contain at least 3 columns
  • First column: Identifier (Name/ID)
  • Remaining columns: Numeric values only
  • Weights must be comma-separated
  • Impacts must be '+' or '-'

Example Input

Fund P1 P2 P3 P4
M1 0.67 0.45 5.6 12.56
M2 0.6 0.36 3.5 14.47

📤 Output Format

The output file contains:

  • Original data
  • Topsis Score column
  • Rank column

Higher score = Better rank


🧮 Mathematical Formula

Normalization

[ R_{ij} = \frac{x_{ij}}{\sqrt{\sum x_{ij}^2}} ]

Weighted Matrix

[ V_{ij} = w_j \cdot R_{ij} ]

Distance Measures

[ S_i^+ = \sqrt{\sum (V_{ij} - A_j^+)^2} ]

[ S_i^- = \sqrt{\sum (V_{ij} - A_j^-)^2} ]

Topsis Score

[ C_i = \frac{S_i^-}{S_i^+ + S_i^-} ]


🛑 Error Handling

The program checks for:

  • File not found
  • Incorrect number of parameters
  • Less than 3 columns
  • Non-numeric values
  • Mismatch in weights and impacts
  • Invalid impacts

🧠 Requirements

  • Python 3.7+
  • numpy
  • pandas
  • openpyxl

👤 Author

Sparsh Gupta
102317228


📜 License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topsis_sparsh_gupta_102317228-1.0.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topsis_sparsh_gupta_102317228-1.0.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file topsis_sparsh_gupta_102317228-1.0.0.tar.gz.

File metadata

File hashes

Hashes for topsis_sparsh_gupta_102317228-1.0.0.tar.gz
Algorithm Hash digest
SHA256 38bd5c636292700f8f908c2e68f7b13ec07980702a4dd23c396a3c2b2f1d6beb
MD5 da9e99be72775f17d6be47017de476c5
BLAKE2b-256 7119f8facd43a212bab5c5b1c2f99c14ca6d363ab0a6b60fd15629feacaf1f32

See more details on using hashes here.

File details

Details for the file topsis_sparsh_gupta_102317228-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for topsis_sparsh_gupta_102317228-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63533de1c025def0faa9b570f4e766326087f4cdaba39be0e6fb47c39843470b
MD5 9022a30b28d75699c112db53a1f479a2
BLAKE2b-256 c32c9f99f16b1c6d12e48867171a6046d4172921e0c46f10a6a66f541fbd1e1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page