|
9 | 9 | ] |
10 | 10 | }, |
11 | 11 | { |
| 12 | + "attachments": {}, |
12 | 13 | "cell_type": "markdown", |
13 | 14 | "id": "32c878b0", |
14 | 15 | "metadata": {}, |
15 | 16 | "source": [ |
16 | | - "This course introduces the [Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/) Julia package for agent based modelling. The notebook is created by [Alejandra Ramirez](https://github.com/MA-Ramirez)\n", |
17 | | - "and George Datseris.\n", |
| 17 | + "This course introduces the [Agents.jl](https://juliadynamics.github.io/Agents.jl/stable/) Julia package for agent based modelling.\n", |
18 | 18 | "\n", |
19 | 19 | "Agent based modelling are simulations where autonomous agents react to their environment and interact with each other given a predefined set of rules. \n", |
20 | 20 | "These rules are formulated based on explicit statements rather than mathematical equations (such as: “If condition X is fulfilled, do action Y, and then perform operation Z on all nearby agents”).\n", |
|
224 | 224 | ] |
225 | 225 | }, |
226 | 226 | { |
| 227 | + "attachments": {}, |
| 228 | + "cell_type": "markdown", |
| 229 | + "id": "c3126a56", |
| 230 | + "metadata": {}, |
| 231 | + "source": [ |
| 232 | + "The first version of the model will be agents (rabbit) performing random walks, losing energy, and dying." |
| 233 | + ] |
| 234 | + }, |
| 235 | + { |
| 236 | + "attachments": {}, |
227 | 237 | "cell_type": "markdown", |
228 | 238 | "id": "5c115fca", |
229 | 239 | "metadata": {}, |
230 | 240 | "source": [ |
231 | | - "The first steps in any simulation with Agents.jl is to decide the space and the agent types. \n", |
232 | | - "\n", |
233 | 241 | "### 1. Choose the space \n", |
234 | 242 | "\n", |
235 | 243 | "The space is a grid space so we define" |
|
622 | 630 | ] |
623 | 631 | }, |
624 | 632 | { |
| 633 | + "attachments": {}, |
625 | 634 | "cell_type": "markdown", |
626 | 635 | "id": "e5994737", |
627 | 636 | "metadata": {}, |
628 | 637 | "source": [ |
629 | 638 | "### 5. Visualize the model and animate its time evolution\n", |
630 | 639 | "\n", |
631 | | - "Alright, things seem to work. All rabbits die, since they eat no food but loose energy. But let's also visualize the model! To do so it is very easy! We choose a color/size/marker for the agents and call `abmplot`!" |
| 640 | + "Alright, things seem to work. All rabbits die, since they eat no food but loose energy. But let's also visualize the model! To do so it is very easy! We choose a color/size/marker for the agents and call `abmplot`!\n", |
| 641 | + "\n", |
| 642 | + "The way this works is that agents are plotted as a scatter plot (each marker is one agent). Then, the user decides how the agents will be plotting by providing a function that given an agent it gives its color or size or marker." |
632 | 643 | ] |
633 | 644 | }, |
634 | 645 | { |
|
642 | 653 | "\n", |
643 | 654 | "using GLMakie # this allows videos and interactive apps\n", |
644 | 655 | "model = init_rabbits() # refresh model\n", |
645 | | - "rabbitcolor(a) = :orange\n", |
646 | | - "rabbitmarker(a) = :circle\n", |
647 | | - "fig, = abmplot(model; ac = rabbitcolor, am = rabbitmarker)\n", |
| 656 | + "rabbitcolor(agent) = :orange # all agents have the same color\n", |
| 657 | + "rabbitmarker(agent) = :circle\n", |
| 658 | + "rabbitsize(agent) = agent.energy # size depends on agent\n", |
| 659 | + "fig, = abmplot(model; ac = rabbitcolor, am = rabbitmarker, as = rabbitsize)\n", |
648 | 660 | "fig" |
649 | 661 | ] |
650 | 662 | }, |
|
664 | 676 | "outputs": [], |
665 | 677 | "source": [ |
666 | 678 | "fig, = abmplot(model; \n", |
667 | | - " ac = rabbitcolor, am = rabbitmarker,\n", |
| 679 | + " ac = rabbitcolor, am = rabbitmarker, as = rabbitsize,\n", |
668 | 680 | " agent_step! = rabbit_step!, \n", |
669 | 681 | ")\n", |
670 | 682 | "\n", |
|
934 | 946 | "plotkwargs = (;\n", |
935 | 947 | " ac = (\"white\", 0.5),\n", |
936 | 948 | " offset = agent -> (0.25rand(), 0.25rand()),\n", |
937 | | - " as = 20,\n", |
| 949 | + " as = agent.energy,\n", |
938 | 950 | " #additional keyword arguments propagated to the scatter! call.\n", |
939 | 951 | " scatterkwargs = (strokewidth = 1.0, strokecolor = :black),\n", |
940 | 952 | " heatarray = grasscolor,\n", |
|
1537 | 1549 | ] |
1538 | 1550 | }, |
1539 | 1551 | { |
| 1552 | + "attachments": {}, |
1540 | 1553 | "cell_type": "markdown", |
1541 | 1554 | "id": "adbefad7", |
1542 | 1555 | "metadata": {}, |
|
1559 | 1572 | "* Reproduction of strategies is only allowed on empty neighbouring sites, to mimic a finite carrying capacity of the system\n", |
1560 | 1573 | "* Mobility is represented via $\\epsilon$, this exchange rate represent the likelihood of agents to swap position with a neighbouring individual or hop onto an empty neighbouring site.\n", |
1561 | 1574 | "\n", |
1562 | | - "\n", |
1563 | | - "\n", |
1564 | 1575 | "Whether selection, reproduction or mobility occurs is computed according to the rates (probability = rate* number of agents).\n", |
1565 | 1576 | "\n", |
1566 | | - "Explore the system's evolution for different exchange rate values.\n", |
1567 | | - "\n" |
| 1577 | + "Explore the system's evolution for different exchange rate values." |
1568 | 1578 | ] |
1569 | | - }, |
1570 | | - { |
1571 | | - "cell_type": "code", |
1572 | | - "execution_count": 36, |
1573 | | - "id": "ced17cdc", |
1574 | | - "metadata": {}, |
1575 | | - "outputs": [], |
1576 | | - "source": [] |
1577 | 1579 | } |
1578 | 1580 | ], |
1579 | 1581 | "metadata": { |
|
0 commit comments