AMPL (and AMPL home page)

AMPL (A Mathematical Programming Modeling Language) is a popular mathematical modeling software that can be used to formulate and solve linear, integer and nonlinear programming problems.

Obtaining AMPL

There are three four possible ways you can get hold of this software:

Download Trial Version

A free version of AMPL for Windows can be downloaded from here. The Mac version is here (please see installation instructions of the Mac version below). The trial version is limited in the size of the problem it can solve. It should suffice for most of your needs, but is likely to be insufficient for the project(s), one of which will involve integer optimization.

Full version

The full version of AMPL, along with the Gurobi solver, is installed on both the fe03.student.math Linux server and the Windows machines in the Nexus labs (MC 3006, MC 3008, MC 3009, MC 3010) and all University of Waterloo math students should have access to these.
AMPL is a licensed software, and each machine/server that is running a copy of AMPL uses up an AMPL license. This means that each user physically running AMPL on a machine in the Nexus labs will use up an AMPL license. Instead, you are strongly encouraged to access AMPL by connecting to fe03.student.math, or by connecting remotely to mef-nts.math.uwaterloo.ca using Remote Desktop on Windows.

Full version: Nexus Labs

As mentioned above, the full version of AMPL, along with the Gurobi solver, is available on the machines in MC 3006, MC 3008, MC 3009, MC 3010. You can also login remotely to use AMPL by using Remote Desktop on a Windows machine to log on to mef-nts.math.uwaterloo.ca. (Note: There is no shortcut on the "All Programs" menu for AMPL; you need to use the command prompt to invoke AMPL as described below.)
Unlike the trial version of AMPL which automatically uses the solver MINOS, you will need to instruct AMPL it to use the Gurobi solver, as shown below.

Suppose you want to solve the LP model prod0.mod. Then do the following:
  1. Make sure that the file prod0.mod is in your current directory. Start AMPL by typing
    ampl
    at the command prompt. (The AMPL directory should already be in your path.) On your screen you should now see the prompt ampl: .
  2. Instruct AMPL to use the Gurobi solver by typing
    option solver gurobi_ampl;
  3. Load the model by typing
    model prod0.mod;
  4. Finally solve the model by typing
    solve;
  5. You can check whether this worked by displaying the value of one of the variables:
    display XB;
    Executing this command should produce the output 6000 .
  6. Here is a transcript of the above procedure:
    Microsoft Windows [Version 5.2.3790]
    (C) Copyright 1985-2003 Microsoft Corp.
    
    N:\>cd NexusMyDocuments\co327
    
    N:\NexusMyDocuments\co327>dir
     Volume in drive N is CIFS.HOMEDIR
     Volume Serial Number is 0000-0000
    
     Directory of N:\NexusMyDocuments\co327
    
    04/05/2011  03:45 PM     DIR           .
    04/05/2011  02:42 PM     DIR           ..
    03/05/2011  09:45 AM         1,163,776 lecture1.ppt
    04/05/2011  03:45 PM               184 prod0.mod
                   2 File(s)      1,163,960 bytes
    
    N:\NexusMyDocuments\co327>ampl
    ampl: option solver gurobi_ampl;
    ampl: model prod0.mod;
    ampl: solve;
    Gurobi 4.0.0: optimal solution; objective 192000
    1 simplex iterations
    ampl: display XB;
    XB = 6000
    
    ampl: quit 

Full version: fe03.student.math

The full version of AMPL is also available on the fe03.student.math Linux server. To access AMPL and Gurobi the directories containing the exectuable files need to be on your path. This should be there by default. (Currently, i.e., Oct 13 2011, they are in "/usr/local/bin" "/software/.admin/bins/bin/". If, for some reason this is not on your default path, you can add this to your path by typing "setenv PATH $PATH\:/software/.admin/bins/bin/" at the command prompt.) Once AMPL and Gurobi are in your path, you can follow the same sequence of steps described above to load AMPL and solve prod0.mod using AMPL. Again, make sure that prod0.mod is in your current directory. Some links to primers on UNIX have been posted under the Announcements tab to help familiarize you with UNIX/Linux.

NEOS Server

The NEOS server is a free optimization engine that can solve several problems written in the AMPL language. It has no limits on the size of the problem. Suppose you want to solve prod0.mod , which is a linear programming problem. Go to the NEOS website , select any solver that takes AMPL input (e.g., MOSEK ), upload the model prod0.mod, and a simple command file like prod0.cmd and hit the solve button! The solution output file can also be emailed to you if you offer your email address.

Macs

You can download the Mac OSX version of AMPL from the AMPL website. A direct link is here .

You'll also need to get one of the solvers, which are listed farther down the page. There is no CPLEX solver for Mac OSX, but lp_solve seemed to work fine.

If you double click on the ampl.gz and lpsolve.gz files, they will unzip themselves to the ampl and lpsolve programs you need. Make sure that all the unzipped files are in the same folder.

Put the model and data files in that same folder as the one containing the ampl and lpsolve programs.

You will need to open a Terminal window at this point. The Terminal application can be found in the Utilities folder, inside the Computer's Applications folder. Double clicking on this will open a command-line or terminal window.

You need to get into the folder where you put the ampl and lpsolve programs. If you named that folder CO370, for example, and it's on your desktop, then type:

cd Desktop/CO370
(and hit return.)

If the folder is named Assignment1, in your Documents folder:

cd Documents/Assignment1

Type "ls", and hit return. You should see a list of all the files in the folder, namely ampl, lpsolve, and the model and data files.

In order to tell OSX that you want to be able to run these programs, you need to make them executable. Type:

chmod +x ampl lpsolve

You can then run ampl:

./ampl

At the ampl prompt, you can then load the model and data, and set the solver, and solve the system:


~/Desktop/CO327 $ ./ampl  
return 2 from
NSCreateObjectFileImageFromFile("/Users/elbie/Desktop/CO327/amplfunc.dll")

ampl: model prod0.mod; ampl: option solver "./lpsolve"; ampl: solve; LP_SOLVE 4.0.1.0: optimal, objective 19200 2 simplex iterations ampl: quit; ~/Desktop/CO327 $

You can ignore the "NSCreateObjectFileImageFromFile" error, if you get it.

Documentation

The first chapter of a book on AMPL by Fourer, Gay and Kernighan is available freely for download: [pdf]. The chapter provides an excellent introduction to the modeling capabilities of the software. The entire book is available on reserve at the DC library.
Additionally, here is a tutorial on AMPL that might be helpful.

Also take a look at the AMPL FAQ, which contains various pieces of useful information.