{"id":16333017,"url":"https://github.com/davidyslu/MWIS","last_synced_at":"2025-08-29T11:30:48.201Z","repository":{"id":93934237,"uuid":"108859044","full_name":"yungshenglu/MWIS","owner":"yungshenglu","description":"Assignment in NCTU course \"Distributed Algorithms 2017\"","archived":false,"fork":false,"pushed_at":"2019-05-13T07:58:07.000Z","size":955,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-13T23:08:12.056Z","etag":null,"topics":["cpp","distributed-computing","graph","mwis"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yungshenglu.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":"2017-10-30T14:03:56.000Z","updated_at":"2024-08-15T22:08:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"9d7fe40c-9613-499a-bfa7-642b53ca0f58","html_url":"https://github.com/yungshenglu/MWIS","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yungshenglu%2FMWIS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yungshenglu%2FMWIS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yungshenglu%2FMWIS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yungshenglu%2FMWIS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yungshenglu","download_url":"https://codeload.github.com/yungshenglu/MWIS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231364149,"owners_count":18365408,"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":["cpp","distributed-computing","graph","mwis"],"created_at":"2024-10-10T23:34:04.497Z","updated_at":"2025-08-29T11:30:42.305Z","avatar_url":"https://github.com/yungshenglu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Maximal Weighted Independent Set (MWIS)\n\nThis repository is an assignment in NCTU course \"Distributed Algorithnms 2017\".\n\n## Description\n\nThis repository is going to solve the **Maximal Weighted Independent Set (MWIS)** problem by given each vertex's weight.\n\n### Maximum Independent Set (MIS)\n\nIn an undirected graph $G = (V, E)$, where $V$ is the vertex set and $E$ is the edge set, $S \\subseteq V$ is an independent set if no vertices in $S$ are adjacent to one another. An independent set that has the maximum cardinality is called **maximum independent set**.\nIf each vertex is associated with a weight (a positive real number), then $S$ is a maximum weighted independent set if it is an independent set that has the maximum total weight among all such sets. Clearly, a maximum independent set is a maximum weighted independent set with uniform weight. Finding either set is known to be NP-hard, for which polynomial-time approximation is NP-hard as well.\n\n### Maximal Weighted Independent Set (MWIS)\n\nThere exist many heuristics for these two problems. One well-known greedy approach works by selecting a vertex into the set, removing it and adjacent vertices from the graph, and repeating this process on the remaining graph. The result found by the *greedy approach* can only be a maximal independent set (MIS), an independent set of which no proper superset is also an independent set. If nodes are associated with weights, then the result is a **maximal weighted independent set (MWIS)**.\n\n---\n## Solutions\n\n### Centralized programming\n\nRead the input test file and estblish a path map to note each vertex's neighbors. By sorting the priority of each vertex, we can update the latest MWIS set.\n* Read the input test file and establish an object called `mwis`.\n* Set the path and each vertex's weight by calling function `set_weight_vector` and `set_path_vector`.\n* Calculate the degree and the priority by calling function `calculate_degree_priority`.\n* Calculate the MWIS set by calling function `calculate_MWIS`.\n    * Check each vertex is MWIS or not.\n    * If not, push the current vertex into MWIS set first. and then calculate its neighbors.\n    * Update the latest degree and priority by calling function `update_degree_priority`.\n* Calculate the total weight of vertex in MWIS set by calling `calculate_MWIS_weight`.\n* Print the result of MWIS set and it's total weight.\n\n### Distributed programming\n\nSimulate the **mailbox operation**, let each vertex to have own send buffer and reveived buffer to pass the own information to it's neightbors.\n* Read the test file and establish each node with an object and store into the vector called `mwis` with type `MWIS`.\n* Establosh another two vector called `latest` and `result` to store each run's reault and pre-run's reault.\n* Set the path and each vertex's weight by calling function `set_wieght` and `set_path`.\n* Set a vector called `map` to store the each vertex's known the current MWIS set.\n* Calculate the degree and priority by calling function `calculate_degree_priority`.\n* Calculate the MWIS set in several runs.\n    * Each run should *compare the current and latest result of MWIS set is same or not*.\n        * If it is same, then the program should break the loop.\n    * In Each run, there are **two sub-runs** in it.\n        * The *first* sub-run is that each vertex should push all send messages to it's own buffer called `send_buff`.\n            * The content of message include the information of sender, receiver, the sender's priority, and each vertex known information.\n            * All send message in going to be sent to its neighbor.\n        * The *second* sub-run is that each vertex should pop out all receive messages from it's own buffer called `recv_buff`.\n            * Decide whether it is in the MWIS set or not by all received messages.\n            * The received messages should be sorted in each sub-run in priority order due to the lower priority message should not affect the decision with the higher priority message.\n* Calculate the total weight of the MWIS set.\n* Print the result of MWIS set and it's total weight.\n\n---\n## File Description\n\n* Folder `centralized` - program by centralized method\n    * `Makefile`\n    * `main.cpp` - main function\n    * `MWIS.cpp` - implement class for MWIS\n    * `MWIS.h` - class for MWIS\n    * `header.h` - include all libraries\n    * `test1.txt` - input file\n    * `test_result1.txt` - reference result for input file\n* Folder `distributed` - program by distributed method\n    * `Makefile`\n    * `main.cpp` - main function\n    * `MWIS.cpp` - implement class for MWIS\n    * `MWIS.h` - class for MWIS\n    * `header.h` - include all libraries\n    * `test2.txt` - input file\n    * `test_result2.txt` - reference result for input file\n\n---\n## Execution\n\n* Centralized\n    ```bash\n    # Make sure your current directory is \"./centralized/\"\n    $ make\n    # Execute with the test input \"../../input/test1.txt\"\n    $ ./main ../../input/test1.txt\n    MWIS: {0, 3, 4, 5, 7, 8}\n    Total MWIS weight: 259\n    ```\n* Distributed\n    ```bash\n    # Make sure your current directory is \"./distributed/\"\n    $ make\n    # Execute with the test input \"../../input/test2.txt\"\n    $ ./main ../../input/test2.txt\n    MWIS: {1, 4, 5, 7, 8, 9}\n    Total MWIS weight: 274\n    ```\n\n---\n## Author\n\n* [David Lu](https://github.com/yungshenglu)\n\n---\n## License\n\n[GNU GENERAL PUBLIC LICENSE Version 3](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidyslu%2FMWIS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidyslu%2FMWIS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidyslu%2FMWIS/lists"}