4

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.

Jack
  • 1,339
  • 1
  • 12
  • 31

1 Answers1

4

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.

Nick Collier
  • 1,786
  • 9
  • 10
  • thank you Nick. The InstanceRunner seems to be a lot complicated. I need to study the codes in details. Meanwhile, I am wondering if there is any other simpler alternatives to do the same work? For instance, ask the server to run the simulation model directly by calling a .bat file and run it in command line, with the batch run parameter set in a file (xml?). Would that give me a chance for quicker implementation? And I just run my other codes (mainly data input and output processing written in python) before and after the simulation.Thanks for advice – Jack Jan 07 '20 at 01:56
  • my another problem in this question is that I cannot start the batch run in java using repast.simphony.runtime.RepastBatchMain.main(args); --- where is wrong here? – Jack Jan 07 '20 at 02:05
  • In https://repast.github.io/docs/RepastBatchRunsGettingStarted.pdf section 9.3, we explain how to do a headless batch run from the command line. If your batch configuration consists of a single run, then that should work for you along the lines of your first comment. – Nick Collier Jan 08 '20 at 14:05
  • thanks a lot Nick. where is wrong in "repast.simphony.runtime.RepastBatchMain.main(args); " – Jack Jan 10 '20 at 08:06
  • Ah, sorry, I wasn't clear. We don't use RepastBatchMain any more for batch runs. Take a look at the doc referenced in my comment above for how to do a headless batch run. I'll also make a note to remove RepastBatchMain from the docs. – Nick Collier Jan 13 '20 at 13:59
  • Hi Nick, could you tell me which section or page I could refer to? In the document I did not find an alternative instruction to RepastBatchMain. – Jack Jan 16 '20 at 17:47
  • With some work, the InstanceRunner stuff I mentioned above would be a replacement for RepastBatchMain. Section 9.3 of the doc is not a replacement for RepastBatchMain, but does describe how to do a headless batch run from the command line, not in code. – Nick Collier Jan 17 '20 at 18:52
  • Is there a way in Java Code to call batch run like RepastMain? – Jack Jan 18 '20 at 11:41