Skip to content
Snippets Groups Projects
README.md 1.56 KiB
Newer Older
Martin Lange's avatar
Martin Lange committed
# Literate NetLogo

This is an example project to demonstrate Literate Programming to create [NetLogo](https://ccl.northwestern.edu/netlogo/) models from ODD+C protocols.
Martin Lange's avatar
Martin Lange committed

Martin Lange's avatar
Martin Lange committed
## Rabies model - ODD protocol

### Purpose

### Entities, state variables, and scales
Martin Lange's avatar
Martin Lange committed

Each patch has a disease state.
Martin Lange's avatar
Martin Lange committed

```netlogo
;- State variables
patches-own [
  state
]
```
Martin Lange's avatar
Martin Lange committed

```netlogo
;- Disease states
globals [
  EMPTY
  S
  I
  R
]
```
Martin Lange's avatar
Martin Lange committed

```netlogo
;- Setup disease states
set EMPTY 0
set S 1
set I 2
set R 3
### Process overview and scheduling


```netlogo
;- Go
to go
  update-patches

; ==> Update patches.
Martin Lange's avatar
Martin Lange committed
### Design concepts
Martin Lange's avatar
Martin Lange committed
### Initialization
Martin Lange's avatar
Martin Lange committed
;- Setup
to setup
  clear-all
  ; ==> Setup disease states.
  update-patches
Martin Lange's avatar
Martin Lange committed
  reset-ticks
end
Martin Lange's avatar
Martin Lange committed
### Input data

### Submodels

#### 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
```

Martin Lange's avatar
Martin Lange committed
## 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.