{ "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 `c:\\Users\\da93p\\Desktop\\SCJ\\SCJ-Projekt\\SCJ-PredatorPrey\\env`\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.growth ./ 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": 48, "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", "\n", "# Scenario 1\n", "#events = [] # -> stabiles System\n", "\n", "# Scenario 2\n", "# events = RecurringEvent[\n", "# RecurringEvent(\"Drought\", 30, 40, 100, 124, 240, 0)\n", "# RecurringEvent(\"Flood\", 0.4, 0, 20, 20, 120, 0)\n", "# ] # -> extreme Populationsschwankungen, Räuber stirbt aus (t=433) und System kollabiert\n", "\n", "# Scenario 3\n", "# events = RecurringEvent[\n", "# RecurringEvent(\"Winter\", 0, 0, 18, 24, 24, 0)\n", "# RecurringEvent(\"PreyReproduceSeasonal\", 0.5, 0.1, 1, 7, 24, 0)\n", "# RecurringEvent(\"PredatorReproduceSeasonal\", 0.1, 0.04, 6, 12, 24, 0)\n", "# ] # -> geringere max. Population, dafür weniger starke Schwankung.\n", "\n", "# Scenario 4\n", "# events = RecurringEvent[\n", "# RecurringEvent(\"Drought\", 30, 40, 100, 124, 240, 0)\n", "# RecurringEvent(\"Flood\", 0.4, 0, 25, 25, 120, 0)\n", "# RecurringEvent(\"Winter\", 0, 0, 18, 24, 24, 0)\n", "# RecurringEvent(\"PreyReproduceSeasonal\", 0.5, 0.1, 1, 7, 24, 0)\n", "# RecurringEvent(\"PredatorReproduceSeasonal\", 0.1, 0.05, 6, 12, 24, 0)\n", "# ] # -> starke Schwankung durch, allerdings bleibt das System stabil\n", "\n", "animal_defs = [\n", "AnimalDefinition(30,'●',RGBAf(1.0, 1.0, 1.0, 0.8),20, 0.3, 20, 3, \"Sheep\", [\"Wolf\",\"Bear\"], [\"Grass\"])\n", "AnimalDefinition(3,'▲',RGBAf(0.2, 0.2, 0.3, 0.8),20, 0.07, 20, 1, \"Wolf\", [], [\"Sheep\"])\n", "#AnimalDefinition('■',RGBAf(1.0, 0.8, 0.5, 0.8),20, 0.07, 20, 1, \"Bear\", [], [\"Sheep\"])\n", "]\n", "parameter_ranges = generate_animal_parameter_ranges(animal_defs)\n", "\n", "stable_params = (;\n", " events = events,\n", " animal_defs = animal_defs,\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", "#fig, ax, abmobs = abmplot(model; add_controls=true, plotkwargs...)\n", "\n", "fig\n", "#run!(model, 2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.10.2", "language": "julia", "name": "julia-1.10" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.10.2" } }, "nbformat": 4, "nbformat_minor": 2 }