So i created some vans on traffic 2 sample and i want my vans to be on top of the road and cars on the bottom.
if i use set ycor -2 or set ycor 2instead of move-to one-of free road-patches my interface is like that here (screenshot) but if i`m using the normal code it is randomly like that here(screenshot).
Can anyone help me with this ? I need my vans to be on the upper patch and my cars on the bottom patch of the road but not after the "bycicle street line" like in the first picture
It looks like you want to set ycor -1 and set ycor 1, because 2 and -2 are too far.
Related
I would need to visualize the below turtles (from three different breeds) in a squared grid where links are only between turtles from the same breed, except for breeds types2 and types3, that can be also linked to each other.
So what I would like to have is a 2D grid where the number of turtles per each type is
40% of type1
40% of type2
20% of type3
(in total 100 turtles).
set-default-shape types1 "circle"
set-default-shape types2 "circle"
set-default-shape types3 "triangle"
ask n-of 100 patches [ sprout-types1 1 ]
ask n-of (100 * 0.4) types1 [set breed types2]
ask n-of (100 * 0.2) types1 [set breed types3]
the values are ok but the turtles are 'free' in the world, not displayed on a grid.
How can I display them into a grid and link them based on the above conditions?
This answer Different types of turtles in a lattice grid has provided some help on this, but the resize of the grid and the number of turtles are not the expected ones.
You should resize the world before creating agents.
That is, from the perspective of the code's workflow: if you want to have n agents, then n is first and foremost the number of patches. Then, once this is the case, all patches will sprout.
You need the resize-world command.
You mentioned that you want to have 100 turtles, that is 100 patches, that is a 10x10 world.
This means that you could do:
to setup
clear-all
resize-world 0 9 0 9 ; This creates a 10x10 world.
set-patch-size 30
ask patches [
sprout 1 [
set shape "circle"
set size 0.5
]
]
end
The code above works as long as you are happy for your world to be the size of exactly 100 patches, given that the size = 100 is hard-coded.
You might want to think about some way to accomodate a change in the number of agents.
For example, the approach below works as long as the number of agents is the perfect square of an integer:
globals [
n-agents
]
to setup
clear-all
set n-agents 100
let side-length n-agents ^ (1 / 2) - 1
resize-world 0 side-length 0 side-length
set-patch-size 30
ask patches [
sprout 1 [
set shape "circle"
set size 0.5
]
]
end
After all the point is that the shape of the world in NetLogo can only be a square or a rectangle; i.e. you cannot have a NetLogo world that is made of a prime number of patches (only exception being a world whose world-height and/or world-width equal 1).
So, in order to have your code be the most accomodating to changes in n, you could come up with more elaborated steps that resize the world based on n so that it gives you n patches even when n is not a perfect square; but for example, unless you are happy to have a monodimensional world, you can never have 53 patches. However, since you are talking of grids, I think this shouldn't be a problem for you.
For a pursuit-evasion assignment I need to use the NetLogo command 'towards', but it doesn't seem to work, or I don't understand it.
What I think it should do: give the angle between the heading of the turtle and the line connecting the turtle with the target.
Here's the code for a simple model I made just to show the problem.
to set-up
clear-all
create-turtles 2
ask turtle 0 [
set xcor 0
set ycor 0
set shape "circle"
]
ask turtle 1 [
set xcor min-pxcor
set ycor max-pycor
set heading 135
]
end
to go
ask turtle 0 [ fd 0.1 ]
ask turtle 1 [ show towards turtle 0 ]
end
And here's a video of the behaviour. https://youtu.be/MUBiAypppc4 (I couldn't find a way to remove the audio without just replacing it using YouTube's current editing system, I'm sorry; you'll have to mute the audio yourself)
Examples of expected behaviour:
from 0:14 to 0:19, I would expect the number to gradually decrease, not increase
at about 0:38, I would expect the number to be 0, not somewhere around 300
between 0:38 and 0:42, I would expect the number to decrease or increase consistently, without those two sudden jumps
Is there a problem somewhere, or does 'towards' mean something different than I thought?
So turtle 0 is moving and turtle 1 is reporting the direction to turtle 0. I think towards is working fine but you have forgotten about the world settings. For example, in the 14-19s part, the shortest path from 0 to 1 is down and left (about 220 heading), but that shortest path is with the world wrapped. Your turtles can move off one side and come in on the other (as you can see turtle 1 doing).
NetLogo measures distances and directions taking into account the wrapping configuration. It knows that the shortest path to get from turtle 0 to turtle 1 goes off the side and comes in the other, and reports the direction that the turtle would have to move to follow that path.
Create a link and you can see this. Revised code:
to set-up
clear-all
create-turtles 2
ask turtle 0 [
set xcor 0
set ycor 0
set shape "circle"
]
ask turtle 1 [
set xcor min-pxcor
set ycor max-pycor
set heading 135
create-link-with turtle 0
]
end
to go
ask turtle 0 [ fd 0.1 ]
ask turtle 1 [ show towards turtle 0 ]
end
I have a problem that I can't seem to find a solution for.
I have 10 turtles called "renards" created on patches with specific attributes. I would like to make them go towards a specific patch with xy coordinates 10 101.
Here is how I created the turtles :
to creerRenard
create-Renards 10
ask Renards
[ move-to one-of patches with [ cimetary = 1 ]
set size 6
set color red
]
end
so they are where I want them to be at the start but I can't seem to make them go towards a target with coordinates (one move per tick). I looked into the move towards target example but couldnt find anything...
Can anyone help me with this ? Thanks a lot !
I've made a animal behavior model involving "turtles" and "roads" and I want the model to report back to me when the turtle "crosses" a road. All I want is that it tells me when the turtle moves from a patch that is the grey color to the red color. I've included the code asking it to report this and the program has no issue with the code. To give me a visual representation of what I want it to report, I put a monitor on interface. But it always gives me a "0" for road crossings, even as I can see that my turtle has crossed roads. I would count it by hand, but it's impossible to tell for certain how many road crossings there are and this is for scientific publication. My code is as follows...
turtles-own [
road-crossings
]
to setup
clear-all
;; create turtles on random patches.
ask patch 6 -15 [
sprout 1 [
set color one-of [green]
set size 1
set road-crossings 0
]
]
ask turtles [
if [pcolor] of patch-here = 14.9 [
set road-crossings road-crossings + 1
]
]
reset-ticks
end
to go
ask turtles [
repeat 100 [
repeat 39 [
pen-down
rt random-float 360
lt random-float 360
fd random-float 1.375
]
setxy 6 -15
]
]
tick
end
Any help is appreciated! Thank you!
There are several potential problems with this that I can see.
First, road-crossings is a turtle variable, which is the correct thing to do if you want each turtle to remember how many times it crosses a road. If so, however, the monitor must report sum [road-crossings] of turtles to get the road crossings of all turtles.
Second, which I think is actually your problem: you have the turtle checking whether it crosses the road in the setup procedure rather than the go procedure. The setup procedure is only run at the beginning.
Third, you don't actually have any roads in your example code, but I suspect that's just a failure to create a proper example. I assume that there are patches with pcolor of 14.9 in your real code. If not, though, that would also cause your error. You can make sure by going into the command center and asking count patches with [pcolor = 14.9]
I am doing a simple radio propagation model in netlogo where i have to generate a plot of power loss Vs. Distance.Is there a way to plot one quantity vs other instead of one vs ticks. Any advice on procedures is greatly appreciated.
Thank you!
The plotxy primitive lets you do that.
I don't know how your power loss and distance data is stored, but let's build a quick example using turtles xcor and ycor as data. You should be able to adapt it easily.
Here is the very basic model:
to setup
ca
ask n-of 100 patches [ sprout 1 ]
reset-ticks
end
to go
ask turtles [ fd 1 ]
tick
end
Now you can create a plot. Put clear-plot in the plot update commands and ask turtles [ plotxy xcor ycor ] in the pen updates commands:
Also make sure that your pen is set to "point mode" in the advanced pen options, or you'll get a jumble of lines:
(Access the pen options by clicking on the pen icon next to the pen definition in the plot dialog.)