NetLogo API
version 3.0.2

org.nlogo.headless
Class HeadlessWorkspace

java.lang.Object
  extended byorg.nlogo.workspace.AbstractWorkspace
      extended byorg.nlogo.headless.HeadlessWorkspace
All Implemented Interfaces:
org.nlogo.workspace.Controllable, org.nlogo.agent.ImporterUser, org.nlogo.nvm.JobManagerOwner, org.nlogo.nvm.Workspace, org.nlogo.agent.WorldResizer

public class HeadlessWorkspace
extends org.nlogo.workspace.AbstractWorkspace
implements org.nlogo.workspace.Controllable

The main class for headless (no GUI) operation of NetLogo.

You may create more than one HeadlessWorkspace object. Multiple instances can operate separately and independently. (Behind the scenes, this is supported by creating a separate thread for each instance.)

When you are done using a HeadlessWorkspace, you should call its dispose() method. This will shut down the thread associated with the workspace and allow resources to be freed.

See the "Controlling" section of the NetLogo User Manual for example code.


Nested Class Summary
 
Nested classes inherited from class org.nlogo.workspace.AbstractWorkspace
org.nlogo.workspace.AbstractWorkspace.HubNetManagerFactory
 
Field Summary
 LogoException lastLogoException
          Internal use only.
 StringBuffer outputAreaBuffer
           
 String[] protocolLines
           
 org.nlogo.render.Renderer renderer
           
static int SPREADSHEET
          constant for specifying format of BehaviorSpace output
static int TABLE
          constant for specifying format of BehaviorSpace output
static String TEST_DECLARATIONS
          Internal use only.
 
Fields inherited from class org.nlogo.workspace.AbstractWorkspace
aggregateManager, DEFAULT_PREVIEW_COMMANDS, jobManager, previewCommands, TYPE_CONVERTED, TYPE_LIBRARY, TYPE_NEW, TYPE_NORMAL, world
 
Fields inherited from interface org.nlogo.nvm.Workspace
OUTPUT_NORMAL, OUTPUT_TO_FILE, OUTPUT_TO_OUTPUT_AREA
 
Constructor Summary
HeadlessWorkspace()
          Makes a new instance of NetLogo capable of running a model "headless", with no GUI.
 
Method Summary
 void clearAll()
           
 void clearDrawing()
           
 void clearOutput()
          Internal use only.
 void command(String source)
          Runs NetLogo commands and waits for them to complete.
 void createPatchesNotify()
          Internal use only.
 void ensureRenderer()
          Internal use only.
 void exportDrawing(String filename, String format)
           
 void exportDrawingToCSV(PrintWriter writer)
           
 void exportGraphics(String filename, String format)
           
 void exportInterface(String filename)
          Not implemented.
 void exportOutput(String filename)
           
 void exportOutputAreaToCSV(PrintWriter writer)
           
 void generateModelTest(String model)
           
static void generateModelTests()
          Internal use only.
 BufferedImage getAndCreateDrawing()
           
 double getColorUnder(double xcor, double ycor)
           
 org.nlogo.agent.Shape getDefaultShape()
           
 BufferedImage getGraphics()
          Get a snapshot of the 2D view.
 int getRGBUnder(double xcor, double ycor)
           
 void halt()
          Halts all running NetLogo code in this workspace.
 void importDrawing(org.nlogo.util.File file)
           
 void initForTesting(int sex, int sey)
           
 void initForTesting(int sex, int sey, String source)
          Internal use only.
 void initModel()
           
 void inspectAgent(Class agentClass, org.nlogo.agent.Agent agent)
          Internal use only.
 boolean isCompilerTestingMode()
          Internal use only.
 boolean isHeadless()
          Internal use only.
 void magicOpen(String name)
          Internal use only.
