[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: breed bug? (formerly commas & turtle orders)
- Date: Fri, 7 Nov 97 20:09:01 -0800
- From: Andrew Begel <abegel@alum.mit.edu>
- Subject: Re: breed bug? (formerly commas & turtle orders)
>The synchronization problem I was having, which I thought was due to
>improper or insufficient use of commas in my code, now looks like it may be
>due to something funny with breeds. I have simplified my code so that both
>breeds are doing the same tasks and the only difference between them is,
>well, their breed.
>
>Basically, it appears that whichever breed is created SECOND (i.e. last)
>always gets the food. I start by creating two dolphins, then two sharks.
>When I do this and the dolphins and sharks both see food at dx dy, they
>both move onto the patch at the next time step, and at the following time
>step the shark always shows the increment. When I reverse the two creation
>lines so that sharks are created first, the dolphins always get the food.
>
>On further investigation, it seems like the bug is not dependent on breeds.
>Even with only a single breed, turtles that are created later get the food
>first.
This is exactly due to StarLogo's turtle scheduler. Perhaps we should
have made it a bit random, but right now, it simply loops through the
turtles in reverse order of creation. Thus, in a simulation where nothing
is hatched or dies, the turtles created later will be run before turtles
created sooner.
Implication: if your code relies on any particular ordering (in-order or
random) of
turtle execution, you're just asking for trouble. Since most turtles get
out of sync with each other relatively quickly (due to "if" statements
and/or any control structure that causes some turtles to run longer than
others), this problem almost never shows up.
I can't say that there is a workaround other than to say why not
randomize the actions of the turtles in the code? You can put a loop in
that turtles will run based on their who or something.
to loop :x
if :x = 0 [stop]
loop :x - 1
end
to setup
crt 50
loop random who
go
end
That way all the turtles will be out of sync when they run the next piece
of code.
Andy
Andrew Begel
Dept. of Computer Science
UC Berkeley