在我的模型中,我有一些代理商可以作为具有固定能量的食物。它们由许多海龟品种喂养,每个品种的食物能量都低于食物的能量。
饲喂代理商的代码如下:
to eat
ifelse [food-energy] of myfood > 1.5 [
set food-energy 1.5]
end
以及食物项目衰减的相关代码是:
to decay
if any? turtles-here [set food-energy
(1.5 * count feeders-here with [myfood = myself]
end
如果食物的能量不是喂食者能够消耗的能量的精确倍数,则会出现问题。因此,例如它可以降至1,这导致馈线采用1.5单位,这是不可能的。当我有不同的具有不同食物能量的品种(即<或1.5)时,这会加剧。
所以我的问题是如何让这些东西得到平衡?
答案 0 :(得分:0)
随后会有一些提示,但需要填写许多细节。
breed [feeders feeder]
patches-own [ food-energy ]
feeders-own [ myfood ]
to setup
ca
ask patches [set food-energy random 50]
create-feeders 500 [
move-to one-of patches
set myfood one-of patches
]
end
to go
ask feeders [move]
ask feeders [feed]
ask patches [growback]
end
to move ;how shd they move?
rt random 20
left random 40
fd 1
;shd movement cost energy?
end
to feed
if (patch-here = myfood) [
let _extracted min (list food-energy 1.5)
set food-energy (food-energy - _extracted)
]
end
to growback
;do you want growback?
end
答案 1 :(得分:0)
感谢您的回复。我会尝试实现它们。这是一个不起眼的解决方法,对我有用:
to eat
ifelse (food-energy / capacity) < 1 and [meat] of myfood > capacity [
set food-energy 1.5] [set food-energy [meat] of myfood
ask myfood [set shape "square"]]
if (food-energy / capacity) = 1 [
set color white]
if (food-energy > 0 and food-energy / capacity < 1)
[ set color white ]
end
这最初导致了一个问题,当食物能量下降到0并且我要求它死亡时,看着我食物的[肉]的任何动物都失去了它的目标,我得到了一个错误。所以当它们的颜色为白色时,我让动物打破这种联系。
to ignore
set myfood nobody
set food-energy food-energy * 1
end