static void main(String[] args)
           
 void open(String path)
          Opens a model stored in a file.
 void openFromSource(String source)
          Opens a model stored in a string.
 void ownerFinished(org.nlogo.nvm.JobOwner owner)
          Internal use only.
 double patchSize()
           
 void patchSize(double patchSize)
           
 void periodicUpdate()
          Internal use only.
 org.nlogo.lab.Protocol protocolFromModel(String name)
           
 Object report(String source)
          Runs a NetLogo reporter.
 void resizeWorld()
           
 void runExperiment(File file, int format, PrintWriter writer)
          Runs a BehaviorSpace experiment.
 void runExperiment(File file, String name, int format, PrintWriter writer)
          Runs a BehaviorSpace experiment.
 void runExperiment(String xml, int format, PrintWriter writer)
          Runs a BehaviorSpace experiment.
 org.nlogo.lab.Experiment runExperimentFromModel(String name)
           
 void runExperimentFromModel(String name, int format, PrintWriter writer)
          Runs a BehaviorSpace experiment.
 void runtimeError(org.nlogo.nvm.JobOwner owner, org.nlogo.nvm.Context context, org.nlogo.command.Instruction instruction, Exception ex)
          Internal use only.
 void setCompilerTestingMode(boolean testing)
          Internal use only.
 void setImporterErrorHandler(org.nlogo.agent.Importer.ErrorHandler importErrorHandler)
          Internal use only.
 void setModelPath(String path)
          Internal use only.
 void setModelType(int modelType)
          Internal use only.
 void setScreenEdges(int screenEdgeX, int screenEdgeY)
          Kills all turtles, clears all patch variables, and makes a new patch grid.
 void setSpotlightSize(double size)
           
 boolean shapesOn()
           
 void shapesOn(boolean shapesOn)
           
 void stamp(org.nlogo.agent.Turtle turtle)
           
 void updateDisplay(boolean force)
          Internal use only.
 void waitFor(org.nlogo.nvm.CommandRunnable runnable)
          Internal use only.
 void waitForQueuedEvents()
          Internal use only.
 Object waitForResult(org.nlogo.nvm.ReporterRunnable runnable)
          Internal use only.
 void writeGraphicsData(PrintWriter writer)
           
 
Methods inherited from class org.nlogo.workspace.AbstractWorkspace
addJobFromJobThread, attachModelDir, compileCommands, compileForRun, compileReporter, computerHubNetRunning, computerHubNetRunning, convertToNormal, dispose, evaluateCommands, evaluateCommands, evaluateCommands, evaluateReporter, evaluateReporter, exportBehaviors, exportWorld, fileManager, forceSaveAs, getExtensionManager, getHubNetManager, getModelDir, getModelFileName, getModelPath, getModelType, guessExportName, hubnetManager, importDrawing, importWorld, init, isApp, isApp, isApplet, isApplet, joinForeverButtons, modelNameForDisplay, outputObject, resetTimer, runCompiledCommands, runCompiledReporter, setOutputAreaContents, updateChecksum, warningMessage, world
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

protocolLines

public String[] protocolLines

TABLE

public static final int TABLE
constant for specifying format of BehaviorSpace output

See Also:
Constant Field Values

SPREADSHEET

public static final int SPREADSHEET
constant for specifying format of BehaviorSpace output

See Also:
Constant Field Values

renderer

public org.nlogo.render.Renderer renderer

outputAreaBuffer

public final StringBuffer outputAreaBuffer

TEST_DECLARATIONS

public static final String TEST_DECLARATIONS
Internal use only.

See Also:
Constant Field Values

lastLogoException

public LogoException lastLogoException
Internal use only.

Constructor Detail

HeadlessWorkspace

public HeadlessWorkspace()
Makes a new instance of NetLogo capable of running a model "headless", with no GUI.

Method Detail

isHeadless

public boolean isHeadless()
Internal use only.


ensureRenderer

public void ensureRenderer()
Internal use only.


setCompilerTestingMode

public void setCompilerTestingMode(boolean testing)
Internal use only.


isCompilerTestingMode

public boolean isCompilerTestingMode()
Internal use only.


waitFor

public void waitFor(org.nlogo.nvm.CommandRunnable runnable)
             throws LogoException
Internal use only.

Specified by:
waitFor in interface org.nlogo.nvm.Workspace
Throws:
LogoException

waitForResult

public Object waitForResult(org.nlogo.nvm.ReporterRunnable runnable)
                     throws LogoException
Internal use only.

Specified by:
waitForResult in interface org.nlogo.nvm.Workspace
Throws:
LogoException

waitForQueuedEvents

public void waitForQueuedEvents()
Internal use only.

Specified by:
waitForQueuedEvents in interface org.nlogo.nvm.Workspace

initForTesting

public void initForTesting(int sex,
                           int sey,
                           String source)
                    throws CompilerException
Internal use only.

Throws:
CompilerException

initForTesting

public void initForTesting(int sex,
                           int sey)

setScreenEdges

public void setScreenEdges(int screenEdgeX,
                           int screenEdgeY)
