Turtle Movement Netlogo - netlogo

I have a network of turltes that each share two links. At the start of each turn the turtles decide to cooperate or defect, which updates a beta distribution of likelihood of cooperation in the next tick. If the turtles fail to cooperate over n turns they no longer interact. Through this I am able to create clusters in the cooperation network.
Right now, I am trying to figure out how to make the turtles move closer together proportional to the weight of their ties. Is there code to do this? I have only been able to find example code for patches.

I think this model might have something similar to what you want:
http://modelingcommons.org/browse/one_model/3632#model_tabs_browse_procedures

Related

Can a patch in net logo have two color and one is hidden sometimes?

I am doing a tree grow in net logo, I have to implement a hidden trunk. But how can I make a patch assign to trunk color when there is no leaf and sometimes hidden behind leaves and showing leaf color ?
When we standing in front a tree, we sometimes cannot see the upper trunk cause the leaves. That is what I am going to model for now.
This may not be the answer you were hoping to get, but it might be the one that helps you the most in the long run:
The tree leaves should not be represented by patches. They should be represented by turtles.
If you use turtles, you get the "hiding what's behind" property for free, but that's just one of the reasons to use turtles.
NetLogo beginners tend to resort to patches as their "go-to" type of agents because they seem easier to use, but it's a trap. Turtles are much more flexible, and it pays to use them in the long run, even if you don't expect to move them around.
A few examples:
Patches are just coloured squares, but turtles can be any shape you want, which usually looks nicer. In your case, you could use the "leaf" shape that comes with NetLogo.
Turtles can have different breeds. Even if you plan to only use one breed of turtles, this makes your code more readable and also more flexible.
You can't have links between patches, but you can have links between turtles. Even if your model is not explicitly a network model, NetLogo links are a surprisingly useful way to represent relationship between agents.
Turtles can be created and killed. This is often a much better approach than trying to modify the state of a patch to reflect the fact that something is there or not. This applies directly to your problem: instead of changing the colour of a patch to signal that there is a leaf on it, just ask your patch to sprout-leaves 1.
So do yourself a favour and start your model with:
breed [ leaves leaf ]
to setup
clear-all
set-default-shape leaves "leaf"
; ...
reset-ticks
end
You'll make your own life much easier.

Netlogo - Controlling specific sets of turtles

I am trying to develop a model to demonstrate a field principle I am trying to work with. I am having trouble finding information on how to control specific groups of turtles. Essentially I would like to make a grid of turtles and links that I can distort, relative to an objective coordinate grid, based upon the placement of a different type of turtle, like a particle interacting with a field?
Any suggestions would be greatly appreciated. Is it possible to write a command that only talks to specific turtles by their who value? for instance if i had a coordinate plane that went from -3,3 in both x and y, rendering 49 vertices, could I set up those first 49 turtles, and then spawn my particle turtles (lets say 3), which would be who 49,50, and 51. could I write a command specifically for those 3 turtles based upon their relations to the first 49 turtles?
I hope this question makes sense.

How do I make linked turtles move together in NetLogo?

I'm trying to model fish movement and need them to form schools when there is more than 1 of the breed in a given patch. So far I have managed to get them to form links when they encounter each other with the function below, but then they continue moving independently. I'd also like to re-scale the color of turtles in a linked group so that the more turtles in the group the darker the color is (I'm guessing this is similar to the way you make contour maps according to environmental gradients but I haven't figured it out yet).
Any assistance is always appreciated!
to form_link
if count breed_1-here > 1
[
ask breed_1
[create-links-with other breed_1-here]]
end
If linking isn't the way to get them to move together, I'm fine with another method.

Move to the opposite location of a detected turtle

I have an agent mouse and an agent cat.
When a mouse detects the presence of a cat around him, I want the mouse to rotate to the opposite positions where it detected the cat.
You can make one agent face another with face. You can then make the agent turn around with rt 180. The result will be that they're facing exactly away from the other agent!
When you have the option of multiple cats there might be a problem when running away from just one of them...
In that case you might want to make some weighted new direction, depending on the cats in the surroundings. But then your definition of the 'empty directions' and possible problems with multiple groups of cats coming in from different directions...
alternatively, you just move-to one-of neighbors with [count cats-here == 0]
(which will probably cause a run-time error if all neighbors harbour a cat.. :-)

Is this an acceptable algorithm for pedestrian motion that searches and mingles with "buddies" on its path to the goal?

I'll put my pseudocode here first, please advise regarding its validity according to real-world pedestrian motion, and how I can improve it.
Premise: A turtle walk from its spawn point to the goal. On the way, it meets other turtles. Turtles of the same color will be treated as a "buddy" and will go near it, simulating a "friends-walking-down-the-street" scenario. Turtles of the same color with nearer distance has higher priority, e.g. friend A is nearer than friend B so I will approach friend A first.
Upon approaching the goal, the turtle goes back to its spawn point.
Pseudocode:
determine if i am already in the goal
if yes,
determine if there are patches I can walk on
set eyes on nearest patch I can walk on (for the goal path)
if there is a friend nearby, approach friend
if there is no friend nearby, continue walking the goal path
if im already in the goal, respawn.
Advise for improvement please?
The premise doesn't say anything about how returning to spawn point occurs so I will assume it is a one step action (ie you are not interested in those details). I see something more along the lines of
spawn loop:
spawn
goal loop:
determine if turtle already reached goal
if no,
determine if there are patches I can walk on
set eyes on nearest patch I can walk on (for the goal path)
if there is a friend nearby, approach friend
if there is no friend nearby, continue walking the goal path
if yes,
setup so can respawn (return to spawn loc, etc)
goal loop ends