1 // Copyright (C) 2005, 2008 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id$
6 //
7 // Authors:  Andreas Waechter            IBM    2005-12-25
8 
9 #ifndef __IPLOWRANKUPDATESYMMATRIX_HPP__
10 #define __IPLOWRANKUPDATESYMMATRIX_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpSymMatrix.hpp"
14 #include "IpMultiVectorMatrix.hpp"
15 
16 namespace Ipopt
17 {
18 
19   /* forward declarations */
20   class LowRankUpdateSymMatrixSpace;
21 
22   /** Class for symmetric matrices, represented as low-rank updates.
23    *  The matrix M is represented as M = P_LR(D + V V^T - U U^T)P_LR^T
24    *  (if reduced_diag is true), or M = D + P_LR(V V^T - U U^T)P_LR^T
25    *  (if reduced_diag is false).  D is a diagonal matrix, and V and U
26    *  are MultiVectorMatrices, and P_LR is an ExpansionMatrix.  The
27    *  vectors in the low-rank update (before expansion) live in the
28    *  LowRankVectorSpace.  If P_LR is NULL, P_LR is assumed to be the
29    *  identity matrix.  If V or U is NULL, it is assume to be a matrix
30    *  of zero columns. */
31   class LowRankUpdateSymMatrix : public SymMatrix
32   {
33   public:
34 
35     /**@name Constructors / Destructors */
36     //@{
37 
38     /** Constructor, given the corresponding matrix space. */
39     LowRankUpdateSymMatrix(const LowRankUpdateSymMatrixSpace* owner_space);
40 
41     /** Destructor */
42     ~LowRankUpdateSymMatrix();
43     //@}
44 
45     /** Method for setting the diagonal elements (as a Vector). */
SetDiag(const Vector & D)46     void SetDiag(const Vector& D)
47     {
48       D_ = &D;
49       ObjectChanged();
50     }
51 
52     /** Method for getting the diagonal elements. */
GetDiag() const53     SmartPtr<const Vector> GetDiag() const
54     {
55       return D_;
56     }
57 
58     /** Method for setting the positive low-rank update part. */
SetV(const MultiVectorMatrix & V)59     void SetV(const MultiVectorMatrix& V)
60     {
61       V_ = &V;
62       ObjectChanged();
63     }
64 
65     /** Method for getting the positive low-rank update part. */
GetV() const66     SmartPtr<const MultiVectorMatrix> GetV() const
67     {
68       return V_;
69     }
70 
71     /** Method for setting the negative low-rank update part. */
SetU(const MultiVectorMatrix & U)72     void SetU(const MultiVectorMatrix& U)
73     {
74       U_ = &U;
75       ObjectChanged();
76     }
77 
78     /** Method for getting the negative low-rank update part. */
GetU() const79     SmartPtr<const MultiVectorMatrix> GetU() const
80     {
81       return U_;
82     }
83 
84     /** Return the expansion matrix to lift the low-rank update to the
85      *  higher-dimensional space. */
86     SmartPtr<const Matrix> P_LowRank() const;
87 
88     /** Return the vector space in with the low-rank update vectors
89      *  live. */
90     SmartPtr<const VectorSpace> LowRankVectorSpace() const;
91 
92     /** Flag indicating whether the diagonal term lives in the smaller
93      *  space (from P_LowRank) or in the full space. */
94     bool ReducedDiag() const;
95 
96   protected:
97     /**@name Methods overloaded from matrix */
98     //@{
99     virtual void MultVectorImpl(Number alpha, const Vector& x,
100                                 Number beta, Vector& y) const;
101 
102     /** Method for determining if all stored numbers are valid (i.e.,
103      *  no Inf or Nan). */
104     virtual bool HasValidNumbersImpl() const;
105 
106     virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
107 
108     virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const;
109 
110     virtual void PrintImpl(const Journalist& jnlst,
111                            EJournalLevel level,
112                            EJournalCategory category,
113                            const std::string& name,
114                            Index indent,
115                            const std::string& prefix) const;
116     //@}
117 
118   private:
119     /**@name Default Compiler Generated Methods
120      * (Hidden to avoid implicit creation/calling).
121      * These methods are not implemented and
122      * we do not want the compiler to implement
123      * them for us, so we declare them private
124      * and do not define them. This ensures that
125      * they will not be implicitly created/called. */
126     //@{
127     /** Default Constructor */
128     LowRankUpdateSymMatrix();
129 
130     /** Copy Constructor */
131     LowRankUpdateSymMatrix(const LowRankUpdateSymMatrix&);
132 
133     /** Overloaded Equals Operator */
134     void operator=(const LowRankUpdateSymMatrix&);
135     //@}
136 
137     /** corresponding matrix space */
138     SmartPtr<const LowRankUpdateSymMatrixSpace> owner_space_;
139 
140     /** Vector storing the diagonal matrix D. */
141     SmartPtr<const Vector> D_;
142 
143     /** Vector storing the positive low-rank update. */
144     SmartPtr<const MultiVectorMatrix> V_;
145 
146     /** Vector storing the negative low-rank update. */
147     SmartPtr<const MultiVectorMatrix> U_;
148   };
149 
150   /** This is the matrix space for LowRankUpdateSymMatrix. */
151   class LowRankUpdateSymMatrixSpace : public SymMatrixSpace
152   {
153   public:
154     /** @name Constructors / Destructors */
155     //@{
156     /** Constructor, given the dimension of the matrix. */
LowRankUpdateSymMatrixSpace(Index dim,SmartPtr<const Matrix> P_LowRank,SmartPtr<const VectorSpace> LowRankVectorSpace,bool reduced_diag)157     LowRankUpdateSymMatrixSpace(Index dim,
158                                 SmartPtr<const Matrix> P_LowRank,
159                                 SmartPtr<const VectorSpace> LowRankVectorSpace,
160                                 bool reduced_diag)
161         :
162         SymMatrixSpace(dim),
163         P_LowRank_(P_LowRank),
164         lowrank_vector_space_(LowRankVectorSpace),
165         reduced_diag_(reduced_diag)
166     {
167       DBG_ASSERT(IsValid(lowrank_vector_space_));
168     }
169 
170     /** Destructor */
~LowRankUpdateSymMatrixSpace()171     virtual ~LowRankUpdateSymMatrixSpace()
172     {}
173     //@}
174 
175     /** Overloaded MakeNew method for the SymMatrixSpace base class.
176      */
MakeNewSymMatrix() const177     virtual SymMatrix* MakeNewSymMatrix() const
178     {
179       return MakeNewLowRankUpdateSymMatrix();
180     }
181 
182     /** Method for creating a new matrix of this specific type. */
MakeNewLowRankUpdateSymMatrix() const183     LowRankUpdateSymMatrix* MakeNewLowRankUpdateSymMatrix() const
184     {
185       return new LowRankUpdateSymMatrix(this);
186     }
187 
P_LowRank() const188     SmartPtr<const Matrix> P_LowRank() const
189     {
190       return P_LowRank_;
191     }
192 
LowRankVectorSpace() const193     SmartPtr<const VectorSpace> LowRankVectorSpace() const
194     {
195       return lowrank_vector_space_;
196     }
197 
ReducedDiag() const198     bool ReducedDiag() const
199     {
200       return reduced_diag_;
201     }
202 
203   private:
204     /**@name Default Compiler Generated Methods
205      * (Hidden to avoid implicit creation/calling).
206      * These methods are not implemented and
207      * we do not want the compiler to implement
208      * them for us, so we declare them private
209      * and do not define them. This ensures that
210      * they will not be implicitly created/called. */
211     //@{
212     /** Default Constructor */
213     LowRankUpdateSymMatrixSpace();
214 
215     /** Copy Constructor */
216     LowRankUpdateSymMatrixSpace(const LowRankUpdateSymMatrixSpace&);
217 
218     /** Overloaded Equals Operator */
219     void operator=(const LowRankUpdateSymMatrixSpace&);
220     //@}
221 
222     /** Expansion matrix to lift the low-rank approximation into a
223      *  possibly higher-dimensional space.  If it is NULL, it is
224      *  assume that no lift is performed. */
225     SmartPtr<const Matrix> P_LowRank_;
226 
227     /** Vector space for the space in which the low-rank approximation
228      *  lives. */
229     SmartPtr<const VectorSpace> lowrank_vector_space_;
230 
231     /** Flag indicating whether the diagonal matrix is nonzero only in
232      *  the space of V or in the full space. */
233     bool reduced_diag_;
234   };
235 
236   inline
P_LowRank() const237   SmartPtr<const Matrix> LowRankUpdateSymMatrix::P_LowRank() const
238   {
239     return owner_space_->P_LowRank();
240   }
241 
242   inline
LowRankVectorSpace() const243   SmartPtr<const VectorSpace> LowRankUpdateSymMatrix::LowRankVectorSpace() const
244   {
245     return owner_space_->LowRankVectorSpace();
246   }
247 
248   inline
ReducedDiag() const249   bool LowRankUpdateSymMatrix::ReducedDiag() const
250   {
251     return owner_space_->ReducedDiag();
252   }
253 
254 } // namespace Ipopt
255 #endif
256