Netlogo 遵循平均摆线会导致乌龟型误差

Netlogo 遵循平均摆线会导致乌龟型误差,netlogo,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' 作为一个观察者,我输入质心0,它也会抛出错误信息。我应该做什么来让它工作?

我试着让每个点跟随它们的等效质心,这是3个不同点的平均值。但当我设置为7个点(数字==7)时,我只看到3个质心,以此类推。质心的数量与点的数量不匹配,当我按下go键时,我会收到以下错误消息:

error while dot 4 running CENTROID
  called by procedure MOVE-DOTS
  called by procedure GO
  called by Button 'go'
作为一个观察者,我输入质心0,它也会抛出错误信息。我应该做什么来让它工作?我创建了(数字)质心,所以我觉得它应该是相同数量的点。meanx和meany的逻辑对我来说似乎很有意义。如果是点0,它会做点1到3,因为没有负数,谁给点编号,它只会做这些。(or部分用于解释那些who数字过高的人,需要将其环绕到0)


尝试使用(number)的不同值运行它,并告诉我们模式是什么。好的,我用错误消息更新了我的帖子。我不确定是否有任何模式,我可以看到错误信息说:“点4不是一个质心”。问题出在
人脸质心who
,即“点上下文”中。所以who数字指的是点。如果您查看所有who编号(例如,
aks turtles[show who]
),您将看到没有centroit 4。由于点将多次分配给不同的质心,因此如何设置质心也存在问题。您可以看到,当您使用inside
移动质心时:
让候选点与我和谁的[(谁>[who]点
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
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```