Netlogo multiple patch layer - netlogo

Can I create multiple patch layers in Netlogo, instead of using several patch variables in one layer?
I'm trying to integrate different maps (geology, traffic, etc.) into the Netlogo environment. So far, I've defined multiple patch variables using patches-own command. But the maps I have are not always stackable. So if I can have separate patch layers for different maps, it would be clearer.

You can't make more patch layers. The structure of the NetLogo patch world is fixed.
But you might consider representing the information using turtles instead. You can sprout them, one per patch, or you could define several breeds of turtle, and have each patch sprout one of each breed. The order in which the breeds are defined will determine the layers' stacking order, and you can hide or show whole layers using hide-turtle and show-turtle. If you want the turtles to look just like patches, do set shape "square" (adjusting the size of the "square" shapes in the turtle shapes editor if necessary).

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.

In a Netlogo network, how can turtles "see" properties of other turtles?

I am trying to build a model in which turtles decide to change colour depending on their environment in a network.
The approach would be to "check" the colour of the surrounding turtles and then set an if statement for the turtle in question to switch colour (there will only be 2 colours).
Specifically I would like to know how can a turtle "see" or check other turtles' colour (or other properties).
If possible I would also like to create a slider for "how many links away" can turtles see their neighbouring turtles' (or neighbours of neighbours, etc) colour.
I am new to both Netlogo and Stackoverflow, so please let me know if I should make any modifications to my model and/or question.
Thanks!
Welcome to Stack Overflow! Typically you'll want to stick to a single question per post, both for simplicity and for the benefit of future users with similar questions. As well, in cases where its applicable you should try to include some code to show what you've tried so far, as well as any setup necessary- you want to make a minimal, complete, and verifiable example. In this case, I think you're okay since your questions are clear and well explained, but if you have more complex questions in the future you will be more likely to get useful answers by following those guidelines.
For your first question, it looks like you want the of primitive- check out the dictionary entry for details. of can be used in a few ways, including allowing agents to check the value of a variable (such as color) of another agent. Check out this example code:
to setup
ca
reset-ticks
crt 10 [
setxy random 30 - 15 random 30 - 15
create-link-with one-of other turtles
]
end
to go
ask turtles [
set color [color] of one-of link-neighbors
]
end
Every time the go procedure is called, one of the turtles changes its color to the color of one of its link-neighbors. If you run it long enough, all connected turtles should end up with the same color.
For your second question, I suggest you check out the Nw extension, which is an extension built to deal more easily with Netlogo networks. Specifically, have a look at nw:turtles-in-radius, which should work with your slider approach. To get it working, include the extension using
extensions [ nw ]
at the start of your code. Then, assuming the same setup as above, you can play around with something like
to network-radius
ask one-of turtles [
set color red
ask other nw:turtles-in-radius 2 [
set color white
]
]
end
When you call the network-radius procedure above, you should see one turtle turn red, and any turtles within 2 links of that turtle turn white. To switch to a slider, just swap the "2" out for your slider variable. Hope that helps!

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.

Show list of relations between turtles and patches

In the model every turtle and patches has certain value. Then by making a comparisiĆ³n of the two values I get a new one. So I need to get the full list of the combinations (turtle-patch, and their values) that arise in the model.
It is not entirely clear what you want, but this example will probalby suffice. Let's use color as an example, because it is present by default.
[(list self color patch-here pcolor)] of turtles
Edit:
You can substitute any list of characteristics you wish. Try it! E.g.
[(list who color pxcor pycor pcolor)] of turtles
Note that is you are thinking of this as documenting a mapping from turtles to the rest of the variables, you probably should use the table extension.

Moving turtles from extension in NetLogo

I am working on creating a traffic grid in NetLogo. I would like to create an extension to go along with the model that contains the rules for updating the grid and moves the cars, turtles in this case, accordingly.
I am having trouble getting the turtles to actually move. The set of turtles is being passed as an argument to the function that should update the turtles' positions. I tried using setVariable(), but it isn't working for me:
Turtle car = args[0].getTurtle();
car.setVariable(AgentVariableNumbers.VAR_XCOR, 29);
car.setVariable(AgentVariableNumbers.VAR_YCOR, 40);
Since it is a traffic grid, I am focused on just moving the turtles forward for now. Is there a way (other than using setVariable) to move turtles from an extension?