Pierre
Pierre

Reputation: 387

Placing turtles at edges of patch clusters

I'm looking for a way to rapidly place turtles at edges of patch clusters. I tried this code but I found that it is a little slow when I increase the size of my study area:

to draw-edges [ID-cluster]
ask patches with [cluster != ID-cluster] [ 
ask neighbors with [cluster = ID-cluster] [ 
  if not any? turtles-here [ 
    sprout 1 [ 
      set shape "x" ] ] ] ] 
end 

Thanks in advance for your help.

Upvotes: 3

Views: 83

Answers (1)

Nicolas Payette
Nicolas Payette

Reputation: 14972

You're currently asking the whole world outside your cluster to check for neighbors that are in the cluster. It should be faster to ask patches that are part of your cluster to check if they are next to an outside patch:

to draw-edges [ ID-cluster ]
  ask patches with [
    cluster = ID-cluster and
    any? neighbors with [cluster != ID-cluster] and
    not any? turtles-here
  ] [
    sprout 1
    set shape "x"
  ] 
end

Upvotes: 3

Related Questions