how to create links with the newly created turtles - netlogo

I cant get some links to get created. I have been working with netlogo for some months now but i cant find the problem in this simple code
for puestos 1 ,2 and 3 the links get created but for 4 and 5 they doesnt. I cant create links using a who number because its variable.
create-puestos 1[
setxy 29.2 6.9
set shape "silla"
set size 1
set color green
]
create-puestos 1[
setxy 29.2 7.45
set shape "silla"
set size 1
set color green
]
create-puestos 1[
setxy 29.2 8.0
set shape "silla"
set size 1
set color green
]
create-entrada-puestos 1 [
setxy 28.5 7.8
set shape "circle"
*create-links-with puestos with [ not any? links]*
]
create-puestos 1[
setxy 29.2 8.55
set shape "silla"
set size 1
set color green
]
create-puestos 1[
setxy 29.2 9.1
set shape "silla"
set size 1
set color green
]
create-entrada-puestos 1 [
setxy 28.5 8.2
set shape "circle"
*create-links-with puestos with [ not any? links]*
]

Replace create-links-with puestos with [ not any? links] with create-links-with puestos with [ not any? my-links]
Once any link is created, then any? links is true. my-links are the links belonging to a specific turtle.

Related

How to calculate turtles within a certain distance in Netlogo

I want to calculate the number of shops within a certain distance of the turtle location. I tried both methods that I write below and I get the same radius. I want to increase the radius to include more than the neighbour patches but changing the value in-radius from 3 to 500 doesn't make a difference in the model. Is there a different way to calculate the shops, let's say within 5 patches from where the turtle is located?
turtles-own [ healthy-exposure
unhealthy-exposure ]
to setup
ca
ask households [ setxy random-xcor random-ycor
set size 0.9
set shape "person"
set color grey ]
ask healthy-shops [ setxy random-xcor random-ycor
set shape "house"
set size 0.6
set color 52 ]
ask unhealthy-shops [ setxy random-xcor random-ycor
set shape "house"
set size 0.6
set color 15 ]
calculate-exposure1 or calculate-exposure2 ;; choose one or the other
end
to calculate-exposure1
ask household 1 [ set healthy-exposure count healthy-shops in-radius 3
set pcolor 15
set unhealthy-exposure sum [unhealthy-shops] of neighbors ]
end
to calculate-exposure2
ask household 1 [ set healthy-exposure count healthy-shops with [ distance myself < 500]
set pcolor 15
set unhealthy-exposure sum [unhealthy-shops] of neighbors ]
end

Netlogo assign group of patches to own variable of a breed

