Closed jbadham closed 8 years ago
just tested a simple use case (which comes straight out of the users group discussion), and it fails with a netlogo error message about not being able to identify which turtle is referenced:
extensions [rnd]
turtles-own [myweight]
to check
create-turtles 10 [ set myweight random 4 + 1 ]
show rnd:weighted-n-of 3 turtles [myweight]
end
Workaround - could be documented if too hard to fix. Need to do rnd:weighted-n-of N agentset [ [weightvariable] of ?]
The only way I found (at the time) to make the primitives work with both lists and agentsets was to have them accept a reporter task (like foreach
, map
, etc.) This means that, for agentsets, you do need to use the awkward [ variable ] of ?
syntax. (The alternative was to have two different sets of primitives for lists and for agentsets. I was trying to avoid that, but maybe it would have been better to bite the bullet. See https://github.com/NetLogo/Rnd-Extension/issues/5.)
This is admittedly not documented well enough. I'll fix that.
And one thing is for sure: it should give a proper NetLogo error, not a Java exception. I'll fix that too.
Thanks for the report, Jen!
@jbadham, which version of NetLogo were you testing with? (I suspect < 5.3.0?)
Current version. Windows 8.1 (and also Windows 7 on work computer)
NetLogo 5.3 (December 14, 2015) Extension API version: 5.0 Java HotSpot(TM) 64-Bit Server VM 1.8.0_65 (Oracle Corporation; 1.8.0_65-b17) operating system: Windows 8.1 6.3 (amd64 processor) Scala version 2.9.2 Java heap: used = 16 MB, free = 342 MB, max = 910 MB
JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized)
I got the java error with the exact code on the SO question for the BA network generator at the top of this report. I got a NetLogo error on the use case example immediately below it.
Here is the full text of the java error if it is of use
error (ClassCastException) while observer running _asm_proceduremakenwba_setprocedurevariable_11 called by procedure MAKENW-BA called by Command Center
NetLogo is unable to supply you with more details about this error. Please report the problem at https://github.com/NetLogo/NetLogo/issues, or to bugs@ccl.northwestern.edu, and paste the contents of this window into your report.
java.lang.ClassCastException: org.nlogo.agent.Observer cannot be cast to org.nlogo.agent.Turtle at org.nlogo.prim._mylinks.report(_mylinks.java:39) at org.nlogo.prim._asm_proceduremakenwba_count_14.report() at org.nlogo.nvm.ReporterTask.report(Task.scala:53) at org.nlogo.nvm.ReporterTask.report(Task.scala:46) at org.nlogo.extensions.rnd.WeightedRndPrim$$anonfun$getWeightFunction$1.apply(Primitives.scala:44) at org.nlogo.extensions.rnd.WeightedRndPrim$$anonfun$getWeightFunction$1.apply(Primitives.scala:43) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233) at scala.collection.Iterator$class.foreach(Iterator.scala:772) at scala.collection.immutable.VectorIterator.foreach(Vector.scala:648) at scala.collection.IterableLike$class.foreach(IterableLike.scala:73) at scala.collection.immutable.Vector.foreach(Vector.scala:63) at scala.collection.TraversableLike$class.map(TraversableLike.scala:233) at scala.collection.immutable.Vector.map(Vector.scala:63) at org.nlogo.extensions.rnd.Picker$.pickIndicesWithoutRepeats(Picker.scala:36) at org.nlogo.extensions.rnd.WeightedNOfWithoutRepeatsPrim$.pickIndices(Primitives.scala:131) at org.nlogo.extensions.rnd.WeightedNOfWithoutRepeatsPrim$.pickIndices(Primitives.scala:121) at org.nlogo.extensions.rnd.WeightedNOfPrim$class.report(Primitives.scala:99) at org.nlogo.extensions.rnd.WeightedNOfWithoutRepeatsPrim$.report(Primitives.scala:121) at org.nlogo.prim._externreport.report(_externreport.java:50) at org.nlogo.prim._asm_proceduremakenwba_setprocedurevariable_11.perform() at org.nlogo.nvm.Context.stepConcurrent(Context.java:91) at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82) at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143) at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78) at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76) at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76) at scala.util.control.Exception$Catch.apply(Exception.scala:88) at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41) at org.nlogo.job.JobThread.run(JobThread.scala:75)
NetLogo 5.3 main: org.nlogo.app.AppFrame thread: JobThread Java HotSpot(TM) 64-Bit Server VM 1.8.0_65 (Oracle Corporation; 1.8.0_65-b17) operating system: Windows 8.1 6.3 (amd64 processor) Scala version 2.9.2 JOGL: (3D View not initialized) OpenGL Graphics: (3D View not initialized) model: Untitled
04:39:51.514 SwitchedTabsEvent (org.nlogo.app.Tabs) AWT-EventQueue-0 04:39:51.514 RuntimeErrorEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 04:39:51.514 JobRemovedEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) JobThread 04:39:51.514 TickStateChangeEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) JobThread 04:39:51.514 OutputEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0 04:39:51.498 AddJobEvent (org.nlogo.app.CommandLine) AWT-EventQueue-0 04:39:51.498 OutputEvent (org.nlogo.app.CommandLine) AWT-EventQueue-0 04:39:51.498 CompiledEvent (org.nlogo.window.CompilerManager) AWT-EventQueue-0 04:39:51.498 CompileMoreSourceEvent (org.nlogo.app.CommandLine) AWT-EventQueue-0 04:39:51.467 PeriodicUpdateEvent (org.nlogo.app.App$$anon$1 (org.nlogo.window.GUIWorkspace)) AWT-EventQueue-0
Actually, it seems like you ran into https://github.com/NetLogo/NetLogo/pull/902. That's a regression that happened between NetLogo 5.2.0 and 5.2.1, so 5.2.1 and 5.3.0 are the only affected versions. In NetLogo <= 5.2.0 and > 5.3.0, the code examples above won't even compile (which is the correct behavior, even if a bit counterintuitive).
I have updated the documentation to try to clarify things a bit. And the forthcoming release of NetLogo 5.3.1 (which has the fix for https://github.com/NetLogo/NetLogo/pull/902) will make the Java exception go away.
Not sure if it is a bug or my coding - but generating a java error rather than a NetLogo error. See http://stackoverflow.com/questions/34802274/preferential-attachment-graph-in-netlogo in case it gets solved. Generated by the following code: