Loading ...
Sorry, an error occurred while loading the content.

Re: [netlogo-users] patch-set question

Expand Messages
  • Alan G Isaac
    ... Does this example answer your question? sum [count turtles-here] of patches with [area-label = 1] Alan Isaac
    Message 1 of 5 , Mar 31, 2012
    • 0 Attachment
      On 3/30/2012 2:29 PM, Trina Rytwinski wrote:
      > What I would like to do is create a patch-set (I believe) out of those habitat blocks so I can count the number of turtles within each habitat block.



      Does this example answer your question?

      sum [count turtles-here] of patches with [area-label = 1]

      Alan Isaac
    • Trina Rytwinski
      ... habitat blocks so I can count the number of turtles within each habitat block. ... Thanks for replying Alan. In short yes, that would do what I would like.
      Message 2 of 5 , Apr 1, 2012
      • 0 Attachment
        > What I would like to do is create a patch-set (I believe) out of those habitat
        blocks so I can count the number of turtles within each habitat block.

        >Does this example answer your question?

        >sum [count turtles-here] of patches with [area-label = 1]



        Thanks for replying Alan. In short yes, that would do what I would like. It is just that the number of roads in my landscape can vary creating anywhere from 4 (if 2 roads) to 88 (if 14 roads) habitat blocks.  So, I could write out the above code 88 times. Essentially I would like to sum the turtles in each habitat block and then kill off any turtles if the sum is over a maximum number allowed. Is there a possibly more efficient way of doing this than writing out the above code 88 times?

        Thanks,

        Trina
      • Alan G Isaac
        ... to cull let %max-turtles 10 ;; or whatever number you wish ;; assume below that block numbering is sequential from 1 let %n-blocks max [area-label] of
        Message 3 of 5 , Apr 1, 2012
        • 0 Attachment
          On 4/1/2012 11:52 AM, Trina Rytwinski wrote:
          > Thanks for replying Alan. In short yes, that would do what
          > I would like. It is just that the number of roads in my
          > landscape can vary creating anywhere from 4 (if 2 roads)
          > to 88 (if 14 roads) habitat blocks. So, I could write out
          > the above code 88 times. Essentially I would like to sum
          > the turtles in each habitat block and then kill off any
          > turtles if the sum is over a maximum number allowed. Is
          > there a possibly more efficient way of doing this than
          > writing out the above code 88 times?



          to cull
          let %max-turtles 10 ;; or whatever number you wish
          ;; assume below that block numbering is sequential from 1
          let %n-blocks max [area-label] of patches
          foreach (n-values %n-blocks [? + 1]) [
          let %blocknum ?
          let %block-patches patches with [area-label = %blocknum]
          let %block-turtles turtle-set [turtles-here] of %block-patches
          let %n-2-cull count %block-turtles - %max-turtles
          if (%n-2-cull > 0) [
          let %cull n-of %n-2-cull %block-turtles
          ask %cull [show (word "dying on area " area-label) die]
          ]
          ]
          end

          hth,
          Alan Isaac
        • Trina Rytwinski
          That worked perfectly! Thanks Alan!
          Message 4 of 5 , Apr 2, 2012
          • 0 Attachment
            That worked perfectly! Thanks Alan!
          Your message has been successfully submitted and would be delivered to recipients shortly.