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.
There are three possible ways you can get hold of this software:
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 project 2, which will be integer optimization.
On Feb 28, 2011:
Gurobi 4.0 and AMPL V20101113 have been installed on all nexus machines
(including Terminal servers). This means that AMPL and Gurobi 4.0 can
be used from MC3006, MC3009, MC3008, and MC3010. You can use remote desktop
to mef-nts.math.uwaterloo.ca to use them (mstsc in search box on a
PC/laptop).
You can also logon to fe03.student.math.uwaterloo.ca for ampl.
Note: there is no shortcut on the "All programs" menu for AMPL, you
need to use command prompt to invoke AMPL. (Also, use:
option solver gurobi_ampl.)
AMPL is available on the machines in the MC 3006 and MC 3009 Nexus Labs and all University of Waterloo math students should have access to this. Suppose you want to solve the LP model prod0.mod . Then do the following:
amplat the command prompt. (You should NOT be in the AMPL directory. You should start AMPL from the command line, i.e. after using cmd with the start button.) On your screen you should now see the prompt ampl: .
model prod0.mod;
solve;
display XB;Executing this command should produce the output 6000 .
ampl: option solver gurobi_ampl; ampl: model prod0.mod; ampl: solve; Gurobi 2.0.1: optimal solution; objective 192000 1 simplex iterations ampl: display XB; XB = 6000
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.
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 (the AMPL model and data files, gtcrev.mod and gtcrev.dat can be found in AMPL folder ):
~/Desktop/CO370 $ ./ampl
return 2 from
NSCreateObjectFileImageFromFile("/Users/elbie/Desktop/CO370/amplfunc.dll")
ampl: model gtcrev.mod;
ampl: data gtcrev.dat;
ampl: option solver "./lpsolve";
ampl: solve;
LP_SOLVE 4.0.1.0: optimal, objective 2460
2 simplex iterations
ampl: quit;
~/Desktop/CO370 $
You can ignore the "NSCreateObjectFileImageFromFile" error, if you get it.
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.
Also take a look at the AMPL FAQ, which contains various pieces of
useful information.
(An
online AMPL Syntax is available.)