Skip to main content

A Python implementation of TOPSIS method

Project description

Topsis-Nikhil-102317179

A Python implementation of the TOPSIS (Technique for Order Preference by Similarity to Ideal Solution) method with full command-line support and PyPI packaging.

This project demonstrates:

  • Implementation of the TOPSIS algorithm
  • Command-line interface using sys.argv
  • Input validation and error handling
  • Packaging using modern pyproject.toml
  • Building distribution files
  • Publishing to PyPI

1. Project Overview

TOPSIS is a multi-criteria decision-making (MCDM) technique used to rank alternatives based on their distance from an ideal best and ideal worst solution.

The implemented workflow:

  1. Normalize the decision matrix
  2. Multiply by weights
  3. Determine ideal best and worst
  4. Compute Euclidean distance from ideal solutions
  5. Calculate performance score
  6. Rank alternatives

2. Command Line Usage

After installation:

topsis <input.csv> "<weights>" "<impacts>" <output.csv>

Example:

topsis input.csv "0.2,0.2,0.2,0.2,0.2" "+,-,+,-,-" output.csv

Input Requirements

  • First column must contain alternative names
  • Remaining columns must be numeric
  • At least 3 columns required
  • Weights must be comma-separated
  • Impacts must be + or -
  • Number of weights and impacts must match criteria columns

3. Example Input File

Fund Name,P1,P2,P3,P4,P5
M1,0.84,0.71,6.7,42.1,12.59
M2,0.91,0.83,7,31.7,10.11
M3,0.79,0.62,4.8,46.7,13.23
M4,0.78,0.61,6.4,42.4,12.55
M5,0.94,0.88,3.6,62.2,16.91
M6,0.88,0.77,6.5,51.5,14.91
M7,0.66,0.44,5.3,48.9,13.83
M8,0.93,0.86,3.4,37,10.55

4. Example Output

Fund Name P1 P2 P3 P4 P5 Topsis Score Rank
M6 0.88 0.77 6.5 51.5 14.91 0.738148132 1
M5 0.94 0.88 3.6 62.2 16.91 0.641885815 2
M1 0.84 0.71 6.7 42.1 12.59 0.56369233 3
M2 0.91 0.83 7 31.7 10.11 0.513032103 4
M4 0.78 0.61 6.4 42.4 12.55 0.491956082 5
M3 0.79 0.62 4.8 46.7 13.23 0.439177283 6
M8 0.93 0.86 3.4 37 10.55 0.408498677 7
M7 0.66 0.44 5.3 48.9 13.83 0.407389532 8

5. Project Structure

Topsis-Nikhil-102317179/
│
├── src/
│   └── TopsisNikhil102317179/
│       ├── __init__.py
│       └── topsis.py
│
├── README.md
├── LICENSE
├── pyproject.toml
├── setup.cfg

6. Packaging Configuration

pyproject.toml

Key configuration:

  • Uses setuptools
  • Defines dependencies: pandas, numpy
  • Registers CLI entry point
  • Uses src layout

Important section:

[project.scripts]
topsis = "TopsisNikhil102317179.topsis:main"

[tool.setuptools.packages.find]
where = ["src"]

7. Development Pipeline

7.1 Algorithm Flow

flowchart TD
    A[Read CSV File] --> B[Validate Inputs]
    B --> C[Normalize Matrix]
    C --> D[Apply Weights]
    D --> E[Determine Ideal Best/Worst]
    E --> F[Compute Distances]
    F --> G[Calculate Score]
    G --> H[Rank Alternatives]
    H --> I[Write Output CSV]

7.2 Packaging and Distribution Flow

flowchart TD
    A[Write topsis.py] --> B[Create src Layout]
    B --> C[Add pyproject.toml]
    C --> D[Add setup.cfg]
    D --> E[Build Package]
    E --> F[Generate dist Files]
    F --> G[Install Locally]
    G --> H[Test CLI Command]
    H --> I[Upload to PyPI]

8. Building the Package Locally

Install build tool:

pip install build

Build:

python -m build

This generates:

dist/
    topsis_nikhil_102317179-0.0.1.tar.gz
    topsis_nikhil_102317179-0.0.1-py3-none-any.whl

