# Literate NetLogo This is an example project to demonstrate Literate Programming to create [NetLogo](https://ccl.northwestern.edu/netlogo/) models from ODD+C protocols. ## Rabies model - ODD protocol ### Purpose ### Entities, state variables, and scales Each patch has a disease state. ```netlogo ;- State variables patches-own [ state infected-neighbours ] ``` ```netlogo ;- Disease states globals [ EMPTY S I R ] ``` ```netlogo ;- Setup disease states set EMPTY 0 set S 1 set I 2 set R 3 ``` ### Process overview and scheduling ```netlogo ;- Go to go infect-patches update-patches tick end ; ==> Infection. ; ==> Update patches. ``` ### Design concepts ### Initialization ```netlogo ;- Setup to setup clear-all ; ==> Setup disease states. ask patches [ set state S ] ask one-of patches [ set state I ] update-patches reset-ticks end ``` ### Input data ### Submodels #### Infection ```netlogo ;- Infection to infect-patches ask patches [ set infected-neighbours 0 ] ask patches with [ state = I ] [ ask neighbors [ set infected-neighbours infected-neighbours + 1 ] ] ask patches with [ state = S ] [ if random-float 1 < calc-infection-prob [ set state I ] ] end ; ==> Infection probability. ``` ```netlogo ;- Infection probability to-report calc-infection-prob report 1 - (1 - beta) ^ infected-neighbours end ``` #### Visualization ```netlogo ;- Update patches to update-patches ask patches [ ifelse state = EMPTY [ set pcolor white ] [ ifelse state = S [ set pcolor blue ] [ ifelse state = I [ set pcolor red ] [ set pcolor green ] ] ] ] end ``` ## Appendix ### Code ```netlogo ;- file:Code.nls ; ==> Disease states. ; ==> State variables. ; ==> Setup. ; ==> Go. ``` ### NetLogo file In the main `nlogo` file, we only "include" an `nls` file to allow for the reverse mode. The file `Model.nlogo` is simply copied from the `nlogo` directory via option `code_files` in the `[paths]` section of the `Yarner.toml`. This separation of model code and user interface also allows to edit the model's UI elements in NetLogo's GUI builder tool, while using Literate Programming for the code.