在我的程序中,每只海龟(即葡萄糖和细菌)都有自己的变量,称为质量。该程序规定,葡萄糖和细菌的初始质量为1 mmol。正在进行的程序说葡萄糖会被水解和分解.因此,glucose_mass将不同于最初的1 mmol。细菌的起始步骤是,当细菌摄入一种葡萄糖时,细菌的质量就会从最初的1 mmol加葡萄糖的质量(在to divide_hydrolyzed_glucose过程中确定的随机数)增长到一个固定的数目(即0.3)。我试图使用“我自己”的命令将另一只海龟的变量包含到细菌海龟中。然而,它给了我一个错误,说“预期这个输入是一个报告块,但得到一个变量或任何东西”。
对这个问题有什么意见或建议吗?
Breed [glucose a-glucose];; Food
Breed [bacteria a-bacteria] ;; Predator
glucose-own [glucose_mass]
Bacteria-own [Bacteria_mass]设置
葡萄糖;葡萄糖;
set-default-shape glucose "circle"
Create-glucose (8) ;; Create the glucose available in mmol/d,
[set glucose_mass (1) ;; in mmol
]细菌;细菌;
Create-Bacteria (8) ;; Create the clostridiales in mmol
[set Batceria_mass (1)
]
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
[ask prey [die]
set Bacteria_mass (Bacteria_mass + ((glucose_mass of myself) * 0.3))
]
end发布于 2018-03-26 09:36:40
一开始,错误消息似乎很难解释,但它告诉您什么是错误的:of原语想要一个报告块,但是您给了它一个变量。
所以你需要:
[ glucose_mass ] of myself方括号告诉NetLogo,glucose_mass应该包装到一个“记者块”中,这是可以在不同的上下文中运行的东西(在本例中,[ glucose_mass ]将在myself上下文中运行)。
然而,更仔细地研究代码,似乎myself并不是您所需要的。myself原语用于从“外部”上下文中引用代理.当有一个的时候,这里就不是这样。
我建议你像这样重组你的Bacteria_eat_glucose程序:
to Bacteria_eat_glucose
let prey one-of glucose-here
if prey != nobody [
set Bacteria_mass Bacteria_mass + [ glucose_mass * 0.3 ] of prey
ask prey [ die ]
]
end有几件事要注意:
myself已被prey取代;* 0.3放进了记者区,因为我觉得它更容易阅读,但是[ glucose_mass ] of prey * 0.3也一样好;set Bacteria_mass ...线需要在猎物死前到达,否则猎物的glucose_mass就无法访问了。https://stackoverflow.com/questions/49486460
复制相似问题