{"id":16570254,"url":"https://github.com/hadisfr/graph-coloring-r","last_synced_at":"2025-07-31T21:02:33.931Z","repository":{"id":112569132,"uuid":"140256892","full_name":"hadisfr/graph-coloring-r","owner":"hadisfr","description":"greedy \u0026 ILP solution for graph coloring problem in R - UT Algorithmic Graph Theory S97 - mirror of https://gitlab.com/hadi_sfr/r_graph_coloring","archived":false,"fork":false,"pushed_at":"2018-07-09T08:44:37.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-16T01:38:37.371Z","etag":null,"topics":["gcp","graph-coloring","greedy-algorithms","integer-programming","linear-programming","r"],"latest_commit_sha":null,"homepage":null,"language":"R","has_issues":false,"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/hadisfr.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":"2018-07-09T08:43:21.000Z","updated_at":"2018-07-09T08:46:01.000Z","dependencies_parsed_at":"2023-05-16T08:45:10.852Z","dependency_job_id":null,"html_url":"https://github.com/hadisfr/graph-coloring-r","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/hadisfr%2Fgraph-coloring-r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hadisfr%2Fgraph-coloring-r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hadisfr%2Fgraph-coloring-r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hadisfr%2Fgraph-coloring-r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hadisfr","download_url":"https://codeload.github.com/hadisfr/graph-coloring-r/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242031301,"owners_count":20060579,"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":["gcp","graph-coloring","greedy-algorithms","integer-programming","linear-programming","r"],"created_at":"2024-10-11T21:18:11.091Z","updated_at":"2025-03-05T12:45:42.311Z","avatar_url":"https://github.com/hadisfr.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"Solving Graph Coloring Problem (GCP) using R\n===\n\n## Greedy Approach\n\nIn `colorize_greedy`,  all vertices of graph will be sorted non-increasing based on their degree. The smallest allowed color  will be assigned to each vertex. It's obvious that at most $`\\|V(G)\\|`$ colors will be needed.\n\n## Integral Linear Programming Approach\n\n### Modeling GCP to ILP\n\nThe graph coloring problem is modeled as in ILP problem.\n\n\u003e **Note**: \n\u003e In writing this part, [Faigle U., Kern W., Still G. (2002) Integer Programming. In: Algorithmic Principles of Mathematical Programming. Kluwer Texts in the Mathematical Sciences (A Graduate-Level Book Series), vol 24. Springer, Dordrecht][Faigle] and [this StackOverflow post][IPLSO] were used.\n\nIf $`X_{i, j}`$ shows that vertex $`i`$ is colored with color $`j`$ and $`Y_i`$ shows that color $`j`$ is used, $`X`$ and $`Y`$ are `boolean` variables (i.e. `integer` variables with bounds 0 and 1), then we are interested in optimizing solution of:\n```math\nmin(\\sum_{k=1}^n{Y_k})\n```\n```math\n\\sum_{k=1}^{n}{X_{i,k} = 1:\\forall i \\in \\{1, …, n\\}}\n```\n```math\nX_{i,k}-Y_{k} \\le 0 : \\forall i, k \\in \\{1, …,n\\}\n```\n```math\nX_{i,k}+X{j,k} \\le 1 : \\forall k \\in \\{1, …,n\\},  \u003ci,j\u003e \\in E(G)\n```\n\n### Solving ILP\n\nBased on the previos model and using `lpsolve` package, the GCP problem can be solved.\n\n## Analyzing Results\n\nSome graphs of second [Erdős–Rényi model][ERM] ($`G(n, m)`$) were used to test and compare these approaches.\n\nOn small graph $`G(5, 5)`$ both algorithms generated result 3 in a short time.\n```\n[[1]]\n[1] \"Graph:\"\n\n[[2]]\nIGRAPH a4a8b9d U--- 5 5 -- Erdos renyi (gnm) graph\n+ attr: name (g/c), type (g/c), loops (g/l), m (g/n)\n+ edges from a4a8b9d:\n[1] 2--3 1--4 2--4 3--4 4--5\n\n[1] \"Greedy:\" \"3\"      \n   user  system elapsed \n  0.035   0.002   0.037 \n[1] \"Integer Linear Programming:\" \"3\"                          \n   user  system elapsed \n  0.032   0.002   0.034 \n\n```\n\nOn $`G(10, 18)`$ both generated 4.\n```\n[[1]]\n[1] \"Graph:\"\n\n[[2]]\nIGRAPH 089488b U--- 10 18 -- Erdos renyi (gnm) graph\n+ attr: name (g/c), type (g/c), loops (g/l), m (g/n)\n+ edges from 089488b:\n [1] 1-- 2 1-- 3 2-- 3 3-- 4 4-- 5 2-- 6 3-- 6 4-- 6 4-- 7 5-- 8 7-- 8 2-- 9\n[13] 3-- 9 5-- 9 6-- 9 7-- 9 2--10 4--10\n\n[1] \"Greedy:\" \"4\"      \n   user  system elapsed \n  0.047   0.002   0.049 \n[1] \"Integer Linear Programming:\" \"4\"                          \n   user  system elapsed \n  0.340   0.003   0.345 \n```\n\nOn $`G(15, 42)`$ both generated 5. ILP approach lasted about 22 times more than greedy approach.\n```\n[[1]]\n[1] \"Graph:\"\n\n[[2]]\nIGRAPH b8c05dc U--- 15 42 -- Erdos renyi (gnm) graph\n+ attr: name (g/c), type (g/c), loops (g/l), m (g/n)\n+ edges from b8c05dc:\n [1]  2-- 3  1-- 5  4-- 5  2-- 7  1-- 8  2-- 8  3-- 8  6-- 8  2-- 9  2--10\n[11]  3--10  4--10  5--10  6--10  8--10  3--11  5--11  6--11  1--12  5--12\n[21]  7--12  9--12 10--12  1--13  2--13  3--13  4--13  7--13 10--13  3--14\n[31]  5--14  7--14 10--14 13--14  1--15  2--15  3--15  5--15  9--15 10--15\n[41] 11--15 14--15\n\n[1] \"Greedy:\" \"5\"      \n   user  system elapsed \n  0.059   0.002   0.061 \n[1] \"Integer Linear Programming:\" \"4\"                          \n   user  system elapsed \n 10.977   0.048  11.080 \n```\n\nOn bigger graph $`G(20, 77)`$, greedy approach gave result 5 in 0.255 s. ILP approach reached result 4 in about 2 h.\n```\n[[1]]\n[1] \"Graph:\"\n\n[[2]]\nIGRAPH a043ffc U--- 20 77 -- Erdos renyi (gnm) graph\n+ attr: name (g/c), type (g/c), loops (g/l), m (g/n)\n+ edges from a043ffc:\n [1]  1-- 2  1-- 3  2-- 4  4-- 5  1-- 6  2-- 6  3-- 6  4-- 6  5-- 6  1-- 7\n[11]  4-- 7  5-- 7  1-- 8  5-- 8  1-- 9  4-- 9  5-- 9  6-- 9  7-- 9  5--10\n[21]  6--10  7--10  8--10  2--11  3--11  5--11  6--11  8--11  9--11 10--11\n[31]  1--12  4--12  5--12  8--12  3--13  4--13  6--13 11--13 12--13  2--14\n[41]  3--14  9--14 10--14 13--14  4--15  9--15 10--15 11--15 14--15  1--16\n[51]  2--16  8--16  9--16 11--16 13--16  4--17  5--17  6--17  8--17 11--17\n[61] 13--17 14--17  1--18 11--18 14--18 17--18  1--19  3--19  4--19  7--19\n[71]  9--19 12--19 16--19 17--19  2--20 11--20 19--20\n\n[1] \"Greedy:\" \"5\"      \n   user  system elapsed \n  0.213   0.012   0.225 \n[1] \"Integer Linear Programming:\" \"5\"                          \n    user   system  elapsed \n6840.432    0.471 6863.336 \n\n```\n\nOn much bigger graph $`G(50, 500)`$, greedy approach gave result 10 in 0.235 s. ILP approach didn't reach the result in a reasonable time.\n\n### Conclusion\n\nIt seems that greedy algorithm has appropriate accuracy. Because of very high temporal cost of ILP algorithm, it seems reasonable to use greedy algorithm for solving GCP in many usages. \n\n[Faigle]: http://wwwhome.math.utwente.nl/~uetzm/do/IP-FKS.pdf\n[IPLSO]: https://stackoverflow.com/a/26764275\n[ERM]: https://en.wikipedia.org/wiki/Erdős–Rényi_model\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhadisfr%2Fgraph-coloring-r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhadisfr%2Fgraph-coloring-r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhadisfr%2Fgraph-coloring-r/lists"}