I have these agentsets called collectors and bins, collectors visit bins once a day (each tick is equal to one hour). But they will keep visiting the same bin on the other days.
I would like to make them on the next day to visit a random different bin, but I do not know how to ask that. Could someone help me, please.
Here is the command where I ask this command.
to search-bins-to-collect
ask one-of collectors [move-to one-of [ bins in-radius 10] of myself]
collect-waste
end
The number of collectors will vary during the year and I can not tell them the exact number of the turtle.
Thank you in advance.
Related
I'm new to Netlogo and I'm now stuck with coding this sentence:
There should be a chance of 10% divided by the total number of turtles that a turtle will hatch a child.
The initial total number of turtles is 1.
So my code is:
let p (0.1 / 1)
ask n-of (0.1 / 1) turtles
[hatch 1]
But it seems to me that my code may not be correct. Anyone any ideas how to change it?
I would appreciate any kinds of help. Many thanks in advance!
"ask n-of" is clearly wrong, if there's only one turtle. And the random function only returns integers, so instead of checking for 0.1, let's choose a random number from 0 to 10 times the number of turtles. Something like this should work.
if random 10 < 1 [
ask one-of turtles
[hatch 1]
]
Here's my justification. Any given turtle has a 10%/N chance of hatching. That means that, 10% of the time, one random turtle has a 100% chance.
Say there are 5 turtles. By the spec, each turtle has a 2% chance of hatching (10%/5). 90% of the time, no one hatches. In the remaining 10% of the cases, 1 of the 5 will definitely get a chance. That means each individual turtle's chances are 10% x 20% which is 2%, as the spec says.
That's what the code does. "random 10" chooses a random number from 0 to 9. If that number is "< 1" (which means 0), then we choose a turtle at random to hatch.
How about this, put the random chance inside the ask
ask turtles
[ if random-float 1 < 0.1
[ hatch 1
]
]
Part of the problem is that the question is badly expressed. "10% divided by the total number of turtles" doesn't really make sense, so I have interpreted it that approximately 10% of the turtles hatch a child turtle
I'm writing a program that is testing the ability of turtles to navigate in an environment. This line of code has two checks. I want it to kill off the oldest turtle that has made the least amount of progress. It does what it is supposed to, but the program slows down dramatically, creating little hiccups every time it makes this check. I was wondering if someone knew a better way to go about this or make this line more efficient. Thanks!
ask one-of turtles with [XCOR = min [XCOR] of turtles with [age = max [age] of turtles]] [
die]
First of all, there are primitives that are specifically finding the turtles with maximum or minimum values of some variable using min-one-of or with-min. So your code would look something like this I think:
ask min-one-of (turtles with-max [age]) [xcor] [...]
I suspect that would solve your efficiency problem, since it may well be because of implicit brackets not being where you think they are so it's trying to loop everything a couple of times. But a much cleaner to read version that would solve the efficiency problem is to specifically limit the position loop to those who are oldest and then choose the lowest position from that set.
let old-turtles turtles with-max [age]
ask min-one-of old-turtles [xcor] [...]
I am writing a NetLogo model to describe the food exchange interactions between pairs of bees until the food is distributed evenly among all. I have two breeds of "fulls" and "hungries" in my model. Right now I am counting the number of interactions until the model stops, like this:
ask turtles [
set neighborhood other hungries-on neighbors
set target one-of neighborhood with-min [distance myself]
ifelse target != nobody
[ exchange-food
set counter counter + 1]
;if there are no hungry neighbors continue moving and searching for one
[continue ]
]
The counter here, counts all the exchange-food interactions but I am also interested in the number of unique interactions. Does it mean that I have to keep a list of tuples as a turtle-own variable for each turtle! But I don't even need the actual ids, I just want to count the number of unique interaction. How can I keep track of this? Any simpler ideas?
My simulation is of farms. Farmer agents own the farms and farms are created from a random number of patches around the agent that then "belong to" the farmer.
Each patch owns a Rate of Production variable (random number up to 50).
How do I then assign a value to an agent-owned variable that sums the RoP for each patch in the farm and makes that the farmer's total RoP? Something like... ask farm to [ set farm-RoP ... to the sum of all patches RoP in-radius ]. I am unsure of how to create the syntax.
Thank you, in advance, for any help anyone can provide!
I built a model that each turtle has their own strategy, and they will earn money according to their strategy.
Therefore, Turtles will own money, and strategy.
I want to rank top10 turtles who has the most money, and want to see which strategy that they have.
Is there any way that I can show it?
You can use max-n-of to get the top 10 agents and ask them about their strategy.
Something like
ask max-n-of 10 turtles [money] [show strategy]
To sort the result use sort-on:
foreach sort-on [(- money)] max-n-of 10 turtles [money]
[ ask ? [ show strategy ] ]