Logout succeed
Logout succeed. See you again!

The AMPL Modeling Language PDF
Preview The AMPL Modeling Language
3rd Int’l Conf. on Numerical Analysis and Optimization Sultan Qaboos University, Muscat, Oman, 5–9 Jan. 2014 The AMPL Modeling Language — an Aid to Formulating and Solving Optimization Problems David M. Gay AMPL Optimization, Inc. [email protected] http://www.ampl.com 1 AMPL summary AMPL: a language for mathematical programming problems, e.g., minimize f (x) s.t. ℓ ≤ c(x) ≤ u, Rn Rn Rm with x ∈ and c : → given algebraically and some x discrete. i 2 AMPL goals • Easy transcription from math (avoid mistakes) •• Explicit indexing (no hidden magic) • Declare before use (one-pass reading) • Separate model, data, commands (orthogonality) • Separate solvers (open solver interface) • Update entities as needed (lazy eval.) ... • Builtin math. prog. stuff (presolve, red. costs, ) • Aim for large scale nonlinear (sparsity, generality) 3 AMPL history • Early 1980’s: little languages at Bell Labs • 1983: Fourer’s TOMS paper, ML’s vs MG’s • 1984: Karmarkar hoopla begins • 1985–6: Fourer sabbatical at Bell Labs • 1987: AMPL CSTR (Fourer, Gay, Kernighan) • Late 1980’s: reimplementation; extensions begin • 1993: 1st edition of AMPL book • 2001: collapse of Bell Labs • 2003: 2nd edition of AMPL book; dmg → Sandia • 2010: dmg → AMPL Optimization 4 Simple declarations, commands ampl: param p; ampl: param q = p + 10; ampl: data; param p := 2.5; ampl data: display p, q; p = 2.5 q = 12.5 ampl: let p := 17; display p, q; p = 17 q = 27 5 Simple sets ampl: set A; set B; ampl: set C = p .. q; ampl: display A; Error executing "display" command: no data for set A ampl: data; set A := a b c; set B := c d; ampl data: display A, B, C; set A := a b c; set B := c d; set C := 17 18 19 20 21 22 23 24 25 26 27; 6 Simple set operations ampl: display A intersect B, A union B; set A inter B := c; set A union B := a b c d; ampl: display A diff B, A symdiff B; set A diff B := a b; set A symdiff B := a b d; 7 Iterated expressions, declarations ampl: print sum {i in 1..4} i; 10 ampl: print prod {i in 1..4} i; 24 ampl: param fac{ i in 1..9 } ampl? = if i == 1 then 1 else i*fac[i-1]; ampl: print max{i in 1..9} ampl? abs(fac[i] - prod{j in 2..i} j); 0 8 More iterated commands ampl: display fac, {i in 1..9} prod{j in 2..i} j; : fac prod{j in 2 .. i} j := 1 1 1 2 2 2 3 6 6 4 24 24 5 120 120 6 720 720 7 5040 5040 8 40320 40320 9 362880 362880 ; 9 Example model: diet.mod set NUTR; set FOOD; param cost {FOOD} > 0; param f_min {FOOD} >= 0; param f_max {j in FOOD} >= f_min[j]; param n_min {NUTR} >= 0; param n_max {i in NUTR} >= n_min[i]; param amt {NUTR,FOOD} >= 0; var Buy {j in FOOD} >= f_min[j], <= f_max[j]; minimize Total_Cost: sum {j in FOOD} cost[j] * Buy[j]; subject to Diet {i in NUTR}: n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <= n_max[i]; 10