Netlogo “打印”;“无补丁”;当没有更多的补丁可占用时
当没有更多的补丁需要占用时,我想打印“无路径”,而不是通过错误“移动到预期输入为代理,但没有得到任何人”发出警告。我做了几件事,但都没有成功。最后,我做了以下工作Netlogo “打印”;“无补丁”;当没有更多的补丁可占用时,netlogo,Netlogo,当没有更多的补丁需要占用时,我想打印“无路径”,而不是通过错误“移动到预期输入为代理,但没有得到任何人”发出警告。我做了几件事,但都没有成功。最后,我做了以下工作 ask migrants [let pot-target patches with [value < 11 and not any? turtles-here] let target pot-target with [count neighbors with [any? turtles-here with [valu
ask migrants
[let pot-target patches with [value < 11 and not any? turtles-here]
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
if target = 0 [print (word "no patch")]
if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
set status "resident"
set color blue]
]
询问移民
[让pot以[value<11的补丁为目标,这里没有海龟]
使用[count Neights with[any?turtles here with[value<11]]]>=1]将目标设定为pot target
如果目标=0[打印(字“无补丁”)]
如果(目标!=0和(状态!=“常驻”))[移动到目标[值]的最小值之一
设置状态为“常驻”
设置颜色[蓝色]
]
这是完整的代码
breed [migrants migrant]
breed [residents resident]
patches-own [value]
turtles-own [income
status]
to setup
ca
let total problo + probmid + probhi
if (total != 100)
[print (word "prob is more than 100")]
ask patches [set value random-normal 10 3
let patch-value value
set pcolor scale-color (gray - 5) patch-value 10 3]
ask patches
[if random 100 < 3
[sprout-residents 1
[set color red
set shape "default"
set size 1
set status "resident"
]
]
]
end
to go
ask patches
[if random 100 < 1
[sprout-migrants 1
[set color green
set shape "default"
set size 1
set status "migrant"
set-move
]]]
end
to set-move
ask migrants
[let pot-target patches with [value < 11 and not any? turtles-here]
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
if target = 0 [print (word "no patch")]
if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
set status "resident"
set color blue]
]
end
繁殖[移民]
品种[居民]
自己的[价值]
海龟拥有[收入]
地位]
设置
ca
总problo+probmid+probi
如果(总计!=100)
[打印(单词“prob大于100”)]
询问补丁[设置值随机正常10 3
让面片值
设置P颜色比例颜色(灰色-5)面片值10 3]
询问补丁
[如果随机100<3
[萌芽居民1
[设置颜色为红色
将形状设置为“默认”
1号套餐
设置状态为“常驻”
]
]
]
结束
外带
询问补丁
[如果随机100<1
[萌芽移民1
[设置颜色为绿色
将形状设置为“默认”
1号套餐
设置“移民”身份
移动
]]]
结束
移动
询问移民
[让pot以[value<11的补丁为目标,这里没有海龟]
使用[count Neights with[any?turtles here with[value<11]]]>=1]将目标设定为pot target
如果目标=0[打印(字“无补丁”)]
如果(目标!=0和(状态!=“常驻”))[移动到目标[值]的最小值之一
设置状态为“常驻”
设置颜色[蓝色]
]
结束
您混淆了一个代理集和该代理集中代理的计数。这一行:
let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
让target使用[count neights with[any?turtles here with[value<11]]>=1]来设置目标
返回一个代理集。因此,变量“target”是所有满足条件的补丁。如果没有满足您条件的修补程序,则agentset不是0,而是agentset的计数
因此,如果目标=0[打印(word“无补丁”)]
需要替换为如果计数目标=0[打印(word“无补丁”)]
或如果没有,需要替换为?[打印(字“无补丁”)
谢谢JenB。它实际上起作用了。但我认为如果“count target=0[print(word“no patch”)]”有效,将结束模拟,但它会继续进行。我想我需要发布一个新问题,对吗?