Search code examples
repast-simphony

Repast - call simulation from java program without GUI


I am following the instruction to test calling my simulation model from another java program.

package test;

//import repast.simphony.runtime.RepastMain;

public class UserMain {

public UserMain(){};

  public void start(){

    String[] args = new String[]{"D:\\user\\Repast_java\\IntraCity_Simulator\\IntraCity_Simulator.rs"};

    repast.simphony.runtime.RepastMain.main(args);
//    repast.simphony.runtime.RepastBatchMain.main(args);
  }

  public static void main(String[] args) {

    UserMain um = new UserMain();
    um.start();
  }
}

The java program will launch the GUI with the RepastMain configuration:

repast.simphony.runtime.RepastMain.main(args);

The java program will soon be terminated without running and returning nothing if I apply non-GUI configuration:

repast.simphony.runtime.RepastBatchMain.main(args);

enter image description here

How to enable the running of the simulation in headless mode?


SECONDLY, I need to deploy my simulation model on a remote server (Linux). What is the best way for the server to call my simulation model? if HTTP, how to perform the configuration subsequently? The running of the model is preferred to be batch run method (either a single run or multiple runs depending on the user choice). The batch run output needs to be transformed into JSON format to feedback to the server.


Solution

  • Parts of the batch run mechanism for Simphony can probably be used for this. For some context on headless command line batch runs, see:

    https://repast.github.io/docs/RepastBatchRunsGettingStarted.pdf

    That doesn't align exactly with what you are trying to do, given that you are embedding the simulation run in other java code, but should help as background.

    Ultimately, though the batch run code calls an InstanceRunner:

    https://github.com/Repast/repast.simphony/blob/master/repast.simphony.distributed.batch/src/repast/simphony/batch/InstanceRunner.java

    The InstanceRunner either iterates over a list of parameters sets in a file or parameter set strings passed to it directly and then performs a simulation run for each of those parameter sets. If you passed it a single parameter set, it would run once which I think is what you want to do. So, I would suggest looking at the InstanceRunner code to get a sense of how it works, and mimic InstanceRunner.main() in your code that calls the simulation.

    As for the remote execution, Simphony cancopy a simulation to a remote resource, run it and copy the results back. That's integrated with the Simphony GUI and so is not callable from other code without some work on your part. All the relevant code is in:

    https://github.com/Repast/repast.simphony/tree/master/repast.simphony.distributed.batch/src/repast/simphony/batch

    The SSHSession class has code for executing commands on a remote resource over SSH, methods for copying files and so on. So, perhaps that might be useful to you.