MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_LineSearchFullStep_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 
54 #include "Teuchos_Assert.hpp"
55 
56 namespace MoochoPack {
57 
59  const bounds_tester_ptr_t& bounds_tester
60  )
61  :
62  bounds_tester_(bounds_tester)
63 {}
64 
65 
67  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
68 {
71  using LinAlgOpPack::V_VpV;
72 
73  NLPAlgo &algo = rsqp_algo(_algo);
74  NLPAlgoState &s = algo.rsqp_state();
75  NLP &nlp = algo.nlp();
76 
77  const size_type
78  m = nlp.m();
79 
80  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
81  std::ostream& out = algo.track().journal_out();
82 
83  // print step header.
84  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
86  print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
87  }
88 
89  // alpha_k = 1.0
90  IterQuantityAccess<value_type>
91  &alpha_iq = s.alpha();
92  if( !alpha_iq.updated_k(0) )
93  alpha_iq.set_k(0) = 1.0;
94 
95  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
96  out << "\nf_k = " << s.f().get_k(0);
97  if(m)
98  out << "\n||c_k||inf = " << s.c().get_k(0).norm_inf();
99  out << "\nalpha_k = " << alpha_iq.get_k(0) << std::endl;
100  }
101 
102  // x_kp1 = x_k + d_k
103  IterQuantityAccess<VectorMutable> &x_iq = s.x();
104  const Vector &x_k = x_iq.get_k(0);
105  VectorMutable &x_kp1 = x_iq.set_k(+1);
106  x_kp1 = x_k;
107  Vp_StV( &x_kp1, alpha_iq.get_k(0), s.d().get_k(0) );
108 
109  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
110  out << "\n||x_kp1||inf = " << s.x().get_k(+1).norm_inf() << std::endl;
111  }
112  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
113  out << "\nx_kp1 =\n" << s.x().get_k(+1);
114  }
115 
116  if(algo.algo_cntr().check_results()) {
118  x_kp1, "x_kp1",true
119  ,int(olevel) >= int(PRINT_ALGORITHM_STEPS) ? &out : NULL
120  );
121  if( nlp.num_bounded_x() ) {
122  if(!bounds_tester().check_in_bounds(
123  int(olevel) >= int(PRINT_ALGORITHM_STEPS) ? &out : NULL
124  , int(olevel) >= int(PRINT_VECTORS) // print_all_warnings
125  , int(olevel) >= int(PRINT_ITERATION_QUANTITIES) // print_vectors
126  , nlp.xl(), "xl"
127  , nlp.xu(), "xu"
128  , x_kp1, "x_kp1"
129  ))
130  {
132  true, TestFailed
133  ,"LineSearchFullStep_Step::do_step(...) : Error, "
134  "the variables bounds xl <= x_k(+1) <= xu where violated!" );
135  }
136  }
137  }
138 
139  // Calcuate f and c at the new point.
140  nlp.unset_quantities();
141  nlp.set_f( &s.f().set_k(+1) );
142  if(m) nlp.set_c( &s.c().set_k(+1) );
143  nlp.calc_f(x_kp1);
144  if(m) nlp.calc_c( x_kp1, false );
145  nlp.unset_quantities();
146 
147  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
148  out << "\nf_kp1 = " << s.f().get_k(+1);
149  if(m)
150  out << "\n||c_kp1||inf = " << s.c().get_k(+1).norm_inf();
151  out << std::endl;
152  }
153 
154  if( m && static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
155  out << "\nc_kp1 =\n" << s.c().get_k(+1);
156  }
157 
158  if(algo.algo_cntr().check_results()) {
159  assert_print_nan_inf( s.f().get_k(+1), "f(x_kp1)", true, &out );
160  if(m)
161  assert_print_nan_inf( s.c().get_k(+1), "c(x_kp1)", true, &out );
162  }
163 
164  return true;
165 }
166 
168  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
169  , std::ostream& out, const std::string& L ) const
170 {
171  out
172  << L << "if alpha_k is not updated then\n"
173  << L << " alpha_k = 1.0\n"
174  << L << "end\n"
175  << L << "x_kp1 = x_k + alpha_k * d_k\n"
176  << L << "f_kp1 = f(x_kp1)\n"
177  << L << "if m > 0 then c_kp1 = c(x_kp1)\n";
178 }
179 
180 } // end namespace MoochoPack
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
AbstractLinAlgPack::size_type size_type
Thrown if a runtime test failed.
#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.
virtual std::ostream & journal_out() const
Return a reference to a std::ostream to be used to output debug information and the like...
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
EJournalOutputLevel
enum for journal output.
void V_VpV(VectorMutable *v_lhs, const V1 &V1_rhs1, const V2 &V2_rhs2)
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.
AlgorithmTracker & track()
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...
Acts as the central hub for an iterative algorithm.
NLPAlgoState & rsqp_state()
<<std aggr>="">> members for algo_cntr
LineSearchFullStep_Step()
Not defined and not to be called.
NLPAlgo & rsqp_algo(Algorithm &algo)
Convert from a Algorithm to a NLPAlgo.