Kills all turtles, clears all patch variables, and makes a new patch grid. Note that the dimensions given are screen "edges", not screen "sizes", so for example calling resizeWorld(10,10) will result in a 21x21 grid.

Specified by:
setScreenEdges in interface org.nlogo.agent.WorldResizer
Parameters:
screenEdgeX - new value for screen-edge-x
screenEdgeY - new value for screen-edge-y

resizeWorld

public void resizeWorld()
Specified by:
resizeWorld in interface org.nlogo.agent.WorldResizer

patchSize

public void patchSize(double patchSize)
Specified by:
patchSize in interface org.nlogo.agent.WorldResizer

patchSize

public double patchSize()
Specified by:
patchSize in interface org.nlogo.nvm.Workspace

setModelPath

public void setModelPath(String path)
Internal use only.


setModelType

public void setModelType(int modelType)
Internal use only.


clearAll

public void clearAll()
              throws LogoException
Specified by:
clearAll in interface org.nlogo.nvm.Workspace
Throws:
LogoException

createPatchesNotify

public void createPatchesNotify()
Internal use only.


inspectAgent

public void inspectAgent(Class agentClass,
                         org.nlogo.agent.Agent agent)
Internal use only.

Specified by:
inspectAgent in interface org.nlogo.nvm.Workspace

getColorUnder

public double getColorUnder(double xcor,
                            double ycor)
Specified by:
getColorUnder in interface org.nlogo.nvm.Workspace

getRGBUnder

public int getRGBUnder(double xcor,
                       double ycor)
Specified by:
getRGBUnder in interface org.nlogo.nvm.Workspace

stamp

public void stamp(org.nlogo.agent.Turtle turtle)
Specified by:
stamp in interface org.nlogo.nvm.Workspace

getAndCreateDrawing

public BufferedImage getAndCreateDrawing()
Specified by:
getAndCreateDrawing in interface org.nlogo.nvm.Workspace

importDrawing

public void importDrawing(org.nlogo.util.File file)
                   throws IOException
Throws:
IOException

clearDrawing

public void clearDrawing()
Specified by:
clearDrawing in interface org.nlogo.nvm.Workspace

exportDrawing

public void exportDrawing(String filename,
                          String format)
                   throws IOException
Specified by:
exportDrawing in interface org.nlogo.nvm.Workspace
Throws:
IOException

exportDrawingToCSV

public void exportDrawingToCSV(PrintWriter writer)

exportOutput

public void exportOutput(String filename)
Specified by:
exportOutput in interface org.nlogo.nvm.Workspace

exportOutputAreaToCSV

public void exportOutputAreaToCSV(PrintWriter writer)

clearOutput

public void clearOutput()
Internal use only.

Specified by:
clearOutput in interface org.nlogo.nvm.Workspace

setImporterErrorHandler

public void setImporterErrorHandler(org.nlogo.agent.Importer.ErrorHandler importErrorHandler)
Internal use only.


getGraphics

public BufferedImage getGraphics()
Get a snapshot of the 2D view.


exportGraphics

public void exportGraphics(String filename,
                           String format)
                    throws IOException
Specified by:
exportGraphics in interface org.nlogo.nvm.Workspace
Throws:
IOException

exportInterface

public void exportInterface(String filename)
Not implemented.

Specified by:
exportInterface in interface org.nlogo.nvm.Workspace

writeGraphicsData

public void writeGraphicsData(PrintWriter writer)

ownerFinished

public void ownerFinished(org.nlogo.nvm.JobOwner owner)
Internal use only.

Specified by:
ownerFinished in interface org.nlogo.nvm.JobManagerOwner

updateDisplay

public void updateDisplay(boolean force)
Internal use only.

Specified by:
updateDisplay in interface org.nlogo.nvm.JobManagerOwner

periodicUpdate

public void periodicUpdate()
Internal use only.

Specified by:
periodicUpdate in interface org.nlogo.nvm.JobManagerOwner

magicOpen

public void magicOpen(String name)
Internal use only.

Specified by:
magicOpen in interface org.nlogo.nvm.Workspace

setSpotlightSize

public void setSpotlightSize(double size)
Specified by:
setSpotlightSize in interface org.nlogo.nvm.Workspace

runtimeError

public void runtimeError(org.nlogo.nvm.JobOwner owner,
                         org.nlogo.nvm.Context context,
                         org.nlogo.command.Instruction instruction,
                         Exception ex)
