00001 // Copyright (C) 2007 Peter Carbonetto. All Rights Reserved. 00002 // This code is published under the Common Public License. 00003 // 00004 // Author: Peter Carbonetto 00005 // Dept. of Computer Science 00006 // University of British Columbia 00007 // May 22, 2007 00008 00009 #ifndef INCLUDE_MULTIPLIERS 00010 #define INCLUDE_MULTIPLIERS 00011 00012 #include "mex.h" 00013 #include "matlabmatrix.h" 00014 #include "arrayofmatrices.h" 00015 00016 // Class Multipliers. 00017 // ----------------------------------------------------------------- 00018 // This class reserves storage for the Lagrange multipliers associated 00019 // with a constrained, nonlinear program. There are three types of 00020 // Lagrange multipliers: those associated with the upper bounds on the 00021 // primal variables, those associated with the lower bounds, and those 00022 // associated with the equality and inequality constraints. Of 00023 // particular interest is the fact that one of the constructors 00024 // accesses the information from a MATLAB structure. The structure 00025 // must be created with the following fields: zl, zu, lambda. There is 00026 // another constructor that creates a new MATLAB structure with those 00027 // fields. See the descriptions of the constructors below for more 00028 // information. 00029 class Multipliers { 00030 public: 00031 00032 // Read the values of the multipliers from the specified MATLAB 00033 // structure. See the comments above for more information as to the 00034 // form the MATLAB structure is expected to take. 00035 explicit Multipliers (const mxArray*& ptr); 00036 00037 // Create a set of multipliers for n variables and m constraints. It 00038 // creates a MATLAB struct array as a side effect. 00039 Multipliers (mxArray*& ptr, int n, int m); 00040 00041 // The copy constructor makes a shallow copy of the data. 00042 Multipliers (const Multipliers& source); 00043 00044 // The destructor. 00045 ~Multipliers(); 00046 00047 // Access the multipliers. 00048 const Matrix& lowerbounds() const { return *zl; }; 00049 const Matrix& upperbounds() const { return *zu; }; 00050 const Matrix& constraints() const { return *lambda; }; 00051 Matrix& lowerbounds() { return *zl; }; 00052 Matrix& upperbounds() { return *zu; }; 00053 Matrix& constraints() { return *lambda; }; 00054 00055 protected: 00056 Matrix* zl; // The Lagrange multipliers corresponding to the 00057 // lower bounds on the optimization variables. 00058 Matrix* zu; // The Lagrange multipliers corresponding to the 00059 // upper bounds on the optimization variables. 00060 Matrix* lambda; // The Lagrange multipliers associated with the 00061 // equality and inequality constraints. 00062 }; 00063 00064 #endif