1

I already confirmed the information on the link. However I could not apply this. The following is a part of the sample model program. I wanted to accumulate the number of turtles, however I could not accumulate it with the sample program. I probably need your advice. Thank you.

globals [num-turtles cumulative-sum average-time number-dead ]
turtles-own [count-up]

to setup
  clear-all
  set num-turtles 5
  reset-ticks
end

to go

  if count turtles < num-turtles
  [ ask patch 0 0
    [ sprout 1
      [ set count-up 0 ]
    ]
  ]

  set cumulative-sum cumulative-sum + 1 ;I would like to calculate the integral value here, but this syntax is not a cumulative value. 
  ask (turtles-on patch 0 0)
    [
      set cumulative-sum count turtles-here
    ]

  set average-time ifelse-value (number-dead = 0)
  [ 0 ][(cumulative-sum) / (number-dead)]

  if (count turtles > 0) [
    ask min-one-of turtles [who] [
      if count-up >= 6 [
        set number-dead number-dead + 1
        die
      ]
    ]
  ]

  ask (turtles-on patch 0 0)
  [ set count-up count-up + 1
  ]

  tick
end
goodgest
  • 418
  • 3
  • 10
  • Goodgest- can you try to reformat this as a [Minimal, Complete, and Verifiable example?](https://stackoverflow.com/help/mcve) Additionally, can you clarify your question? Are you trying to add any new yellow turtles to your existing count of yellow turtles? – Luke C Oct 21 '17 at 22:24
  • Unfortunately, that code is problematic- it is missing variables (like the `number-of-turtles`) and has things like `cd` as a variable- but `cd` is a primitive in Netlogo already. A true MCVE is one that you have pared down to the **absolute** minimum code necessary to isolate your problem. That means cutting as much code as possible that is not relevant, and often it is easier to just make a toy model from scratch that replicates the issue you are trying to solve. Really, you want a short piece of code that users will just be able to copy, paste, and run- remove sliders etc to simplify. – Luke C Oct 22 '17 at 01:06
  • LukeC @, Hello, The meaning of cumulative-sum is the number of live turtles in each tick, the cumulative result of the number of turtles of all ticks executed. For example, if there is one turtle living in the first tick, cumulative-sum is one. If there are three turtles living on the second tick, cumulative-sum is 1 + 3 = 4. If there are two turtles living with the third tick, cumulative-sum is 1 + 3 + 2 = 6. The meaning of average-time is the result of dividing cumulative-sum by number-dead. It is the average time the turtle was alive. Number-dead is ok and cumulative value. – goodgest Oct 22 '17 at 06:25
  • LukeC @ Thank you very much. I could accumulate safely in the test model with your sample model. In the actual model, I use the syntax "ask (turtles - on patch 0 0) [set count-up count turtles-here with [color = yellow]]". "turtles-own [count-up]" this setting is required. Since I want to use "BehaviorSpace", I will register "count-up" in globals. So there is some error, but I will calculate the integrated value using "count-turtles". For error handling, I can arrange some formulas. Thank you! – goodgest Oct 22 '17 at 09:29

1 Answers1

2

that's much better, thanks- I can now run the code no problem. However, I still don't think I understand what you are wanting cumulative-sum to actually count. Are you just looking for the total number of turtles, including both those still alive and the ones that have died? If so, I think it's just a matter of moving your set cumulative-sum cumulative-sum + 1 line. For example:

EDIT:

Ok I think I understand now from your comment. Try this:

globals [num-turtles cumulative-sum average-time number-dead ]
turtles-own [count-up]

to setup
  clear-all
  set num-turtles 5
  reset-ticks
end

to go

  if count turtles < num-turtles [
    ask patch 0 0 [
      sprout 1 [
        set count-up 0
      ]
    ]
  ] 

  if (count turtles > 0) [
    ask min-one-of turtles [who] [
      if count-up >= 6 [
        set number-dead number-dead + 1
        die
      ]
    ]
  ]

  ask turtles-on patch 0 0 [
    set count-up count-up + 1
  ]

  set cumulative-sum cumulative-sum + count turtles
  set average-time ifelse-value (number-dead = 0) [0]  [(cumulative-sum) / (number-dead)]

  tick
end
Luke C
  • 10,081
  • 1
  • 14
  • 21