{"id":26253918,"url":"https://github.com/p2-718na/sir-model-simulation","last_synced_at":"2025-03-13T18:18:38.836Z","repository":{"id":51569992,"uuid":"362515028","full_name":"P2-718na/SIR-model-simulation","owner":"P2-718na","description":"SIR model implementation for pandemic spread","archived":false,"fork":false,"pushed_at":"2021-10-14T10:49:04.000Z","size":492,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T22:47:37.526Z","etag":null,"topics":["differential-equations","doctest","lyra","sir-model"],"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/P2-718na.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}},"created_at":"2021-04-28T15:16:40.000Z","updated_at":"2024-11-12T14:35:22.000Z","dependencies_parsed_at":"2022-08-22T07:01:07.976Z","dependency_job_id":null,"html_url":"https://github.com/P2-718na/SIR-model-simulation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P2-718na%2FSIR-model-simulation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P2-718na%2FSIR-model-simulation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P2-718na%2FSIR-model-simulation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/P2-718na%2FSIR-model-simulation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/P2-718na","download_url":"https://codeload.github.com/P2-718na/SIR-model-simulation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243456562,"owners_count":20293905,"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":["differential-equations","doctest","lyra","sir-model"],"created_at":"2025-03-13T18:18:38.160Z","updated_at":"2025-03-13T18:18:38.829Z","avatar_url":"https://github.com/P2-718na.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"Alma Mater Studiorum Logo\" src=\"assets/unibo-logo.png\"\u003e\n\u003c/div\u003e\n\n# SIR-model-simulation\nThis is a very basic implementation of the [SIR model for virus spreading][1].\nIt lets you visualize how the three differential equations evolve over time, by\nprinting a table to the terminal. This is the first part of my coding exam\n[final project][2] at University of Bologna, year one physics course.  \nAll the code in this project (excluding external libraries) is written entirely\nby [me (Matteo Bonacini)][3].\n\n[1]: https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology#The_SIR_model\n[2]: https://baltig.infn.it/giaco/pf2020/-/blob/master/progetto/progetto.md\n[3]: https://github.com/P2-718na\n\n--------------------------------------------------------------------------------\n\n## Dependencies\n- [Lyra](https://github.com/bfgroup/Lyra) (bundled)\n- [Doctest](https://github.com/onqtam/doctest) (bundled)\n- [CMake](https://cmake.org/) (recommended)\n- [gnuplot](http://www.gnuplot.info/) (optional)\n\n## Building\nThe preferred way to build this code is by using CMake.\n```shell\nmkdir build\ncd build\ncmake ..\n```\nThen, run either of these commands\n```shell\nmake sir       # compile the program only\nmake sir-test  # compile tests only\nmake           # compile both\n```\nBoth executables will be generated inside the build folder.\n\n## Running\nThis code was tested and running on _Mac OS X 10.14.6 Mojave_ and\n_Ubuntu 20.04 LTS (running on WSL)_.\n\n### Running via terminal\nThe easiest way to learn how to use this program is to read the help message.\n```\n$ ./sir --help\nUSAGE:\n  \u003cexecutable\u003e [-?|-h|--help] -b|--beta \u003cbeta\u003e -c|--gamma \u003cgamma\u003e -s|--susceptible \u003csusceptible\u003e [-i|--infected \u003cinfected\u003e] [-r|--removed \u003cremoved\u003e] -t|--day-count \u003cdayCount\u003e [--pretty] [--no-headings]\n\nDisplay usage information.\n\nOPTIONS, ARGUMENTS:\n  -?, -h, --help\n  -b, --beta \u003cbeta\u003e       Beta constant. Must be a number in range [0, 1].\n  -c, -g, --gamma \u003cgamma\u003e     Gamma constant. Must be a number in range [0, 1].\n  -s, --susceptible \u003csusceptible\u003e\n                          Number of susceptible people.\n  -i, --infected \u003cinfected\u003e\n                          Number of infected people. Defaults to 1.\n  -r, --removed \u003cremoved\u003e Number of removed people. Defaults to 0.\n  -t, --day-count \u003cdayCount\u003e\n                          Duration of the simulation.\n  --pretty                Prints a pretty table to the terminal.\n  --no-headings           Remove headings from normal print.Ignored if --pretty is added as well.\n```\nExample run with pretty-print option enabled:\n```\n$ ./sir -b 0.2 -c 0.1 -s 1000 -t 160 --pretty\n┌-----┬-----┬-----┬-----┐\n│  T  │  S  │  I  │  R  │\n├-----┼-----┼-----┼-----┤\n│    1| 1000│    1│    0│\n├-----┼-----┼-----┼-----┤\n│    2| 1000│    1│    0│\n├-----┼-----┼-----┼-----┤\n│    3| 1000│    1│    0│\n├-----┼-----┼-----┼-----┤\n≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠\n├-----┼-----┼-----┼-----┤\n│  161|  198│    1│  802│\n└-----┴-----┴-----┴-----┘\n```\nExample run with pretty-print option disabled:\n```\n$ ./sir -b 0.2 -c 0.1 -s 1000 -t 160 --no-headings\n0 1000 1 0\n1 1000 1 0\n2 1000 1 0\n3 1000 1 0\n≠≠≠≠≠≠≠≠≠≠≠≠≠\n160 198 1 802\n```\nPlease note that the `≠` symbols mean that the output was truncated.  \nThe four columns represent the number of susceptible (S), infected (I) and\nretired (R) people on each day (T) of the simulation. The initial state of the\nsimulation is printed as well, which means that the number of rows printed is\none more than the number specified using `--day-count`.\n\n### Graphing data\nIf you have gnuplot installed, you can use it to display the data.\n```shell\n./sir -b 0.2 -c 0.1 -s 1000 -t 160 | (    \\\n  cat \u003e /tmp/sir-data \u0026\u0026                  \\\n  trap 'rm /tmp/sir-data' EXIT \u0026\u0026         \\\n  gnuplot -p -e                               \\\n  \"plot for [col=2:4] '/tmp/sir-data'     \\\n  using 0:col with lines title columnheader\")\n```\nThe previous command will display the following graph:\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"\" src=\"assets/gnuplot.png\"\u003e\n\u003c/div\u003e\n\nIf you are running on WSL 1, you might get this error:\n```shell\ngnuplot: error while loading shared libraries: libQt5Core.so.5: cannot open shared object file\n```\nIt can be solved by running\n```shell\nsudo strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5\n```\n\n### Testing\nMake sure to compile tests (see [Building](#building)), then run\n```shell\n./sir-tests\n```\n\n--------------------------------------------------------------------------------\n\n## Components\nWhat follows is a quick overview of the components that make up this program.\nAdditional information is present in the comments alongside the code.\n\n### SIR Model\nClass that handles the calculations of the SIR model. The model used consists\nof three differential equations:\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"SIR model equations\" src=\"assets/equations.png\"\u003e\n\u003c/div\u003e\n\nWhere `S`, `I` and `R` represent respectively the number of susceptible, infected and\nremoved (dead/vaccinated/recovered) people. The equations are solved\nnumerically, using an arbitrary value of `dS = 1 day`. The value of `S` is\ncomputed using the constraint that `S + I + R` is constant throughout the\nsimulation.\n`S`, `I` and `R` are handled internally as `double` types, but the respective\ngetter (or setter) functions will return (or accept) an integer value.\nThis was done because these three variables represent natural numbers, but decimal\nnumbers are required for solving the equations correctly.\n\n### Visualizer\nClass that handles the display of table data. Its constructor takes a reference\nto a `Model` instance. The methods `visualize` and `visualizePretty` will run\nthe model for the specified number of days. Please note that the `Model` instance\nwill be altered by the visualizer.\n\n### Parser\nClass that handles the parsing of command line arguments and exposes getter\nfunctions for them. The parsing is done using Lyra library (see dependencies).\nThe parser checks that the input format is correct.\nThe only value check performed here is for the `--day-count` parameter (if it is\nnegative, an error is shown). This is not strictly needed, but it can be helpful\nto the user, since there are no explicit warnings for this anywhere else.  \nAll the needed value checks on parameters are performed inside the `Model` class\nconstructor.\n\n### Tests\nUnit Tests are performed using Doctest and are built separately from the main\nexecutable. Tests are centered on the Model component, and they check that all\nthe constraints imposed by the model are met. For additional information on how\nto run tests, see [Testing](#testing).\n\n--------------------------------------------------------------------------------\n\n## Additional notes\n1. A requirement of the project was that there must be no memory leaks or\nillegal memory accesses. This program was run through Valgrind Memcheck\nand is completely devoid of them.\n2. This code was run through Clang-Tidy to check for additional warnings.\nThe configuration used was [CLion default][4] from JetBrains.\n\n[4]: https://confluence.jetbrains.com/display/CLION/Clang-Tidy+in+CLion%3A+default+configuration\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp2-718na%2Fsir-model-simulation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp2-718na%2Fsir-model-simulation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp2-718na%2Fsir-model-simulation/lists"}