multipliers.h
Go to the documentation of this file.
1 // Copyright (C) 2007 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 // May 22, 2007
8 
9 #ifndef INCLUDE_MULTIPLIERS
10 #define INCLUDE_MULTIPLIERS
11 
12 #include "mex.h"
13 #include "matlabmatrix.h"
14 #include "arrayofmatrices.h"
15 
16 // Class Multipliers.
17 // -----------------------------------------------------------------
18 // This class reserves storage for the Lagrange multipliers associated
19 // with a constrained, nonlinear program. There are three types of
20 // Lagrange multipliers: those associated with the upper bounds on the
21 // primal variables, those associated with the lower bounds, and those
22 // associated with the equality and inequality constraints. Of
23 // particular interest is the fact that one of the constructors
24 // accesses the information from a MATLAB structure. The structure
25 // must be created with the following fields: zl, zu, lambda. There is
26 // another constructor that creates a new MATLAB structure with those
27 // fields. See the descriptions of the constructors below for more
28 // information.
29 class Multipliers {
30 public:
31 
32  // Read the values of the multipliers from the specified MATLAB
33  // structure. See the comments above for more information as to the
34  // form the MATLAB structure is expected to take.
35  explicit Multipliers (const mxArray*& ptr);
36 
37  // Create a set of multipliers for n variables and m constraints. It
38  // creates a MATLAB struct array as a side effect.
39  Multipliers (mxArray*& ptr, int n, int m);
40 
41  // The copy constructor makes a shallow copy of the data.
42  Multipliers (const Multipliers& source);
43 
44  // The destructor.
45  ~Multipliers();
46 
47  // Access the multipliers.
48  const Matrix& lowerbounds() const { return *zl; };
49  const Matrix& upperbounds() const { return *zu; };
50  const Matrix& constraints() const { return *lambda; };
51  Matrix& lowerbounds() { return *zl; };
52  Matrix& upperbounds() { return *zu; };
53  Matrix& constraints() { return *lambda; };
54 
55 protected:
56  Matrix* zl; // The Lagrange multipliers corresponding to the
57  // lower bounds on the optimization variables.
58  Matrix* zu; // The Lagrange multipliers corresponding to the
59  // upper bounds on the optimization variables.
60  Matrix* lambda; // The Lagrange multipliers associated with the
61  // equality and inequality constraints.
62 };
63 
64 #endif