I too like find-new-spot but I once used a similar procedure and all was well until it was used in a context in which every patch was occupied. find-new-spot looped forever. At least move-to one-of patches with [not any? turtles-here] reports a helpful error if there are no unoccupied patches.
On the other hand while performance isn't an issue for the Segregation Model that may not always be the case when move-to-unoccupied-patch is called in other models. Note that move-to-unoccupied-patch should on average be faster than find-new-spot when nearly all patches are occupied. Another issue with find-new-spot is how to make a generic version where turtles-here is not always appropriate. E.g. households-here might be needed if there are other breeds of turtles on patches. How about this? to find-new-spot [satisfying-condition] move-to one-of neighbors4 if not run satisfying-condition [ find-new-spot] end to find-new-spot-without-any-turtles-here find-new-spot task [not any? other turtles-here] end - ken kahn On 30 December 2014 at 15:07, Seth Tisue <s...@tisue.net> wrote: > Some thoughts about possible alternate versions of the Segregation > model. > > In addition to considering how easily the code "reads" -- call it code > simplicity -- I suggest also weighing computational simplicity. > heavily. This sometimes aligns with code simplicity, but not always. > > NetLogo makes it really easy to write down something like `one-of > patches with [not any? turtles-here]` without calling the coder's > attention to the fact that running it always involves querying every > patch in the entire world. This is problematic because it's slow, > but you might also consider it conceptually problematic. > > I'm not saying it would be necessarily be wrong to decide in the end > that exhaustive global search is a good thing to base a version of the > model on. I just hope that the simplicity of the code involved isn't > causing the issue to be glossed over. > > I would lean against anything involving `in-radius` because it's a > circular neighborhood, which is both computationally expensive and a > downright peculiar thing to be using at all in a grid-based model. > (Imagine Thomas Schelling pulling out a compass and drawing circles on > his checkerboard.) It's unfortunate that NetLogo doesn't have > `in-von-neumann-radius` or `in-moore-radius`, so we end up reaching for > `in-radius` just because it's there. (`von-neumann-distance` and > `moore-distance` are missing as well.) > > Schelling writes of his 1D version, "rearrange the pluses and zeros by > moving each dotted one to the nearest point where [...]". Another > unfortunate gap in the NetLogo language is any simple way of expressing > nearest-first search with early exit. One version of the model we've > considered involves using `min-one-of`, but the resulting computation > isn't done in nearest-first order, so more distant candidates are > sometimes examined before nearer candidates, and it becomes necessary to > limit the radius to prevent the search from becoming global. If NetLogo > offered a concise way of expressing this kind of search, using it might > result in my favorite version of all, but the language doesn't have it. > > None of my feelings about any of these choices are super strong, but > personally, I like the random walk version: > > to find-new-spot > move-to one-of neighbors4 > if any? other turtles-here > [ find-new-spot] > end > > I like it because it's strictly local, because it's dead simple, and > because (like Schelling) it favors shorter moves. And it doesn't just > happen to be dead simple when expressed in NetLogo's particular > idiosyncratic vocabulary of primitives; it would be dead simple in any > programming language, because it's dead simple conceptually. > > Note that I've used `neighbors4` rather than `neighbors`, since allowing > diagonal moves is conceptually more complex and has an inconsistent > distance metric (some moves are distance 1, others are distance > 1.414...). > > If the use of recursion is considered obscure, consider rewriting as: > > to find-new-spot > move-to one-of neighbors4 > while [any? other turtles-here] [ > move-to one-of neighbors4 > ] > end > > Seth > > -- > You received this message because you are subscribed to the Google Groups > "netlogo-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to netlogo-devel+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "netlogo-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-devel+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.