【问题标题】:How to limit the amount of prey “eaten’ by predator and recalculate the residues?如何限制捕食者“吃掉”的猎物数量并重新计算残留物?
【发布时间】:2018-12-24 23:24:41
【问题描述】:

在我的程序中,每只海龟(即葡萄糖和细菌)都有自己的变量,称为质量。设置程序表明葡萄糖和细菌的初始质量为 1 mmol。 to-go程序说葡萄糖将被水解和分裂。因此,葡萄糖质量将不同于最初的 1 毫摩尔。细菌的待处理程序说,当细菌吃一个葡萄糖时,细菌的质量将从最初的 1 mmol 加上它消耗的葡萄糖质量(在分解水解葡萄糖程序中确定的随机数)增长一次固定数字(即 0.3)。如何限制细菌每次滴答时可以消耗的葡萄糖质量(最大摄取率)? (1 滴答= 1 小时)我如何设置猎物剩余的葡萄糖质量?例如,如果细菌只能吃(摄取)0.0207 mmol葡萄糖/h,但水解后的葡萄糖质量为0.6 mmol;那么,细菌只能使用 0.0207 的葡萄糖质量。剩余的葡萄糖质量必须重新计算为 (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

【问题讨论】:

    标签: variables netlogo agents


    【解决方案1】:

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

    在限制上,最清楚的方法是构造一个临时变量(下面命名为“食物”),即要调整的量。

    myself 问题似乎是(尚未测试),因为细菌是实际运行代码的代理。也就是说,没有“外部”上下文。您正在对细菌代理的变量直接操作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
    

    【讨论】:

    • 亲爱的 JenB,非常感谢您的回复。我尝试了您的建议,但出现了两个问题: 1. 对于代码行:“让食物最小摄取猎物的 [glucose_mass]”,错误是它是“预期的命令”。然后,我从同一代码行中删除了“[glucose_mass] of prey”,但问题是“MIN 预期输入是一个列表,但得到的数字是 0.0207”,这是摄取的限制数字。您还有什么建议吗?
    • 抱歉,我的格式有误。现在就试试。最小值的一般形式是min (list val1 val2 val3....),这就是我将其更改为的形式。因为只有两个数字,你也可以min [val1 val2]
    • 没问题。请注意,我并没有自始至终应用逻辑。例如,您需要将行 ask prey [set glucose_mass glucose_mass – 0.3] 更改为 ask prey [set glucose_mass glucose_mass – food] 以及任何其他类似的更改
    猜你喜欢
    • 2012-02-14
    • 1970-01-01
    • 2017-10-21
    • 2013-02-23
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多