Netlogo 目标补丁不抓任何人
我想检查目标补丁是否满足条件。如果发现符合条件的修补程序, 然后海龟们应该搬到那里去。如果“无人”满足此条件,则应打印错误消息 条件是,一块区域的半径应为102只相同品种的海龟 我试图通过Netlogo 目标补丁不抓任何人,netlogo,move,patch,catch-block,Netlogo,Move,Patch,Catch Block,我想检查目标补丁是否满足条件。如果发现符合条件的修补程序, 然后海龟们应该搬到那里去。如果“无人”满足此条件,则应打印错误消息 条件是,一块区域的半径应为102只相同品种的海龟 我试图通过ifelse和nobody来实现这一点。然而,目前我总是收到错误消息,即使 目标变量不是空的(您可以使用if循环检查) 对模型效率的一点评论:因为我想在以后的每个刻度中添加海龟,所以必须重新评估目标 在每个勾号中(因此它处于“go”状态,而不是“setup”状态) 另一个问题:是否有可能做类似于[breed=m
ifelse
和nobody
来实现这一点。然而,目前我总是收到错误消息,即使
目标变量不是空的(您可以使用if循环检查)
对模型效率的一点评论:因为我想在以后的每个刻度中添加海龟,所以必须重新评估目标
在每个勾号中(因此它处于“go”状态,而不是“setup”状态)
另一个问题:是否有可能做类似于[breed=my]
的事情,而不是[breed=breed1s]
,所以
我不必为每个品种都输入品种
编辑:
移动到目标区域的海龟应该与目标区域中的海龟具有相同的品种。问题实际上是如何创建target1,而不是检查它是否为
无人。你有:
set target1 ( count turtles in-radius 10 with [breed = breed1s] ) >= 2
这条线首先识别附近所有的海龟,并对它们进行计数。如果计数为2或更高,则变量target1设置为true
,如果计数为0或1,则设置为false
。因此,您将布尔值true
或false
与nobody
(一种特殊类型的代理)进行比较。这将始终是不匹配的,因此打印错误
只是关于调试的一个注意事项——当您遇到此类问题时,在执行检查之前,为检查的每一方准备一个print语句总是很有用的。你会立刻发现target1不是你想象的那样
由于您要求移动到
补丁中的一个,您可能真的希望存储10距离内(我认为)的可用补丁,并且有足够的合适类型的海龟。所以,你需要像这样的东西:
to go
ask turtles [
set target1 patches in-radius 10 with [count breed1s-here >= 2]
set target2 patches in-radius 10 with [count breed2s-here >= 2]
new-position
]
end
那么您的空测试是any?
to new-position
ifelse any? target1
[ move-to one-of target1 ]
[ print "Not enough agents in the neighborhood" ]
ifelse any? target2
[ move-to one-of target2 ]
[ print "Not enough agents in the neighborhood" ]
end
假设我已经正确地解释了,您希望在距离询问海龟10英里以内的地方获得补丁(相比于距离10英里以内有足够海龟的任何补丁),并且您所关心的只是其自身品种的海龟数量,那么:
to go
ask turtles [
let target-breed [breed] of myself
set targets patches in-radius 10 with [count turtles-here with [breed = target-breed] >= 2]
new-position
]
end
to new-position
ifelse any? targets
[ move-to one-of targets ]
[ print "Not enough agents in the neighborhood" ]
end
效率取决于你有多少只海龟。如果你有相当多的海龟,那么要求每只海龟数自己的邻居将是昂贵的。相反,您可以为每个品种提供补丁集。也就是说,在go程序开始时,使用[count Breed1 here>=2]将target1设置为补丁。然后你可以做:
to go
let targets1 patches with [count breed1s-here >= 2]
let targets2 patches with [count breed2s-here >= 2]
ask turtles
[ set targets targets1 in-radius 10
new-position
]
end
但是,您不能再使用海龟品种和我自己
技巧来选择正确的补丁集。有一些方法可以解决这个问题(例如,使用一个包含两个项目的列表,在第一个位置繁殖,而补丁集作为第二个位置),但这已经偏离了这个答案的轨道
to new-position
ifelse any? targets
[ move-to one-of targets ]
[ print "Not enough agents in the neighborhood" ]
end
问题实际上是如何创建target1,而不是检查它是否是nobody
。你有:
set target1 ( count turtles in-radius 10 with [breed = breed1s] ) >= 2
这条线首先识别附近所有的海龟,并对它们进行计数。如果计数为2或更高,则变量target1设置为true
,如果计数为0或1,则设置为false
。因此,您将布尔值true
或false
与nobody
(一种特殊类型的代理)进行比较。这将始终是不匹配的,因此打印错误
只是关于调试的一个注意事项——当您遇到此类问题时,在执行检查之前,为检查的每一方准备一个print语句总是很有用的。你会立刻发现target1不是你想象的那样
由于您要求移动到
补丁中的一个,您可能真的希望存储10距离内(我认为)的可用补丁,并且有足够的合适类型的海龟。所以,你需要像这样的东西:
to go
ask turtles [
set target1 patches in-radius 10 with [count breed1s-here >= 2]
set target2 patches in-radius 10 with [count breed2s-here >= 2]
new-position
]
end
那么您的空测试是any?
to new-position
ifelse any? target1
[ move-to one-of target1 ]
[ print "Not enough agents in the neighborhood" ]
ifelse any? target2
[ move-to one-of target2 ]
[ print "Not enough agents in the neighborhood" ]
end
假设我已经正确地解释了,您希望在距离询问海龟10英里以内的地方获得补丁(相比于距离10英里以内有足够海龟的任何补丁),并且您所关心的只是其自身品种的海龟数量,那么:
to go
ask turtles [
let target-breed [breed] of myself
set targets patches in-radius 10 with [count turtles-here with [breed = target-breed] >= 2]
new-position
]
end
to new-position
ifelse any? targets
[ move-to one-of targets ]
[ print "Not enough agents in the neighborhood" ]
end
效率取决于你有多少只海龟。如果你有相当多的海龟,那么要求每只海龟数自己的邻居将是昂贵的。相反,您可以为每个品种提供补丁集。也就是说,在go程序开始时,使用[count Breed1 here>=2]将target1设置为补丁。然后你可以做:
to go
let targets1 patches with [count breed1s-here >= 2]
let targets2 patches with [count breed2s-here >= 2]
ask turtles
[ set targets targets1 in-radius 10
new-position
]
end
但是,您不能再使用海龟品种和我自己
技巧来选择正确的补丁集。有一些方法可以解决这个问题(例如,使用一个包含两个项目的列表,在第一个位置繁殖,而补丁集作为第二个位置),但这已经偏离了这个答案的轨道
to new-position
ifelse any? targets
[ move-to one-of targets ]
[ print "Not enough agents in the neighborhood" ]
end
你好@JenB,谢谢你的详细回答。你说得对,我应该更经常地使用打印选项。我对你关于10个补丁的假设有点困惑。因此,我将再次描述,我希望避免误解(抱歉,如果我只是重复你所说的话):我希望在半径为10的区域内有2只相同品种的海龟。然后,海龟应该移动到所述补丁选项(1)是距离询问海龟10距离内的补丁,该补丁上至少有2只正确品种的海龟;(2)在10个距离内,至少有2只海龟属于正确的品种(因此,计算相邻区域的一只海龟)。你上一次的方法很有魅力,正是我想做的(谢谢!!)。然而,我有一个关于你的品种=[品种]我自己的方法的问题。我收到一条错误消息,上面说“补丁程序无法访问海龟或链接varia