Ipopt 3.12.10

- Main Page
- Classes
- Files

- File List
- File Members

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"
16 #include "IpIpoptCalculatedQuantities.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.
29 class CallbackFunctions {
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.
38 ~CallbackFunctions();
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,
83 Ipopt::IpoptCalculatedQuantities* ip_cq,
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
x
Number * x
Input: Starting point Output: Optimal solution.
Definition: IpStdCInterface.h:238
CallbackFunctions::hesstrucfunc
MatlabFunctionHandle * hesstrucfunc
Definition: callbackfunctions.hpp:93
iterate.hpp
sparsematrix.hpp
Ipopt::IpoptCalculatedQuantities
Class for all IPOPT specific calculated quantities.
Definition: IpIpoptCalculatedQuantities.hpp:81
CallbackFunctions::CallbackFunctions
CallbackFunctions(const mxArray *ptr)
m
Number Number Index m
Number of constraints.
Definition: IpStdCInterface.h:137
g
Number Number * g
Values of constraint at final point (output only - ignored if set to NULL)
Definition: IpStdCInterface.h:238
IpIpoptCalculatedQuantities.hpp
CallbackFunctions::objfunc
MatlabFunctionHandle * objfunc
Definition: callbackfunctions.hpp:87
CallbackFunctions
Definition: callbackfunctions.hpp:29
CallbackFunctions::~CallbackFunctions
~CallbackFunctions()
CallbackFunctions::constraintfunc
MatlabFunctionHandle * constraintfunc
Definition: callbackfunctions.hpp:89
CallbackFunctions::computeGradient
void computeGradient(const Iterate &x, double *g) const
CallbackFunctions::constraintFuncIsAvailable
bool constraintFuncIsAvailable() const
Definition: callbackfunctions.hpp:42
IpOrigIpoptNLP.hpp
MatlabFunctionHandle
Definition: matlabfunctionhandle.hpp:28
CallbackFunctions::gradfunc
MatlabFunctionHandle * gradfunc
Definition: callbackfunctions.hpp:88
matlabfunctionhandle.hpp
CallbackFunctions::getHessianStructure
SparseMatrix * getHessianStructure(int n) const
SparseMatrix
Definition: sparsematrix.hpp:34
CallbackFunctions::computeHessian
void computeHessian(const Iterate &x, double sigma, int m, const double *lambda, SparseMatrix &H) const
CallbackFunctions::jacobianfunc
MatlabFunctionHandle * jacobianfunc
Definition: callbackfunctions.hpp:90
Ipopt::IpoptData
Class to organize all the data required by the algorithm.
Definition: IpIpoptData.hpp:83
CallbackFunctions::hessianFuncIsAvailable
bool hessianFuncIsAvailable() const
Definition: callbackfunctions.hpp:44
CallbackFunctions::iterFuncIsAvailable
bool iterFuncIsAvailable() const
Definition: callbackfunctions.hpp:45
CallbackFunctions::computeObjective
double computeObjective(const Iterate &x) const
Iterate
Definition: iterate.hpp:31
CallbackFunctions::iterfunc
MatlabFunctionHandle * iterfunc
Definition: callbackfunctions.hpp:94
CallbackFunctions::jacstrucfunc
MatlabFunctionHandle * jacstrucfunc
Definition: callbackfunctions.hpp:91
CallbackFunctions::iterCallback
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
IpTNLPAdapter.hpp
CallbackFunctions::computeConstraints
void computeConstraints(const Iterate &x, int m, double *c) const
CallbackFunctions::hessianfunc
MatlabFunctionHandle * hessianfunc
Definition: callbackfunctions.hpp:92
CallbackFunctions::computeJacobian
void computeJacobian(int m, const Iterate &x, SparseMatrix &J) const
IpIpoptData.hpp
CallbackFunctions::getJacobianStructure
SparseMatrix * getJacobianStructure(int n, int m) const
CallbackFunctions::jacobianFuncIsAvailable
bool jacobianFuncIsAvailable() const
Definition: callbackfunctions.hpp:43