{"id":16905980,"url":"https://github.com/hopding/bipartite-graph-checker","last_synced_at":"2025-08-19T19:05:02.552Z","repository":{"id":87966568,"uuid":"185034355","full_name":"Hopding/bipartite-graph-checker","owner":"Hopding","description":"Find disjoint vertex sets of bipartite graphs ","archived":false,"fork":false,"pushed_at":"2019-05-05T17:53:34.000Z","size":103,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-20T16:27:17.923Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hopding.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2019-05-05T13:22:44.000Z","updated_at":"2019-05-05T17:54:16.000Z","dependencies_parsed_at":"2023-05-22T04:00:32.630Z","dependency_job_id":null,"html_url":"https://github.com/Hopding/bipartite-graph-checker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Hopding/bipartite-graph-checker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fbipartite-graph-checker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fbipartite-graph-checker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fbipartite-graph-checker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fbipartite-graph-checker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hopding","download_url":"https://codeload.github.com/Hopding/bipartite-graph-checker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fbipartite-graph-checker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266671190,"owners_count":23966138,"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","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-13T18:40:27.838Z","updated_at":"2025-07-23T11:39:47.197Z","avatar_url":"https://github.com/Hopding.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bipartite Graph Checker\n\nThis program takes the adjacency matrix for an undirected graph as input. It outputs, for each connected component in the graph, the two bipartite vertex sets, or the first three-cycle it encounters.\n\n## Program Outline\n\nWhen processing an input file, the following steps are performed:\n\n1. **Input** - The input file is read, and split into rows based on newlines. Each row is split into cells based on spaces. The result is a matrix.\n2. **Validation** - The matrix is validated as follows. If any of these validations fail, the program will notify the user and exit.\n\n   - **Square Matrix** - The matrix must have the same number of rows and columns.\n   - **Bit Value Entries** - Each cell in the matrix must be `0` or `1`.\n   - **No Self-Loops** - The diagonal cells (from top left to bottom right) must all be `0`.\n   - **Undirected Graph** - The adjacency matrix must be symmetric over the diagonal (from top left to bottom right).\n\n3. **Find all Connected Components** - The matrix is converted into a graph. Each connected component in this graph is identified.\n4. **Bipartite Validation** - Each connected component is validated to ensure it is bipartite. If a component is found to have at least one cycle of length 3, it is not bipartite.\n5. **Find Vertex Sets** - Each bipartite component is processed to split its vertices into two disjoint and independent sets.\n6. **Output Results** - For each connected component, one of two things is output, depending on whether or not it is bipartite. If the component is bipartite, its two vertex sets are printed to the console. Otherwise, the first cycle of length 3 is printed.\n\n## Requirements\n\nTo run this program, you must have Python 3.7 installed on your machine. Older and newer versions may work, but only 3.7 has been tested.\n\n## Running\n\n- You can use the included `run` script:\n  ```\n  ./run data/test11.matrix\n  ```\n- Alternatively, you can run the `main.py` script directly:\n  ```\n  python3.7 src/main.py data/test11.matrix\n  ```\n\n## Unit Tests\n\n- You can use the included `test` script:\n  ```\n  ./test\n  ```\n- Alternatively, you can run the `test_*.py` files directly:\n  ```\n  python3.7 src/test_adjacency_matrix.py\n  python3.7 src/test_graph.py\n  python3.7 src/test_cycles.py\n  python3.7 src/test_bipartite.py\n  ```\n\n## Output For `data/*.matrix` Files\n\n```\n$ ./run data/test1.matrix\nReading input file: data/test1.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----\n0 1 0\n1 0 1\n0 1 0\n-----\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound 1 connected components.\n\nFinding bipartite vertex sets in connected component 0...\nVertex Set 1: [1]\nVertex Set 2: [0, 2]\n\nDone.\n```\n\n```\n$ ./run data/test2.matrix\nReading input file: data/test2.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----\n1 0 x\n0 1 0\n1 0 1\n-----\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\n\nFound invalid matrix cell: \"x\"\nExiting.\n```\n\n```\n$ ./run data/test3.matrix\nReading input file: data/test3.matrix\n\nUsing the following input data as Adjacency Matrix:\n-------\n1 0 1\n0 1 0 0\n1 0 1\n-------\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\n\nMatrix is not square.\nExiting.\n```\n\n```\n$ ./run data/test4.matrix\nReading input file: data/test4.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----\n1 0 1\n0 1 0\n1 0 1\n0\n-----\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\n\nMatrix is not square.\nExiting.\n```\n\n```\n$ ./run data/test5.matrix\nReading input file: data/test5.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----\n1 0 1\n0 1 0\n1 0 1\n-----\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\n\nFound self loop on vertex 0\nExiting.\n```\n\n```\n$ ./run data/test6.matrix\nReading input file: data/test6.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----\n0 1 0\n0 0 1\n0 1 0\n-----\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound nonsymmetric cell in matrix: row=0 col=1\nExiting.\n```\n\n```\n$ ./run data/test7.matrix\nReading input file: data/test7.matrix\n\nUsing the following input data as Adjacency Matrix:\n---------------\n0 1 0 0 1 0 0 0\n1 0 0 0 0 1 0 0\n0 0 0 1 0 1 1 0\n0 0 1 0 0 0 1 1\n1 0 0 0 0 0 0 0\n0 1 1 0 0 0 1 0\n0 0 1 1 0 1 0 1\n0 0 0 1 0 0 1 0\n---------------\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound 1 connected components.\n\nFinding bipartite vertex sets in connected component 0...\nConnected component 0 is not bipartite.\nFound cycle with length 3:\n  5 -\u003e 6 -\u003e 2 -\u003e 5\n\nDone.\n```\n\n```\n$ ./run data/test8.matrix\nReading input file: data/test8.matrix\n\nUsing the following input data as Adjacency Matrix:\n---------\n0 1 0 1 0\n1 0 1 1 1\n0 1 0 0 1\n1 1 0 0 0\n0 1 1 0 0\n---------\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound 1 connected components.\n\nFinding bipartite vertex sets in connected component 0...\nConnected component 0 is not bipartite.\nFound cycle with length 3:\n  0 -\u003e 3 -\u003e 1 -\u003e 0\n\nDone.\n```\n\n```\n$ ./run data/test9.matrix\nReading input file: data/test9.matrix\n\nUsing the following input data as Adjacency Matrix:\n-------------\n0 1 0 0 0 0 1\n1 0 1 1 1 0 0\n0 1 0 1 0 0 1\n0 1 1 0 1 1 1\n0 1 0 1 0 0 0\n0 0 0 1 0 0 0\n1 0 1 1 0 0 0\n-------------\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound 1 connected components.\n\nFinding bipartite vertex sets in connected component 0...\nConnected component 0 is not bipartite.\nFound cycle with length 3:\n  1 -\u003e 3 -\u003e 2 -\u003e 1\n\nDone.\n```\n\n```\n$ ./run data/test10.matrix\nReading input file: data/test10.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----------------\n0 0 0 0 0 1 0 0 0\n0 0 0 0 0 1 1 0 0\n0 0 0 0 0 0 0 1 1\n0 0 0 0 0 0 1 0 0\n0 0 0 0 0 1 0 0 1\n1 1 0 0 1 0 0 0 0\n0 1 0 1 0 0 0 0 0\n0 0 1 0 0 0 0 0 0\n0 0 1 0 1 0 0 0 0\n-----------------\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound 1 connected components.\n\nFinding bipartite vertex sets in connected component 0...\nVertex Set 1: [1, 2, 0, 4, 3]\nVertex Set 2: [7, 5, 6, 8]\n\nDone.\n```\n\n```\n$ ./run data/test11.matrix\nReading input file: data/test11.matrix\n\nUsing the following input data as Adjacency Matrix:\n-----------------\n0 0 0 0 0 1 0 0 0\n0 0 0 0 0 1 1 0 0\n0 0 0 0 0 0 1 1 0\n0 0 0 0 1 0 0 0 1\n0 0 0 1 0 0 0 0 1\n1 1 0 0 0 0 0 0 0\n0 1 1 0 0 0 0 0 0\n0 0 1 0 0 0 0 0 0\n0 0 0 1 1 0 0 0 0\n-----------------\n\nParsing matrix...\nValidating matrix cells are 0 or 1...\nValidating matrix is square...\nValidating matrix contains no self loops...\nValidating matrix is symmetric...\n\nFound 2 connected components.\n\nFinding bipartite vertex sets in connected component 0...\nVertex Set 1: [0, 2, 1]\nVertex Set 2: [7, 5, 6]\n\nFinding bipartite vertex sets in connected component 1...\nConnected component 1 is not bipartite.\nFound cycle with length 3:\n  3 -\u003e 8 -\u003e 4 -\u003e 3\n\nDone.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopding%2Fbipartite-graph-checker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhopding%2Fbipartite-graph-checker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopding%2Fbipartite-graph-checker/lists"}