Tag: repast-simphony

Exporting standalone batch runs in Repast Simphony: start_model.sh

As discussed in Exporting standalone batch runs, Christof Zellweger developed a .sh file for Repast that will run in “batch mode” on non-development Mac and *nix machines. That file and his comments appear below. (I’ve also posted a sample .bat file and a sample .command file, both contributed by others. You may get some benefit from looking at those as well.)

start_model.command, modified by Christof Zellweger in 2012 to use BatchMain

#!/bin/bash
# The version of Repast Simphony being used.
export VERSION=2.0.0
# The installed path of Repast. Quotes may be necessary if there is a space character in the path.
export REPAST="/path/to/your/repast/home/folder"
# The installed path of Eclipse. Quotes may be necessary if there is a space character in the path.
export ECLIPSE=$REPAST/eclipse
# The plugins path of Eclipse.
export PLUGINS=$ECLIPSE/plugins
export REPAST_SIMPHONY_LIB=$PLUGINS/repast.simphony.runtime_$VERSION/lib
# The Eclipse workspace containing the Repast model.
export WORKSPACE=/path/to/your/workspace/
# The name of the model. This might be case-sensitive. This is the name of your package. It should 
# be the package at the top of all your .java files and match the "package" listed in your 
# model.score file (when viewed as a text file).
export MODELNAME=
# The folder of the model. This might be case-sensitive. This is the base folder of your 
# project in the file system.
export MODELFOLDER=$WORKSPACE/
# The file containing the batch parameters. For some additional information, see Repast 
# documentation of batch parameters at http://repast.sourceforge.net/docs/reference/SIM/Batch%20Parameters.html
# and/or an example batch_params.xml file at 
# http://www.pamelatoman.net/blog/2010/08/sample-batchparamsxml/.
# The following is the usual location within your Repast workspace - change according to your location / system
export BATCHPARAMS=$MODELFOLDER/batch/batch_params.xml
# Change to the root folder of your project so that the relative paths are handled correctly
cd $MODELFOLDER
# Execute in batch mode.
java -classpath $MODELFOLDER/lib/*:$MODELFOLDER/bin:$PLUGINS/repast.simphony.scenario_$VERSION/bin:
$PLUGINS/repast.simphony.batch_$VERSION/bin:$PLUGINS/repast.simphony.runtime_$VERSION/lib/*:
$PLUGINS/repast.simphony.runtime_$VERSION/bin:$PLUGINS/repast.simphony.core_$VERSION/lib/*:
$PLUGINS/repast.simphony.core_$VERSION/bin:$PLUGINS/repast.simphony.data_$VERSION/lib/*:
$PLUGINS/repast.simphony.score.runtime_$VERSION/lib/*:$PLUGINS/repast.simphony.score.runtime_$VERSION/bin:
$PLUGINS/repast.simphony.dataLoader_$VERSION/bin:$PLUGINS/repast.simphony.data_$VERSION/bin:
$PLUGINS/repast.simphony.score_$VERSION/bin:$REPAST_SIMPHONY_LIB/saf.core.runtime.jar:
$REPAST_SIMPHONY_LIB/commons-logging-1.0.4.jar:$REPAST_SIMPHONY_LIB/groovy-all-1.5.7.jar:
$REPAST_SIMPHONY_LIB/javassist-3.7.0.GA.jar:$REPAST_SIMPHONY_LIB/jpf.jar:$REPAST_SIMPHONY_LIB/jpf-boot.jar:
$REPAST_SIMPHONY_LIB/log4j-1.2.13.jar:$REPAST_SIMPHONY_LIB/xpp3_min-1.1.4c.jar:
$REPAST_SIMPHONY_LIB/xstream-1.3.jar repast.simphony.batch.BatchMain -params $BATCHPARAMS $MODELFOLDER/$MODELNAME.rs

Christof Zellweger writes:

I’ve tested this on Mac OS X Snow Leopard 10.6.8. I didn’t have a Linux box available but seeing that OS X uses a XNU (Unix Mach/BSD hybrid) kernel, I would assume that this script runs on many *NIX platforms unchanged and if not, only small changes would be necessary.

The main difference in this script (apart from usage of the *NIX ‘export’ equivalent to Window’s ‘set’ command) was that I’ve added 2-3 search locations/directories in the classpath argument. Plus I’ve added a few comments.

Exporting standalone batch runs in Repast Simphony: start_model.command

As discussed in Exporting standalone batch runs, Stefan König and Axel Pürkhauer developed a .command file for Repast that will run in “batch mode” on non-development Mac and *nix machines. That file appears below. (I’ve also posted a sample .bat file and a sample .sh file, both contributed by others. You may get some benefit from looking at those as well.)

start_model.command, modified by Stefan König and Axel Pürkhauer in 2010 to use BatchMain

#!/bin/bash
# Repast Simphony Model Starter
# By Michael J. North and Jonathan Ozik
# 11/12/2007
# Edited by Stefan König for use with batch files
# Note the Repast Simphony Directories.

PWD="${0%/*}"
cd $PWD

REPAST_VERSION=1.2.0
REPAST_BASE=$PWD/repast.simphony
REPAST_SIMPHONY_ROOT=$REPAST_BASE/repast.simphony.runtime_$REPAST_VERSION
REPAST_SIMPHONY_LIB=$REPAST_SIMPHONY_ROOT/lib

# Define the Core Repast Simphony Directories and JARs
CP=$CP:$REPAST_BASE/repast.simphony.batch_$REPAST_VERSION/bin
CP=$CP:$REPAST_BASE/repast.simphony.runtime_$REPAST_VERSION/lib/*
CP=$CP:$REPAST_BASE/repast.simphony.core_$REPAST_VERSION/lib/*
CP=$CP:$REPAST_BASE/repast.simphony.core_$REPAST_VERSION/bin
CP=$CP:$REPAST_SIMPHONY_ROOT/bin
CP=$CP:$REPAST_SIMPHONY_ROOT/bin-groovy
CP=$CP:$REPAST_BASE/repast.simphony.score.runtime_$REPAST_VERSION/lib/*
CP=$CP:$REPAST_BASE/repast.simphony.score.runtime_$REPAST_VERSION/bin
CP=$CP:$REPAST_BASE/repast.simphony.dataLoader_$REPAST_VERSION/bin
CP=$CP:$REPAST_BASE/repast.simphony.data_$REPAST_VERSION/bin
CP=$CP:$REPAST_BASE/repast.simphony.score_$REPAST_VERSION/bin
CP=$CP:$PWD/yourModelDirectory/bin #### NOTE: yourModelDirectory
CP=$CP:$REPAST_SIMPHONY_LIB/saf.core.runtime.jar
CP=$CP:$REPAST_SIMPHONY_LIB/commons-logging-1.0.4.jar
CP=$CP:$REPAST_SIMPHONY_LIB/groovy-all-1.5.7.jar
CP=$CP:$REPAST_SIMPHONY_LIB/javassist-3.7.0.GA.jar
CP=$CP:$REPAST_SIMPHONY_LIB/jpf.jar
CP=$CP:$REPAST_SIMPHONY_LIB/jpf-boot.jar
CP=$CP:$REPAST_SIMPHONY_LIB/log4j-1.2.13.jar
CP=$CP:$REPAST_SIMPHONY_LIB/xpp3_min-1.1.4c.jar
CP=$CP:$REPAST_SIMPHONY_LIB/xstream-1.3.jar
CP=$CP:$REPAST_BASE/repast.simphony.data_$REPAST_VERSION/lib/*

# Change to the Default Repast Simphony Directory
cd yourModelDirectory #### NOTE: yourModelDirectory

# Start the Model
/path/to/bin/java -Xss10M -Xmx400M -cp $CP repast.simphony.batch.BatchMain -params $PWD/batch/params.xml yourModel .rs

Exporting standalone batch runs in Repast Simphony: start_model.bat

As discussed in Exporting standalone batch runs, I developed a .bat file for Repast that will run in “batch mode” on non-development Windows machines. That file appears below. (I’ve also posted a sample .sh file and a sample .command file, both contributed by others. You may get some benefit from looking at those as well.)

start_model.bat, modified by Pamela Toman in 2010 to use BatchMain

@ECHO OFF
TITLE yourModelNameHere
REM Repast Simphony Batch Run Model Starter
REM By Michael J. North and Jonathan Ozik,
REM edited for batch runs by Pamela Toman,
REM on basis of .command file from Stefan König
REM
REM Please note that the paths given below use
REM a unusual Linux-like notation. This is a
REM unfortunate requirement of the Java Plugin
REM framework application loader.

REM fill out the below information so it is true for your installation
set REPAST_VERSION=1.2.0
set REPAST_SIMPHONY=../repast.simphony
set REPAST_SIMPHONY_ROOT=%REPAST_SIMPHONY%/repast.simphony.runtime_1.2.0
set REPAST_SIMPHONY_LIB=%REPAST_SIMPHONY_ROOT%/lib

REM Define the Core Repast Simphony Directories and JARs
REM You may not need the line below. I had to reset the classpath (as in the next line)
REM to avoid the character length limit on classpaths (I was getting an "input line is too
REM long" error upon running this file).
set CP=
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.batch_%REPAST_VERSION%/bin
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.runtime_%REPAST_VERSION%/lib/*
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.core_%REPAST_VERSION%/lib/*
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.core_%REPAST_VERSION%/bin
SET CP=%CP%;%REPAST_SIMPHONY_ROOT%/bin/
SET CP=%CP%;%REPAST_SIMPHONY_ROOT%/bin-groovy
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.score.runtime_%REPAST_VERSION%/lib/*
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.score.runtime_%REPAST_VERSION%/bin
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.dataLoader_%REPAST_VERSION%/bin
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.data_%REPAST_VERSION%/bin
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.score_%REPAST_VERSION%/bin
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/saf.core.runtime.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/commons-logging-1.0.4.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/groovy-all-1.5.7.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/javassist-3.7.0.GA.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/jpf.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/jpf-boot.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/log4j-1.2.13.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/xpp3_min-1.1.4c.jar
SET CP=%CP%;%REPAST_SIMPHONY_LIB%/xstream-1.3.jar
SET CP=%CP%;%REPAST_SIMPHONY%/repast.simphony.data_%REPAST_VERSION%/lib/*
SET CP=%CP%;./bin
REM adding the bin to the classpath (above) is important!

REM Change to the Default Repast Simphony Directory
cd yourModelDirectory
REM directory change is needed so that local links don't break when running the
REM program -- e.g. when pulling in data from a folder

REM Start the Model. In the batch version you must include the path to
REM the batch file parameters in addition to the XXX.rs folder containing the model.score file.
java -Xss10M -Xmx400M -cp %CP% repast.simphony.batch.BatchMain -params batch/batch_params.xml yourModel.rs

REM move back up a level, to where you started
cd ..

Repast Simphony: Exporting standalone batch runs

For running your model, the Repast development environment offers three options out of the box:

  • run the model once, using the GUI you’ve developed, within the development environment
  • export the model, such that you can install it in a production version on other computers (on those computers, it also runs under the GUI in single-run mode)
  • run the model in “batch mode” from the development environment (in batch mode, the model runs multiple iterations as defined in the batch_params.xml file, without the involvement of the GUI)

It is missing the fourth option: export the model in a version that can run in “batch mode” in a production environment.  The logical hole is palpable.

To create a standalone model that runs in batch mode, you’ll need to change the default batch (Windows) and/or command (Linux, Unix, Mac) file in your project.  You need to change the classpath of the .bat/.command/.sh so that it includes all the files that are required for batch runs.  You also need to change the invocation command from repast.simphony.runtime.RepastMain into repast.simphony.batch.BatchMain, and add the location of your batch parameters as a parameter to the command.

Stefan König and Axel Pürkhauer at the University of Bayreuth wrote a .command file with the appropriate modifications.  I used this file as the basis for a batch file, after Mr. König and I corresponded based on an email he sent to the Repast-interest listserv.  In 2012, Christof Zellweger, a postgraduate student at University of Melbourne, reached out with a further modified .sh shell script, which he kindly provided for posting here. Each script is provided in full on its own page:


So that’s all well and good. However, if you modify the original batch run file, you will lose the ability to run your model in a one-run-at-a-time-in-GUI-mode manner within standalone installs.   So, if you would rather create a new .batch or .command file to handle BatchMain runs vs. RepastMain runs, you will also want to alter the files used by the installer to build the standalone installer package.  Unless you alter those files, Repast will not know to include your new .batch file in the standalone installer package it builds.

If the new .batch or .command has a different name….

=> installer/installation_coordinator.xml

Add the third line below to the file at the appropriate place (around line 34):

<include name="installer/start_model.bat" />
<include name="installer/start_model.command" />
<include name="installer/yourNewBatchRunFile.fileType" />

=> installer/installation_components.xml

Add the sixth line below at the appropriate place in the file (around line 87):

<packs>
<pack name="Model" required="yes">
<description>The core model files</description>
<file src="repast.simphony.bin_and_src_$REPAST_VERSION/temp/installer/start_model.bat" 
 targetdir="$INSTALL_PATH"/>
<file src="repast.simphony.bin_and_src_$REPAST_VERSION/temp/installer/start_model.command" 
 targetdir="$INSTALL_PATH"/>
<file src="repast.simphony.bin_and_src_$REPAST_VERSION/temp/installer/yourNewBatchRunFile.fileType" 
 targetdir="$INSTALL_PATH"/>

With those two files modified, any future exports of the model will include your new .batch or .command file as well.


Updated 2012-07-28.

Repast Simphony: Hide the integrated tool buttons in the runtime environment

I wanted to configure the runtime environment to get rid of the extraneous tool buttons near the top, since I’m not launching those tools from within Repast (and they aren’t much use anyway).

With thanks again to Nick Collier for the suggestion, the right way to hide most of the tool buttons along the top of screen near the reset button is to rename the file plugin_jpf.xml to something else in the each of the directories that you want the tool button to disappear for:

  • JUNG: repast.simphony\repast.simphony.jung_1.2.0
  • MATLAB: repast.simphony\repast.simphony.matlab_1.2.0
  • VisAD: repast.simphony\repast.simphony.visad_1.2.0
  • Weka: repast.simphony\repast.simphony.weka_1.2.0
  • R: repast.simphony\repast.simphony.R_1.2.0
  • Spreadsheet: repast.simphony\repast.simphony.spreadsheet_1.2.0
  • iReport: repast.simphony\repast.simphony.iReport_1.2.0

The leaves you with the “Export geography layers to a shapefile” button.  That one’s a bit harder — you have to actually edit one of the plugin_jpf.xml files.  To remove that last button, open up repast.simphony\repast.simphony.gui\_1.2.0\plugin\_jpf.xml in an editor.

Near the bottom, replace the following lines:

<parameter id="actionSpec">

<parameter id="actionID" value="repast.simphony.ui.gis.ShowExportDialog"/>
<parameter id="label" value="&amp;Export Geography Layers"/>
<parameter id="class" value="repast.simphony.ui.gis.ShowExportDialog"/>
<parameter id="icon" value="nfs_mount.png"/>
<parameter id="menuID" value="repast.simphony.ui.tools_menu"/>
<parameter id="groupID" value="runTools"/>
<parameter id="tooltip" value="Export geography layers to a shapefile"/>

</parameter>

with:

<parameter id="actionSpec">

<!-- ORIGINAL
<parameter id="actionID" value="repast.simphony.ui.gis.ShowExportDialog"/>
<parameter id="label" value="&amp;Export Geography Layers"/>
<parameter id="class" value="repast.simphony.ui.gis.ShowExportDialog"/>
<parameter id="icon" value="nfs_mount.png"/>
<parameter id="menuID" value="repast.simphony.ui.tools_menu"/>
<parameter id="groupID" value="runTools"/>
<parameter id="tooltip" value="Export geography layers to a shapefile"/>
-->
<!-- to avoid displaying the Export to Shapefile button -->
<parameter id="actionID" value=""/>
<parameter id="class" value="repast.simphony.ui.gis.ShowExportDialog"/>
<parameter id="menuID" value="repast.simphony.ui.tools_menu"/>
<parameter id="groupID" value="runTools"/>

</parameter>

If you remove the entire parent entry actionSpec, your model won’t run at all. Removing too many parameters from the inside that the actionSpec parameter makes Repast complain. If you get rid of the user-assistance items like button images and tooltips, the text set as the actionID will still form a working (ugly) button. The above approach removes the least amount you can remove to get rid of the visual cues.