I added Matteo's suggestion of more efficiently choosing their initial patch by having them move-to one-of patches with of myself]. By making this a variable tied to the turtles, you don't need a new movement code for each new type of turtle. This variable is set to a color at creating of the fishes and determines which color of patches they can move to. I added a fishes-own variable called habitat. Ifelse who <= ( 3 * 0.5 ) Set proportion of fishes in lagoon determined by slider Moving x0 and y0 to the end of the create-fishes block solves this problem. Since your code has them looking for a destination around that point, rejecting all gray destinations, you will be stuck in an endless searching. This means that a fish can have its x0 and y0 set to the land. You define them before shuffeling your turtles around to find a good initial position. In your new version, the x0 and y0 are creating your problems. However, as I have only joined stackoverflow relatively recently, I will follow someone elses judgement and append this to my previous post if requested. Note: As the question has been changed, I feel it warrants a new answer rather than editing the previous answer which is in and off itself still correct. Which is a slightly shorter way of writing it. Let destination patch-at (random-normal 0 1) (random-normal 0 1) Set destination patch (xcor + random-normal 0 1 ) (ycor + random-normal 0 1 ) [let destination patch (xcor + random-normal 0 1 ) (ycor + random-normal 0 1 ) Set shape "fish" set size 2.5 set color white Are the fish meant to continuously hover around the same patch? I assumed not so I removed them and let the fishes determine their destination based on their current location instead ( xcor and ycor) breed Now I did also notice that you give each fish a x0 and y0 and you never update them. While of destination != cyan ] Īnd then finally, after a satisfying destination has been found, moving to it: Then we continue by evaluating whether or not destination is a viable patch and, if necessary, choosing a new destination: Let destination patch (xcor + random-normal 0 1 ) (ycor + random-normal 0 1 ) That is why I prefer to split the problem into three parts: Choosing the destination, evaluating the destination, moving to the destination.įor this, you can use let to create a local variable that is creatively named "destination": Now this brings with it its own set of problems, because it means that fishes that come near the grey may move onto it and travel a long distance before finally ending in a cyan tile again. Setxy (x0 + random-normal 0 1 ) (y0 + random-normal 0 1 ) Since they all start on a cyan tile, non of them will move.Ī first way to go about this would be to simply ask them to move once, and then move again as long as they are on the grey to fish-move The problem with your code is that you ask your fishes to only move while they are on a non-cyan tile. Set destination patch random-xcor random-ycor Let destination patch random-xcor random-ycor Set destination patch (x0 + random-normal 0 1) (y0 + random-normal 0 1) Let destination patch (x0 + random-normal 0 1) (y0 + random-normal 0 1) Updated code below: breed Īsk patches with Any thoughts on this?ĮDIT 2: the x0 and y0 are no mistakes and need to be kept in the code. When I incorporate the solution by LeirsW for the fish and for the cows/sheep, my Netlogo freezes and i have to force quit. Any thoughts?ĮDIT: In addition to having 2 fishes in the water, i have 2 other turtles (e.g., cow and sheep) on land that, similarly to the fishes, cannot/shouldn't enter the water when they move (in fact I have 3 such 'habitats' total where turtles shouldn't leave the habitats in which they started). I tried the same while that i used to constrain the starting locations of fish to the ocean, but this doesn't seem to work here i.e. Logically, when moving the fish should stay within the ocean and not move onto the beach. Now each tick the fish move following a random walk with step length drawn from a normal distribution (mean=0, SD=1). I have some turtles (fish) whose starting location I constrained randomly somewhere in the ocean. Suppose I have a beach and an ocean, denoted by patch colors gray and cyan respectively.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |