问题
This is my first post here (as is my first work with netlogo) so I'll try to be concise:
I'm trying to write a list for my turtles like Epstein and Axtell did in GAS (p. 73).
Until now I tried this with no results.
to setup-culture-tags ;set variable
let initial-culture-tags n-values 67 [ random 2 ] ;create a random
binary list of 67
set culture-tags initial-culture-tags ;
end
After making the list I would like to classify these based on the number of 0s. For example "00011" would be "blue" and "00111" would be "red".
The idea here is to give the turtles a random binary list of length 67. Then, they'll interact and change its values based on "tag-flipping": For each neighbor, a tag is randomly selected. If the neighbour agrees with the agent at that position, no change is made; if they disagree, the neighbor's tag is flipped to agree with the agent's tag.
I don't know if this is a stupid question but I'm beginning to feel frustrated so I would appreciate a little help.
回答1:
Not sure exactly what error you're getting here, but it looks like you may be trying to globally set a turtles-own
variable. If culture-tags
is a turtles-own
variable (which it must be if you want all turtles to have their own culture-tags
list), you must use ask turtles [ ...
to ask each individual turtle to populate the list you want. Try this:
turtles-own [ culture-tags ]
to setup
ca
reset-ticks
crt 10
ask turtles [
set culture-tags n-values 67 [ random 2 ]
]
ask one-of turtles [
show length culture-tags
show culture-tags
]
end
To get your counts of zeroes / ones, check out the dictionary entry for filter
and try combining it with length
.
来源:https://stackoverflow.com/questions/44503221/how-to-make-a-random-binary-list-of-lenght-67