如何限制捕食者“吃掉”的猎物数量并重新计算残差?

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

在我的程序中,每只乌龟(即葡萄糖和细菌)都有自己的变量,称为质量。设置程序规定葡萄糖和细菌的初始质量为 1 mmol。待办程序表示葡萄糖将被水解和分解。因此 glucose_mass 将不同于最初的 1 mmol。细菌的待处理程序表示,当细菌吃掉一个葡萄糖时,细菌的质量将从最初的 1 mmol 加上葡萄糖的质量(在 divide_hydrolyzed_glucose 程序中确定的随机数)增长,即它消耗了固定数量的时间(即 0.3)。我怎样才能限制细菌每次滴答可以消耗的glucose_mass(最大摄取率)? (1 tick=1 hour) 猎物剩下的glucose_mass怎么设置?例如,如果细菌只能吃掉(摄取)0.0207毫摩尔的glucose/h,但水解的glucose_mass是0.6毫摩尔;那么,细菌只能利用0.0207的glucose_mass。剩余的 glucose_mass 必须重新计算为 (0.6 – 0.0207)。我使用原始的“我自己”来指代来自“外部”上下文的代理——在这种情况下,“外部”代理是细菌。但是,错误显示“没有我自己可以参考的代理”。

对这个问题有什么意见或建议吗?

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

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

设置
;;;葡萄糖;;;

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

;;;细菌;;;

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

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

通常,您可以使用minmax 函数来进行这种限制。 myself 缺少参考是一个单独的问题。

关于限制,最明确的方法是构造一个临时变量(下面命名为'food'),即要调整的数量。

myself 问题似乎是(尚未测试)因为细菌实际上是 运行 代码的代理人。也就是说,没有 'outer' 上下文。您直接对细菌代理的变量运行 set 命令。如果细菌要求猎物做某事然后猎物需要访问细菌拥有的一些变量,那么只有外部环境。

如果我的解释是正确的,那么您只需参考 bacteria_mass 而不是 [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