java.lang.Objectorg.nlogo.workspace.AbstractWorkspace
org.nlogo.headless.HeadlessWorkspace
public class HeadlessWorkspace
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/interfaces inherited from class org.nlogo.workspace.AbstractWorkspace |
|---|
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, worldLoader |
| Fields inherited from interface org.nlogo.nvm.Workspace |
|---|
CONTINUOUS_UPDATES, OUTPUT_NORMAL, OUTPUT_TO_FILE, OUTPUT_TO_OUTPUT_AREA, TICK_BASED_UPDATES |
| Constructor Summary | |
|---|---|
HeadlessWorkspace()
Makes a new instance of NetLogo capable of running a model "headless", with no GUI. |
|
| Method Summary | |
|---|---|
int |
calculateHeight(int worldHeight,
double patchSize)
|
int |
calculateWidth(int worldWidth,
double patchSize)
|
void |
changeTopology(boolean wrapX,
boolean wrapY)
|
void |
clearDrawing()
|
void |
clearOutput()
Internal use only. |
void |
clearTurtles()
|
void |
command(String source)
Runs NetLogo commands and waits for them to complete. |
double |
computePatchSize(int width,
int numPatches)
|
void |
createPatchesNotify()
Internal use only. |
void |
deleteLogFiles()
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 |
fontSize(int fontSize)
|
void |
generateModelTest(String model)
|
static void |
generateModelTests()
Internal use only. |
BufferedImage |
getAndCreateDrawing()
|
org.nlogo.compiler.AutoConverter.ErrorHandler |
getAutoConverterErrorHandler()
|
Shape |
getDefaultLinkShape()
|
Shape |
getDefaultShape()
|
BufferedImage |
getGraphics()
Get a snapshot of the 2D view. |
void |
getGraphics(BufferedImage image)
Get a snapshot of the 2D view, using an existing BufferedImage object. |
float[] |
getHSB(int[] rgb)
|
int |
getMinimumWidth()
|
void |
halt()
Halts all running NetLogo code in this workspace. |
void |
importDrawing(org.nlogo.util.File file)
|
void |
initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor)
|
void |
initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor,
String source)
Internal use only. |
void |
initForTesting(WorldDimensions d)
Internal use only. |
void |
initForTesting(WorldDimensions d,
String source)
|
void |
initModelForChecksumming()
|
int |
insetWidth()
|
void |
inspectAgent(Class agentClass,
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 |
makePreviews(boolean allModels,
boolean overwrite)
|
void |
open(String path)
Opens a model stored in a file. |
void |
openFromSource(String source)
Opens a model stored in a string. |
void |
openIndex()
Internal use only. |
void |
openNext()
Internal use only. |
void |
openPrevious()
Internal use only. |
void |
ownerFinished(JobOwner owner)
Internal use only. |
void |
paint(Graphics2D g)
Internal use only. |
double |
patchSize()
|
void |
patchSize(double patchSize)
|
void |
perhapsUpdateDisplay()
Internal use only. |
void |
periodicUpdate()
Internal use only. |
org.nlogo.lab.Protocol |
protocolFromModel(String name)
|
void |
refreshShaped(boolean shapesOn)
|
Object |
report(String source)
Runs a NetLogo reporter. |
void |
requestDisplayUpdate(boolean force)
Internal use only. |
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(JobOwner owner,
Context context,
Instruction instruction,
Exception ex)
Internal use only. |
void |
setCompilerTestingMode(boolean testing)
Internal use only. |
void |
setDimensions(WorldDimensions d)
Kills all turtles, clears all patch variables, and makes a new patch grid. |
void |
setDimensions(WorldDimensions d,
double patchSize)
|
void |
setImporterErrorHandler(Importer.ErrorHandler importErrorHandler)
Internal use only. |
void |
setSize(int x,
int y)
|
boolean |
shapesOn()
|
void |
shapesOn(boolean shapesOn)
|
boolean |
showTickCounter()
|
void |
showTickCounter(boolean visible)
|
void |
startLogging(String properties)
Internal use only. |
String |
tickCounterLabel()
|
void |
tickCounterLabel(String label)
|
void |
updateDisplay(boolean haveWorldLockAlready)
Internal use only. |
void |
updateMode(int updateMode)
|
void |
waitFor(CommandRunnable runnable)
Internal use only. |
void |
waitForQueuedEvents()
Internal use only. |
Object |
waitForResult(ReporterRunnable runnable)
Internal use only. |
void |
writeGraphicsData(PrintWriter writer)
|
void |
zipLogFiles(String filename)
Internal use only. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public String[] protocolLines
public static final int TABLE
public static final int SPREADSHEET
public org.nlogo.render.Renderer renderer
public final StringBuffer outputAreaBuffer
public static final String TEST_DECLARATIONS
public LogoException lastLogoException
| Constructor Detail |
|---|
public HeadlessWorkspace()
| Method Detail |
|---|
public boolean isHeadless()
isHeadless in class AbstractWorkspacepublic void ensureRenderer()
public void setCompilerTestingMode(boolean testing)
public boolean isCompilerTestingMode()
isCompilerTestingMode in class AbstractWorkspace
public void waitFor(CommandRunnable runnable)
throws LogoException
waitFor in interface WorkspaceLogoException
public Object waitForResult(ReporterRunnable runnable)
throws LogoException
waitForResult in interface WorkspaceLogoExceptionpublic void waitForQueuedEvents()
waitForQueuedEvents in interface Workspace
public void initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor,
String source)
throws CompilerException
CompilerException
public void initForTesting(WorldDimensions d,
String source)
throws CompilerException
CompilerException
public void initForTesting(int minPxcor,
int maxPxcor,
int minPycor,
int maxPycor)
public void initForTesting(WorldDimensions d)
AbstractWorkspace
initForTesting in class AbstractWorkspacepublic void setDimensions(WorldDimensions d)
setDimensions in interface WorldResizer
public void setDimensions(WorldDimensions d,
double patchSize)
setDimensions in interface WorldLoaderInterfacepublic int getMinimumWidth()
getMinimumWidth in interface WorldLoaderInterfacepublic int insetWidth()
insetWidth in interface WorldLoaderInterface
public double computePatchSize(int width,
int numPatches)
computePatchSize in interface WorldLoaderInterface
public int calculateHeight(int worldHeight,
double patchSize)
calculateHeight in interface WorldLoaderInterface
public int calculateWidth(int worldWidth,
double patchSize)
calculateWidth in interface WorldLoaderInterfacepublic void resizeWorld()
resizeWorld in interface WorldResizerpublic void tickCounterLabel(String label)
tickCounterLabel in interface WorldLoaderInterfacepublic String tickCounterLabel()
tickCounterLabel in interface WorldLoaderInterfacepublic void showTickCounter(boolean visible)
showTickCounter in interface WorldLoaderInterfacepublic boolean showTickCounter()
showTickCounter in interface WorldLoaderInterfacepublic void patchSize(double patchSize)
patchSize in interface WorldResizerpatchSize in interface WorldLoaderInterfacepublic double patchSize()
patchSize in interface Workspace
public void changeTopology(boolean wrapX,
boolean wrapY)
changeTopology in interface WorkspacechangeTopology in interface WorldLoaderInterfacepublic void refreshShaped(boolean shapesOn)
refreshShaped in interface WorldLoaderInterfacepublic void updateMode(int updateMode)
updateMode in interface WorldLoaderInterfacepublic void fontSize(int fontSize)
fontSize in interface WorldLoaderInterface
public void setSize(int x,
int y)
setSize in interface WorldLoaderInterfacepublic void clearTurtles()
clearTurtles in interface WorldLoaderInterfacepublic void createPatchesNotify()
public void inspectAgent(Class agentClass,
Agent agent)
inspectAgent in interface Workspacepublic BufferedImage getAndCreateDrawing()
getAndCreateDrawing in interface Workspace
public void importDrawing(org.nlogo.util.File file)
throws IOException
IOExceptionpublic void clearDrawing()
clearDrawing in interface WorkspaceclearDrawing in class AbstractWorkspace
public void exportDrawing(String filename,
String format)
throws IOException
exportDrawing in interface WorkspaceIOExceptionpublic void exportDrawingToCSV(PrintWriter writer)
exportDrawingToCSV in class AbstractWorkspacepublic void exportOutput(String filename)
exportOutput in interface Workspacepublic void exportOutputAreaToCSV(PrintWriter writer)
exportOutputAreaToCSV in class AbstractWorkspacepublic void clearOutput()
clearOutput in interface Workspacepublic org.nlogo.compiler.AutoConverter.ErrorHandler getAutoConverterErrorHandler()
getAutoConverterErrorHandler in interface Workspacepublic void setImporterErrorHandler(Importer.ErrorHandler importErrorHandler)
public BufferedImage getGraphics()
public void getGraphics(BufferedImage image)
public void paint(Graphics2D g)
public void exportGraphics(String filename,
String format)
throws IOException
exportGraphics in interface WorkspaceIOExceptionpublic void exportInterface(String filename)
exportInterface in interface Workspacepublic void writeGraphicsData(PrintWriter writer)
writeGraphicsData in class AbstractWorkspacepublic void ownerFinished(JobOwner owner)
ownerFinished in interface JobManagerOwnerpublic void updateDisplay(boolean haveWorldLockAlready)
updateDisplay in interface JobManagerOwnerpublic void requestDisplayUpdate(boolean force)
requestDisplayUpdate in interface WorkspacerequestDisplayUpdate in class AbstractWorkspacepublic void perhapsUpdateDisplay()
perhapsUpdateDisplay in interface WorkspaceperhapsUpdateDisplay in class AbstractWorkspacepublic void periodicUpdate()
periodicUpdate in interface JobManagerOwnerpublic void magicOpen(String name)
magicOpen in interface WorkspacemagicOpen in class AbstractWorkspacepublic void openIndex()
openIndex in interface Workspacepublic void openNext()
openNext in interface Workspacepublic void openPrevious()
openPrevious in interface Workspacepublic void startLogging(String properties)
startLogging in interface Workspacepublic void zipLogFiles(String filename)
zipLogFiles in interface Workspacepublic void deleteLogFiles()
deleteLogFiles in interface Workspace
public void runtimeError(JobOwner owner,
Context context,
Instruction instruction,
Exception ex)
runtimeError in interface JobManagerOwner
public void open(String path)
throws IOException,
CompilerException,
LogoException
open in interface Controllableopen in class AbstractWorkspacepath - the path (absolute or relative) of the NetLogo model to open.
IOException
CompilerException
LogoException
public void openFromSource(String source)
throws CompilerException,
LogoException
source - The complete model, including widgets and so forth,
in the same format as it would be stored in a file.
CompilerException
LogoException
public void command(String source)
throws CompilerException,
LogoException
command in interface Controllablesource - The command or commands to run
CompilerException - if the code fails to compile
LogoException - if the code fails to run
public Object report(String source)
throws CompilerException,
LogoException
report in interface Controllablesource - The reporter to run
LogoList,
Agent, AgentSet, or Nobody
CompilerException - if the code fails to compile
LogoException - if the code fails to runpublic void halt()
halt in class AbstractWorkspace
public void runExperiment(String xml,
int format,
PrintWriter writer)
throws CompilerException,
SAXException
xml - a single experiment setup represented in XMLformat - TABLE or SPREADSHEETwriter - where to send the results
Writes the results of the experiment to the given writer in
CSV (comma separated values) format.
CompilerException
SAXException
public void runExperiment(File file,
int format,
PrintWriter writer)
throws IOException,
CompilerException,
SAXException
file - file containing a single experiment setup
represented in XMLformat - TABLE or SPREADSHEETwriter - where to send the results
Writes the results of the experiment to the given writer in
CSV (comma separated values) format.
IOException
CompilerException
SAXException
public void runExperiment(File file,
String name,
int format,
PrintWriter writer)
throws IOException,
CompilerException,
SAXException
file - file containing one or more experiment setups
represented in XMLname - name of the experiment setup to run; must match
the name of one of the setups in the XML fileformat - TABLE or SPREADSHEETwriter - where to send the results
Writes the results of the experiment to the given writer in
CSV (comma separated values) format.
IOException
CompilerException
SAXException
public org.nlogo.lab.Protocol protocolFromModel(String name)
throws SAXException
SAXException
public org.nlogo.lab.Experiment runExperimentFromModel(String name)
throws CompilerException,
SAXException
CompilerException
SAXException
public void runExperimentFromModel(String name,
int format,
PrintWriter writer)
throws CompilerException,
SAXException
name - the name of an experiment setup which is stored
in the currently loaded model fileformat - TABLE or SPREADSHEETwriter - where to send the results
Writes the results of the experiment to the given writer in
CSV (comma separated values) format.
CompilerException
SAXException
public static void main(String[] args)
throws InterruptedException
InterruptedExceptionpublic void shapesOn(boolean shapesOn)
shapesOn in class AbstractWorkspacepublic boolean shapesOn()
shapesOn in class AbstractWorkspace
public void generateModelTest(String model)
throws IOException,
CompilerException,
LogoException
IOException
CompilerException
LogoException
public void initModelForChecksumming()
throws LogoException,
CompilerException
initModelForChecksumming in interface WorkspaceLogoException
CompilerException
public static void generateModelTests()
throws IOException
IOException
public void makePreviews(boolean allModels,
boolean overwrite)
makePreviews in interface Workspacepublic float[] getHSB(int[] rgb)
getHSB in interface Workspacepublic Shape getDefaultShape()
getDefaultShape in class AbstractWorkspacepublic Shape getDefaultLinkShape()
getDefaultLinkShape in class AbstractWorkspace