MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_DecompositionSystemHandlerStd_Strategy.cpp
Go to the documentation of this file.
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 #include <ostream>
43 #include <typeinfo>
44 
60 #include "Teuchos_dyn_cast.hpp"
61 #include "Teuchos_Assert.hpp"
62 
63 namespace MoochoPack {
64 
65 // Constructors / initializers
66 
68 {}
69 
70 // Overridden from DecompositionSystemHandler_Strategy
71 
73  NLPAlgo &algo
74  ,NLPAlgoState &s
75  ,NLPFirstOrder &nlp
76  ,EDecompSysTesting decomp_sys_testing
77  ,EDecompSysPrintLevel decomp_sys_testing_print_level
78  ,bool *new_decomp_selected
79  )
80 {
81  using Teuchos::dyn_cast;
82 
83  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
84  std::ostream& out = algo.track().journal_out();
85 
86  const size_type
87  n = nlp.n(),
88  m = nlp.m(),
89  r = s.decomp_sys().equ_decomp().size();
90 
91  // Get the iteration quantity container objects
92  IterQuantityAccess<MatrixOp>
93  *Gc_iq = ( m > 0 ) ? &s.Gc() : NULL,
94  *Z_iq = ( n > m && r > 0 ) ? &s.Z() : NULL,
95  *Y_iq = ( r > 0 ) ? &s.Y() : NULL,
96  *Uz_iq = ( m > 0 && m > r ) ? &s.Uz() : NULL,
97  *Uy_iq = ( m > 0 && m > r ) ? &s.Uy() : NULL;
98  IterQuantityAccess<MatrixOpNonsing>
99  *R_iq = ( m > 0 ) ? &s.R() : NULL;
100 
101  if( n > m ) {
102 
103  //
104  // Update range/null decomposition
105  //
106 
107  // Determine if we will test the decomp_sys or not
108  const DecompositionSystem::ERunTests
109  ds_test_what = ( ( decomp_sys_testing == DST_TEST
110  || ( decomp_sys_testing == DST_DEFAULT
111  && algo.algo_cntr().check_results() ) )
112  ? DecompositionSystem::RUN_TESTS
113  : DecompositionSystem::NO_TESTS );
114 
115  // Determine the output level for decomp_sys
116  DecompositionSystem::EOutputLevel ds_olevel;
117  switch(olevel) {
118  case PRINT_NOTHING:
120  ds_olevel = DecompositionSystem::PRINT_NONE;
121  break;
123  case PRINT_ACTIVE_SET:
124  ds_olevel = DecompositionSystem::PRINT_BASIC_INFO;
125  break;
126  case PRINT_VECTORS:
128  break;
130  ds_olevel = DecompositionSystem::PRINT_EVERY_THING;
131  break;
132  default:
133  TEUCHOS_TEST_FOR_EXCEPT(true); // Should not get here!
134  };
135 
136  // Form the decomposition of Gc and update the decomposition system matrices
137  if( olevel >= PRINT_ALGORITHM_STEPS ) {
138  out << "\nUpdating the range/null decompostion matrices ...\n";
139  }
140  s.decomp_sys().update_decomp(
141  &out // out
142  ,ds_olevel // olevel
143  ,ds_test_what // test_what
144  ,Gc_iq->get_k(0) // Gc
145  ,&Z_iq->set_k(0) // Z
146  ,&Y_iq->set_k(0) // Y
147  ,&R_iq->set_k(0) // R
148  ,Uz_iq ? &Uz_iq->set_k(0) : NULL // Uz
149  ,Uy_iq ? &Uy_iq->set_k(0) : NULL // Uy
150  ,DecompositionSystem::MATRICES_ALLOW_DEP_IMPS // ToDo: Change this!
151  );
152  s.equ_decomp( s.decomp_sys().equ_decomp() );
153  s.equ_undecomp( s.decomp_sys().equ_undecomp() );
154 
155  *new_decomp_selected = false;
156 
157  }
158  else {
159  //
160  // Update decomposition
161  //
162  // R = C
163  // Y = I
164  //
165  const BasisSystem &basis_sys = *nlp.basis_sys();
166  basis_sys.update_basis(
167  Gc_iq->get_k(0) // Gc
168  ,&R_iq->set_k(0 ) // C
169  ,NULL // D
170  ,NULL // GcUP
171  ,BasisSystem::MATRICES_ALLOW_DEP_IMPS // Meaningless
172  ,static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ? &out : NULL
173  );
174  dyn_cast<MatrixSymIdent>(Y_iq->set_k(0)).initialize( nlp.space_x() );
175  s.equ_decomp( basis_sys.equ_decomp() );
176  s.equ_undecomp( basis_sys.equ_undecomp() );
177  }
178 
179  return true;
180 }
181 
183  const NLPAlgo &algo
184  ,const NLPAlgoState &s
185  ,std::ostream &out
186  ,const std::string &L
187  ) const
188 {
189  using Teuchos::dyn_cast;
190 
191  const NLPFirstOrder &nlp = dyn_cast<const NLPFirstOrder>(algo.nlp());
192  const size_type n = nlp.n(), m = nlp.m(), r = nlp.basis_sys()->equ_decomp().size();
193  out
194  << L << "*** Updating the range/null decomposition.\n";
195  if( n == m && m == r ) {
196  out
197  << L << "R = C\n"
198  << L << "Y = I\n";
199  }
200  else {
201  out
202  << L << "begin update decomposition\n"
203  << L << "(class = \'" << typeName(s.decomp_sys()) << "\')\n"
204  ;
205  s.decomp_sys().print_update_decomp( out, L + " " );
206  out
207  << L << "end update decomposition\n"
208  ;
209  }
210 }
211 
212 } // end namespace MoochoPack
AbstractLinAlgPack::size_type size_type
std::string typeName(const T &t)
rSQP Algorithm control class.
virtual std::ostream & journal_out() const
Return a reference to a std::ostream to be used to output debug information and the like...
EJournalOutputLevel
enum for journal output.
T_To & dyn_cast(T_From &from)
Reduced space SQP state encapsulation interface.
std::ostream * out
void print_update_decomposition(const NLPAlgo &algo, const NLPAlgoState &s, std::ostream &out, const std::string &leading_spaces) const
AlgorithmTracker & track()
bool update_decomposition(NLPAlgo &algo, NLPAlgoState &s, NLPFirstOrder &nlp, EDecompSysTesting decomp_sys_testing, EDecompSysPrintLevel decomp_sys_testing_print_level, bool *new_decomp_selected)
int n
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)