AMPL > >Faqs

Use AMPL’s shell command to invoke the editor you want to use. For example, if your editor is called `edit`

and your file is `diet2a.dat`

, give the command

shell "edit diet2a.dat";

The editor temporarily pops up (or takes over the screen or current window). When you quit the editor, the AMPL prompt reappears, and all models, data and options are as before.

When you have returned from the editor, AMPL cannot tell which files you have changed! Thus to use a changed file, you must reset and read it again. The simplest approach is to reset and re-read everything, as in this example:

ampl: shell "edit diet.mod"; ampl: reset; ampl: model diet.mod; ampl: data diet2a.dat;

In most circumstances, however, it’s easier to edit files in their own windows, separate from the windows where you’re running AMPL. Some editors can be configured with syntax highlighting specific to AMPL. You still need to reset and re-read after changing a file, though.

Use AMPL’s `reset data`

command to resample from all of the random-valued functions in the model. For example, in model steel4.mod from the AMPL book, suppose that parameter `avail`

is changed so that its value is given by a random function:

param avail_mean {STAGE} >= 0; param avail_variance {STAGE} >= 0; param avail {s in STAGE} := Normal (avail_mean[s], avail_variance[s]);

with corresponding data

param: avail_mean avail_variance := reheat 35 5 roll 40 2 ;

Then AMPL will take new samples from the Normal distribution after each `reset data`

:

ampl: model steel4.mod; ampl: data steel4.dat; ampl: solve; MINOS 5.4: optimal solution found. 3 iterations, objective 187632.2489 avail [*] := reheat 32.3504 roll 43.038 ; ampl: reset data avail; ampl: solve; MINOS 5.4: optimal solution found. 4 iterations, objective 158882.901 ampl: display avail; avail [*] := reheat 32.0306 roll 32.6855 ;

Using this feature together with one of AMPL’s looping commands, you can automatically solve a series of random realizations from the model, and summarize the results:

model steel4.mod; data steel4.dat; param nruns := 5; param optvalue {1..nruns}; for {k in 1..nruns} { reset data avail; solve; let optvalue[k] := Total_Profit; } display (sum {k in 1..nruns} optvalue[k]) / nruns;

If you use `reset`

rather than `reset data`

, then AMPL’s random number generator is reset, and the values of avail repeat from the beginning. To get a different sequence of random numbers from the generator, you must change the random number seed; give the command `option randseed n`

— where `n`

is a positive integer — or `option randseed 0`

to have AMPL choose a seed based on the system clock.

The `check`

conditions are evaluated each time that AMPL generates (or re-generates) an instance of your model. Normally the generation of an instance is triggered by a `solve`

command, but a few other commands such as `write`

and `solution`

can have the same effect.

You can force all `check`

statements to be evaluated immediately by typing the command

check;

or by inserting this command into an AMPL script at the point where you want the checking to occur.

You can use AMPL’s `write`

command to create a file that contains a representation of your linear or integer program in a standard format known as MPS form. To write an MPS-form file for the diet LP from Chapter 2 of the AMPL book, for example, you could proceed as follows:

ampl: model diet.mod; ampl: data diet2a.dat; ampl: option auxfiles rc; ampl: write mdiet2;

AMPL interprets `write m...`

as indicating that you want to write an MPS file, and creates the filename by appending `.mps`

to the letters after the `m`

. Thus our example creates a file named diet2.mps. The format of this file is explained in the Linear Programming FAQ and in the manuals for many solvers.

Because MPS form limits the row (constraint or objective) and column (variable) names to 8 characters, AMPL substitutes artificial names such as `R0001`

and `C0007`

. You can ask for supplementary files of the true AMPL component names, by also resetting option `auxfiles rc;`

in the above example, you would get files diet2.row and diet2.col. The ordering of the names in these files corresponds to their numbering in the MPS file. (For a more detailed description of `write`

and the `auxfiles`

option, see Sections A.18.3 and A.18.4 in the reference appendix to the AMPL book.)

An MPS file contains only the nonzero values that define one instance of your model. Thus an MPS file generated by AMPL is mainly useful as input to solvers that do not yet have a direct AMPL interface; because MPS form has been in use for a longer time than any comparable format, it is recognized by more solvers than any other file type. You may also find AMPL’s MPS-file option useful for generating new instances of test problems, for submission to libraries such as netlib’s lp/data or miplib. If you want to encourage people to use AMPL with your own solver, however, then you should consider hooking your solver to AMPL by use of AMPL’s file format, which takes less space, can be processed faster, represents numbers more accurately, and applies to a broader variety of optimization problems (especially nonlinear ones).

Several kinds of transformations may be applied by AMPL before it writes out any representation of your problem. Normally you need not be aware of these changes, because AMPL reverses them after receiving the optimal solution from the solver. If you write an MPS file, however, it will correspond to the transformed problem; its coefficients and other values may have been changed, it may lack some of the variables and constraints that you defined, or it may contain auxiliary variables and constraints that AMPL added. To get a summary of AMPL’s transformations, set `option show_stats 1`

. To force AMPL to write the MPS file for your problem as stated, turn off the transformations.

Representations of numbers in MPS form are limited to 12 characters. As a consequence, the numbers in an MPS file may not have the full precision of the numbers that were generated from your AMPL model and data. Usually these precision discrepancies are inconsequential, but they do give rise to inaccuracies in the optimal solution computed from the MPS file.

Although MPS form is regarded as a standard, it has no definitive statement. As a result, there are a few special cases that are treated differently by different solvers; examples include variables that have an upper bound of zero and no lower bound, and integer variables declared without any bounds. AMPL’s version of MPS form is designed to avoid using these unresolved default options, so that its MPS files can be compatible with as many solvers as possible. If using the MPS file gets you a significantly different optimal value from what you get by typing `solve`

, however, then check your solver’s definition of MPS form.

AMPL’s presolve phase attempts to transform your problem to an equivalent one that is smaller and easier to solve. Presolve first removes trivial model components, such as variables fixed at constant values and constraints that express simple lower or upper bounds. Then it applies an iterative procedure to tighten certain bounds on variables and constraints, with the result that additional variables may be fixed and constraints may be dropped. Many of these transformations are based on ideas first presented by A.L. Brearly, G. Mitra and H.P. Williams, in “Analysis of Mathematical Programming Problems Prior to Applying the Simplex Algorithm,” *Mathematical Programming* 8 (1975) 54-83. See also Experience with a Primal Presolve Algorithm for a detailed discussion of the implementation in AMPL.

If your model uses AMPL’s notation for piecewise-linear terms in individual variables, then AMPL transforms your problem’s piecewise-linear expressions to equivalent linear expressions, through the addition of auxiliary variables and constraints. Chapter 17 of the AMPL book describes the piecewise-linear notation in more detail. See also Expressing Special Structures in an Algebraic Modeling Language for Mathematical Programming for further discussion of how the transformation is carried out.

You can cause AMPL to eliminate certain variables from your problem, by substituting expressions specified in `var`

declarations or in certain constraints. If the substitution comes from a constraint, then the constraint is also eliminated. See Sections 18.2 and A.8.1 of the AMPL book for more information.

To suppress the presolve phase, set `option presolve 0`

.

To suppress transformation of piecewise-linear terms, set `option pl_linearize 0`

.

To suppress elimination of variables by substitution from constraints, set `option substout 0`

. (This is the default setting.) Substitutions specified within `var`

declarations are always applied.

To see a summary of transformations performed, set `option show_stats 1`

.

© 2013 AMPL Optimization inc. All rights reserved.
Web Development by Baytech Web Design