java.lang.Object org.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 AbstractWorkspace
public void ensureRenderer()
public void setCompilerTestingMode(boolean testing)
public boolean isCompilerTestingMode()
isCompilerTestingMode
in class AbstractWorkspace
public void waitFor(CommandRunnable runnable) throws LogoException
waitFor
in interface Workspace
LogoException
public Object waitForResult(ReporterRunnable runnable) throws LogoException
waitForResult
in interface Workspace
LogoException
public 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 AbstractWorkspace
public void setDimensions(WorldDimensions d)
setDimensions
in interface WorldResizer
public void setDimensions(WorldDimensions d, double patchSize)
setDimensions
in interface WorldLoaderInterface
public int getMinimumWidth()
getMinimumWidth
in interface WorldLoaderInterface
public 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 WorldLoaderInterface
public void resizeWorld()
resizeWorld
in interface WorldResizer
public void tickCounterLabel(String label)
tickCounterLabel
in interface WorldLoaderInterface
public String tickCounterLabel()
tickCounterLabel
in interface WorldLoaderInterface
public void showTickCounter(boolean visible)
showTickCounter
in interface WorldLoaderInterface
public boolean showTickCounter()
showTickCounter
in interface WorldLoaderInterface
public void patchSize(double patchSize)
patchSize
in interface WorldResizer
patchSize
in interface WorldLoaderInterface
public double patchSize()
patchSize
in interface Workspace
public void changeTopology(boolean wrapX, boolean wrapY)
changeTopology
in interface Workspace
changeTopology
in interface WorldLoaderInterface
public void refreshShaped(boolean shapesOn)
refreshShaped
in interface WorldLoaderInterface
public void updateMode(int updateMode)
updateMode
in interface WorldLoaderInterface
public void fontSize(int fontSize)
fontSize
in interface WorldLoaderInterface
public void setSize(int x, int y)
setSize
in interface WorldLoaderInterface
public void clearTurtles()
clearTurtles
in interface WorldLoaderInterface
public void createPatchesNotify()
public void inspectAgent(Class agentClass, Agent agent)
inspectAgent
in interface Workspace
public BufferedImage getAndCreateDrawing()
getAndCreateDrawing
in interface Workspace
public void importDrawing(org.nlogo.util.File file) throws IOException
IOException
public void clearDrawing()
clearDrawing
in interface Workspace
clearDrawing
in class AbstractWorkspace
public void exportDrawing(String filename, String format) throws IOException
exportDrawing
in interface Workspace
IOException
public void exportDrawingToCSV(PrintWriter writer)
exportDrawingToCSV
in class AbstractWorkspace
public void exportOutput(String filename)
exportOutput
in interface Workspace
public void exportOutputAreaToCSV(PrintWriter writer)
exportOutputAreaToCSV
in class AbstractWorkspace
public void clearOutput()
clearOutput
in interface Workspace
public org.nlogo.compiler.AutoConverter.ErrorHandler getAutoConverterErrorHandler()
getAutoConverterErrorHandler
in interface Workspace
public 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 Workspace
IOException
public void exportInterface(String filename)
exportInterface
in interface Workspace
public void writeGraphicsData(PrintWriter writer)
writeGraphicsData
in class AbstractWorkspace
public void ownerFinished(JobOwner owner)
ownerFinished
in interface JobManagerOwner
public void updateDisplay(boolean haveWorldLockAlready)
updateDisplay
in interface JobManagerOwner
public void requestDisplayUpdate(boolean force)
requestDisplayUpdate
in interface Workspace
requestDisplayUpdate
in class AbstractWorkspace
public void perhapsUpdateDisplay()
perhapsUpdateDisplay
in interface Workspace
perhapsUpdateDisplay
in class AbstractWorkspace
public void periodicUpdate()
periodicUpdate
in interface JobManagerOwner
public void magicOpen(String name)
magicOpen
in interface Workspace
magicOpen
in class AbstractWorkspace
public void openIndex()
openIndex
in interface Workspace
public void openNext()
openNext
in interface Workspace
public void openPrevious()
openPrevious
in interface Workspace
public void startLogging(String properties)
startLogging
in interface Workspace
public void zipLogFiles(String filename)
zipLogFiles
in interface Workspace
public 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 Controllable
open
in class AbstractWorkspace
path
- 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 Controllable
source
- The command or commands to run
CompilerException
- if the code fails to compile
LogoException
- if the code fails to runpublic Object report(String source) throws CompilerException, LogoException
report
in interface Controllable
source
- 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
InterruptedException
public void shapesOn(boolean shapesOn)
shapesOn
in class AbstractWorkspace
public 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 Workspace
LogoException
CompilerException
public static void generateModelTests() throws IOException
IOException
public void makePreviews(boolean allModels, boolean overwrite)
makePreviews
in interface Workspace
public float[] getHSB(int[] rgb)
getHSB
in interface Workspace
public Shape getDefaultShape()
getDefaultShape
in class AbstractWorkspace
public Shape getDefaultLinkShape()
getDefaultLinkShape
in class AbstractWorkspace