Tag: repast-simphony

Repast Simphony: FileNotFoundException upon saving model scenario

After creating new display items in the Repast runtime environment (a Data Set and a Chart) , I wanted to save the scenario so that Repast would remember to create these display items each time I ran the model.  (When you click the Save Button/diskette in the runtime environment, the display items currently in the Scenario Tree are saved and then will always automatically load with the model — it saves a lot of work in recreating displays.)

But each time I clicked the diskette to save the model, I got this file not found exception:

2010/07/28 15:27:59,640: Error while saving scenario
java.io.FileNotFoundException: C:\Program 
Files\RepastSimphony-1.2.0\workspace\yourModelName\yourModelName.rs\styles\.svn\all-wcprops (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(Unknown Source)
at java.io.FileOutputStream.(Unknown Source)
at repast.simphony.util.FileUtils.copyDirs(FileUtils.java:88)
at repast.simphony.util.FileUtils.copyDirs(FileUtils.java:81)
at repast.simphony.ui.RSApplication.doSave(RSApplication.java:420)
at repast.simphony.ui.RSApplication.save(RSApplication.java:376)
at repast.simphony.ui.action.SaveModel.actionPerformed(SaveModel.java:17)
(and so on)

And then suddenly my /yourModelName.rs/ folder (the one containing model.score) would be suddenly, horribly, inexplicably gone — which meant that running the model again was impossible until I reinstated it.  (Repast was renaming the directory to /yourModelName.rs.bak/ and renaming any existing .bak files to .bak0, .bak1, and so on.)

At first I thought that the problem was a case of Repast moving /yourModelName.rs/ in expectation of generating a new version from my current runtime settings in its place, and then trying to copy previous data from the old filename (that no longer existed) rather than the renamed .bak version, but this is actually not what was happening.  The FileNotFoundException wasn’t actually indicating a missing file (although by the time I got the exception, that file was indeed missing on that path)… it was indicating an unwriteable file.

In fact, for me, this was a Subversion-related problem.  I was able to fix it by unsetting the read-only attributes on my .svn folders and their files and subfolders (both /yourModelName.rs/.svn and /yourModelName.rs/styles/.svn).  I unchecked all the read-only checkboxes in the properties of those files.  And then, magically, I could save the model scenario.  Repast generated scenario.xml without any trouble once the .svn directory properties were changed.

I am unsure why this happened.  Repast hasn’t complained about the other .svn directories in the project (which are all still marked as read-only).  Other team members have not had this issue.  I was able to successfully save scenarios earlier this year.  But in any event, lesson learned and solution found.

Exposing data file paths in Repast

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.