# Introduction to Complex Systems

Prof. Dirk Brockmann, Winter Term 2021

# Practical Problem 2: Predator Prey Agents

In Panel 1 in the Script on 2D dynamical systems an agent based simulation is shown that is driven by the reactions:

[ A\xrightarrow{\alpha}2A \qquad A+A\xrightarrow{\beta}A ]

[ B\xrightarrow{\gamma}\emptyset\qquad A+B\xrightarrow{\delta}2B ]

The system has four parameter, each governing the rate of one of the reactions

## To do:

Write a netlogo simulations in which two types of particles randomly move around in the world.

Because we have predators and prey, it would be nice to have two different types of turtles. This is done by the breed concept. In the beginning of the code you can define breeds using this:

breed [humans human]
breed [animals animal]

This defines two breeds, humans and animals. You could also name them differently like

breed [habecks habeck]
breed [lindners lindner]

and then you can loop over these breeds separately using commands like ask habecks [...] or create-lindners 100 (Let's not think about this literally).

1. Let's begin by writing a setup function that creates 50 turtles of each breed
2. Let's make them move around randomly using what we've learned. Each breed should have two individual movement parameters, the wiggle and the speed.
3. Now let's write four functions each for the four reactions and each one should be executed in the go function.
• For reaction $A\xrightarrow{\alpha}2A$ you can use the hatch command. But make sure that you limit the reaction by the total number of prey individuals, otherwise netlogo will freeze. You could do this like this

 to reproduce
if random-float 1 < reproduction-rate and count animals < 500 [
hatch 1
]
]
end

• For the reaction $B\xrightarrow{\gamma}\emptyset$ you can just loop over all predators using something like ask predators [....].
• The two particle reactions are more tricky. For the reaction $A+B\xrightarrow{\delta}2B$ you can use the following construct (replace "B" by whatever breed you defined for the predators)

ask "B" [
; check if there are any prey in a radius
; hatch
; kill one of the prey in the radius using
]
{"ft_lang_label":"__label__en","ft_lang_prob":0.8610082,"math_prob":0.90296966,"size":2307,"snap":"2022-40-2023-06","text_gpt3_token_len":551,"char_repetition_ratio":0.1202779,"word_repetition_ratio":0.0,"special_character_ratio":0.22626787,"punctuation_ratio":0.078947365,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9760864,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-25T05:07:00Z\",\"WARC-Record-ID\":\"<urn:uuid:1740bcde-6474-4d88-81ee-4f8a2a5b5c1c>\",\"Content-Length\":\"10052\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:009e987a-792d-481a-af6a-beb5032605b9>\",\"WARC-Concurrent-To\":\"<urn:uuid:c95a11de-ba2b-4917-b50d-f3f2f536b87b>\",\"WARC-IP-Address\":\"141.20.67.168\",\"WARC-Target-URI\":\"https://rocs.hu-berlin.de/courses/complex-systems-2021/lab/p2-predator-prey/\",\"WARC-Payload-Digest\":\"sha1:REWW6WKGUWQSZA2J2NQUHPZY5QKDNMQU\",\"WARC-Block-Digest\":\"sha1:M7ZUGLMH5THIXRD4Z7XVMDOOCYUAS3EC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030334514.38_warc_CC-MAIN-20220925035541-20220925065541-00456.warc.gz\"}"}