{"id":18364645,"url":"https://github.com/refiaa/topsis-py","last_synced_at":"2025-04-10T10:09:34.764Z","repository":{"id":239736733,"uuid":"800404534","full_name":"refiaa/TOPSIS-py","owner":"refiaa","description":"Technique for Order Preference by Similarity to Ideal Solution (TOPSIS) for multi-criteria decision","archived":false,"fork":false,"pushed_at":"2024-05-14T09:49:07.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-24T00:24:16.941Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/refiaa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-14T09:14:26.000Z","updated_at":"2024-05-15T05:19:12.000Z","dependencies_parsed_at":"2024-05-14T11:05:09.340Z","dependency_job_id":null,"html_url":"https://github.com/refiaa/TOPSIS-py","commit_stats":null,"previous_names":["refiaa/py_topsis"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refiaa%2FTOPSIS-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refiaa%2FTOPSIS-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refiaa%2FTOPSIS-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/refiaa%2FTOPSIS-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/refiaa","download_url":"https://codeload.github.com/refiaa/TOPSIS-py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239048243,"owners_count":19573187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T23:11:31.354Z","updated_at":"2025-02-15T19:48:34.215Z","avatar_url":"https://github.com/refiaa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TOPSIS Multi-Criteria Decision Making\n\nThis project implements the Technique for Order Preference by Similarity to Ideal Solution (TOPSIS) for multi-criteria decision making. The project is structured into three main Python scripts: `data_loader.py`, `model_ranker.py`, and `topsis.py`. These scripts work together to load data, process it using the TOPSIS method, and rank models based on multiple criteria.\n\n## Introduction to TOPSIS\n\nTOPSIS is a multi-criteria decision analysis method that ranks alternatives based on their distance from an ideal solution. The method involves the following steps:\n\n1. **Normalize the Decision Matrix**:\n   Each criterion value is normalized to ensure comparability.\n\n\n   $R_{ij} = \\frac{X_{ij}}{\\sqrt{\\sum_{i=1}^{n} X_{ij}^2}}$\n\n\n2. **Calculate the Weighted Normalized Decision Matrix**:\n   Apply the weights to the normalized criteria.\n\n\n   $V_{ij} = w_j \\cdot R_{ij}$\n\n\n3. **Determine the Positive and Negative Ideal Solutions**:\n   Identify the best and worst values for each criterion.\n\n    $A^+ = \\{ \\max(V_{ij}) \\, | \\, j \\in J \\}, \\, \\min(V_{ij}) \\, | \\, j \\in J' \\$\n\n    $A^- = \\{ \\min(V_{ij}) \\, | \\, j \\in J \\}, \\, \\max(V_{ij}) \\, | \\, j \\in J' \\$\n\n4. **Calculate the Separation Measures**:\n   Compute the distance of each alternative from the positive and negative ideal solutions.\n\n\n   $S_i^+ = \\sqrt{\\sum_{j=1}^{m} (V_{ij} - A_j^+)^2}$\n\n\n   $S_i^- = \\sqrt{\\sum_{j=1}^{m} (V_{ij} - A_j^-)^2}$\n\n\n5. **Calculate the Relative Closeness to the Ideal Solution**:\n   Determine the relative closeness of each alternative to the ideal solution.\n\n\n   $C_i^* = \\frac{S_i^-}{S_i^+ + S_i^-}$\n\n\n6. **Rank the Alternatives**:\n   Rank the alternatives based on the relative closeness to the ideal solution.\n\n## Scripts Explanation\n\n### data_loader.py\n\nThis script is responsible for loading and preprocessing the data. The criteria, weights, and benefit criteria are dynamically loaded from environment variables.\n\n- **load_data**: Reads the CSV file and extracts the decision matrix and model names.\n- **preprocess_data**: Retrieves weights and benefit criteria from the environment variables.\n\n### model_ranker.py\n\nThis script orchestrates the data loading, model ranking, and saving the results.\n\n- **load_and_prepare_data**: Loads the data and prepares the decision matrix, weights, and benefit criteria.\n- **rank_models**: Uses the TOPSIS class to rank the models.\n- **gather_rankings**: Collects the rankings and prepares them for saving.\n- **save_rankings**: Saves the rankings to a CSV file.\n\n### topsis.py\n\nThis script implements the TOPSIS method.\n\n- **normalize**: Normalizes the decision matrix.\n- **apply_weights**: Applies the weights to the normalized matrix.\n- **determine_ideal_solutions**: Determines the positive and negative ideal solutions.\n- **calculate_separation_measures**: Calculates the separation measures.\n- **calculate_scores**: Computes the relative closeness to the ideal solution.\n- **rank**: Ranks the alternatives based on the calculated scores.\n\n## Example Usage\n\nHere is an example of how to run the script with the given environment variables and CSV data.\n\n1. Create a `.env` file with the following content:\n\n    ```plaintext\n    CRITERIA=index1,index2,index3,index4\n    WEIGHTS=0.25,0.25,0.25,0.25\n    BENEFIT_CRITERIA=False,False,True,True\n    INPUT_FILE=./data/sample.csv\n    OUTPUT_FILE=./data/sample_ranked.csv\n    ```\n\n2. Create a CSV file `sample.csv` with the following content:\n\n    ```csv\n    Model,index1,index2,index3,index4\n    Model_1,5.0,0.1,0.9,0.8\n    Model_2,6.0,0.15,0.85,0.75\n    Model_3,4.5,0.2,0.8,0.7\n    Model_4,5.5,0.12,0.88,0.78\n    Model_5,6.1,0.11,0.87,0.79\n    ```\n\n3. Run the script:\n\n    ```python\n    if __name__ == \"__main__\":\n        input_file = os.getenv(\"INPUT_FILE\")\n        output_file_path = os.getenv(\"OUTPUT_FILE\")\n        ranker = ModelRanker(input_file, output_file_path)\n        ranker.run()\n    ```\n\nThis will read the input file, process the data using the TOPSIS method, and save the ranked models to the specified output file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefiaa%2Ftopsis-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frefiaa%2Ftopsis-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frefiaa%2Ftopsis-py/lists"}