An Introduction to Ampl

Post date: Jan 25, 2011 5:31:06 AM

Through out the course we will be using AMPL as a modeling language for our mathematical models. Working with AMPL is very easy and intuitive. AMPL requires a working model file with .mod as extension. This model file will contain the mathematical model translated in AMPL syntax for the AMPL compiler. To support this model file, one would essentially requires a data file with .dat as extension. Combined these two one can solve a given problem using the AMPL solver. Note that one may just work the model file with variables expressed as they appear in the problem but this would lead to a non-reusable inflexible model file.

How to get AMPL?

  1. The student version is free to download at AMPL website.
  2. A simple but yet powerful web interface is also available at AMPL website.

How to use AMPL?

  1. Make a model file. (mymodelfile.mod)
  2. Make a supporting data file. (mydatafile.dat)
  3. Save them in AMPL directory.
  4. Load the model file using the command: model mymodelfile.mod;
  5. Load the data file using the command: data mydatafile.dat;
  6. Set the solver to be CPLEX using the command: option solver cplex;
  7. Solve the system using: solve;
  8. View the solution using: display _varname,_var;

To summarize:

sw: ampl

ampl: model mymodelfile.mod;

ampl: data mydatafile.dat;

ampl: option solver cplex;

ampl: solve;

ampl: display _varname,_var;

Note the semicolon (;) at the end of each command. Please refer to the documents attached at the end of the post for a more detailed version of AMPL intro and manual.