MoochoPack : Framework for Large-Scale Optimization Algorithms  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MoochoPack_CalcDFromYPYZPZ_Step.cpp
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 <limits>
43 #include <ostream>
44 
45 #include "MoochoPack_CalcDFromYPYZPZ_Step.hpp"
46 #include "MoochoPack_moocho_algo_conversion.hpp"
47 #include "IterationPack_print_algorithm_step.hpp"
48 //#include "ConstrainedOptPack_print_vector_change_stats.hpp"
49 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
50 #include "AbstractLinAlgPack_VectorMutable.hpp"
51 #include "AbstractLinAlgPack_VectorStdOps.hpp"
52 #include "AbstractLinAlgPack_VectorOut.hpp"
53 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
54 #include "Teuchos_implicit_cast.hpp"
55 
56 namespace LinAlgOpPack {
58 }
59 
61  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
62 {
63 
66  using LinAlgOpPack::V_VpV;
67 
68  NLPAlgo &algo = rsqp_algo(_algo);
69  NLPAlgoState &s = algo.rsqp_state();
70 
71  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
72  EJournalOutputLevel ns_olevel = algo.algo_cntr().null_space_journal_output_level();
73  std::ostream& out = algo.track().journal_out();
74 
75  // print step header.
76  if( implicit_cast<int>(olevel) >= implicit_cast<int>(PRINT_ALGORITHM_STEPS) ) {
77  using IterationPack::print_algorithm_step;
78  print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
79  }
80 
81  // d = Ypy + Zpz
82  VectorMutable &d_k = s.d().set_k(0);
83  const Vector &Ypy_k = s.Ypy().get_k(0);
84  const Vector &Zpz_k = s.Zpz().get_k(0);
85  V_VpV( &d_k, Ypy_k, Zpz_k );
86 
87  Range1D
88  var_dep = s.var_dep(),
89  var_indep = s.var_indep();
90 
91  if( implicit_cast<int>(olevel) >= implicit_cast<int>(PRINT_ALGORITHM_STEPS) ) {
92  const value_type very_small = std::numeric_limits<value_type>::min();
93  out
94  << "\n(Ypy_k'*Zpz_k)/(||Ypy_k||2 * ||Zpz_k||2 + eps)\n"
95  << " = ("<<dot(Ypy_k,Zpz_k)<<")/("<<Ypy_k.norm_2()<<" * "<<Zpz_k.norm_2()<<" + "<<very_small<<")\n"
96  << " = " << dot(Ypy_k,Zpz_k) / ( Ypy_k.norm_2() * Zpz_k.norm_2() + very_small ) << "\n";
97 /*
98  ConstrainedOptPack::print_vector_change_stats(
99  s.x().get_k(0), "x", s.d().get_k(0), "d", out );
100 */
101  // ToDo: Replace the above with a reduction operator!
102  }
103 
104  if( implicit_cast<int>(olevel) >= implicit_cast<int>(PRINT_ALGORITHM_STEPS) ) {
105  out << "\n||d_k||inf = " << d_k.norm_inf();
106  if( var_dep.size() )
107  out << "\n||d(var_dep)_k||inf = " << d_k.sub_view(var_dep)->norm_inf();
108  if( var_indep.size() )
109  out << "\n||d(var_indep)_k||inf = " << d_k.sub_view(var_indep)->norm_inf();
110  out << std::endl;
111  }
112  if( implicit_cast<int>(olevel) >= implicit_cast<int>(PRINT_VECTORS) ) {
113  out << "\nd_k = \n" << d_k;
114  if( var_dep.size() )
115  out << "\nd(var_dep)_k = \n" << *d_k.sub_view(var_dep);
116  }
117  if( implicit_cast<int>(ns_olevel) >= implicit_cast<int>(PRINT_VECTORS) ) {
118  if( var_indep.size() )
119  out << "\nd(var_indep)_k = \n" << *d_k.sub_view(var_indep);
120  }
121 
122  return true;
123 
124 }
125 
127  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
128  , std::ostream& out, const std::string& L ) const
129 {
130  out
131  << L << "*** Calculates the search direction d from Ypy and Zpz\n"
132  << L << "d_k = Ypy_k + Zpz_k \n";
133 }
rSQP Algorithm control class.
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)
virtual std::ostream & journal_out() const
void V_VpV(VectorMutable *v_lhs, const V1 &V1_rhs1, const V2 &V2_rhs2)
Reduced space SQP state encapsulation interface.
TypeTo implicit_cast(const TypeFrom &t)
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)
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr