I am trying to get two breeds of agents (xagents and yagents) to check to see if the value of a variable is the same when they move within one of xagents' radius. Then they should link.
When I try the code below, they link but when I inspect the values of the linked agents, the variable values are not equal; they should not be linking. The problem procedure is at the end of the code. Any ideas why this is?
When I can move past this part, I want the agents to change the value of another variable, but only if they have the same value as VAR1 (hence the link).
breed [xagents xagent]
breed [yagents yagent]
turtles-own [var1]
to setup
clear-all
resize-world -20 20 -20 20
setup-patches
setup-turtles
reset-ticks
end
to
setup-patches
ask patches [set pcolor gray ]
end
to
setup-turtles
set-default-shape xagents "circle 3"
create-xagents 10
[
set color white
set size 2
set var1 random-normal 5 1
setxy random-xcor random-ycor
]
set-default-shape yagents "circle 3"
create-yagents 20
[
set color blue
set size 2
set var1 random-normal 5 1
setxy random-xcor random-ycor
]
end
to go
move-xagents
move-yagents
ask xagents [communicate]
tick
end
to move-xagents
ask xagents [
rt random 50
lt random 50
forward 1
]
end
to move-yagents
ask yagents [
rt random 50
lt random 50
forward 1
]
end
;;THIS IS THE PROBLEM
to communicate
ask xagents in-radius 1 with [var1 = [var1] of myself]
[create-links-with other yagents-here
[
set color white
set thickness 0.1
]
]
end
There are a few issues here that might be causing you problems. First:
If you need have matches occur, the likelihood that two agents will share the value from
random-normal
is extremely low- it returns a float value:Choose another way to select values for your
var1
(egrandom-poisson
, orone-of [ 1 2 3 4 5 ]
) or you will not get matches. The only reason your original code was giving links was becauseother xagents
was not included in yourto communicate
code block (see below).Here you should use
other xagents
or you will include the asking agent, not just the other onesin-radius 1
.So here, you have already used the conditional to select the
xagents
that you would like to form a link, but the same conditional is not applied to theyagents
side. So, you were gettingxagents
forming links with anyyagents-here
. To fix that, just make sure that theyagents
must also have thevar1
that you're after, something like: