options.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_OPTIONS
10 #define INCLUDE_OPTIONS
11 
12 #include "mex.h"
13 #include "iterate.hpp"
14 #include "ipoptoptions.hpp"
15 
16 // Class Options.
17 // -----------------------------------------------------------------
18 // This class processes the options input from MATLAB.
19 class Options {
20 public:
21 
22  // The constructor expects as input a point to a MATLAB array, in
23  // particular a structure array with the appropriate fields. Note
24  // that the Options object does *not* possess an independent copy of
25  // some of the MATLAB data (such as the auxiliary data).
27  const mxArray* ptr);
28 
29  // The destructor.
30  ~Options();
31 
32  // Get the number of variables and the number of constraints.
33  friend int numvars (const Options& options) { return options.n; };
34  friend int numconstraints (const Options& options) { return options.m; };
35 
36  // Access the lower and upper bounds on the variables and constraints.
37  const double* lowerbounds () const { return lb; };
38  const double* upperbounds () const { return ub; };
39  const double* constraintlb() const { return cl; };
40  const double* constraintub() const { return cu; };
41 
42  // Access the auxiliary data.
43  const mxArray* getAuxData() const { return auxdata; };
44 
45  // Access the IPOPT options object.
46  const IpoptOptions ipoptOptions() const { return ipopt; };
47 
48  // Access the Lagrange multpliers.
49  const double* multlb () const { return zl; };
50  const double* multub () const { return zu; };
51  const double* multconstr() const { return lambda; };
52 
53 protected:
54  int n; // The number of optimization variables.
55  int m; // The number of constraints.
56  double* lb; // Lower bounds on the variables.
57  double* ub; // Upper bounds on the variables.
58  double* cl; // Lower bounds on constraints.
59  double* cu; // Upper bounds on constraints.
60  double* zl; // Lagrange multipliers for lower bounds.
61  double* zu; // Lagrange multipliers for upper bounds.
62  double* lambda; // Lagrange multipliers for constraints.
63  const mxArray* auxdata; // MATLAB array containing the auxiliary data.
64  IpoptOptions ipopt; // The IPOPT options.
65 
66  // These are helper functions used by the class constructor.
67  static double* loadLowerBounds (int n, const mxArray* ptr,
68  double neginfty);
69  static double* loadUpperBounds (int n, const mxArray* ptr,
70  double posinfty);
71  static int loadConstraintBounds (const mxArray* ptr, double*& cl,
72  double*& cu, double neginfty,
73  double posinfty);
74  static void loadMultipliers (int n, int m, const mxArray* ptr,
75  double*& zl, double*& zu,
76  double*& lambda);
77 };
78 
79 #endif