AMPL Book Examples#
Use this page to download all the model, data, and script files that appear as examples in the AMPL book (second edition). You can download everything in one file:
zipfile
with line endings characteristic of Windowsgzipped tar file
with line endings characteristic of Unix
Or download individual files from our listings below, by filename or by figure number.
Book examples by filename#
Model file |
Figure |
Data file |
Figure |
Script file |
Figure |
---|---|---|---|---|---|
3-2 |
|||||
2-4 |
|||||
14-2 |
14-4 |
14-3 |
|||
14-6 |
|||||
2-1 |
2-2 |
||||
2-3 |
14-1 |
||||
2-3 |
|||||
5-1 |
5-2 |
||||
19-3 |
19-2 |
||||
19-1 |
|||||
19-4 |
|||||
19-5 |
|||||
16-2 |
|||||
16-3 |
|||||
16-1 |
|||||
17-9 |
|||||
4-1 |
4-2 |
||||
6-5 |
|||||
20-1a |
20-1b |
||||
20-2a |
20-2b |
||||
15-2a |
15-2b |
||||
15-10 |
|||||
15-3a |
15-3b |
||||
15-4a |
15-4b |
||||
15-11 |
|||||
15-9 |
|||||
15-14 |
|||||
15-6 |
|||||
15-12 |
|||||
16-6 |
|||||
15-13 |
|||||
15-7 |
|||||
15-15 |
|||||
18-4 |
18-5 |
||||
1-2 |
1-3 |
||||
16-4 |
16-5 |
||||
1-4a |
1-4b |
||||
1-5a |
1-5b |
||||
1-6a |
1-6b |
||||
4-6 |
4-7 |
||||
17-5a |
17-5b |
||||
4-3 |
|||||
4-4 |
4-5 |
13-1 |
|||
13-3 |
|||||
13-4 |
|||||
13-5 |
|||||
13-2 |
|||||
5-3 |
5-4 |
||||
6-3 |
6-4 |
||||
3-1a |
3-1b |
||||
6-1 |
|||||
6-2a |
6-2b |
Book examples by figure number#
Figure |
File |
---|---|
1-2 |
|
1-3 |
|
1-4a |
|
1-4b |
|
1-5a |
|
1-5b |
|
1-6a |
|
1-6b |
|
2-1 |
|
2-2 |
|
2-3 |
|
2-4 |
|
3-1a |
|
3-1b |
|
3-2 |
|
4-1 |
|
4-2 |
|
4-3 |
|
4-4 |
|
4-5 |
|
4-6 |
|
4-7 |
|
5-1 |
|
5-2 |
|
5-3 |
|
5-4 |
|
6-1 |
|
6-2a |
|
6-2b |
|
6-3 |
|
6-4 |
|
6-5 |
|
13-1 |
|
13-2 |
|
13-3 |
|
13-4 |
|
13-5 |
|
14-1 |
|
14-2 |
|
14-3 |
|
14-4 |
|
14-6 |
|
15-2a |
|
15-2b |
|
15-3a |
|
15-3b |
|
15-4a |
|
15-4b |
|
15-6 |
|
15-7 |
|
15-9 |
|
15-10 |
|
15-11 |
|
15-12 |
|
15-13 |
|
15-14 |
|
15-15 |
|
16-1 |
|
16-2 |
|
16-3 |
|
16-4 |
|
16-5 |
|
16-6 |
|
17-2 |
|
17-3a |
|
17-3b |
|
17-5a |
|
17-5b |
|
17-9 |
|
18-4 |
|
18-5 |
|
19-1 |
|
19-2 |
|
19-3 |
|
19-4 |
|
19-5 |
|
20-1a |
|
20-1b |
|
20-2a |
|
20-2b |
Additional Scripts: Looping and Testing - 1#
Writing “scripts” in the AMPL command language
All examples use steelT.mod as the model file and the steelT.dat as the data file.
Implements |
Script file |
---|---|
One pass of sensitivity analysis on avail[3] in the multi-period production problem (Section 4.2) |
|
Same as steelT.sa1 but split into two scripts, using the commands command |
|
Iterated sensitivity analysis, using contents of steelT.sa1a and steelT.sa1b within a for loop |
|
… also building a table of results |
|
… also using repeat until, and building up an index set for the table |
|
… also using if to record only those parameter values at which the dual price changes |
|
Binary search to find a breakpoint in the dual value |
|
… also handling the case of more than one breakpoint in the initial interval |
|
… also counting the extra breakpoints detected |
|
Sensitivity analysis using break and continue |
|
… also for each t, printing at the end of each pass |
|
… also for each t, storing all values until the end |
|
… also incorporating a break criterion requiring a named loop |
|
Data-specific script for a formatted table |
|
General script for formatted table, using a for loop |
|
… also with if statement to suppress printing of 100% |
Additional Scripts: Looping and Testing - 2#
Implementing algorithms through AMPL scripts
Implements |
Script |
Uses |
---|---|---|
Gilmore-Gomory column generation procedure for the cutting-stock (roll trim) problem |
||
Same as cut1.run, but using an alternative arrangement wherein problems are defined immediately before before their members are declared |
||
Same as cut1.run, but with better formatting of output |
||
Dantzig-Wolfe decomposition for a multi-commodity transportation problem, using a single subproblem |
||
Same as multi1.run, but using the same repeat loop for both phase I (infeasible) and phase II (feasible). |
||
Same as multi1.run, but using a separate subproblem for each product; subproblems are represented in AMPL by an indexed collection of named problems |
||
Same as multi2.run, except that the separate subproblems are realized by changing the data to a single AMPL named problem |
||
Benders decomposition for a stochastic programming variant of a multi-period production problem (see Exercise 4-5) |
||
Same as stoch1.run, but using a separate subproblem for each scenario; subproblems are represented in AMPL by an indexed collection of named problems |
||
Same as stoch2.run, except that the separate subproblems are realized by changing the data to a single AMPL named problem |
||
Benders decomposition for a location-transportation problem (original model in trnloc.mod) |
||
Same as trnloc2a.run, but model has upper limits on the Ship variables: LP relaxation bound is still poor, but subproblem does not have the integrality property and considerable improvement is made |
||
Same as trnloc2b.run, but model has 0-1 constraints disaggregated: LP relaxation bound is good, but subproblem has the integrality property and no further improvement can be made |
||
Lagrangian relaxation for a location-transportation problem: LP relaxation bound is poor, and subproblem has the integrality property so no improvement can be made |
Logic & Constraint Programming Examples#
This is a preliminary set of examples to offer some starting points for experimenting with AMPL’s “logic” and constraint programming interfaces. We welcome comments for improvements or other examples.
Represents |
Model File |
---|---|
Integer program for assignment of people of groups so that each group is “balanced” by various criteria. |
|
Constraint program for balanced assignment of people to groups, using the numberof operator. |
|
Model for map coloring using not-equals constraint. |
|
Integer program for the n queens problem: put n queens on an n-by-n chessboard so that no queen is attacking any other queen. |
|
Constraint program for the n queens problem, using the alldiff operator. |
|
Open-shop scheduling model using disjunctive constraints to avoid job and machine conflicts. |
|
Line up a group of people to maximize the number of adjacency preferences satisfied, modeling with alldiff, equivalence (<==>), and strict inequality (<) |
|
Hoist scheduling model using disjunctive constraints |
|
Model to solve instances of the 3 x 3 Sudoku problem, using the alldiff operator |
List of example files#
- assign.dat
- balAssign0.dat
- balAssign0.mod
- balAssign1.dat
- balAssign1.mod
- blend.mod
- cut.dat
- cut.mod
- cut.run
- cut1.mod
- cut1.run
- cut2.mod
- cut2.run
- cut3.run
- diet.dat
- diet.mod
- diet.run
- diet2.dat
- diet2a.dat
- dietu.dat
- dietu.mod
- econ.dat
- econ.mod
- econ2.dat
- econ2.mod
- econ2min.mod
- econmin.mod
- econnl.dat
- econnl.mod
- iocol1.mod
- iocol2.mod
- iorow.mod
- mapColoring.mod
- minmax.mod
- multi.dat
- multi.mod
- multi1.dat
- multi1.mod
- multi1.run
- multi1a.run
- multi2.dat
- multi2.mod
- multi2.run
- multi3.dat
- multi3.mod
- multi3.run
- multic.mod
- multmip1.dat
- multmip1.mod
- multmip2.dat
- multmip2.mod
- multmip3.dat
- multmip3.mod
- nQueens.mod
- nQueens0.mod
- net1.dat
- net1.mod
- net1node.mod
- net2.dat
- net2.mod
- net3.dat
- net3.mod
- net3node.mod
- netasgn.mod
- netfeeds.mod
- netmax.mod
- netmax3.mod
- netmcol.mod
- netmulti.mod
- netshort.mod
- netthru.mod
- nltrans.dat
- nltrans.mod
- nltransb.mod
- nltransc.mod
- nltransd.mod
- openShop.dat
- openShop.mod
- photo.mod
- photo11.dat
- photo9.dat
- prod.dat
- prod.mod
- prod0.mod
- sched.dat
- sched.mod
- singleHoist.mod
- singleHoist3.dat
- singleHoist4.dat
- steel.dat
- steel.mod
- steel2.dat
- steel3.dat
- steel3.mod
- steel4.dat
- steel4.mod
- steel4r.dat
- steel4r.mod
- steelP.dat
- steelP.mod
- steelT.dat
- steelT.mod
- steelT.sa1
- steelT.sa1a
- steelT.sa1b
- steelT.sa2
- steelT.sa3
- steelT.sa4
- steelT.sa5
- steelT.sa6
- steelT.sa6a
- steelT.sa6b
- steelT.sa7
- steelT.sa7a
- steelT.sa7b
- steelT.sa7c
- steelT.tab0
- steelT.tab1
- steelT.tab2
- steelT0.mod
- steelT2.dat
- steelT2.mod
- steelT3.dat
- steelT3.mod
- steelpl1.dat
- steelpl1.mod
- steelpl2.dat
- steelpl2.mod
- steelpl3.mod
- steelpl4.dat
- steelpl4.mod
- steelpl5.dat
- steelpl5.mod
- stoch.dat
- stoch1.mod
- stoch1.run
- stoch2.mod
- stoch2.run
- stoch3.mod
- stoch3.run
- sudoku.mod
- sudokuHard.dat
- sudokuVeryEasy.dat
- transp.dat
- transp.mod
- transp2.mod
- transp3.dat
- transp3.mod
- transpl1.mod
- transpl2.dat
- transpl2.mod
- trnloc.dat
- trnloc1.mod
- trnloc1.run
- trnloc2.dat
- trnloc2a.mod
- trnloc2a.run
- trnloc2b.mod
- trnloc2b.run
- trnloc2c.mod
- trnloc2c.run