From a0f8850031d5821c69b286d17004166f870fcd8e Mon Sep 17 00:00:00 2001 From: Frank Duncan Date: Sat, 30 May 2015 19:14:27 -0500 Subject: [PATCH] Update runcmd to actually run comands from input --- bin/runcmd.scala | 35 +++++++++++++------- resources/empty.nlogo | 75 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 resources/empty.nlogo diff --git a/bin/runcmd.scala b/bin/runcmd.scala index 1e7987b..eb0d463 100755 --- a/bin/runcmd.scala +++ b/bin/runcmd.scala @@ -1,8 +1,12 @@ #!/bin/sh -exec scalas "$0" "$@" +exec scalas "$0" -q "$@" !# /*** + logLevel := Level.Error + + logLevel in Global := Level.Error + scalaVersion := "2.10.3" libraryDependencies ++= Seq( @@ -19,29 +23,36 @@ import org.nlogo.api import org.nlogo.nvm import org.nlogo.util.Utils.url2String +System.out.println("----") val workspace = HeadlessWorkspace.newInstance workspace.silent = true -workspace.openFromSource(url2String(api.ModelReader.emptyModelPath)) -/* -workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands("resize-world -2 2 -2 2 crt 1", api.AgentKind.Observer)) +workspace.openFromSource(url2String("file:resources/empty.nlogo")) + +val commands = io.Source.stdin.getLines.mkString("\n") + +workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands(commands, api.AgentKind.Observer)) mirror.Mirrorables.allMirrorables(workspace.world).map( x => { System.out.print("(") - System.out.print(x.kind) + System.out.print(":" + x.kind) System.out.print(" ") System.out.print(x.agentKey.id) System.out.print(" (") x.kind.Variables.values.toSeq.map( k => { - System.out.print("(" + k + " ") - x.getVariable(k.id) match { - case s: java.lang.String => System.out.print("\"s\"") - case v => System.out.print(v) - } + System.out.print("(:" + k + " ") + System.out.print(x.getVariable(k.id) match { + case s: java.lang.String => "\"s\"" + case d: java.lang.Double => d + "d0" + case b: java.lang.Boolean => if(b)"T" else "NIL" + case _: org.nlogo.api.ShapeList => ":SHAPELIST" + case v => v + }) System.out.print(") ") }) System.out.println(")") - })*/ + }) +/* workspace.runCompiledCommands(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileCommands("random-seed 15", api.AgentKind.Observer)) for(_ <- 1 to 40) System.out.println(workspace.runCompiledReporter(new api.SimpleJobOwner("test", workspace.world.mainRNG, api.AgentKind.Observer), workspace.compileReporter("random-float 30"))) @@ -49,6 +60,6 @@ for(_ <- 1 to 40) val m = new org.nlogo.util.MersenneTwisterFast(); m.setSeed(15); for(_ <- 1 to 40) - System.out.println(30d * m.nextDouble()) + System.out.println(30d * m.nextDouble())*/ workspace.dispose diff --git a/resources/empty.nlogo b/resources/empty.nlogo new file mode 100644 index 0000000..7777839 --- /dev/null +++ b/resources/empty.nlogo @@ -0,0 +1,75 @@ +@#$#@#$#@ +GRAPHICS-WINDOW +210 +10 +649 +470 +1 +1 +13.0 +1 +10 +1 +1 +1 +0 +1 +1 +1 +-1 +1 +-1 +1 +0 +0 +1 +ticks +30.0 + +@#$#@#$#@ +## WHAT IS IT? + +(a general understanding of what the model is trying to show or explain) + +## HOW IT WORKS + +(what rules the agents use to create the overall behavior of the model) + +## HOW TO USE IT + +(how to use the model, including a description of each of the items in the Interface tab) + +## THINGS TO NOTICE + +(suggested things for the user to notice while running the model) + +## THINGS TO TRY + +(suggested things for the user to try to do (move sliders, switches, etc.) with the model) + +## EXTENDING THE MODEL + +(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.) + +## NETLOGO FEATURES + +(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features) + +## RELATED MODELS + +(models in the NetLogo Models Library and elsewhere which are of related interest) + +## CREDITS AND REFERENCES + +(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links) +@#$#@#$#@ +@#$#@#$#@ +NetLogo (no version) +@#$#@#$#@ +@#$#@#$#@ +@#$#@#$#@ +@#$#@#$#@ +@#$#@#$#@ +@#$#@#$#@ +0 +@#$#@#$#@ -- 2.25.1