{"id":16905985,"url":"https://github.com/hopding/graph-girth-finder","last_synced_at":"2025-03-20T16:23:56.970Z","repository":{"id":87966590,"uuid":"181782775","full_name":"Hopding/graph-girth-finder","owner":"Hopding","description":"Find the girth of an undirected graph","archived":false,"fork":false,"pushed_at":"2019-05-05T17:56:11.000Z","size":102,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-25T15:23:57.035Z","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-04-16T23:34:29.000Z","updated_at":"2019-05-05T17:56:54.000Z","dependencies_parsed_at":"2023-05-22T04:15:30.226Z","dependency_job_id":null,"html_url":"https://github.com/Hopding/graph-girth-finder","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/Hopding%2Fgraph-girth-finder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fgraph-girth-finder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fgraph-girth-finder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hopding%2Fgraph-girth-finder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hopding","download_url":"https://codeload.github.com/Hopding/graph-girth-finder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244647873,"owners_count":20487160,"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-10-13T18:40:28.580Z","updated_at":"2025-03-20T16:23:56.942Z","avatar_url":"https://github.com/Hopding.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph Girth Finder\n\nThis program takes the adjacency matrix for an undirected graph as input, and outputs the graph's girth along with all cycles whose length is equal to the girth.\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   - **At Least 1 Cycle** - The matrix must contain at least one cycle.\n\n3. **Find all Cycles** - The matrix is converted into a graph. All cycles in this graph are identified via a modified version of breadth first search.\n4. **Find the Girth** - The length of the shortest cycles in the graph are identified. This is the Girth.\n5. **Output Results** - The girth is output to the console, along with all cycles whose length is equal to the girth.\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/test8.matrix\n  ```\n- Alternatively, you can run the `main.py` script directly:\n  ```\n  python3.7 src/main.py data/test8.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  ```\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\nFinding all cycles in graph...\nGraph contains no cycles.\nExiting.\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\nFinding all cycles in graph...\n• Found cycle: 5 -\u003e 6 -\u003e 2 -\u003e 5\n• Found cycle: 5 -\u003e 2 -\u003e 6 -\u003e 5\n• Found cycle: 2 -\u003e 3 -\u003e 6 -\u003e 2\n• Found cycle: 5 -\u003e 6 -\u003e 3 -\u003e 2 -\u003e 5\n• Found cycle: 5 -\u003e 6 -\u003e 7 -\u003e 3 -\u003e 2 -\u003e 5\n• Found cycle: 5 -\u003e 2 -\u003e 3 -\u003e 7 -\u003e 6 -\u003e 5\n\nFinding girth of graph...\n• Found girth: 3\n\nFinding all cycles whose length equals the girth...\n• Found girth cycle: 5 -\u003e 6 -\u003e 2 -\u003e 5\n• Found girth cycle: 5 -\u003e 2 -\u003e 6 -\u003e 5\n• Found girth cycle: 2 -\u003e 3 -\u003e 6 -\u003e 2\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\nFinding all cycles in graph...\n• Found cycle: 0 -\u003e 3 -\u003e 1 -\u003e 0\n• Found cycle: 0 -\u003e 1 -\u003e 3 -\u003e 0\n• Found cycle: 1 -\u003e 4 -\u003e 2 -\u003e 1\n• Found cycle: 1 -\u003e 2 -\u003e 4 -\u003e 1\n\nFinding girth of graph...\n• Found girth: 3\n\nFinding all cycles whose length equals the girth...\n• Found girth cycle: 0 -\u003e 3 -\u003e 1 -\u003e 0\n• Found girth cycle: 0 -\u003e 1 -\u003e 3 -\u003e 0\n• Found girth cycle: 1 -\u003e 4 -\u003e 2 -\u003e 1\n• Found girth cycle: 1 -\u003e 2 -\u003e 4 -\u003e 1\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\nFinding all cycles in graph...\n• Found cycle: 1 -\u003e 2 -\u003e 6 -\u003e 3 -\u003e 1\n• Found cycle: 1 -\u003e 3 -\u003e 6 -\u003e 2 -\u003e 1\n• Found cycle: 0 -\u003e 6 -\u003e 2 -\u003e 1 -\u003e 0\n• Found cycle: 1 -\u003e 3 -\u003e 2 -\u003e 1\n• Found cycle: 0 -\u003e 6 -\u003e 3 -\u003e 1 -\u003e 0\n• Found cycle: 1 -\u003e 2 -\u003e 3 -\u003e 4 -\u003e 1\n• Found cycle: 1 -\u003e 4 -\u003e 3 -\u003e 2 -\u003e 1\n• Found cycle: 1 -\u003e 3 -\u003e 4 -\u003e 1\n\nFinding girth of graph...\n• Found girth: 3\n\nFinding all cycles whose length equals the girth...\n• Found girth cycle: 1 -\u003e 3 -\u003e 2 -\u003e 1\n• Found girth cycle: 1 -\u003e 3 -\u003e 4 -\u003e 1\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopding%2Fgraph-girth-finder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhopding%2Fgraph-girth-finder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopding%2Fgraph-girth-finder/lists"}