Martin Erlic
Martin Erlic

Reputation: 5667

Counting breeds with neighbors (to plot)

I have two breeds: supras and subs.

I'd like to draw two lines:

How can I do this? I've tried this:

The number is always 0 for each population, which should not be the case. Here is my code:

breed [supras supra]
breed [subs sub]

turtles-own [age]
subs-own [status]

to setup
  clear-all

  ;; Color the patches so they're easier to see
  ask patches [ set pcolor random-float 2 ]

  ;; 1/2 of num-turtles patches will sprout subs
  ask n-of (num-turtles / 2) patches [
    if not any? turtles-on patch-set self [
      sprout-subs 1
    ]
  ]

  ;; 1/2 of num-turtles patches will sprout supras
  ask n-of (num-turtles / 2) patches [
    if not any? turtles-on patch-set self [
      sprout-supras 1
    ]
  ]

  ;; Set breed colors and own-variables
  ask subs [
    set color blue
    set shape "dot"
    set age 0
    set status random 10
  ]

  ask supras [
    set color pink
    set shape "dot"
    set age 0
  ]

  reset-ticks
end

to go

  ask turtles [
    let empty-patches neighbors with [not any? turtles-here]
    if any? empty-patches[
      let target one-of empty-patches
      face target
      move-to target
    ]
  ]

  ;; Mating conditions
  ask supras [
    if any? subs-on neighbors [
      ;; Mate with highest status sub
      mate
    ]
  ]

  tick
end

to mate
  move-to max-one-of subs [status]
end

Upvotes: 2

Views: 405

Answers (1)

Luke C
Luke C

Reputation: 10336

neighbors returns an agentset of patches, so saying neighbors = supras is not going to get your what you need- no patches are supras or subs. Instead, you want to check if any of the neighbors have any supras-here or subs-here. This worked for me:

plot (count ( subs with [ any? neighbors with [ any? supras-here ] ] ) ) /  ( count turtles )

plot (count ( supras with [ any? neighbors with [ any? subs-here ] ] ) ) /  ( count turtles )

You will probably want to scale your Y max down to 1 in order to see much.

Upvotes: 3

Related Questions