我正在尝试对海龟寻找工作进行编程。他们按年龄组分开。
补丁是工作,有两个随机生成的变量,名为“salary-here
”和“hours-worked
”。
我试图让我的乌龟(人)在找到工资/工作时间最高的补丁(工作)时停止移动(寻找),但他们总是继续移动。
patches-own
[salary-here ; amount of salary paid in one specific job (patch)
hours-worked ; time working and leisure
reward-ratio ; ratio between salary and hours ]
turtles-own [age]
to search-job ; they can only find jobs according to age "zones"
if age = 1 [ move-to one-of patches with [ pxcor > 10 and pxcor < 40 ] ]
if age = 2 [ move-to one-of patches with [ pxcor > 40 and pxcor < 70 ] ]
if age = 3 [ move-to one-of patches with [ pxcor > 70 and pxcor < 100 ] ]
end
to go
ask turtles [ search-job ]
ask turtles [ keep-job ]
tick
end'
想法是:如果条件满足(周围区域奖励比例最大),则保留工作(留在补丁中),如果不满足,则搜索工作。
预先感谢您的帮助。
最佳答案
我们的想法是,如果海龟应该留下来,就不要移动它们。
随心所欲,
ask turtles with [should-stay = false] [search-job]
然后我会编写一个名为“should-stay”的函数,并在其中插入您的停留逻辑。
to-report should-stay
report [reward-ratio] of patch-here >= max [reward-ration] of neighbors4
end
还有其他方法,包括存储海龟变量,如果性能存在问题,这可以帮助提高速度。
关于netlogo:如果满足条件(补丁变量值),则使海龟停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34693790/