Subsections

## Using IPOPT through AMPL

Using the AMPL solver executable is by far the easiest way to solve a problem with IPOPT. The user must simply formulate the problem in AMPL syntax, and solve the problem through the AMPL environment. There are drawbacks, however. AMPL is a 3rd party package and, as such, must be appropriately licensed (a free student version for limited problem size is available from the AMPL website, http://www.ampl.com). Furthermore, the AMPL environment may be prohibitive for very large problems. Nevertheless, formulating the problem in AMPL is straightforward and even for large problems, it is often used as a prototyping tool before using one of the code interfaces.

This tutorial is not intended as a guide to formulating models in AMPL. If you are not already familiar with AMPL, please consult [3].

The problem presented in equations (4)-(8) can be solved with IPOPT with the following AMPL model.

```# tell ampl to use the ipopt executable as a solver
# make sure ipopt is in the path!
option solver ipopt;

# declare the variables and their bounds,
# set notation could be used, but this is straightforward
var x1 >= 1, <= 5;
var x2 >= 1, <= 5;
var x3 >= 1, <= 5;
var x4 >= 1, <= 5;

# specify the objective function
minimize obj:
x1 * x4 * (x1 + x2 + x3) + x3;

# specify the constraints
s.t.
inequality:
x1 * x2 * x3 * x4 >= 25;

equality:
x1^2 + x2^2 + x3^2 +x4^2 = 40;

# specify the starting point
let x1 := 1;
let x2 := 5;
let x3 := 5;
let x4 := 1;

# solve the problem
solve;

# print the solution
display x1;
display x2;
display x3;
display x4;
```

The line, ``option solver ipopt;'' tells AMPL to use IPOPT as the solver. The IPOPT executable (installed in Section 2.4) must be in the PATH for AMPL to find it. The remaining lines specify the problem in AMPL format. The problem can now be solved by starting AMPL and loading the mod file:

```\$ ampl
> model hs071_ampl.mod;
.
.
.
```
The problem will be solved using IPOPT and the solution will be displayed.

At this point, AMPL users may wish to skip the sections about interfacing with code, but should read Section 5 concerning IPOPT options, and Section 6 which explains the output displayed by IPOPT.

### Using IPOPT from the command line

It is possible to solve AMPL problems with IPOPT directly from the command line. However, this requires a file in format .nl produced by ampl. If you have a model and data loaded in Ampl, you can create the corresponding .nl file with name, say, myprob.nl by using the Ampl command:

write gmyprob

There is a small .nl file available in the IPOPT distribution. It is located at Ipopt/test/mytoy.nl. We use this file in the remainder of this section. We assume that the file mytoy.nl is in the current directory and that the command ipopt is a shortcut for running the ipopt binary available in the bin directory of the installation of IPOPT.

We list below commands to perform basic tasks from the Linux prompt.

• To solve mytoy.nl from the Linux prompt, use:

ipopt mytoy

• To see all command line options for IPOPT, use:

ipopt -=

• To see more detailed information on all options for IPOPT:

ipopt mytoy 'print_options_documentation yes'

• To run ipopt, setting the maximum number of iterations to 2 and print level to 4:

ipopt mytoy 'max_iter 2 print_level 4'

If many options are to be set, they can be collected in a file ipopt.opt that is automatically read by IPOPT if present in the current directory, see Section 5.