SolverStudio & AMPL

SolverStudio allows you to build and solve models using the excellent AMPL modelling language. It works with either a copy of AMPL you have purchased and installed, or you can install a copy of the student version of AMPL using the menu item  in SolverStudio’s AMPL menu. (The student version limitations have recently been increased, and are now 500 for linear problems and 300 for nonlinear ones.) SolverStudio also allows AMPL models to be solved using NEOS, as described here, and supports the open source GMPL modelling language that supports a subset of AMPL’s commands.

Instructors may wish to install the free time-limited “AMPL for courses” which works fine with SolverStudio, and has no problem size limitations.

As with the other languages, you type (or paste) your AMPL model directly into the SolverStudio editor in Excel. You then enter data for your AMPL sets and parameters into the spreadsheet, and define these as data items using SolverStudio’s Data Items editor. The data is then immediately available to AMPL using a special ‘data’ command (see below); you do not need to use AMPL’s database commands to access the spreadsheet data.

SolverStudio does not use an AMPL “.run” file, but instead the solve and display commands from the .run file go at the end of the SolverStudio model.

AMPL Tutorial: We have published a tutorial on using AMPL with SolverStudio.  We have also listed the key steps for building and solving an AMPL model next.

AMPL Model Construction in SolverStudio

In your AMPL model, declare your AMPL parameters, sets and variables in the normal way, but please include only one definition per line, such as:
set SUPPLY_NODES;
set DEMAND_NODES;
param Supply {SUPPLY_NODES} >= 0, integer;
param Demand {DEMAND_NODES} >= 0, integer;
param Cost {SUPPLY_NODES, DEMAND_NODES} default 0;
param Lower {SUPPLY_NODES, DEMAND_NODES}  integer default 0;
var Flow {i in SUPPLY_NODES, j in DEMAND_NODES}  >= Lower[i, j], <= Upper[i, j], integer;
var Build {SUPPLY_NODES} binary;

You will then need to define data items on the spreadsheet for each parameter and set that has data on the sheet, and each variable you wish to write to the sheet. The names of the data items should match those in your model.

Then include your model objective and constraints in the usual AMPL way.

Next, make sure that AMPL menu item “Fix Minor Errors” is ticked. This tells SolverStudio to automatically add a few more lines of AMPL code (that you don’t see) to get the data, solve the problem, and then write the solution back to the sheet.

Optional Steps: If you wish to have more control, you can add further lines as follows. (These are the extra lines that SolverStudio adds itself if “Fix Minor Errors” is ticked. If these lines are already present, SolverStudio won’t add them again, even if “Fix Minor Errors” is ticked.)

You can, optionally, add the following lines in your AMPL file after your AMPL model; these get the data from the sheet and solve the problem:
data SheetData.dat;
option solver cbc; # or another solver of your choice, eg ipopt
solve;

(Note: you can use the AMPL menu item “View Last Data File” to look at the contents of this “SheetData.dat” file which is created by SolverStudio to pass the data to AMPL.)

Next, include commands of the form “display <variable> > Sheet;” to write your results back to the spreadsheet. Use one line per variable, as in:
display Build > Sheet;
display Flow > Sheet;

Note: Older versions of SolverStudio required a line like “option display_1col 9999999;“. This is no longer needed.

Useful AMPL Links
Victor Zverovich’s posts on Using SCIP with AMPL & Constraint Programming in AMPL, and his AMPL repository Wiki including his Gecode and IlogCP interfaces for AMPL and AMPL support for the GNU Scientific Library (GSL) functions.
AMPL on NetLib with the AMPL Solver Library (source code for linking AMPL to different solvers such as Gurobi), sample models, table interface code, student download versions, etc
AMPL Google Group for help  on using AMPL.

Notes and Hints
“cplexamp”: Some of the AMPL examples have included the line “solver cplexamp”. Bob Fourer (personal communication, Jan 2013) has explained that third party suppliers of AMPL, in this case IBM/CPLEX, create their own names for the solver executables. This changes the name the user has to use in AMPL to reference the solver, in this case to “cplexamp” instead of the more normal “cplex”.

If “Fix minor errors” is on, then the output commands like “display Flow > Sheet;” are converted into “_display Flow > Sheet;” before AMPL is run.  Both of these display commands simply output to a file called “Sheet”. The “_display” command is preferred because SolverStudio can read the resulting output more reliably. Note that AMPL considers “sheet” and “Sheet” to be different files (even though this is not the case in Windows), which can result in data being lost if “… > Sheet” and “… > sheet” occur in the same AMPL file. SolverStudio will, if “Fix Minor Errors” is on, always use “Sheet” when converting “display Flow > Sheet;” regardless of the case used by the user. Thanks to Victor and David from AMPL for confirming this AMPL behaviour.

Advanced AMPL  Installations
SolverStudio works by looking for AMPL on the system PATH (i.e. looking for ampl.exe in a directory in the system PATH), or an envionment variable SolverStudio_AMPL_PATH that contains the full path to some user-installed ampl.exe, and runs this if it exists. Otherwise, it looks for …\SolverStudio\SolverStudio\AMPL\amplcml\ampl.exe, being a copy of AMPL SolverStudio has installed, and uses this. If both AMPL options exist, then the menu item Use SolverStudio’s AMPL Student Version can force SolverStudio to use the latter of these two.

SolverStudio will report the versions of AMPL found in its About box, as in:

AMPL Path (as installed by SolverStudio):
D:\Documents\Projects\SolverStudio\SolverStudio\SolverStudio\AMPL\amplcml\ampl.exe

AMPL Path (as installed separately outside SolverStudio):
C:\ILOG\amlpl110\AMPL110\ampl.exe

AMPL provide an unrestricted time-limited version of AMPL for use in teaching. As at 26/6/2013, I am not sure how the unrestricted student version of AMPL works. If the unrestricted student AMPL has an installer, and so adds its folder into the PATH system variable, then SolverStudio will find it. (Check this using the About box.) If you also install SolverStudio’s restricted version, the students will be able to choose between these two version using the “Use SolverStudio’s AMPL Student Version” menu item. If the unrestricted student AMPL does not have an installer (and from memory this is the case), then you should install your unrestricted student version into …\SolverStudio\SolverStudio\AMPL\amplcml, so that …\SolverStudio\SolverStudio\AMPL\amplcml\ampl.exe is the unrestricted AMPL executable. Then this will be the only version SolverStudio uses.

2 thoughts on “SolverStudio & AMPL

  1. FYI - similar to "cplexamp," If you are using the gurobi solver with AMPL (gurobi also has a free academic license), the call is "option solver gurobi_ampl"
  2. You may find that SolverStudio (v 0.09.02 or earlier) is not working with NEOS. NEOS have recently tweaked their systems, and so you need to edit RunGAMSNEOS.py or RunAMPLNEOS.py and change all lines with “time.sleep(1)” into “time.sleep(5)”. This will be fixed in the next release. Andrew

Leave a Reply

Your email address will not be published. Required fields are marked *