IpSymMatrix.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Copyright (C) 2004, 2008 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: IpSymMatrix.hpp 2161 2013-01-01 20:39:05Z stefan $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPSYMMATRIX_HPP__
  9. #define __IPSYMMATRIX_HPP__
  10. #include "IpUtils.hpp"
  11. #include "IpMatrix.hpp"
  12. namespace Ipopt
  13. {
  14. /* forward declarations */
  15. class SymMatrixSpace;
  16. /** This is the base class for all derived symmetric matrix types.
  17. */
  18. class SymMatrix : public Matrix
  19. {
  20. public:
  21. /** @name Constructor/Destructor */
  22. //@{
  23. /** Constructor, taking the owner_space.
  24. */
  25. inline
  26. SymMatrix(const SymMatrixSpace* owner_space);
  27. /** Destructor */
  28. virtual ~SymMatrix()
  29. {}
  30. //@}
  31. /** @name Information about the size of the matrix */
  32. //@{
  33. /** Dimension of the matrix (number of rows and columns) */
  34. inline
  35. Index Dim() const;
  36. //@}
  37. inline
  38. SmartPtr<const SymMatrixSpace> OwnerSymMatrixSpace() const;
  39. protected:
  40. /** @name Overloaded methods from Matrix. */
  41. //@{
  42. /** Since the matrix is
  43. * symmetric, it is only necessary to implement the
  44. * MultVectorImpl method in a class that inherits from this base
  45. * class. If the TransMultVectorImpl is called, this base class
  46. * automatically calls MultVectorImpl instead. */
  47. virtual void TransMultVectorImpl(Number alpha, const Vector& x, Number beta,
  48. Vector& y) const
  49. {
  50. // Since this matrix is symetric, this is the same operation as
  51. // MultVector
  52. MultVector(alpha, x, beta, y);
  53. }
  54. /** Since the matrix is symmetric, the row and column max norms
  55. * are identical */
  56. virtual void ComputeColAMaxImpl(Vector& cols_norms, bool init) const
  57. {
  58. ComputeRowAMaxImpl(cols_norms, init);
  59. }
  60. //@}
  61. private:
  62. /** Copy of the owner space ptr as a SymMatrixSpace instead
  63. * of a MatrixSpace
  64. */
  65. const SymMatrixSpace* owner_space_;
  66. };
  67. /** SymMatrixSpace base class, corresponding to the SymMatrix base
  68. * class. */
  69. class SymMatrixSpace : public MatrixSpace
  70. {
  71. public:
  72. /** @name Constructors/Destructors */
  73. //@{
  74. /** Constructor, given the dimension (identical to the number of
  75. * rows and columns).
  76. */
  77. SymMatrixSpace(Index dim)
  78. :
  79. MatrixSpace(dim,dim)
  80. {}
  81. /** Destructor */
  82. virtual ~SymMatrixSpace()
  83. {}
  84. //@}
  85. /** Pure virtual method for creating a new matrix of this specific
  86. * type. */
  87. virtual SymMatrix* MakeNewSymMatrix() const=0;
  88. /** Overloaded MakeNew method for the MatrixSpace base class.
  89. */
  90. virtual Matrix* MakeNew() const
  91. {
  92. return MakeNewSymMatrix();
  93. }
  94. /** Accessor method for the dimension of the matrices in this
  95. * matrix space.
  96. */
  97. Index Dim() const
  98. {
  99. DBG_ASSERT(NRows() == NCols());
  100. return NRows();
  101. }
  102. private:
  103. /**@name Default Compiler Generated Methods
  104. * (Hidden to avoid implicit creation/calling).
  105. * These methods are not implemented and
  106. * we do not want the compiler to implement
  107. * them for us, so we declare them private
  108. * and do not define them. This ensures that
  109. * they will not be implicitly created/called. */
  110. //@{
  111. /** default constructor */
  112. SymMatrixSpace();
  113. /* Copy constructor */
  114. SymMatrixSpace(const SymMatrixSpace&);
  115. /** Overloaded Equals Operator */
  116. SymMatrixSpace& operator=(const SymMatrixSpace&);
  117. //@}
  118. };
  119. /* inline methods */
  120. inline
  121. SymMatrix::SymMatrix(const SymMatrixSpace* owner_space)
  122. :
  123. Matrix(owner_space),
  124. owner_space_(owner_space)
  125. {}
  126. inline
  127. Index SymMatrix::Dim() const
  128. {
  129. return owner_space_->Dim();
  130. }
  131. inline
  132. SmartPtr<const SymMatrixSpace> SymMatrix::OwnerSymMatrixSpace() const
  133. {
  134. return owner_space_;
  135. }
  136. } // namespace Ipopt
  137. #endif