我对堆栈溢出和网络标识很陌生,事实上这是我的第一个问题。我预先感谢大家。
在netlogo中,我创建了4个区域来表示与象限I-IV相一致的4个办公空间:
to setup-environment
ask patches with [ pycor mod 2 = 0 and pxcor <= -16] [ set pcolor grey ]
ask patches with [ pycor mod 2 = 0 and pxcor >= 16] [ set pcolor grey ]
ask patches with [ pxcor mod 2 = 0 and pycor <= -16] [ set pcolor grey ]
ask patches with [ pxcor mod 2 = 0 and pycor >= 16] [ set pcolor grey ]
ask patches with [ pycor = 0] [ set pcolor red ]
ask patches with [ pxcor = 0] [ set pcolor red ]
; THIS PART IN PARTICULAR
ask patches [
set a-space patches with [(pxcor < 0) and (pycor > 0)]
set b-space patches with [(pxcor > 0) and (pycor > 0)]
set c-space patches with [(pxcor > 0) and (pycor < 0)]
set d-space patches with [(pxcor < 0) and (pycor < 0)]
]这个设置,例如,一个空间完全在象限II中,我需要在一个空间中的补丁在一定的范围内。我尝试了(-14 < pxcor < 0) and (14 > pycor > 0),使区域在x= (-14,0)和y (16,0)之间,但得到了以下错误:
期望这个输入是一个代理、数字或字符串,但却得到了真/假。
我知道您不能设置补丁,但这不是我在这里要做的,我正在尝试用我指定的范围设置一个带有补丁的区域。
发布于 2019-11-28 20:55:51
欢迎来到StackOverflow (和NetLogo)。对于未来的问题,请显示生成错误的特定代码,作为示例代码的一部分。然而,如果我正确地理解了你的问题,你就会发现:
set a-space patches with [(-14 < pxcor < 0) and (14 > pycor > 0)]不能在NetLogo中使用这种复合比较。数学中的-14 < pxcor < 0语句是两个独立的逻辑语句:-14 < pxcor和pxcor < 0。您必须将它们构造为两个语句,并使用逻辑运算符and将它们连接起来。
下面是一个完整的模型,我认为它能做你想做的事。注意,除了逻辑结构之外,我还删除了您的ask patches。您的代码设置方式,每个补丁设置变量a-space等。因此,如果您有2500个补丁,那么这些变量将被设置2500次(相同的值)。
globals [a-space b-space c-space d-space]
to setup-environment
ask patches with [ pycor mod 2 = 0 and pxcor <= -16] [ set pcolor grey ]
ask patches with [ pycor mod 2 = 0 and pxcor >= 16] [ set pcolor grey ]
ask patches with [ pxcor mod 2 = 0 and pycor <= -16] [ set pcolor grey ]
ask patches with [ pxcor mod 2 = 0 and pycor >= 16] [ set pcolor grey ]
ask patches with [ pycor = 0] [ set pcolor red ]
ask patches with [ pxcor = 0] [ set pcolor red ]
; THIS PART IN PARTICULAR
set a-space patches with [(-14 < pxcor) and (pxcor < 0) and (pycor > 0) and (pycor < 5)]
ask a-space [set pcolor blue]
endhttps://stackoverflow.com/questions/59093388
复制相似问题