# matlabprogram.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 25, 2008
    00008
    00009 #ifndef INCLUDE_MATLABPROGRAM
    00010 #define INCLUDE_MATLABPROGRAM
    00011
    00012 #include "iterate.hpp"
    00013 #include "options.hpp"
    00014 #include "matlabinfo.hpp"
    00015 #include "callbackfunctions.hpp"
    00016 #include "IpTNLP.hpp"
    00017
    00018 using Ipopt::TNLP;
    00019 using Ipopt::SolverReturn;
    00020 using Ipopt::AlgorithmMode;
    00021 using Ipopt::IpoptData;
    00022 using Ipopt::IpoptCalculatedQuantities;
    00023
    00024 // Class MatlabProgram
    00025 // -----------------------------------------------------------------
    00026 class MatlabProgram : public TNLP {
    00027 public:
    00028
    00029   // The constructor.
    00030   MatlabProgram (const Iterate& x0, const CallbackFunctions& funcs,
    00031                  const Options& options, Iterate& x, MatlabInfo& info);
    00032
    00033   // The destructor.
    00034   virtual ~MatlabProgram();
    00035
    00036   // Method to return some info about the nonlinear program.
    00037   virtual bool get_nlp_info (int& n, int& m, int& sizeOfJ, int& sizeOfH,
    00038                              IndexStyleEnum& indexStyle);
    00039
    00040   // Return the bounds for the problem.
    00041   virtual bool get_bounds_info (int n, double* lb, double* ub, int m,
    00042                                 double* cl, double* cu);
    00043
    00044   // Return the starting point for the algorithm.
    00045   virtual bool get_starting_point (int n, bool initializeVars, double* vars,
    00046                                    bool initializez, double* zl, double* zu,
    00047                                    int m, bool initializeLambda,
    00048                                    double* lambda);
    00049
    00050   // Compute the value of the objective.
    00051   virtual bool eval_f (int n, const double* vars, bool ignore, double& f);
    00052
    00053   // Compute the gradient of the objective.
    00054   virtual bool eval_grad_f (int n, const double* vars, bool ignore,
    00055                             double* grad);
    00056
    00057   // Evaluate the constraint residuals.
    00058   virtual bool eval_g (int n, const double* vars, bool ignore, int m,
    00059                        double* g);
    00060
    00061   // This method either returns: 1.) The structure of the Jacobian
    00062   // (if "Jacobian" is zero), or 2.) The values of the Jacobian (if
    00063   // "Jacobian" is not zero).
    00064   virtual bool eval_jac_g (int numVariables, const double* variables,
    00065                            bool ignoreThis, int numConstraints,
    00066                            int sizeOfJ, int* rows, int *cols, double* Jx);
    00067
    00068   // This method either returns: 1.) the structure of the Hessian of
    00069   // the Lagrangian (if "Hessian" is zero), or 2.) the values of the
    00070   // Hessian of the Lagrangian (if "Hesson" is not zero).
    00071   virtual bool eval_h (int n, const double* vars, bool ignore, double sigma,
    00072                        int m, const double* lambda, bool ignoretoo,
    00073                        int sizeOfH, int* rows, int* cols, double* Hx);
    00074
    00075   // This method is called when the algorithm is complete.
    00076   virtual void finalize_solution (SolverReturn status, int numVariables,
    00077                                   const double* variables, const double* zl,
    00078                                   const double* zu, int numConstraints,
    00079                                   const double* constraints,
    00080                                   const double* lambda, double objective,
    00081                                   const IpoptData* ip_data,
    00082                                   IpoptCalculatedQuantities* ip_cq);
    00083
    00084   // Intermediate callback method. It is called once per iteration
    00085   // of the IPOPT algorithm.
    00086   virtual bool intermediate_callback (AlgorithmMode mode, int t, double f,
    00087                                       double inf_pr, double inf_du,
    00088                                       double mu, double d_norm,
    00089                                       double regularization_size,
    00090                                       double alpha_du, double alpha_pr,
    00091                                       int ls_trials,
    00092                                       const IpoptData* ip_data,
    00093                                       IpoptCalculatedQuantities* ip_cq);
    00094
    00095 protected:
    00096   const Iterate&           x0;       // The initial point.
    00097   const CallbackFunctions& funcs;    // Callback routines.
    00098   const Options&           options;  // Further program info.
    00099   Iterate&                 x;        // Current point.
    00100   MatlabInfo&              info;     // Info passed back to MATLAB.
    00101
    00102   // These next two members store information about the structure of
    00103   // the sparse Matlab matrix for the Jacobian of the constraints
    00104   // and the Hessian of the Lagragian.
    00105   SparseMatrix* J;
    00106   SparseMatrix* H;
    00107 };
    00108
    00109 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines