netlogo - 遵循平均摆线导致海龟类型错误
问题描述
我试图让每个点都遵循它们的等效质心,这是 3 个不同点的平均值。但是当我设置 7 个点(数字 == 7)时,我只看到 3 个质心,等等。质心的数量与点的数量不匹配,当我按下 go 时,我收到以下错误消息:
error while dot 4 running CENTROID
called by procedure MOVE-DOTS
called by procedure GO
called by Button 'go'
作为观察者,我输入 centroid 0 并且它还会抛出错误消息。我应该修复什么才能使其正常工作?我创建了(数字)质心,所以我觉得它应该是相同数量的点。卑鄙和卑鄙的逻辑对我来说似乎很有意义。如果它是点 0,它会做点 1 到 3,因为没有负数的点,它只会做那些。(or部分是为了解释那些数字太高的人,它需要它环绕到0)
globals [number2]
breed [centroids centroid]
breed [dots dot]
to setup
clear-all
setup-patches
setup-dots
set-default-shape centroids "x"
setup-centroid
reset-ticks
end
to setup-patches
ask patches [ set pcolor green ]
end
to setup-dots
create-dots number ;; uses the value of the number slider to create dots
set number2 (number)
ask dots [ setxy random-xcor random-ycor ]
end
to go
ifelse number2 = number ;check if user changed number
[
move-dots
move-centroid
tick-advance 1 ;; increment the tick counter]
]
[setup]
end
to move-dots
ask dots [
face centroid who
forward (distance centroid who) / (ticks/sec * number ) ; divide by number is alpha = 1/N for stability
]
end
; add a dot that shows center of formation/mass
to setup-centroid
create-centroids (number)
move-centroid
end
to move-centroid
ask centroids[
let meanx (mean ([xcor] of (dots with [(who > [who] of myself and who <= (([who] of myself) + 3)) or (who <= (([who] of myself) - (number - 4)))] )))
let meany (mean ([ycor] of (dots with [(who > [who] of myself and who <= (([who] of myself) + 3)) or (who <= (([who] of myself) - (number - 4)))] )))
setxy meanx meany
]
end
我得到的错误是这样的(数字等于 5,但错误语句中的点数发生了变化(例如,有时会说“点 4 不是 CENTROID”或“点 0 不是 CENTROID”)
error while dot 2 running CENTROID
called by procedure MOVE-DOTS
called by procedure GO
called by Button 'go'
org.nlogo.nvm.RuntimePrimitiveException: dot 2 is not a CENTROID
at org.nlogo.prim._asm_proceduremovedots_face_1.perform(:2)
at org.nlogo.nvm.Context.runExclusive(Context.java:133)
at org.nlogo.nvm.ExclusiveJob.run(ExclusiveJob.scala:39)
at org.nlogo.nvm.Context.runExclusiveJob(Context.java:177)
at org.nlogo.prim._asm_proceduremovedots_ask_0.perform(:1)
at org.nlogo.nvm.Context.stepConcurrent(Context.java:107)
at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.scala:65)
at org.nlogo.job.JobThread.runPrimaryJobs(JobThread.scala:133)
at org.nlogo.job.JobThread.$anonfun$run$1(JobThread.scala:68)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
at scala.util.control.Exception$Catch.apply(Exception.scala:228)
at org.nlogo.api.Exceptions$.handling(Exceptions.scala:41)
at org.nlogo.job.JobThread.run(JobThread.scala:66)
NetLogo 6.2.0
main: org.nlogo.app.AppFrame
thread: JobThread
OpenJDK 64-Bit Server VM 1.8.0_275 (BellSoft; 1.8.0_275-b01)
operating system: Windows 10 10.0 (amd64 processor)
Scala version 2.12.12
JOGL: (3D View not initialized)
OpenGL Graphics: (3D View not initialized)
model: Cyclic Group
07:11:49.060 RuntimeErrorEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
07:11:49.047 AddJobEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
07:11:48.959 InterfaceGlobalEvent (org.nlogo.app.interfacetab.InterfacePanel$$anon$1 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
07:11:48.959 InterfaceGlobalEvent (org.nlogo.app.interfacetab.InterfacePanel$$anon$1 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
07:11:48.959 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
07:11:48.837 InputBoxLoseFocusEvent (org.nlogo.window.ButtonWidget) AWT-EventQueue-0
07:11:48.758 InterfaceGlobalEvent (org.nlogo.app.interfacetab.InterfacePanel$$anon$1 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
07:11:48.758 InterfaceGlobalEvent (org.nlogo.app.interfacetab.InterfacePanel$$anon$1 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0
07:11:48.758 PeriodicUpdateEvent (org.nlogo.app.App$$anon$4 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
07:11:48.558 InterfaceGlobalEvent (org.nlogo.app.interfacetab.InterfacePanel$$anon$1 (org.nlogo.window.SliderWidget)) AWT-EventQueue-0```
解决方案
推荐阅读
- linux - 向 getopts 发送一个带连字符/双连字符的参数
- javascript - 如何通过尊重他们的父母在jQuery中包装两个元素?
- codeigniter-4 - 使用 CI4 活动记录编写 SQL 子查询
- javascript - vuejs $emit 没有在第二个组件上触发
- r - 如何使用均匀分布将马尔可夫链的模拟状态转换为模拟时间序列?
- batch-file - 我需要断开 ane 锁定 vm 以及会话 ID 来控制
- html - 为什么 Aristocrat 字体不能工作 HTML CSS?
- azure - 如何在 azure AD 中为 Spring Boot api 设置权限?
- javascript - 如何在 javascript 对象中嵌套一些值?
- python - 如何使用 selenium 和 python 通过存储在 pandas 数据框中的直接链接下载所有文件