MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_PreEvalNewPointBarrier_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 #include <typeinfo>
44 #include <iostream>
45 
53 #include "MoochoPack_IpState.hpp"
56 
58 
59 #include "Teuchos_dyn_cast.hpp"
60 
61 namespace MoochoPack {
62 
64  const value_type relative_bound_push,
65  const value_type absolute_bound_push
66  )
67  :
68  relative_bound_push_(relative_bound_push),
69  absolute_bound_push_(absolute_bound_push)
70  {}
71 
73  Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
74  ,poss_type assoc_step_poss
75  )
76  {
77  using Teuchos::dyn_cast;
80 
81  NLPAlgo &algo = dyn_cast<NLPAlgo>(_algo);
82  IpState &s = dyn_cast<IpState>(_algo.state());
83  NLP &nlp = algo.nlp();
84  NLPFirstOrder *nlp_foi = dynamic_cast<NLPFirstOrder*>(&nlp);
85 
86  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
87  std::ostream& out = algo.track().journal_out();
88 
89  if(!nlp.is_initialized())
90  nlp.initialize(algo.algo_cntr().check_results());
91 
92  // print step header.
93  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) )
94  {
96  print_algorithm_step( _algo, step_poss, type, assoc_step_poss, out );
97  }
98 
99  IterQuantityAccess<value_type> &barrier_parameter_iq = s.barrier_parameter();
100  IterQuantityAccess<VectorMutable> &x_iq = s.x();
101 
102  if( x_iq.last_updated() == IterQuantity::NONE_UPDATED )
103  {
104  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) )
105  {
106  out << "\nInitialize x with x_k = nlp.xinit() ...\n"
107  << " and push x_k within bounds.\n";
108  }
109  VectorMutable& x_k = x_iq.set_k(0) = nlp.xinit();
110 
111  // apply transformation operator to push x sufficiently within bounds
112  force_in_bounds_buffer(relative_bound_push_,
113  absolute_bound_push_,
114  nlp.xl(),
115  nlp.xu(),
116  &x_k);
117 
118  // evaluate the func and constraints
119  IterQuantityAccess<value_type>
120  &f_iq = s.f();
121  IterQuantityAccess<VectorMutable>
122  &Gf_iq = s.Gf(),
123  *c_iq = nlp.m() > 0 ? &s.c() : NULL;
124  IterQuantityAccess<MatrixOp>
125  *Gc_iq = nlp_foi ? &s.Gc() : NULL;
126 
128  assert_print_nan_inf(x_k, "x", true, NULL); // With throw exception if Inf or NaN!
129 
130  // Wipe out storage for computed iteration quantities (just in case?) : RAB: 7/29/2002
131  if(f_iq.updated_k(0))
132  f_iq.set_not_updated_k(0);
133  if(Gf_iq.updated_k(0))
134  Gf_iq.set_not_updated_k(0);
135  if (c_iq)
136  {
137  if(c_iq->updated_k(0))
138  c_iq->set_not_updated_k(0);
139  }
140  if (nlp_foi)
141  {
142  if(Gc_iq->updated_k(0))
143  Gc_iq->set_not_updated_k(0);
144  }
145  }
146 
147  if (barrier_parameter_iq.last_updated() == IterQuantity::NONE_UPDATED)
148  {
149  barrier_parameter_iq.set_k(-1) = 0.1; // RAB: 7/29/2002: This should be parameterized! (allow user to set this!)
150  }
151 
152  // Print vector information
153  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) )
154  {
155  out << "x_k =\n" << x_iq.get_k(0);
156  }
157 
158  return true;
159  }
160 
161 
163  const Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
164  ,poss_type assoc_step_poss, std::ostream& out, const std::string& L
165  ) const
166  {
167  //const NLPAlgo &algo = rsqp_algo(_algo);
168  //const NLPAlgoState &s = algo.rsqp_state();
169  out << L << "# Evaluate information specific to primal / dual barrier algorithms\n"
170  << L << "if (x never updated) then\n"
171  << L << " x_k = nlp.xinit()\n"
172  << L << " force_in_bounds(x_k)\n"
173  << L << " set f_k not updated\n"
174  << L << " set Gf_k not updated\n"
175  << L << " if (m > 0) then\n"
176  << L << " set c_k not updated\n"
177  << L << " set Gc_k not updated\n"
178  << L << "end\n";
179  }
180 
181 
182 namespace {
183 
184 const int local_num_options = 2;
185 
186 enum local_EOptions
187  {
188  RELATIVE_BOUND_PUSH,
189  ABSOLUTE_BOUND_PUSH
190  };
191 
192 const char* local_SOptions[local_num_options] =
193  {
194  "relative_bound_push",
195  "absolute_bound_push"
196  };
197 
198 }
199 
200 
203  , const char opt_grp_name[] )
204  :
205  OptionsFromStreamPack::SetOptionsFromStreamNode(
206  opt_grp_name, local_num_options, local_SOptions ),
207  OptionsFromStreamPack::SetOptionsToTargetBase< PreEvalNewPointBarrier_Step >( target )
208  {
209  }
210 
212  int option_num, const std::string& option_value )
213  {
215 
216  typedef PreEvalNewPointBarrier_Step target_t;
217  switch( (local_EOptions)option_num )
218  {
219  case RELATIVE_BOUND_PUSH:
220  target().relative_bound_push(std::atof(option_value.c_str()));
221  break;
222  case ABSOLUTE_BOUND_PUSH:
223  target().absolute_bound_push(std::atof(option_value.c_str()));
224  break;
225  default:
226  TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only?
227  }
228  }
229 
230 } // end namespace MoochoPack
bool StringToBool(const char *opt_name, const char *str)
Convert a string "true" or "false" into bool #true# or #false#.
void print_step(const IterationPack::Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss, std::ostream &out, const std::string &leading_str) const
Called by Algorithm::print_algorithm() to print out what this step does in Matlab like format...
PreEvalNewPointBarrier_Step(const value_type relative_bound_push=0.01, const value_type absolute_bound_push=0.001)
void force_in_bounds_buffer(const value_type rel_push, const value_type abs_push, const Vector &xl, const Vector &xu, VectorMutable *x)
Force a vector sufficiently within bounds according to a specified absolute and relative buffer...
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.
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
T_To & dyn_cast(T_From &from)
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()
PreEvalNewPointBarrier_StepSetOptions(PreEvalNewPointBarrier_Step *target=0, const char opt_grp_name[]="PreEvalNewPointBarrier")
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...
AbstractLinAlgPack::value_type value_type
Acts as the central hub for an iterative algorithm.
Standard evaluation step class for extra parameters in primal/dual barrier method.
void setOption(int option_num, const std::string &option_value)
Overridden from SetOptionsFromStreamNode.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
const std::string & option_value(OptionsGroup::const_iterator &itr)