Reputation: 69
I'm trying to set up a toy model of connected turtles. Every turtle has a random belief [0,1] and I want to implement some conditions:
The basic setup:
turtles-own [belief]
to setup
ca
reset-ticks
crt 5 [
set shape "person"
layout-circle turtles 5
set belief random-float 1
]
ask turtles [ create-links-with min-n-of 2 other turtles [distance myself] ]
end
This creates a 5 turtles cycle network. Now they have to check the beliefs of their (two) closest neighbors. I tried this:
to go
ask turtles with [one-of link-neighbors with [belief > .5]] [
set belief belief + .1
]
end
So the basic idea is that every turtle with a connected neighbour with belief > .5 has to add .1 to its own belief. I have tried several variations of the ask turtles with
line, but it always shows me a runtime error of this sort: WITH expected a true/false value from (turtle 0), but got (turtle 2) instead. Any ideas? Thank you in advance.
Upvotes: 1
Views: 481
Reputation: 10301
one-of
returns an agent. It is not suitable in this case for evaluating a condition with with
- the condition is incomplete, since the line ask turtles with [one-of link-neighbors with [belief > .5]]
translates (roughly) to "ask turtles with the condition turtle x to do something".
I think what you're after is something that uses count
to count the number of believing turtles
or any?
to evaluate if an agentset exists:
to go-1
ask turtles with [ (count link-neighbors with [belief > 0.5]) > 0 ] [
set belief belief + 0.1
]
end
to go-2
ask turtles with [ any? link-neighbors with [ belief > 0.5 ] ] [
set belief belief + 0.1
]
end
Upvotes: 2