9. Installing Locally

pip install dist/topsis_nikhil_102317179-0.0.1-py3-none-any.whl

10. Uploading to PyPI

Install twine:

pip install twine

Upload:

twine upload dist/*

11. Installing from PyPI

After publication:

pip install Topsis-Nikhil-102317179

Then run:

topsis input.csv "0.2,0.2,0.2,0.2,0.2" "+,-,+,-,-" output.csv

12. Dependencies

  • pandas
  • numpy
  • Python >= 3.8

13. License

MIT License


14. Conclusion

This project demonstrates the complete lifecycle of:

  • Algorithm implementation
  • CLI development
  • Modern Python packaging
  • Local build testing
  • Distribution through PyPI
  • Reproducible installation

15. Part II – Web Service using Streamlit

In addition to the command-line interface, this project also includes a web-based implementation of TOPSIS using Streamlit.

This web application allows users to:

  • Upload a CSV file
  • Enter weights
  • Enter impacts
  • Provide an email ID
  • Generate the TOPSIS result file

The web interface validates all inputs before processing.


15.1 Functional Requirements

The web service ensures:

  • User must upload an input CSV file
  • Number of weights must equal number of criteria columns
  • Number of impacts must equal number of criteria columns
  • Impacts must be either + or -
  • Weights must be comma-separated numeric values
  • Email ID format must be valid
  • Result file is generated only after successful validation

15.2 Web Application Flow

flowchart TD
    A[User Uploads CSV] --> B[Enter Weights]
    B --> C[Enter Impacts]
    C --> D[Enter Email ID]
    D --> E[Validate All Inputs]
    E -->|Valid| F[Run TOPSIS Algorithm]
    F --> G[Generate Result File]
    G --> H[Display / Send Result]
    E -->|Invalid| I[Show Error Message]

15.3 Running the Web Application Locally

Activate virtual environment:

.venv\Scripts\activate

Install required dependencies:

pip install streamlit pandas numpy

Run the application:

streamlit run app.py

After running, open:

http://localhost:8501

The web interface will be available in the browser.


15.4 Web Project Structure

Topsis-Nikhil-102317179/
│
├── app.py
├── src/
│   └── TopsisNikhil102317179/
│       ├── __init__.py
│       └── topsis.py
│
├── README.md
├── pyproject.toml
├── setup.cfg

15.5 Integration with Core Algorithm

The Streamlit application reuses the same TOPSIS implementation from:

TopsisNikhil102317179/topsis.py

This ensures:

  • No duplication of logic
  • Consistent ranking results
  • Single source of truth for algorithm implementation

15.6 Deployment (Optional)

The Streamlit application can be deployed using:

  • Streamlit Community Cloud
  • Render
  • Railway
  • Any cloud VM running Python

Basic deployment steps:

  1. Push project to GitHub
  2. Connect repository to Streamlit Cloud
  3. Set entry file as app.py
  4. Deploy

This completes the second part of the assignment by providing a user-friendly web interface for the TOPSIS algorithm.

The repository serves as both an academic submission and a reproducible packaging reference.

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_nikhil_102317179-0.0.1.tar.gz (6.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_nikhil_102317179-0.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file topsis_nikhil_102317179-0.0.1.tar.gz.

File metadata

  • Download URL: topsis_nikhil_102317179-0.0.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for topsis_nikhil_102317179-0.0.1.tar.gz
Algorithm Hash digest
SHA256 871c50ed2a99480652560c09c3db6dc822057780df6f6a1eb70becdb81864962
MD5 5243532747057d6816dbe52b500c24bd
BLAKE2b-256 cd93fe2c1e432d91f6a311b7111db95f00ad5d79b060d7b4fc8aaad4a7565ac3

See more details on using hashes here.

File details

Details for the file topsis_nikhil_102317179-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for topsis_nikhil_102317179-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc426e8486ce2465193c63b331bd2d65641a9366fbd5fb4cc86fba28648c651
MD5 7f98dbf2b92fd046c9550fb2cd35ba81
BLAKE2b-256 59f16913c32a849cd3e7b988dbd8df2676f5b03d747446bb32596a0cce7d8ad9

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