2 # ifndef CPPAD_IPOPT_SOLVE_CALLBACK_HPP
3 # define CPPAD_IPOPT_SOLVE_CALLBACK_HPP
16 # include <coin/IpIpoptApplication.hpp>
17 # include <coin/IpTNLP.hpp>
41 template <
class Dvector,
class ADvector,
class FG_eval>
159 for(i = 0; i <
nx_; i++)
169 for(i = 0; i <
nx_; i++)
232 bool sparse_forward ,
233 bool sparse_reverse ,
256 for(i = 0; i <
nx_; i++)
258 for(i = 0; i < nfg; i++)
263 ADvector a_x(nx_), a_fg(nfg);
264 for(i = 0; i <
nx_; i++)
286 vectorBool r(nx_ * n_column), s(m * n_column);
289 size_t n_loop = (nx_ - 1) / n_column + 1;
290 for(
size_t i_loop = 0; i_loop < n_loop; i_loop++)
292 size_t i_column = i_loop * n_column;
295 for(i = 0; i <
nx_; i++)
296 {
for(j = 0; j < n_column; j++)
297 r[i * n_column + j] = (i == i_column + j);
302 for(i = 0; i < m; i++)
303 {
for(j = 0; j < n_column; j++)
304 {
if( i_column + j < nx_ )
321 size_t n_loop = (m - 1) / n_row + 1;
322 for(
size_t i_loop = 0; i_loop < n_loop; i_loop++)
324 size_t i_row = i_loop * n_row;
327 for(i = 0; i < n_row; i++)
328 {
for(j = 0; j < m; j++)
329 r[i * m + j] = (i_row + i == j);
334 for(i = 0; i < n_row; i++)
335 {
for(j = 0; j <
nx_; j++)
354 for(i =
nf_; i < nfg; i++)
355 {
for(j = 0; j <
nx_; j++)
372 vectorBool r(nx_ * n_column), h(nx_ * n_column);
376 for(i = 0; i < m; i++)
380 size_t n_loop = (nx_ - 1) / n_column + 1;
381 for(
size_t i_loop = 0; i_loop < n_loop; i_loop++)
383 size_t i_column = i_loop * n_column;
386 for(i = 0; i <
nx_; i++)
387 {
for(j = 0; j < n_column; j++)
388 r[i * n_column + j] = (i == i_column + j);
394 bool transpose =
true;
398 for(i = 0; i <
nx_; i++)
399 {
for(j = 0; j < n_column; j++)
400 {
if( i_column + j < nx_ )
408 for(i = 0; i <
nx_; i++)
409 {
for(j = 0; j <
nx_; j++)
421 for(i =
nf_; i < nfg; i++)
422 {
for(j = 0; j <
nx_; j++)
429 for(i = 0; i <
nx_; i++)
430 {
for(j = 0; j <= i; j++)
475 {
size_t nnz =
static_cast<size_t>(nnz_jac_g);
478 nnz =
static_cast<size_t>(nnz_h_lag);
484 index_style = C_STYLE;
535 for(i = 0; i <
nx_; i++)
539 for(i = 0; i <
ng_; i++)
599 for(j = 0; j <
nx_; j++)
635 for(i = 0; i <
nf_; i++)
637 obj_value =
static_cast<Number>(sum);
674 for(i = 0; i <
nf_; i++)
676 for(i = 0; i <
ng_; i++)
679 for(i = 0; i <
nx_; i++)
720 for(i = 0; i <
ng_; i++)
792 {
size_t i, j, k, ell;
803 {
for(k = 0; k < nk; k++)
807 iRow[k] =
static_cast<Index>(i -
nf_);
808 jCol[k] =
static_cast<Index>(j);
821 for(k = 0; k < nk; k++)
829 for(k = 0; k < nk; k++)
835 for(j = 0; j <
nx_; j++)
840 for(j = 0; j <
nx_; j++)
844 while( ell < nk &&
col_jac_[k] <= j )
860 Dvector w(nfg), dw(
nx_);
861 for(i = 0; i < nfg; i++)
865 for(i =
nf_; i < nfg; i++)
983 {
for(k = 0; k < nk; k++)
986 iRow[k] =
static_cast<Index>(i);
987 jCol[k] =
static_cast<Index>(j);
997 for(i = 0; i <
nf_; i++)
999 for(i = 0; i <
ng_; i++)
1000 w[i + nf_] = lambda[i];
1007 for(k = 0; k < nk; k++)
1011 { Dvector hes(
nx_ *
nx_);
1013 for(k = 0; k < nk; k++)
1016 values[k] = hes[i * nx_ + j];
1092 Ipopt::SolverReturn status ,
1101 const Ipopt::IpoptData* ip_data ,
1102 Ipopt::IpoptCalculatedQuantities* ip_cq
1111 case Ipopt::SUCCESS:
1115 case Ipopt::MAXITER_EXCEEDED:
1120 case Ipopt::STOP_AT_TINY_STEP:
1125 case Ipopt::STOP_AT_ACCEPTABLE_POINT:
1130 case Ipopt::LOCAL_INFEASIBILITY:
1135 case Ipopt::USER_REQUESTED_STOP:
1140 case Ipopt::DIVERGING_ITERATES:
1145 case Ipopt::RESTORATION_FAILURE:
1150 case Ipopt::ERROR_IN_STEP_COMPUTATION:
1155 case Ipopt::INVALID_NUMBER_DETECTED:
1160 case Ipopt::INTERNAL_ERROR:
1173 for(j = 0; j <
nx_; j++)
1180 for(i = 0; i <
ng_; i++)
bool sparse_reverse_
Should sparse methods be used to compute Jacobians and Hessians with reverse mode used for Jacobian...
class used by SparseHessian to hold information so it does not need to be recomputed.
includes the entire CppAD package in the necessary order.
solve_callback(size_t nf, size_t nx, size_t ng, const Dvector &xi, const Dvector &xl, const Dvector &xu, const Dvector &gl, const Dvector &gu, FG_eval &fg_eval, bool retape, bool sparse_forward, bool sparse_reverse, solve_result< Dvector > &solution)
Constructor for the interface between ipopt::solve and Ipopt.
Ipopt::Number Number
A Scalar value used by Ipopt.
size_t SparseJacobianReverse(const VectorBase &x, const VectorSet &p, const VectorSize &r, const VectorSize &c, VectorBase &jac, sparse_jacobian_work &work)
Compute user specified subset of a sparse Jacobian using forward mode.
virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)
Return bound information about optimization problem.
virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g)
Evaluate the function g(x).
CppAD::ADFun< double > adfun_
AD function object that evaluates x -> [ f(x) , g(x) ] If retape is false, this object is initialzed ...
Dvector fg0_
value of fg corresponding to previous new_x
The CppAD Simple Vector template class.
solve_result< Dvector > & solution_
final results are returned to this structure
bool sparse_forward_
Should sparse methods be used to compute Jacobians and Hessians with forward mode used for Jacobian...
const Dvector & xi_
initial value for x
static size_t bit_per_unit(void)
const size_t nf_
dimension of the range space for f(x). The objective is sum_i f_i (x). Note that, at this point...
Class that contains information about solve problem result.
virtual void finalize_solution(Ipopt::SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Pass solution information from Ipopt to users solution structure.
const size_t ng_
dimension of the range space for g(x)
CppAD::vectorBool pattern_jac_
Sparsity pattern for Jacobian of [f(x), g(x) ]. If sparse is true, this pattern set by constructor an...
Scalar nan(const Scalar &zero)
size_t SparseJacobianForward(const VectorBase &x, const VectorSet &p, const VectorSize &r, const VectorSize &c, VectorBase &jac, sparse_jacobian_work &work)
Compute user specified subset of a sparse Jacobian using forward mode.
CppAD::vector< size_t > row_jac_
Row indices of [f(x), g(x)] for Jacobian of g(x) in row order. (Set by constructor and not changed...
CppAD::vector< size_t > col_order_jac_
col_order_jac_ sorts row_jac_ and col_jac_ in column order. (Set by constructor and not changed...
Class that Ipopt uses for obtaining information about this problem.
Ipopt::TNLP::IndexStyleEnum IndexStyleEnum
Indexing style used in Ipopt sparsity structure.
virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda)
Return initial x value where optimiation is started.
CppAD::sparse_hessian_work work_hes_
Work vector used by SparseJacobian, stored here to avoid recalculation.
void Independent(VectorAD &x, size_t abort_op_index)
Declaration of independent variables.
VectorSet RevSparseJac(size_t q, const VectorSet &s, bool transpose=false, bool dependency=false)
User API for Jacobian sparsity patterns using reverse mode.
const Dvector & xl_
lower limit for x
VectorSet RevSparseHes(size_t q, const VectorSet &s, bool transpose=false)
User API for Hessian sparsity patterns using reverse mode.
const Dvector & gu_
upper limit for g(x)
CppAD::vectorBool pattern_hes_
Sparsity pattern for Hessian of Lagragian If sparse is true, this pattern set by constructor and doe...
void Dependent(local::ADTape< Base > *tape, const ADvector &y)
change the operation sequence corresponding to this object
void index_sort(const VectorKey &keys, VectorSize &ind)
Compute the indices that sort a vector of keys.
class used by SparseJacobian to hold information so it does not need to be recomputed.
const Dvector & xu_
upper limit for x
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
Dvector x0_
value of x corresponding to previous new_x
void optimize(const std::string &options="")
Optimize a player object operation sequence.
CppAD::sparse_jacobian_work work_jac_
Work vector used by SparseJacobian, stored here to avoid recalculation.
VectorBase Forward(size_t q, size_t r, const VectorBase &x)
forward mode user API, one order multiple directions.
const size_t nx_
dimension of the domain space for f(x) and g(x)
VectorSet ForSparseJac(size_t q, const VectorSet &r, bool transpose=false, bool dependency=false)
User API for Jacobian sparsity patterns using forward mode.
virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value)
Evaluate the objective fucntion f(x).
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
Return dimension information about optimization problem.
CppAD::vector< size_t > col_hes_
Column indices of Hessian left triangle in same order as row_hes_. (Set by constructor and not change...
VectorBase SparseHessian(const VectorBase &x, const VectorBase &w)
calculate sparse Hessians
Ipopt::Index Index
An index value used by Ipopt.
void cache_new_x(const Number *x)
Cache information for a new value of x.
VectorBase Hessian(const VectorBase &x, const VectorBase &w)
calculate Hessian for one component of f
Class that contains information about solve problem result.
bool retape_
should operation sequence be retaped for each new x.
const Dvector & gl_
lower limit for g(x)
CppAD::vector< size_t > row_hes_
Row indices of Hessian lower left triangle in row order. (Set by constructor and not changed...
void resize(size_t n)
change number of elements in this vector
virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
Evaluate the Jacobian of g(x).
virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values)
Evaluate the Hessian of the Lagragian.
virtual bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f)
Evaluate the gradient of f(x).
FG_eval & fg_eval_
object that evaluates f(x) and g(x)
CppAD::vector< size_t > col_jac_
Column indices for Jacobian of g(x), same order as row_jac_. (Set by constructor and not changed...
VectorBase Reverse(size_t p, const VectorBase &v)
reverse mode sweep