# callbackfunctions.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2008 Peter Carbonetto. All Rights Reserved.
    00002 // This code is published under the Eclipse Public License.
    00003 //
    00004 // Author: Peter Carbonetto
    00005 //         Dept. of Computer Science
    00006 //         University of British Columbia
    00007 //         September 18, 2008
    00008
    00009 #ifndef INCLUDE_CALLBACKFUNCTIONS
    00010 #define INCLUDE_CALLBACKFUNCTIONS
    00011
    00012 #include "mex.h"
    00013 #include "iterate.hpp"
    00014 #include "sparsematrix.hpp"
    00015 #include "matlabfunctionhandle.hpp"
    00016 #include "IpIpoptCalculatedQuantities.hpp"
    00017 #include "IpIpoptData.hpp"
    00018 #include "IpTNLPAdapter.hpp"
    00019 #include "IpOrigIpoptNLP.hpp"
    00020
    00021 // Class CallbackFunctions.
    00022 // -----------------------------------------------------------------
    00023 // An object of this class does two things. First of all, it stores
    00024 // handles to MATLAB functions (type HELP FUNCTION_HANDLE in the
    00025 // MATLAB console) for all the necessary and optional callback
    00026 // functions for IPOPT. Secondly, this class actually provides the
    00027 // routines for calling these functions with the necessary inputs and
    00028 // outputs.
    00029 class CallbackFunctions {
    00030 public:
    00031
    00032   // The constructor must be provided with a single MATLAB array, and
    00033   // this MATLAB array must be a structure array in which each field
    00034   // is a function handle.
    00035   explicit CallbackFunctions (const mxArray* ptr);
    00036
    00037   // The destructor.
    00038   ~CallbackFunctions();
    00039
    00040   // These functions return true if the respective callback functions
    00041   // are available.
    00042   bool constraintFuncIsAvailable() const { return *constraintfunc; };
    00043   bool jacobianFuncIsAvailable  () const { return *jacobianfunc;   };
    00044   bool hessianFuncIsAvailable   () const { return *hessianfunc;    };
    00045   bool iterFuncIsAvailable      () const { return *iterfunc;       };
    00046
    00047   // These functions execute the various callback functions with the
    00048   // appropriate inputs and outputs. Here, m is the number of constraints.
    00049   // The first function returns the value of the objective at x.
    00050   double computeObjective (const Iterate& x) const;
    00051
    00052   // This function computes the value of the gradient at x, and
    00053   // returns the gradient entries in the array g, which must be of
    00054   // length equal to the number of optimization variables.
    00055   void computeGradient (const Iterate& x, double* g) const;
    00056
    00057   // This function computes the response of the vector-valued
    00058   // constraint function at x, and stores the result in the array c
    00059   // which must be of length m.
    00060   void computeConstraints (const Iterate& x, int m, double* c) const;
    00061
    00062   // This function gets the structure of the sparse m x n Jacobian matrix.
    00063   SparseMatrix* getJacobianStructure (int n, int m) const;
    00064
    00065   // This function gets the structure of the sparse n x n Hessian matrix.
    00066   SparseMatrix* getHessianStructure (int n) const;
    00067
    00068   // This function computes the Jacobian of the constraints at x.
    00069   void computeJacobian (int m, const Iterate& x, SparseMatrix& J) const;
    00070
    00071   // This function computes the Hessian of the Lagrangian at x.
    00072   void computeHessian (const Iterate& x, double sigma, int m,
    00073                        const double* lambda, SparseMatrix& H) const;
    00074
    00075   // Call the intermediate callback function. A return value of false
    00076   // tells IPOPT to terminate.
    00077   bool iterCallback (int t, double f,
    00078                                       double inf_pr, double inf_du,
    00079                                       double mu, double d_norm,
    00080                                       double regularization_size,
    00081                                       double alpha_du, double alpha_pr,
    00082                                       int ls_trials, const Ipopt::IpoptData* ip_data,
    00083                                       Ipopt::IpoptCalculatedQuantities* ip_cq,
    00084                                       int n) const;
    00085
    00086 protected:
    00087   MatlabFunctionHandle* objfunc;        // Objective callback function.
    00088   MatlabFunctionHandle* gradfunc;       // Gradient callback function.
    00089   MatlabFunctionHandle* constraintfunc; // Constraint callback function.
    00090   MatlabFunctionHandle* jacobianfunc;   // Jacobian callback function.
    00091   MatlabFunctionHandle* jacstrucfunc;   // Jacobian structure function.
    00092   MatlabFunctionHandle* hessianfunc;    // Hessian callback function.
    00093   MatlabFunctionHandle* hesstrucfunc;   // Hessian structure function.
    00094   MatlabFunctionHandle* iterfunc;       // Iterative callback function.
    00095 };
    00096
    00097 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines