Prev Next Index-> contents reference index search external Up-> CppAD ipopt_solve ipopt_solve_retape.cpp ipopt_solve_retape.cpp Headings-> Purpose

$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$This is cppad-20221105 documentation. Here is a link to its current documentation .
Nonlinear Programming Retaping: Example and Test

Purpose
This example program demonstrates a case were the ipopt::solve argument retape should be true.
# include <cppad/ipopt/solve.hpp>

namespace {

class FG_eval {
public:
{   assert( fg.size() == 1 );
assert( x.size()  == 1 );

// compute the Huber function using a conditional
// statement that depends on the value of x.
double eps = 0.1;
if( fabs(x[0]) <= eps )
fg[0] = x[0] * x[0] / (2.0 * eps);
else
fg[0] = fabs(x[0]) - eps / 2.0;

return;
}
};
}

bool retape(void)
{   bool ok = true;

// number of independent variables (domain dimension for f and g)
size_t nx = 1;
// number of constraints (range dimension for g)
size_t ng = 0;
// initial value, lower and upper limits, for the independent variables
Dvector xi(nx), xl(nx), xu(nx);
xi[0] = 2.0;
xl[0] = -1e+19;
xu[0] = +1e+19;
// lower and upper limits for g
Dvector gl(ng), gu(ng);

// object that computes objective and constraints
FG_eval fg_eval;

// options
std::string options;
// retape operation sequence for each new x
options += "Retape  true\n";
// turn off any printing
options += "Integer print_level   0\n";
options += "String  sb          yes\n";
// maximum number of iterations
options += "Integer max_iter      10\n";
// approximate accuracy in first order necessary conditions;
// see Mathematical Programming, Volume 106, Number 1,
// Pages 25-57, Equation (6)
options += "Numeric tol           1e-9\n";
// derivative testing
options += "String  derivative_test            second-order\n";
// maximum amount of random pertubation; e.g.,
// when evaluation finite diff

// place to return solution

// solve the problem
options, xi, xl, xu, gl, gu, fg_eval, solution
);
//
// Check some of the solution values
//
}