156 lines
6.2 KiB
Plaintext
156 lines
6.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Studium/SCJ-PredatorPrey/env`\n",
|
|
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mSpecialFunctions\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mColorVectorSpace → SpecialFunctionsExt\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mSpecialFunctions → SpecialFunctionsChainRulesCoreExt\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mDualNumbers\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mHypergeometricFunctions\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mStatsFuns\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mStatsFuns → StatsFunsInverseFunctionsExt\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mStatsFuns → StatsFunsChainRulesCoreExt\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mDistributions\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mDistributions → DistributionsTestExt\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mDistributions → DistributionsChainRulesCoreExt\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mKernelDensity\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mStreamSampling\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39mAgents\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mMakie\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39m\u001b[90mAgents → AgentsVisualizations\u001b[39m\n",
|
|
"\u001b[32m ✓ \u001b[39mAgentsExampleZoo\n",
|
|
"\u001b[32m ✓ \u001b[39mCairoMakie\n",
|
|
"\u001b[32m ✓ \u001b[39mGLMakie\n",
|
|
" 19 dependencies successfully precompiled in 272 seconds. 270 already precompiled.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import Pkg\n",
|
|
"Pkg.activate(\"./env\")\n",
|
|
"Pkg.instantiate()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"(agent_color = acolor, agent_size = 25, agent_marker = ashape, agentsplotkwargs = (strokewidth = 1.0, strokecolor = :black), heatarray = grasscolor, heatkwargs = (colormap = [:brown, :green], colorrange = (0, 1)))"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"# To view our starting population, we can build an overview plot using [`abmplot`](@ref).\n",
|
|
"# We define the plotting details for the wolves and sheep:\n",
|
|
"#offset(a) = a.def.type == \"Sheep\" ? (-0.1, -0.1*rand()) : (+0.1, +0.1*rand())\n",
|
|
"ashape(a) = a.def.symbol\n",
|
|
"acolor(a) = a.def.color\n",
|
|
"\n",
|
|
"# and instruct [`abmplot`](@ref) how to plot grass as a heatmap:\n",
|
|
"grasscolor(model) = model.countdown ./ model.regrowth_time\n",
|
|
"# and finally define a colormap for the grass:\n",
|
|
"heatkwargs = (colormap = [:brown, :green], colorrange = (0, 1))\n",
|
|
"\n",
|
|
"# and put everything together and give it to [`abmplot`](@ref)\n",
|
|
"return plotkwargs = (;\n",
|
|
" agent_color = acolor,\n",
|
|
" agent_size = 25,\n",
|
|
" agent_marker = ashape,\n",
|
|
" #offset,\n",
|
|
" agentsplotkwargs = (strokewidth = 1.0, strokecolor = :black),\n",
|
|
" heatarray = grasscolor,\n",
|
|
" heatkwargs = heatkwargs,\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"include(\"./predator_prey_generic.jl\")\n",
|
|
"#Pkg.status([\"Agents\",\"GLMakie\"]; mode = Pkg.Types.PKGMODE_MANIFEST, io=stdout)\n",
|
|
"using GLMakie\n",
|
|
"GLMakie.activate!()\n",
|
|
"events = RecurringEvent[]\n",
|
|
"#push!(events, RecurringEvent(\"Drought\", 80, 30, 30, 50, 120, 1))\n",
|
|
"#push!(events, RecurringEvent(\"Flood\", 50, 30, 70, 80, 120, 1))\n",
|
|
"push!(events, RecurringEvent(\"PreyReproduceSeasonal\", 0.5, 0.1, 1, 4, 12, 1))\n",
|
|
"push!(events, RecurringEvent(\"PredatorReproduceSeasonal\", 0.1, 0.07, 4, 6, 12, 1))\n",
|
|
"sheep_def = AnimalDefinition('●',RGBAf(1.0, 1.0, 1.0, 0.8),20, 0.3, 20, 3, \"Sheep\", [\"Wolf\",\"Bear\"], [\"Grass\"])\n",
|
|
"wolf_def = AnimalDefinition('▲',RGBAf(0.2, 0.2, 0.3, 0.8),20, 0.07, 20, 1, \"Wolf\", [], [\"Sheep\"])\n",
|
|
"bear_def = AnimalDefinition('■',RGBAf(1.0, 0.8, 0.5, 0.8),20, 0.07, 20, 1, \"Bear\", [], [\"Sheep\"])\n",
|
|
"parameter_ranges = generate_animal_parameter_ranges([sheep_def,wolf_def,bear_def])\n",
|
|
"\n",
|
|
"stable_params = (;\n",
|
|
" events = events,\n",
|
|
" start_defs = [StartDefinition(30,sheep_def),StartDefinition(3,wolf_def),StartDefinition(3,bear_def)],\n",
|
|
" dims = (30, 30),\n",
|
|
" regrowth_time = 30,\n",
|
|
" Δenergy_grass = 6,\n",
|
|
" seed = 71758,\n",
|
|
")\n",
|
|
"\n",
|
|
"params = Dict(\n",
|
|
" :regrowth_time => 0:1:100,\n",
|
|
" :Δenergy_grass => 0:1:50,\n",
|
|
")\n",
|
|
"params = merge(params,parameter_ranges)\n",
|
|
"sheep(a) = a.def.type == \"Sheep\"\n",
|
|
"wolf(a) = a.def.type == \"Wolf\"\n",
|
|
"eaten(a) = a.def.type == \"Sheep\" && a.death_cause == Predation\n",
|
|
"starved(a) = a.def.type == \"Sheep\" && a.death_cause == Starvation\n",
|
|
"count_grass(model) = count(model.fully_grown)\n",
|
|
"adata = [(sheep, count), (wolf, count), (eaten, count), (starved, count)]\n",
|
|
"mdata = [count_grass]\n",
|
|
"model = initialize_model(;stable_params...)\n",
|
|
"fig, abmobs = abmexploration(\n",
|
|
" model;\n",
|
|
" params,\n",
|
|
" plotkwargs...,\n",
|
|
" adata,\n",
|
|
" alabels = [\"Sheep\", \"Wolf\", \"Eaten\", \"Starved\"],\n",
|
|
" mdata, mlabels = [\"Grass\"]\n",
|
|
")\n",
|
|
"#, step! = (model) -> begin event_handler!(model, \"Dürre\") model.wolf_reproduce = 0.1 Agents.step!() end\n",
|
|
"#fig, ax, abmobs = abmplot(model; add_controls=true, plotkwargs...)\n",
|
|
"\n",
|
|
"fig\n",
|
|
"#run!(model, 100)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Julia 1.10.3",
|
|
"language": "julia",
|
|
"name": "julia-1.10"
|
|
},
|
|
"language_info": {
|
|
"file_extension": ".jl",
|
|
"mimetype": "application/julia",
|
|
"name": "julia",
|
|
"version": "1.10.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|