

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Math364 - March 3, 2005 1
Details of how to download and start up the student version of AMPL are given in http://www.ampl.com. Download and install AMPL in your PC (if you do not have a PC, you can submit your models on-line at the above web page, but this procedure is rather inconvenient). To solve problems using AMPL, you will also have to download a solver (such as CPLEX). For Windows, the solver is included in the zip file that you download (amplcml.zip). For Unix/Linux, you need to download cplex separately (details are given in the web page too). Cplex is the preferred solver.
The first chapter from the AMPL book is available as a PDF document from the above web page. Go through the first chapter in detail. You can also borrow the book from me for additional reference.
AMPL Basics
You need to create a model file (for example FarmerJones.mod) and a data file (FarmerJones.dat). The model file declares the parameters, the variables, objective function, and the constraints in a symbolic fashion. All the numbers (actual data) are provided in the data file. Note the following.
Example: The Farmer Jones problem
Model file: FarmerJones.mod
set Crops; # corn, wheat param Yield {j in Crops}; # yield per acre param Labor {j in Crops}; # labor hrs per acre param Price {j in Crops}; # selling price per bushel param Min_Crop {j in Crops}; # min levels of corn and wheat (bushels) param Max_Acres; # total land available (acres) param Max_Hours; # total labor hrs available
var x {j in Crops} >= 0; # x[corn] = acres of corn, x[wheat] = acres of wheat
maximize total_revenue: sum {j in Crops} Price[j]Yield[j]x[j];
subject to land_constraint: sum {j in Crops} x[j] <= Max_Acres; subject to labor_constraint: sum {j in Crops} Labor[j]x[j] <= Max_Hours; subject to min_crop_constraint {j in Crops}: Yield[j]x[j] >= Min_Crop[j];
Math364 - March 3, 2005 2
Data file: FarmerJones.dat
set Crops := corn wheat;
param Yield := corn 10 wheat 25;
param Labor := corn 4 wheat 10;
param Price := corn 3 wheat 4;
param Min_Crop := corn 30 wheat 0; # No minimum level specified for wheat
param Max_Acres := 7; param Max_Hours := 40;
Output from AMPL session
sw: ampl ampl: option solver cplex; ampl: model FarmerJones.mod; data FarmerJones.dat; ampl: expand land_constraint; subject to land_constraint: x[’corn’] + x[’wheat’] <= 7;
ampl: expand min_crop_constraint; subject to min_crop_constraint[’corn’]: 10*x[’corn’] >= 30;
subject to min_crop_constraint[’wheat’]: 25*x[’wheat’] >= 0;
ampl: solve; CPLEX 8.0.0: optimal solution; objective 370 1 dual simplex iterations (1 in phase I) ampl: display x; x [*] := corn 3 wheat 2. ;
ampl: display total_revenue; total_revenue = 370
ampl: