Repast – Pack and distribute the model as jar without GUI and source code

Previously I am working with an ABM model, which is now turning to be put into the production environment (embed it into an online platform system).

In order to do this, I have two important objectives to achieve:

  1. How to pack and distribute the model and the assiciated files to other people, in an aggragated way, preferably as one single jar file, which could be called easily and automatically by other program to run the simulation when needed. Running the model in headless mode is prefered. The repast GUI control window pop up should be avoided when calling and running the model. BTW:the current version of the model does not require the batch runs of different scenarios at the same time, only a single run each time needed.

  2. How to hide/obfuscate the source code of the model completely or at least partially, in order to secure my intellectual property assoicated with the model itself.


For 1, this isn’t ideal but you could essentially mimic what a single batch run does. It is not a single jar solution, but it is certainly the easiest way to do a single headless run. So,

  1. Create the complete_model.jar using the batch run GUI (Click the Create Model Archive for Batch runs button, second button from the right). This creates a jar file with everything needed to run the model.
  2. Make a directory into which the complete_model.jar will be unzipped.
  3. Copy the complete_model.jar to that directory.
  4. Extract that jar with jar -xf or just unzip it.
  5. Make an “instance” directory within the directory where you extracted the model

With all that in place, you should be able to run your model using repast.simphony.batch.InstanceRunner as the main class, using a shell script. On MacOS, that script would look something like:

cd instance
java -cp "../lib/*" repast.simphony.batch.InstanceRunner -pxml ../ -scenario ../ -id 1 -pinput param_line.txt

The param_line.txt file should be a single line with your model parameters in this format: RtP1tV1,P2tV2,... where R is a run number (i.e. 1), ‘t’ is a tab, P1 is the name of the first parameter, V1 is the value of the first parameter and so on.

More info about InstanceRunner arguments here:

What you’d give to people is a zipped copy of the top level directory and the model can be run by executing your shell script. Like I said, its not ideal, but its the only headless solution I can think of.

Source: stackoverflow