matlabprogram.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 25, 2008
8 
9 #ifndef INCLUDE_MATLABPROGRAM
10 #define INCLUDE_MATLABPROGRAM
11 
12 #include "iterate.hpp"
13 #include "options.hpp"
14 #include "matlabinfo.hpp"
15 #include "callbackfunctions.hpp"
16 #include "IpTNLP.hpp"
17 
18 using Ipopt::TNLP;
21 using Ipopt::IpoptData;
23 
24 // Class MatlabProgram
25 // -----------------------------------------------------------------
26 class MatlabProgram : public TNLP {
27 public:
28 
29  // The constructor.
31  const Options& options, Iterate& x, const mxArray* auxdata,
32  MatlabInfo& info);
33 
34  // The destructor.
35  virtual ~MatlabProgram();
36 
37  // Method to return some info about the nonlinear program.
38  virtual bool get_nlp_info (int& n, int& m, int& sizeOfJ, int& sizeOfH,
39  IndexStyleEnum& indexStyle);
40 
41  // Return the bounds for the problem.
42  virtual bool get_bounds_info (int n, double* lb, double* ub, int m,
43  double* cl, double* cu);
44 
45  // Return the starting point for the algorithm.
46  virtual bool get_starting_point (int n, bool initializeVars, double* vars,
47  bool initializez, double* zl, double* zu,
48  int m, bool initializeLambda,
49  double* lambda);
50 
51  // Compute the value of the objective.
52  virtual bool eval_f (int n, const double* vars, bool ignore, double& f);
53 
54  // Compute the gradient of the objective.
55  virtual bool eval_grad_f (int n, const double* vars, bool ignore,
56  double* grad);
57 
58  // Evaluate the constraint residuals.
59  virtual bool eval_g (int n, const double* vars, bool ignore, int m,
60  double* g);
61 
62  // This method either returns: 1.) The structure of the Jacobian
63  // (if "Jacobian" is zero), or 2.) The values of the Jacobian (if
64  // "Jacobian" is not zero).
65  virtual bool eval_jac_g (int numVariables, const double* variables,
66  bool ignoreThis, int numConstraints,
67  int sizeOfJ, int* rows, int *cols, double* Jx);
68 
69  // This method either returns: 1.) the structure of the Hessian of
70  // the Lagrangian (if "Hessian" is zero), or 2.) the values of the
71  // Hessian of the Lagrangian (if "Hesson" is not zero).
72  virtual bool eval_h (int n, const double* vars, bool ignore, double sigma,
73  int m, const double* lambda, bool ignoretoo,
74  int sizeOfH, int* rows, int* cols, double* Hx);
75 
76  // This method is called when the algorithm is complete.
77  virtual void finalize_solution (SolverReturn status, int numVariables,
78  const double* variables, const double* zl,
79  const double* zu, int numConstraints,
80  const double* constraints,
81  const double* lambda, double objective,
82  const IpoptData* ip_data,
84 
85  // Intermediate callback method. It is called once per iteration
86  // of the IPOPT algorithm.
87  virtual bool intermediate_callback (AlgorithmMode mode, int t, double f,
88  double inf_pr, double inf_du,
89  double mu, double d_norm,
90  double regularization_ize,
91  double alpha_du, double alpha_pr,
92  int ls_trials,
93  const IpoptData* ip_data,
95 
96 protected:
97  const Iterate& x0; // The initial point.
98  const CallbackFunctions& funcs; // Callback routines.
99  const Options& options; // Further program info.
100  Iterate& x; // Current point.
101  const mxArray* auxdata; // The auxiliary data.
102  MatlabInfo& info; // Info passed back to MATLAB.
103 
104  // These next two members store information about the structure of
105  // the sparse Matlab matrix for the Jacobian of the constraints
106  // and the Hessian of the Lagragian.
109 };
110 
111 #endif