variablesnetlogoagents

How to limit the amount of prey “eaten’ by predator and recalculate the residues?


In my program, each turtle (namely glucose and bacteria) has their own variable called mass. The setup procedure states that the initial mass of glucose and the bacteria is 1 mmol. The to-go procedure says that the glucose will be hydrolyzed and divided. Thus the glucose_mass will be different to the initial 1 mmol. The to-go procedure for the bacteria says that when the bacteria eats one glucose then the mass of the bacteria will grow from the initial 1 mmol plus the mass of the glucose (stochastic number determined in the to divide_hydrolyzed_glucose procedure) that it consumed times a fixed number (i.e. 0.3). How can I limit the glucose_mass that the bacteria can consume (maximum uptake rate) each tick? (1 tick=1 hour) And how can I set the remaining glucose_mass of the prey? For example, if the bacteria can only eat (uptake) 0.0207 mmol of glucose/h, but the hydrolyzed glucose_mass is 0.6 mmol; then, the bacteria can only use 0.0207 of the glucose_mass. The remaining glucose_mass has to be recalculated as (0.6 – 0.0207). I am using the primitive “myself” to refer to the agent from the “outer” context – in this case the “outer” agent is the bacteria. However, the error says that “There is no agent for myself to refer to”.

Any comments or suggestions on this issue?

Breed [glucose a-glucose];; Food-prey  
Breed [bacteria bacterium] ;; Predator

glucose-own [glucose_mass] 
Bacteria-own [bacteria_mass uptake]

to setup
;;;GLUCOSE;;;

 Create-glucose (8) ;; Create the glucose available in mmol/d, 
 [set glucose_mass (1)] ;; in mmol

;;; BACTERIA;;;

Create-Bacteria (10) ;; Create the clostridiales in mmol
  [set batceria_mass (1)
   Set uptake (0.0207)
  ]
end

to go

ask glucose
 [
  Hydrolyse_glucose
  Divide_hydrolyzed_glucose
 ]

ask Bacteria
 [Bacteria_eat_glucose]

to hydrolyse_glucose
  if (glucose_mass < 200) [
   set glucose_mass ((glucose_mass * 0.025 + random-float 32.975) / 24)
  ]
end

to divide_hydrolyzed_glucose
   if (glucose_mass > 1)
   [
    set glucose_mass (glucose_mass / 2)
    hatch 1
 ]
end

to Bacteria_eat_glucose
  let prey one-of glucose-here
  if prey != nobody
  [ 
    ifelse [glucose_mass] of prey > [ uptake ] of myself
    [
      set bacteria_mass bacteria_mass + [[ uptake] of myself * 0.3]
      ask prey [set glucose_mass glucose_mass – [uptake] of myself]
    ]
    [
      set bacteria_mass bacteria_mass + [glucose_mass * 0.3] of prey
      ask prey [die]
    ]
  ]

end

Solution

  • Generally, you can use the min and max functions for this sort of limiting. The lack of reference for myself is a separate problem.

    On the limiting, the clearest way is to construct a temporary variable (named 'food' below) that is the amount to be adjusted.

    The myself problem appears to be (haven't tested) because the bacteria are the agents actually running the code. That is, there is no 'outer' context. You are operating the set commands on the variables of the bacteria agent directly. There would only be an outer context if the bacteria asked the prey to do something and then the prey would need to access some variable owned by the bacteria.

    If my interpretation is correct then you simply refer to bacteria_mass rather than [bacteria_mass] of myself

    to Bacteria_eat_glucose
      let prey one-of glucose-here
      if prey != nobody
      [ 
        ifelse [glucose_mass] of prey > uptake
        [ let food min (list uptake [glucose_mass] of prey)
          set bacteria_mass bacteria_mass + food * 0.3
          ask prey [set glucose_mass glucose_mass – 0.3]
        ]
        [
          set bacteria_mass bacteria_mass + [glucose_mass * 0.3] of prey
          ask prey [die]
        ]
      ]
    
    end