我正在努力让海龟找工作。他们按年龄分开。
补丁是作业,随机生成两个名为“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'
这个想法是:如果条件(奖励比率在周围区域最大),保持工作(留在补丁),如果没有,搜索工作。
提前感谢您的帮助。
答案 0 :(得分:2)
如果他们留下来,他们的想法就是不要移动乌龟。
随时随地
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
还有其他方法可以包括存储乌龟变量,如果性能有问题,可以帮助提高速度。