0

Currently the sharks and fish continue growing in size and speed what I'm attempting to do is have the energy for the fish and sharks go down more as they continue to move faster as as demonstrated with forward energy over 7 I'm also attempting to set a limit on the size the sharks and fish can reach

To go
  update-plots
  tick
   ask sharks[
    set Btimer (Btimer - 1)
    forward Energy / 7
    right random 80
    left random 80
      ask fishes[die]
      set Energy (Energy + 7) ;this essentially controls speed making it so it will go faster if enough energy is collected
       set size size + 0.1 ; this makes it so the sharks will continue growing and I'm not sure how to set a limit to the size they can grow to be
    ]
    set Energy (Energy - 1)
    if (Energy <= 0)[                                    
      die
    ]
    if any? sharks-on patch-ahead 0 and Btimer <= 0[  
      ask sharks-on patch-ahead 0 [
        set Btimer (Btimer + 400 - random 200)
        set Energy (Energy - 50)
      ]
       hatch 10 [                                         
      ]
    ]
  ]
end
  • You need to ask a specific question and only show us the relevant code. What is the bit that doesn't work? What is it doing and what is it supposed to be doing? – JenB Nov 17 '20 at 19:37
  • Well fish and sharks die out rather quickly and I'm attempting to have the population rise and fall rather than become entirely extinct. I'm also attempting to have the sharks and fish lose more energy as they continue to move faster and set a limit on how big they can grow. As of the moment the sharks and fish will continue growing non-stop and they become faster with no loss of energy as their speed increases – Mitri Torres Nov 18 '20 at 20:43
  • What is the ONE thing you need help to fix? Is the main problem is that the limit on growth is not working? If so, edit your question to focus on that and get rid of everything else. Also, you would only show the code that is supposed to limit the growth and probably the code that calls it. – JenB Nov 18 '20 at 22:40
  • Alright so now I've labeled the parts that increase speed and size and specifically put down what I want to do with them – Mitri Torres Nov 18 '20 at 23:23
  • `tick` goes at the end of `go`, not at the start. – Seth Tisue Nov 22 '20 at 17:52

1 Answers1

0

The basic problem appears to be that you increase speed every tick but don't have any code to stop growth. Here is one way to do it - you just have a test to see if the shark is fully grown:

to go
  update-plots
  tick
  ask sharks
  [ set Btimer (Btimer - 1)
    forward Energy / 7
    right random 80
    left random 80
    ask fishes [ die ]
    if energy <= max-energy      ; here is where you set the condition
    [ set Energy (Energy + 7) ; also increases speed
      set size size + 0.1
    ]
  ]
  ask sharks                       ; There must be an ask here, otherwise error message
  [ set Energy (Energy - 1)
    if (Energy <= 0) [ die ]
    if any? sharks-on patch-ahead 0 and Btimer <= 0
    [ ask sharks-on patch-ahead 0
      [ set Btimer (Btimer + 400 - random 200)
        set Energy (Energy - 50)
      ]
      hatch 10 [ ]
    ]
  ]
end

But this is primarily a design issue - what are you trying to represent with stopping the growth? Is it that the shark has become an adult, in which case a condition like the one I have inserted is the right approach.

Or is it that you expect growth to stop naturally for some other reason? For example, you might be thinking that the shark will stop growing because it runs out of food. However, the growth happens whether there is food or not. If you wanted the growth to happen only if there is food (fish) where the shark is, then you would do something like this:

to go
  ....
  ask sharks with [any? fishes-here]  ; restrict to sharks with food
  [ set Btimer (Btimer - 1)
    forward Energy / 7
    right random 80
    left random 80
    ask fishes-here [ die ]          ; since they are shark food
    set Energy (Energy + 7)          ; max not required, grows if food available
    set size size + 0.1
  ]
  ....
end

Just a general comment, agent-based models are hard to debug because the complex interactions between agents, environment and behaviour means that it is not always clear which bit of the code is causing a problem, and the logic can be difficult. The best way to deal with this is to code in smaller pieces - just add the minimum change and make that work before writing anything else. For example, the way you have the code written, all fishes die immediately. That is a different problem. If you write only one piece at a time, then you only ever have one problem and you know what is causing it.

JenB
  • 17,620
  • 2
  • 17
  • 45