Sunday, March 6, 2011

AMPL:Tutorial

Installing AMPL

Windows users:
  1. Download the package amplcml.zip (this link is from the AMPL home page).
  2. Unzip the file amplcml.zip (double-click it).
  3. The unzipped amplcml/ folder contains, among others:
    • sw.exe: a command line interface;
    • ampl.exe: the true AMPL modeler;
    • cplex.exe: a solver for Linear and Integer Programming problems;
    • minos.exe: a solver for Nonlinear Programming problems.
  4. Create a new folder C:\Programs\AMPL (you may instead create the AMPL folder on the desktop, depending on your preference or if C:\Programs is read-only), and move all the files (the four above AND all the others) into the newly created AMPL folder.
  5. For your convenience, create a link to sw.exe and place it on your desktop.
  6. Double-click on sw.exe (either the link or the real file).
  7. A window appears with a prompt "sw:". Type "ampl". The AMPL prompt appears.
You can now enter your optimization model. Note: When using AMPL, the working directory is C:\Programs\AMPL or wherever you placed the sw.exe file. This means that, if you are using model files, you should place ALL these files in the same folder where sw.exe is located, otherwise you would have to specify the full path (e.g. model "C:\Documents and settings\pietro\Desktop\tin-can.mod").

Using AMPL

You can also create model files and data files with your favorite text editor (Notepad, WinEDT, etc.) and use the ampl prompt simply to specify model and data before solving the problem. Examples:
Notice: clicking on these .mod files may suggest Windows that these are music files. You may want to right-click on them and select "Save link as..." instead. In order to solve these models, start AMPL and type, at the prompt:
 ampl: model tin-can.mod;
Then set the proper solver for each problem (Minos for tin-can.mod and all Nonlinear Programming problems, Cplex for all Linear and Integer Programming problems).
 ampl: option solver minos;
(notice the ";" at the end of each command). Finally, give the "solve;" command to solve it:
 ampl: solve;
At this point, AMPL calls the Minos solver, and when Minos is done you will see again the AMPL prompt. At this point, if the solver did not encounter errors, you should be able to visualize the value of the variables:
 ampl: display radius, height;
http://coral.ie.lehigh.edu/~belotti/teaching/ampl/ampl.html

ampl: include branch_and_bound.run
reset

No comments:

Post a Comment