Ipopt  3.12.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
callbackfunctions.hpp
Go to the documentation of this file.
1 // Copyright (C) 2008 Peter Carbonetto. All Rights Reserved.
2 // This code is published under the Eclipse Public License.
3 //
4 // Author: Peter Carbonetto
5 // Dept. of Computer Science
6 // University of British Columbia
7 // September 18, 2008
8 
9 #ifndef INCLUDE_CALLBACKFUNCTIONS
10 #define INCLUDE_CALLBACKFUNCTIONS
11 
12 #include "mex.h"
13 #include "iterate.hpp"
14 #include "sparsematrix.hpp"
15 #include "matlabfunctionhandle.hpp"
17 #include "IpIpoptData.hpp"
18 #include "IpTNLPAdapter.hpp"
19 #include "IpOrigIpoptNLP.hpp"
20 
21 // Class CallbackFunctions.
22 // -----------------------------------------------------------------
23 // An object of this class does two things. First of all, it stores
24 // handles to MATLAB functions (type HELP FUNCTION_HANDLE in the
25 // MATLAB console) for all the necessary and optional callback
26 // functions for IPOPT. Secondly, this class actually provides the
27 // routines for calling these functions with the necessary inputs and
28 // outputs.
30 public:
31 
32  // The constructor must be provided with a single MATLAB array, and
33  // this MATLAB array must be a structure array in which each field
34  // is a function handle.
35  explicit CallbackFunctions (const mxArray* ptr);
36 
37  // The destructor.
39 
40  // These functions return true if the respective callback functions
41  // are available.
42  bool constraintFuncIsAvailable() const { return *constraintfunc; };
43  bool jacobianFuncIsAvailable () const { return *jacobianfunc; };
44  bool hessianFuncIsAvailable () const { return *hessianfunc; };
45  bool iterFuncIsAvailable () const { return *iterfunc; };
46 
47  // These functions execute the various callback functions with the
48  // appropriate inputs and outputs. Here, m is the number of constraints.
49  // The first function returns the value of the objective at x.
50  double computeObjective (const Iterate& x) const;
51 
52  // This function computes the value of the gradient at x, and
53  // returns the gradient entries in the array g, which must be of
54  // length equal to the number of optimization variables.
55  void computeGradient (const Iterate& x, double* g) const;
56 
57  // This function computes the response of the vector-valued
58  // constraint function at x, and stores the result in the array c
59  // which must be of length m.
60  void computeConstraints (const Iterate& x, int m, double* c) const;
61 
62  // This function gets the structure of the sparse m x n Jacobian matrix.
63  SparseMatrix* getJacobianStructure (int n, int m) const;
64 
65  // This function gets the structure of the sparse n x n Hessian matrix.
66  SparseMatrix* getHessianStructure (int n) const;
67 
68  // This function computes the Jacobian of the constraints at x.
69  void computeJacobian (int m, const Iterate& x, SparseMatrix& J) const;
70 
71  // This function computes the Hessian of the Lagrangian at x.
72  void computeHessian (const Iterate& x, double sigma, int m,
73  const double* lambda, SparseMatrix& H) const;
74 
75  // Call the intermediate callback function. A return value of false
76  // tells IPOPT to terminate.
77  bool iterCallback (int t, double f,
78  double inf_pr, double inf_du,
79  double mu, double d_norm,
80  double regularization_size,
81  double alpha_du, double alpha_pr,
82  int ls_trials, const Ipopt::IpoptData* ip_data,
84  int n) const;
85 
86 protected:
87  MatlabFunctionHandle* objfunc; // Objective callback function.
88  MatlabFunctionHandle* gradfunc; // Gradient callback function.
89  MatlabFunctionHandle* constraintfunc; // Constraint callback function.
90  MatlabFunctionHandle* jacobianfunc; // Jacobian callback function.
91  MatlabFunctionHandle* jacstrucfunc; // Jacobian structure function.
92  MatlabFunctionHandle* hessianfunc; // Hessian callback function.
93  MatlabFunctionHandle* hesstrucfunc; // Hessian structure function.
94  MatlabFunctionHandle* iterfunc; // Iterative callback function.
95 };
96 
97 #endif
Number * x
Input: Starting point Output: Optimal solution.
MatlabFunctionHandle * hesstrucfunc
Class for all IPOPT specific calculated quantities.
CallbackFunctions(const mxArray *ptr)
Number Number Index m
Number of constraints.
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
MatlabFunctionHandle * objfunc
MatlabFunctionHandle * constraintfunc
void computeGradient(const Iterate &x, double *g) const
bool constraintFuncIsAvailable() const
MatlabFunctionHandle * gradfunc
SparseMatrix * getHessianStructure(int n) const
void computeHessian(const Iterate &x, double sigma, int m, const double *lambda, SparseMatrix &H) const
MatlabFunctionHandle * jacobianfunc
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:83
bool hessianFuncIsAvailable() const
bool iterFuncIsAvailable() const
double computeObjective(const Iterate &x) const
MatlabFunctionHandle * iterfunc
MatlabFunctionHandle * jacstrucfunc
bool iterCallback(int t, double f, double inf_pr, double inf_du, double mu, double d_norm, double regularization_size, double alpha_du, double alpha_pr, int ls_trials, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq, int n) const
void computeConstraints(const Iterate &x, int m, double *c) const
MatlabFunctionHandle * hessianfunc
void computeJacobian(int m, const Iterate &x, SparseMatrix &J) const
SparseMatrix * getJacobianStructure(int n, int m) const
bool jacobianFuncIsAvailable() const