How do you let the user specify the location of files in Repast?

To expose any variables to the user in Repast, the variables need to be specified as model parameters (not as, say, command line arguments).  When the model is set up that way, after the Repast modeling environment is launched but before the model itself begins to run, the user can change the paths to the data files for that particular run within the Parameters tab.

In practice, this means you first define a new set of attributes in the model.score file (one for each file).  Set SType as STRING.  Set the default path.  Then, to retrieve the user-provided values during a model run, you use the parameter access syntax (as used without previous explanation in the Repast Predator-Prey tutorial code):

This approach to letting the user select data input files is not nearly as robust as it should/could be.  It would be nice to launch a file chooser, for instance.  Additionally, although Repast lists “File” on the drop-down for SType, I haven’t been able to run anything with that type selected.  The internet has been massively unhelpful in explaining what Repast expects when you set SType to File, and now that the basic functionality needed is in the model and the to-do list has continued to grow, I just don’t feel up to reading the source code or bothering the Repast listserv on this particular issue…. But I am curious about the purpose of File as an SType.


Notes on Standalone Repast Runtime Models

This topic comes up because I recently built a runtime version of the Repast model I’m working on, according to the Build Installer instructions. As I quickly found out, the directory structure gets shuffled around during the build. As a result, as soon as the model is run from that new standalone installation, any hard-coded paths to files generate a NullPointerException. (And if those paths are fixed to work in the runtime environment, then the new paths will not continue to work in the development environment.) The easiest development-period fix was to allow the user to specify the location of all files — including GIS files so fundamental to the way the model operates that I hadn’t previously thought about exposing them.

Two more notes related to running the model as a standalone runtime version:

  • In the parameter setting screen, the current directory . is INSTALLNAME/yourModelName.  If you intend to keep the input data files there, congratulations!  If not, you’ll need to update the path accordingly.
  • Data files in the project’s root directory were ignored during Build Installer for me.  When I moved the data files to a /data folder parallel to /src, they were included as part of the installer.  The data files originally stored in /data installed into the INSTALLNAME/yourModelName/bin/data directory.