Prev Next

Nonlinear Programming Using Ipopt and CppAD

Syntax
# include "ipopt_cppad_nlp.hpp"
# ipopt_cppad_solution solution;
ipopt_cppad_nlp cppad_nlp(
     
nmx_ix_lx_ug_lg_u, &fg_adretape, &solution
)


Purpose
The class ipopt_cppad_nlp is used to solve nonlinear programming problems of the form  \[
\begin{array}{rll}
{\rm minimize}      & f(x) 
\\
{\rm subject \; to} & g_l \leq g(x) \leq g_u
\\
                    & x_l  \leq x   \leq x_u
\end{array}
\] 
This is done using Ipopt optimizer and CppAD Algorithmic Differentiation package.

Warning
This is only and example use of CppAD. It is expected that this class will be improved and that its user interface may change in ways that are not backward compatible.

NumberVector
The type NumberVector is defined by the ipopt_cppad_nlp.hpp include file to be a SimpleVector class with elements of type Ipopt::Number.

ADNumber
The type ADNumber is defined by the ipopt_cppad_nlp.hpp include file to be a an AD type that can be used to compute derivatives.

ADVector
The type ADVector is defined by the ipopt_cppad_nlp.hpp include file to be a SimpleVector class with elements of type ADNumber.

n
The argument n has prototype
     Ipopt::Index 
n
It specifies the dimension of the argument space; i.e.,  x \in \R^n .

m
The argument m has prototype
     Ipopt::Index 
m
It specifies the dimension of the range space for  g ; i.e.,  g : \R^n \rightarrow \R^m .

x_i
The argument x_i has prototype
     const NumberVector& 
x_i
and its size is equal to  n . It specifies the initial point where Ipopt starts the optimization process.

x_l
The argument x_l has prototype
     const NumberVector& 
x_l
and its size is equal to  n . It specifies the lower limits for the argument in the optimization problem.

x_u
The argument x_u has prototype
     const NumberVector& 
x_u
and its size is equal to  n . It specifies the upper limits for the argument in the optimization problem.

g_l
The argument g_l has prototype
     const NumberVector& 
g_l
and its size is equal to  m . It specifies the lower limits for the constraints in the optimization problem.

g_u
The argument g_u has prototype
     const NumberVector& 
g_u
and its size is equal to  n . It specifies the upper limits for the constraints in the optimization problem.

fg_ad
The argument fg_ad has prototype
     ADVector 
fg_ad(const ADVector& x);
This function computes the value of  f(x) and  g(x) using the syntax
     
fg = fg_ad(x)

x
The fg_ad argument x has prototype
     const ADVector& 
x
and its size is equal to  n . It is the value of  x at which to compute fg .

fg
The fg_ad return value fg has prototype
     ADVector& 
fg
and its size is equal to  m+1 . It is the vector of  ( f(x) , g(x) ) ; i.e.,  \[
\begin{array}{rcl}
     f(x)        & = &        fg[0] \\
     g_0 (x)     & = &        fg[1] \\
                 & \vdots &         \\
     g_{m-1} (x) & = &        fg[m]
     \end{array}
\] 


retape
This argument has the prototype
        bool 
retape
If retape is true, ipopt_cppad_nlp will retape the operation sequence for every new x value. The program should use much less memory and run faster if retape is false. You can test both the true and false cases to make sure the operation sequence does not depend on x.

solution
After the optimization process is completed, solution contains the following information:

status
The status field of solution has prototype
     ipopt_cppad_solution::solution_status 
solution.status
It is the final Ipopt status for the optimizer. Here is a list of the possible values for the status:
status Meaning
not_defined The optimizer did not return a final status to this ipopt_cppad_nlp object.
unknown The status returned by the optimizer is not defined in the Ipopt documentation for finalize_solution.
success Algorithm terminated successfully at a point satisfying the convergence tolerances (see Ipopt options).
maxiter_exceeded The maximum number of iterations was exceeded (see Ipopt options).
stop_at_tiny_step Algorithm terminated because progress was very slow.
stop_at_acceptable_point Algorithm stopped at a point that was converged, not to the 'desired' tolerances, but to 'acceptable' tolerances (see Ipopt options).
local_infeasibility Algorithm converged to a non-feasible point (problem may have no solution).
user_requested_stop This return value should not happen.
diverging_iterates It the iterates are diverging.
restoration_failure Restoration phase failed, algorithm doesn't know how to proceed.
error_in_step_computation An unrecoverable error occurred while Ipopt tried to compute the search direction.
invalid_number_detected Algorithm received an invalid number (such as nan or inf) from the users function fg_ad or from the CppAD evaluations of its derivatives (see the Ipopt option check_derivatives_for_naninf).
internal_error An unknown Ipopt internal error occurred. Contact the Ipopt authors through the mailing list.

x
The x field of solution has prototype
     NumberVector 
solution.x
and its size is equal to  n . It is the final  x value for the optimizer.

z_l
The z_l field of solution has prototype
     NumberVector 
solution.z_l
and its size is equal to  n . It is the final Lagrange multipliers for the lower bounds on  x .

z_u
The z_u field of solution has prototype
     NumberVector 
solution.z_u
and its size is equal to  n . It is the final Lagrange multipliers for the upper bounds on  x .

g
The g field of solution has prototype
     NumberVector 
solution.g
and its size is equal to  m . It is the final value for the constraint function  g(x) .

lambda
The lambda field of solution has prototype
     NumberVector 
solution.lambda
and its size is equal to  m . It is the final value for the Lagrange multipliers corresponding to the constraint function.

obj_value
The obj_value field of solution has prototype
     Number 
solution.obj_value
It is the final value of the objective function  f(x) .

Example
The file ipopt_cppad.cpp is an example and test of ipopt_cppad_nlp. It returns true if it succeeds and false otherwise.
Input File: example/ipopt_cppad_nlp.hpp