MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_NLPAlgoContainer.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 //#define RELEASE_TRACE
43 
44 #include <assert.h>
45 
46 #include <iostream> // used for debugging the Release version.
47 
51 #include "NLPInterfacePack_NLP.hpp"
52 #include "Teuchos_Assert.hpp"
53 
54 namespace {
55 
56 void report_final_point( const MoochoPack::NLPAlgoState& s, const bool optimal, NLPInterfacePack::NLP* nlp )
57 {
59  m = nlp->m(),
60  nb = nlp->num_bounded_x();
62  &x_iq = s.x();
63  if( x_iq.updated_k(0) ) {
65  x_iq.get_k(0) // x
66  ,( m && s.lambda().updated_k(0) ) ? &s.lambda().get_k(0) : NULL // lambda
67  ,( nb && s.nu().updated_k(0) ) ? &s.nu().get_k(0) : NULL // nu
68  , optimal // optimal = false
69  );
70  }
71 }
72 
73 } // end namespace
74 
75 namespace MoochoPack {
76 
77 // Overridden from rSQPAlgoClient interface
78 
79 void NLPAlgoContainer::set_config(const config_ptr_t& config)
80 {
81  algo_ = Teuchos::null; // Remove our reference to the current (configured?) algorithm.
82  config_ = config;
83 }
84 
87 {
88  return config_;
89 }
90 
93 {
94  return config_;
95 }
96 
99 {
100  return *config_;
101 }
102 
103 const NLPAlgoConfig&
105 {
106  return *config_;
107 }
108 
111 {
112  config().init_algo(&algo());
113  EFindMinReturn solve_return;
114  try {
115  solve_return = algo().dispatch();
116  }
117  catch(...) {
118  report_final_point(algo().retrieve_state(),false,&nlp());
119  throw;
120  }
121  report_final_point(algo().retrieve_state(),solve_return==NLPSolverClientInterface::SOLUTION_FOUND,&nlp());
122  return solve_return;
123 }
124 
125 void NLPAlgoContainer::configure_algorithm(std::ostream* trase_out)
126 {
128  if(!get_algo().get())
129  config().config_algo_cntr(this,trase_out);
130 }
131 
132 void NLPAlgoContainer::print_algorithm(std::ostream& out) const
133 {
134  algo().interface_print_algorithm(out);
135 }
136 
137 void NLPAlgoContainer::set_algo_timing( bool algo_timing )
138 {
139  algo().interface_set_algo_timing(algo_timing);
140 }
141 
143 {
144  return algo().interface_algo_timing();
145 }
146 
148  std::ostream& out ) const
149 {
150  algo().interface_print_algorithm_times(out);
151 }
152 
156  ,"NLPAlgoContainer::assert_valid_setup() : The NLP object has not been set" );
158  !get_track().get(), NLPSolverClientInterface::InvalidSetup
159  ,"NLPAlgoContainer::assert_valid_setup() : The AlgorithmTracker object has not been set" );
162  ,"NLPAlgoContainer::assert_valid_setup() : The NLPAlgoConfig object has not been set" );
163 }
164 
165 } // end namespace MoochoPack
virtual void init_algo(NLPAlgoInterface *algo)=0
Initialize the rSQP algorithm object for the start of SQP iterations.
virtual void report_final_solution(const Vector &x, const Vector *lambda, const Vector *nu, bool is_optimal)
Used by the solver to report the final solution and multipliers.
void set_config(const config_ptr_t &config)
virtual void config_algo_cntr(NLPAlgoContainer *algo_cntr, std::ostream *trase_out=0)=0
Configure the rSQP algorithm container with an rSQP algorithm object.
Interface to typed iteration quantities.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual T_info & get_k(int offset)=0
Return a reference for the k + offset iteration quanity.
void print_algorithm_times(std::ostream &out) const
virtual bool updated_k(int offset) const =0
Determine if the quanity for the k offset iteration has been accessed by a call to set_k() (see IterQ...
void print_algorithm(std::ostream &out) const
Reduced space SQP state encapsulation interface.
std::ostream * out
virtual size_type num_bounded_x() const =0
Returns the number of variables in x(i) for which xl(i)> -infinite_bound() or xu(i) < +infinite_bound...
void configure_algorithm(std::ostream *trase_out)
Interface for objects responsible for configuring an rSQP algorithm.
NLP interface class {abstract}.
virtual size_type m() const
Return the number of general equality constraints.