ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ConstrainedOptPack_MatrixKKTFullSpaceRelaxed.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef MATRIX_KKT_FULL_SPACE_RELAXED_H
43 #define MATRIX_KKT_FULL_SPACE_RELAXED_H
44 
45 #include "ConstrainedOptPack_Types.hpp"
46 #include "AbstractLinAlgPack/src/MatrixWithOpFactorized.hpp"
47 #include "AbstractLinAlgPack/src/MatrixConvertToSparseFortranCompatible.hpp"
49 
50 namespace ConstrainedOptPack {
51 
95  : public MatrixWithOpFactorized
96  , public MatrixConvertToSparseFortranCompatible
97 {
98 public:
99 
101  typedef AbstractLinAlgPack::DirectSparseFortranCompatibleSolver
103 
105  class NotInitializedException : public std::logic_error
106  {public: NotInitializedException (const std::string& what_arg) : std::logic_error(what_arg) {}};
107 
109  class SingularMatrixException : public std::logic_error
110  {public: SingularMatrixException (const std::string& what_arg) : std::logic_error(what_arg) {}};
111 
113  class InvalidMatrixType : public std::logic_error
114  {public: InvalidMatrixType (const std::string& what_arg) : std::logic_error(what_arg) {}};
115 
117  enum ERunTests { RUN_TESTS, NO_TESTS };
118 
120  enum EPrintMoreOrLess { PRINT_MORE, PRINT_LESS };
121 
124 
126  MatrixKKTFullSpaceRelaxed( const direct_solver_ptr_t& direct_solver = 0 );
127 
164 
168  void initialize( const MatrixOp& G, const MatrixOp& A
169  , std::ostream* out = 0, EPrintMoreOrLess print_what = PRINT_LESS
170  , ERunTests test_what = NO_TESTS );
171 
177  void initialize_relaxed( const MatrixOp& G, const MatrixOp& A
178  , const DVectorSlice& c, value_type bigM = 1e+10
179  , std::ostream* out = 0, EPrintMoreOrLess print_what = PRINT_LESS
180  , ERunTests test_what = NO_TESTS );
181 
192  void set_uninitialized();
193 
200  void release_memory();
201 
203 
204  // /////////////////////////////////////////////////////
205  // Overridden from Matrix
206 
208  size_type rows() const;
209 
211  size_type cols() const;
212 
213  // /////////////////////////////////////////////////////////
214  // Overridden from MatrixOp
215 
217  std::ostream& output(std::ostream& out) const;
218 
220  MatrixOp& operator=(const MatrixOp& m);
221 
223  void Vp_StMtV(DVectorSlice* vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1
224  , const DVectorSlice& vs_rhs2, value_type beta) const;
225 
226  // ////////////////////////////////////////////////////////////
227  // Overridden from MatrixFactorized
228 
230  void V_InvMtV( DVectorSlice* v_lhs, BLAS_Cpp::Transp trans_rhs1
231  , const DVectorSlice& vs_rhs2) const;
232 
233  // ////////////////////////////////////////////////////////////
234  // Overridden from MatrixConvertToSparseFortranCompatible
235 
237  FortranTypes::f_int num_nonzeros( EExtractRegion extract_region ) const;
238 
241  EExtractRegion extract_region
242  , const FortranTypes::f_int len_Aval
243  , FortranTypes::f_dbl_prec Aval[]
244  , const FortranTypes::f_int len_Aij
245  , FortranTypes::f_int Arow[]
246  , FortranTypes::f_int Acol[]
247  , const FortranTypes::f_int row_offset
248  , const FortranTypes::f_int col_offset
249  ) const;
250 
251 private:
252 
253  // //////////////////////////////
254  // Private data members
255 
256  bool initialized_;
257  size_type n_; // Number of rows and columns in G and number of rows in A.
258  size_type m_; // Number of columns in A
259  bool use_relaxation_;
260  value_type bigM_;
261  EPrintMoreOrLess print_what_;
262  ERunTests test_what_;
263  std::ostream *out_;
264  const MatrixOp *G_;
265  const MatrixConvertToSparseFortranCompatible
266  *convG_;
267  size_type G_nz_; // Remember the number of nonzeros of G
268  const MatrixOp *A_;
269  const MatrixConvertToSparseFortranCompatible
270  *convA_;
271  size_type A_nz_; // Remember the number of nonzeros of A
272 
273  // //////////////////////////////
274  // Private member functions
275 
277  void assert_matrices_set() const;
278 
280  void assert_initialized() const;
281 
285  void validate_and_set_matrices( const MatrixOp& G, const MatrixOp& A );
286 
287 }; // end class MatrixKKTFullSpaceRelaxed
288 
289 } // end namespace ConstrainedOptPack
290 
291 #endif // MATRIX_KKT_FULL_SPACE_RELAXED_H
void set_uninitialized()
Set the matrix to uninitialized.
void coor_extract_nonzeros(EExtractRegion extract_region, const FortranTypes::f_int len_Aval, FortranTypes::f_dbl_prec Aval[], const FortranTypes::f_int len_Aij, FortranTypes::f_int Arow[], FortranTypes::f_int Acol[], const FortranTypes::f_int row_offset, const FortranTypes::f_int col_offset) const
STANDARD_COMPOSITION_MEMBERS(DirectSparseFortranCompatibleSolver, direct_solver)
<<std comp>="">> members for the direct sparse linear solver
FortranTypes::f_int num_nonzeros(EExtractRegion extract_region) const
void Vp_StMtV(DVectorSlice *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2, value_type beta) const
(2) vs_lhs = alpha * op(M_rhs1) * vs_rhs2 + beta * vs_lhs (BLAS xGEMV)
void release_memory()
Clear all allocated storage.
MatrixOp & operator=(const MatrixOp &m)
MatrixKKTFullSpaceRelaxed(const direct_solver_ptr_t &direct_solver=0)
AbstractLinAlgPack::DirectSparseFortranCompatibleSolver DirectSparseFortranCompatibleSolver
size_t size_type
void V_InvMtV(DVectorSlice *v_lhs, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2) const
(1) v_lhs = inv(op(M_rhs1)) * vs_rhs2
void initialize(const MatrixOp &G, const MatrixOp &A, std::ostream *out=0, EPrintMoreOrLess print_what=PRINT_LESS, ERunTests test_what=NO_TESTS)
Initialize the nonrelaxed matrix.
void initialize_relaxed(const MatrixOp &G, const MatrixOp &A, const DVectorSlice &c, value_type bigM=1e+10, std::ostream *out=0, EPrintMoreOrLess print_what=PRINT_LESS, ERunTests test_what=NO_TESTS)
Initialize the relaxed matrix.
std::ostream & output(std::ostream &out) const
Transp
Implementation of a KKT matrix factorized in the full space.