Save a Case from an AIMMS Procedure

It can be convenient to save a case from within a procedure.

For example, let’s say you want to run multiple scenarios and store the result of each one to a separate case. One possible solution is to manually save a case after running each scenario. However, for several long-running scenarios, this is very tedious.

Instead, you can save cases automatically with a procedure. This way you can run a procedure that solves all your scenarios and saves cases after each solve, and let it run unattended. This is exemplified on Employee Scheduling example .

Writing the procedure

You can save a case in AIMMS using predefined case related functions.

To make it easier to save a case with any given name, you can introduce a new procedure, say pr_saveCase, with a string parameter sp_in_caseName as an input argument.

The body argument of the procedure should contain the following code:

 1Procedure pr_saveCase {
 2    Arguments: (sp_in_caseName);
 3    Body: {
 4        ! Save the case in the folder "data".
 5        if not DirectoryExists( "data" ) then
 6            DirectoryCreate("data");
 7        endif ;
 8        CaseFileSave("data\\" + sp_in_caseName + ".data", AllIdentifiers);
 9    }
10    StringParameter sp_in_caseName {
11        Property: Input;
12    }

Calling the procedure

To save a case with the name “Case 1” from within any of your procedures, you can call your procedure as follows:

1pr_saveCase("Case 1") ;

Upgrading an AIMMS project to a newer AIMMS release

If you still work with .dat files, please convert to .data first. You may want to follow the instructions in our conversation guide.