![]() |
Prev | Next |
# include "ipopt_cppad_nlp.hpp"
# ipopt_cppad_solution solution;
ipopt_cppad_nlp cppad_nlp(
n, m, x_i, x_l, x_u, g_l, g_u, &fg_info, &solution
)
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.
fg : \R^n \rightarrow \R^{m+1}
is defined by
\[
\begin{array}{rcl}
fg_0 (x) & = & f(x) \\
fg_1 (x) & = & g_0 (x) \\
& \vdots & \\
fg_m (x) & = & g_{m-1} (x)
\end{array}
\]
I
is an index vector
|I|
is used to denote the
number of elements in
I
and
\| I \|
is used
to denote the value of the maximum element in
I
.
J
and a positive integer
n
where
n > \| J \|
, we use
J \otimes n
for
the mapping
( J \otimes n ) : \R^n \rightarrow \R^{|J|}
defined by
\[
[ J \otimes n ] (x)_j = x_{J(j)}
\]
for
j = 0 , \ldots |J| - 1
.
I
and a positive integer
m
where
m > \| I \|
, we use
m \otimes I
for
the mapping
( m \otimes I ): \R^{|I|} \rightarrow \R^m
defined by
\[
[ m \otimes I ] (y)_i = \left\{ \begin{array}{ll}
y_k & {\rm if} \; i = I(k) \; {\rm for \; some} \;
k \in \{ 0 , \cdots, |I|-1 \}
\\
0 & {\rm otherwise}
\end{array} \right.
\]
fg(x)
only depend on a few of the components of
x
.
In this case, expressing
fg(x)
in terms of simpler functions
with fewer arguments can greatly reduce the amount of work required
to compute its derivatives.
We use the functions
r_k : \R^{q(k)} \rightarrow \R^{p(k)}
for
k = 0 , \ldots , K
to express our
representation of
fg(x)
in terms of simpler functions
as follows
\[
fg(x) = \sum_{k=0}^{K-1} \; \sum_{\ell=0}^{L(k) - 1}
[ (m+1) \otimes I_{k,\ell} ] \; \circ
\; r_k \; \circ \; [ J_{k,\ell} \otimes n ] \; (x)
\]
where
\circ
represents function composition,
for
k = 0 , \ldots , K - 1
, and
\ell = 0 , \ldots , L(k)
,
I_{k,\ell}
and
J_{k,\ell}
are index vectors with
| J_{k,\ell} | = q(k)
,
\| J_{k,\ell} \| < n
,
| I_{k,\ell} | = p(k)
, and
\| I_{k,\ell} \| \leq m
.
r_0 (x) = fg(x)
,
K = 1
,
q(0) = n
,
p(0) = m+1
,
L(0) = 1
,
I_{0,0} = (0 , \ldots , m)
,
and
J_{0,0} = (0 , \ldots , n-1)
.
SizeVector
is defined by the
ipopt_cppad_nlp.hpp
include file to be a
SimpleVector
class with elements of type
size_t
.
NumberVector
is defined by the
ipopt_cppad_nlp.hpp
include file to be a
SimpleVector
class with elements of type
Ipopt::Number
.
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
is defined by the
ipopt_cppad_nlp.hpp
include file to be a
SimpleVector
class with elements of type
ADNumber
.
n
has prototype
size_t n
It specifies the dimension of the argument space;
i.e.,
x \in \R^n
.
m
has prototype
size_t m
It specifies the dimension of the range space for
g
;
i.e.,
g : \R^n \rightarrow \R^m
.
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
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;
i.e.,
x^l
.
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;
i.e.,
x^u
.
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;
i.e.,
g^l
.
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;
i.e.,
g^u
.
fg_info
has prototype
FG_info fg_info
where the class
FG_info
is derived from the
base class ipopt_cppad_fg_info
.
Certain virtual member functions of
fg_info
are used to
compute the value of
fg(x)
.
The specifications for these member functions are given below:
virtual size_t ipopt_cppad_fg_info::number_functions(void)
If
K
has type size_t
, the syntax
K = fg_info.number_functions()
sets
K
to the number of functions used in the
representation of
fg(x)
; i.e.,
K
in
the representation
above.
The ipopt_cppad_fg_info
implementation of this function
corresponds to the simple representation mentioned above; i.e.
K = 1
.
virtual ADVector ipopt_cppad_fg_info::eval_r(size_t k, const ADVector& u) = 0;
Thus it is a pure virtual function and must be defined in the
derived class
FG_info
.
This function computes the value of
r_k (u)
used in the representation
for
fg(x)
.
If
k
in
\{0 , \ldots , K-1 \}
has type size_t
,
u
is an ADVector
of size
q(k)
and
r
is an ADVector
of size
p(k)
the syntax
r = fg_info.eval_r(k, u)
set
r
to the vector
r_k (u)
.
virtual bool ipopt_cppad_fg_info::retape(size_t k)
If
k
in
\{0 , \ldots , K-1 \}
has type size_t
,
and
retape
has type bool
,
the syntax
retape = fg_info.retape(k)
sets
retape
to true or false.
If
retape
is true,
ipopt_cppad_nlp
will retape the operation sequence
corresponding to
r_k (u)
for
every value of
u
.
An ipopt_cppad_nlp
object
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
u
.
The ipopt_cppad_fg_info
implementation of this function
sets
retape
to true
(while slower it is also safer to always retape).
virtual size_t ipopt_cppad_fg_info::domain_size(size_t k)
If
k
in
\{0 , \ldots , K-1 \}
has type size_t
,
and
q
has type size_t
, the syntax
q = fg_info.domain_size(k)
sets
q
to the dimension of the domain space for
r_k (u)
;
i.e.,
q(k)
in
the representation
above.
The ipopt_cppad_h_base
implementation of this function
corresponds to the simple representation mentioned above; i.e.,
q = n
.
virtual size_t ipopt_cppad_fg_info::range_size(size_t k)
If
k
in
\{0 , \ldots , K-1 \}
has type size_t
,
and
p
has type size_t
, the syntax
p = fg_info.range_size(k)
sets
p
to the dimension of the range space for
r_k (u)
;
i.e.,
p(k)
in
the representation
above.
The ipopt_cppad_h_base
implementation of this function
corresponds to the simple representation mentioned above; i.e.,
p = m+1
.
virtual size_t ipopt_cppad_fg_info::number_terms(size_t k)
If
k
in
\{0 , \ldots , K-1 \}
has type size_t
,
and
L
has type size_t
, the syntax
L = fg_info.number_terms(k)
sets
L
to the number of terms in representation
for this value of
k
;
i.e.,
L(k)
in
the representation
above.
The ipopt_cppad_h_base
implementation of this function
corresponds to the simple representation mentioned above; i.e.,
L = 1
.
virtual void ipopt_cppad_fg_info::index(
size_t k, size_t ell, SizeVector& I, SizeVector& J
)
The argument
k
has type
size_t
and is a value between zero and
K-1
inclusive.
The argument
ell
has type
size_t
and is a value between zero and
L(k)-1
inclusive.
The argument
I
is a SimpleVector
with elements
of type size_t
and size greater than or equal to
p(k)
.
The input value of the elements of
I
does not matter.
The output value of
the first
p(k)
elements of
I
must be the corresponding elements of
I_{k,ell}
in the representation
above.
The argument
J
is a SimpleVector
with elements
of type size_t
and size greater than or equal to
q(k)
.
The input value of the elements of
J
does not matter.
The output value of
the first
q(k)
elements of
J
must be the corresponding elements of
J_{k,ell}
in the representation
above.
The ipopt_cppad_h_base
implementation of this function
corresponds to the simple representation mentioned above; i.e.,
for
i = 0 , \ldots , m
,
I[i] = i
,
and for
j = 0 , \ldots , n-1
,
J[j] = j
.
solution
contains
the following information:
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_info.eval
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
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
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
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
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
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
field of
solution
has prototype
Number solution.obj_value
It is the final value of the objective function
f(x)
.
ipopt_cppad_nlp
that uses the
simple representation
.
It returns true if it succeeds and false otherwise.
The section ipopt_cppad_ode
discusses an example that
uses a more complex representation.