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 four possible ways you can get hold of this software:
amplat the command prompt. (The AMPL directory should already be in your path.) On your screen you should now see the prompt ampl: .
option solver gurobi_ampl;
model prod0.mod;
solve;
display XB;Executing this command should produce the output 6000 .
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
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:
~/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.
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.