Internal use only.

Specified by:
runtimeError in interface org.nlogo.nvm.JobManagerOwner

open

public void open(String path)
          throws IOException,
                 CompilerException,
                 LogoException
Opens a model stored in a file.

Parameters:
path - the path (absolute or relative) of the NetLogo model to open.
Throws:
IOException
CompilerException
LogoException

openFromSource

public void openFromSource(String source)
                    throws CompilerException,
                           LogoException
Opens a model stored in a string. Can only be called once per instance of HeadlessWorkspace

Parameters:
source - The complete model, including widgets and so forth, in the same format as it would be stored in a file.
Throws:
CompilerException
LogoException

command

public void command(String source)
             throws CompilerException,
                    LogoException
Runs NetLogo commands and waits for them to complete.

Specified by:
command in interface org.nlogo.workspace.Controllable
Parameters:
source - The command or commands to run
Throws:
CompilerException - if the code fails to compile
LogoException - if the code fails to run

report

public Object report(String source)
              throws CompilerException,
                     LogoException
Runs a NetLogo reporter.

Specified by:
report in interface org.nlogo.workspace.Controllable
Parameters:
source - The reporter to run
Returns:
the result reported; may be of type java.lang.Integer, java.lang.Double, java.lang.Boolean, java.lang.String, LogoList, Agent, AgentSet, or Nobody
Throws:
CompilerException - if the code fails to compile
LogoException - if the code fails to run

halt

public void halt()
Halts all running NetLogo code in this workspace.


runExperiment

public void runExperiment(String xml,
                          int format,
                          PrintWriter writer)
                   throws CompilerException,
                          SAXException
Runs a BehaviorSpace experiment.

Parameters:
xml - a single experiment setup represented in XML
format - TABLE or SPREADSHEET
writer - where to send the results Writes the results of the experiment to the given writer in CSV (comma separated values) format.
Throws:
CompilerException
SAXException

runExperiment

public void runExperiment(File file,
                          int format,
                          PrintWriter writer)
                   throws IOException,
                          CompilerException,
                          SAXException
Runs a BehaviorSpace experiment.

Parameters:
file - file containing a single experiment setup represented in XML
format - TABLE or SPREADSHEET
writer - where to send the results Writes the results of the experiment to the given writer in CSV (comma separated values) format.
Throws:
IOException
CompilerException
SAXException

runExperiment

public void runExperiment(File file,
                          String name,
                          int format,
                          PrintWriter writer)
                   throws IOException,
                          CompilerException,
                          SAXException
Runs a BehaviorSpace experiment.

Parameters:
file - file containing one or more experiment setups represented in XML
name - name of the experiment setup to run; must match the name of one of the setups in the XML file
format - TABLE or SPREADSHEET
writer - where to send the results Writes the results of the experiment to the given writer in CSV (comma separated values) format.
Throws:
IOException
CompilerException
SAXException

protocolFromModel

public org.nlogo.lab.Protocol protocolFromModel(String name)
                                         throws SAXException
Throws:
SAXException

runExperimentFromModel

public org.nlogo.lab.Experiment runExperimentFromModel(String name)
                                                throws CompilerException,
                                                       SAXException
Throws:
CompilerException
SAXException

runExperimentFromModel

public void runExperimentFromModel(String name,
                                   int format,
                                   PrintWriter writer)
                            throws CompilerException,
                                   SAXException
Runs a BehaviorSpace experiment.

Parameters:
name - the name of an experiment setup which is stored in the currently loaded model file
format - TABLE or SPREADSHEET
writer - where to send the results Writes the results of the experiment to the given writer in CSV (comma separated values) format.
Throws:
CompilerException
SAXException

main

public static void main(String[] args)
                 throws InterruptedException
Throws:
InterruptedException

shapesOn

public void shapesOn(boolean shapesOn)

shapesOn

public boolean shapesOn()

generateModelTest

public void generateModelTest(String model)
                       throws IOException,
                              CompilerException,
                              LogoException
Throws:
IOException
CompilerException
LogoException

initModel

public void initModel()
               throws LogoException,
                      CompilerException
Specified by:
initModel in interface org.nlogo.nvm.Workspace
Throws:
LogoException
CompilerException

generateModelTests

public static void generateModelTests()
                               throws IOException
Internal use only.

Throws:
IOException

getDefaultShape

public org.nlogo.agent.Shape getDefaultShape()

NetLogo API
version 3.0.2