I'm very new to netlogo and am wondering how I can set a group of patches to be an own variable to a certain breed. For example, let's say I have:
breed [ buildings building ]
buildings-own [ my-patches ]
I want to be able to have a set of patches (let's say a rectangle, so constrained by some coordinates) that are assigned to each individual building's my-patches field. How would I do this?
First thing you need to know is that you can't have breeds of patches. While you don't say that's what you want, I just want to make sure you are aware of this.
Have a look at this code. It is a complete program that creates some turtles (called realtors) and assigns them each some patches. It then turns those patches the same colour as the realtor.
breed [realtors realtor]
realtors-own [my-patches]
to setup
clear-all
create-realtors 10
[ setxy random-xcor random-ycor
set size 2
set shape "circle"
set my-patches n-of 5 patches in-radius 3
]
ask realtors [ask my-patches [set pcolor [color] of myself ] ]
reset-ticks
end
You can run it by creating a button for 'setup' or simply typing setup in the command centre.
Welcome to Stack Overflow and Netlogo! Given your breed and buildings-own as above, you can simply use set to assign the patch-set that you want a building's my-patches variable to hold.
to setup
ca
ask patches with [ pxcor mod 10 = 0 and pycor mod 10 = 0 ] [
sprout-buildings 1 [
set shape "square"
set heading 0
set size 1.5
set my-patches patches with [
pxcor > [pxcor] of myself - 3 and
pxcor < [pxcor] of myself + 3 and
pycor > [pycor] of myself - 3 and
pycor < [pycor] of myself + 3
]
ask my-patches [
set pcolor [color] of myself - 2
]
]
]
reset-ticks
end

Initial proportion of three different patches with only two sliders

i am trying to create a predation model in netlogo with foxes and rabbits. foxes eat rabbits and waste (left from people) und rabbits eat grass in a special pleasure ground.
the initial proportion of patches fixed in the setup should be: 65% green patches (grass), 35 % brown patches (eaten grass), 10 % margenta patches (waste from people). they can be distributed randomly.
at the moment it looks like that :
globals [grass waste]
breed [rabbits rabbit]
breed [foxes fox]
turtles-own [energy]
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
if grass? [
ask patches [
set pcolor one-of [green brown]
if-else pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ]
]
]
ask patches [ set pcolor magenta ]
if waste? [
ask patches [
set pcolor one-of [ green brown magenta ]
if-else pcolor = [ green brown ]
[ set countdown waste-regeneration-time ]
[ set countdown random waste-regeneration-time ]
]
]
set-default-shape rabbits "rabbit"
create-rabbits initial-number-rabbits
[
set color white
set size 2.2
set label-color gray + 1
set energy random ( 2 * rabbit-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape foxes "fox"
create-foxes initial-number-foxes
[
set color red
set label-color gray + 1
set size 2.2
set energy random ( fox-gain-from-food )
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
set waste count patches with [pcolor = magenta]
reset-ticks
end

How to setup a slider for pen size into the code in Netlogo

this is my code , i need to fit the slider so i edit the pen size my global variable is turtle-pen-size
to setup
clear-all
ask patches [ set pcolor sky ]
setup-turtles
end
to setup-turtles
create-turtles turtles-to-create
[ set color lime setxy random-xcor random-ycor set size size-of-turtle]
set-default-shape turtles "circle"
end
to go
ask turtles[
ifelse pen-down? [ pen-down ] [ pen-up ]
fd 1
]
end
You could set pen-size where you are asking each turtle to pen-down
I am not exactly sure what you want to do in your code, the pen-down? is not defined in your code, I assume you have a turtle property which defines a pen-down? to one of values of true and false, if you define it a global value I believe all of your turtles end up with same value, for pen-size you can use following code
set pen-size turtle-pen-size
This is your completed code:
turtles-own[pen-down?]
to setup
clear-all
reset-ticks
ask patches [ set pcolor sky ]
setup-turtles
end
to setup-turtles
create-turtles turtles-to-create
[
set color lime
setxy random-xcor random-ycor
set size size-of-turtle
set pen-size turtle-pen-size
set pen-down? one-of [true false]
]
set-default-shape turtles "circle"
end
to go
ask turtles[
ifelse pen-down?
[ pen-down ]
[ pen-up ]
fd 1
]
tick
end

Netlogo: Turtles inherit event from other turtles

How to let other turtles inherit event from other turtle? In my code I have this simple setup that has 50 turtles. I have also a panic button that if it is clicked some turtle will set their mood to panic and color to orange.
I have some changes with this one. Disregard the percentage. Now all turtles will check around them if they found/see turtles with mood = panic and color orange they will also go to panic and color orange.
turtles-own[
mood
]
to setup
__clear-all-and-reset-ticks
create-Humans
end
to create-humans
crt 50[
setxy random-pxcor random-pycor
set color blue
set mood "calm"
]
end
to panic
ask n-of initial-panic turtles [
set mood "panic"
set color orange
]
end
I tried this.
to go
ask turtles[
fd 1
lt random 90]
ask turtles[
ask turtles in-cone 3 60
[ if any? turtles with [ color orange]
set mood "panic"] ]
end
But it doesn't work.
welcome to StackOverflow, you can try this:
turtles-own[
mood
]
to setup
__clear-all-and-reset-ticks
create-Humans
panic
end
to create-humans
crt 50[
setxy random-pxcor random-pycor
set color blue
set mood "calm"
]
end
to panic
ask n-of initial-panic turtles [
set mood "panic"
set color orange
]
end
to go
ask turtles[
fd 1
lt random 90
if any? turtles in-cone 3 60 with [ color = orange]
[set mood "panic"
set color orange
]
]
end