MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_TangentialStepWithoutBounds_Step.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 
57 #include "Teuchos_dyn_cast.hpp"
58 #include "Teuchos_Assert.hpp"
59 
60 
61 namespace LinAlgOpPack {
63 }
64 
65 
66 namespace MoochoPack {
67 
68 
70  :max_pz_norm_(-1.0),
71  num_pz_damp_iters_(0)
72 {}
73 
74 
76  Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
77  ,poss_type assoc_step_poss
78  )
79 {
80 
81  using std::endl;
82  using BLAS_Cpp::no_trans;
83  using Teuchos::dyn_cast;
88  using LinAlgOpPack::V_StV;
89  using LinAlgOpPack::V_MtV;
90 
91  NLPAlgo &algo = rsqp_algo(_algo);
92  NLPAlgoState &s = algo.rsqp_state();
93 
94  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
95  EJournalOutputLevel ns_olevel = algo.algo_cntr().null_space_journal_output_level();
96  std::ostream& out = algo.track().journal_out();
97 
98  // print step header.
99  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
101  print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
102  }
103 
104  if( algo.nlp().num_bounded_x() )
106  true, std::logic_error
107  ,"TangentialStepWithoutBounds_Step::do_step(...): Error, "
108  "can't solve for pz for NLP with undecomposed constraints or "
109  "has bounds on the variables");
110 
111  // Comupte qp_grad which is an approximation to rGf + Z' * HL * Y * py
112 
113  // qp_grad_k = rGf_k
114  VectorMutable &qp_grad_k = s.qp_grad().set_k(0) = s.rGf().get_k(0);
115 
116  IterQuantityAccess<value_type> &zeta_iq = s.zeta();
117  IterQuantityAccess<VectorMutable> &w_iq = s.w();
118  if( w_iq.updated_k(0) && zeta_iq.updated_k(0) ) {
119  // qp_grad += zeta * w
120  Vp_StV( &qp_grad_k, zeta_iq.get_k(0), w_iq.get_k(0) );
121  }
122 
123  // Solve the system pz = - inv(rHL) * qp_grad
124  VectorMutable &pz_k = s.pz().set_k(0);
125  const MatrixSymOpNonsing &rHL_k = dyn_cast<MatrixSymOpNonsing>(s.rHL().get_k(0));
126  V_InvMtV( &pz_k, rHL_k, no_trans, qp_grad_k );
127  Vt_S( &pz_k, -1.0 );
128 
129  // nu = 0.0
130  s.nu().set_k(0) = 0.0;
131 
132  value_type pz_norm_inf = -1.0;
133  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
134  pz_norm_inf = pz_k.norm_inf();
135  out << "\n||pz_k||inf = " << pz_norm_inf << endl;
136  }
137  if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_VECTORS) )
138  out << "\npz_k = \n" << pz_k << std::endl;
139 
140  // Check to see if we need to dampen pz
141  const bool dampen_pz = max_pz_norm() >= 0.0 && s.k() <= num_pz_damp_iters();
142  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
143  out
144  << "\nChecking if we need to dampen pz:"
145  << " ( (max_pz_norm="<<max_pz_norm()<<") >= 0.0 )"
146  << " && ( (k="<<s.k()<<") <= (num_pz_damp_iters="<<num_pz_damp_iters()<<") ) : "
147  << ( dampen_pz ? "true, dampen pz ..." : "false, no dampen pz!" )
148  << endl;
149  }
150 
151  if ( dampen_pz ) {
152  // pz_new = ( max_pz_norm / pz_norm_inf ) * pz
153  if (pz_norm_inf < 0.0 )
154  pz_norm_inf = pz_k.norm_inf();
155  const value_type pz_damp_factor = ( max_pz_norm() / pz_norm_inf );
156  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
157  out
158  << "\npz_damp_factor = max_pz_norm / ||pz||inf = "
159  << max_pz_norm() << " / " << pz_norm_inf << " = "
160  << pz_damp_factor;
161  }
162  Vt_S( &pz_k, pz_damp_factor );
163  }
164 
165  // Zpz = Z * pz
166  V_MtV( &s.Zpz().set_k(0), s.Z().get_k(0), no_trans, pz_k );
167 
168  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
169  out << "\n||pz_k||inf = " << s.pz().get_k(0).norm_inf()
170  << "\n||Zpz_k||2 = " << s.Zpz().get_k(0).norm_2() << std::endl;
171  }
172 
173  if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_VECTORS) ) {
174  out << "\npz_k = \n" << s.pz().get_k(0);
175  out << std::endl;
176  }
177 
178  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
179  out << "\nnu_k = \n" << s.nu().get_k(0);
180  out << "\nZpz_k = \n" << s.Zpz().get_k(0);
181  out << std::endl;
182  }
183 
184  if(algo.algo_cntr().check_results()) {
185  assert_print_nan_inf(s.pz().get_k(0), "pz_k",true,&out);
186  assert_print_nan_inf(s.Zpz().get_k(0), "Zpz_k",true,&out);
187  }
188 
189  return true;
190 }
191 
192 
194  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
195  , std::ostream& out, const std::string& L ) const
196 {
197  out
198  << L << "*** Calculate the null space step by solving an unconstrainted QP\n"
199  << L << "qp_grad_k = rGf_k + zeta_k * w_k\n"
200  << L << "solve:\n"
201  << L << " min qp_grad_k' * pz_k + 1/2 * pz_k' * rHL_k * pz_k\n"
202  << L << " pz_k <: R^(n-r)\n"
203  << L << "Zpz_k = Z_k * pz_k\n"
204  << L << "nu_k = 0\n";
205 }
206 
207 
208 } // end namespace MoochoPack
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
rSQP Algorithm control class.
void V_StV(VectorMutable *v_lhs, value_type alpha, const V &V_rhs)
v_lhs = alpha * V_rhs.
void print_step(const Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss, std::ostream &out, const std::string &leading_str) const
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
Not transposed.
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_algorithm_step(const Algorithm &algo, Algorithm::poss_type step_poss, EDoStepType type, Algorithm::poss_type assoc_step_poss, std::ostream &out)
Prints to 'out' the algorithm step.
void V_InvMtV(VectorMutable *v_lhs, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs = inv(op(M_rhs1)) * v_rhs2
AlgorithmTracker & track()
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta=1.0)
v_lhs = alpha * op(M_rhs1) * v_rhs2 + beta * v_lhs (BLAS xGEMV)
bool assert_print_nan_inf(const value_type &val, const char name[], bool throw_excpt, std::ostream *out)
This function asserts if a value_type scalare is a NaN or Inf and optionally prints out these entires...
void V_MtV(VectorMutable *v_lhs, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const V &V_rhs2)
v_lhs = op(M_rhs1) * V_rhs2.
AbstractLinAlgPack::value_type value_type
Acts as the central hub for an iterative algorithm.
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr
NLPAlgo & rsqp_algo(Algorithm &algo)
Convert from a Algorithm to a NLPAlgo.