MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLPInterfacePack_NLPBarrier.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 <math.h>
43 #include <iostream>
44 #include <limits>
45 
50 #include "Teuchos_Assert.hpp"
51 
52 namespace NLPInterfacePack {
53 
55  :
56  barrier_term_(0.0),
57  objective_term_(0.0),
58  nlp_(Teuchos::null)
59  {
60  }
61 
62 
64  Teuchos::RCP<NLP> original_nlp
65  )
66  {
68  !original_nlp.get(),
69  std::logic_error,
70  "null nlp passed to NLPBarrier decorator"
71  );
72 
73  nlp_ = Teuchos::rcp_dynamic_cast<NLPObjGrad>(original_nlp);
74 
76  !nlp_.get(),
77  std::logic_error,
78  "non NLPObjGrad NLP passed to NLPBarrier decorator"
79  );
80  }
81 
82 void NLPBarrier::mu(const value_type mu)
83  {
84  mu_ = mu;
85  }
86 
88  {
89  return barrier_term_;
90  }
91 
93  {
94  return objective_term_;
95  }
96 
98  {
99  return grad_barrier_term_;
100  }
101 
103  {
104  return grad_objective_term_;
105  }
106 
107 
108 void NLPBarrier::calc_f(const Vector& x, bool newx) const
109  {
110  nlp_->calc_f(x, newx);
111  value_type* f_val = nlp_->get_f();
112 
113  objective_term_ = *f_val;
115 
116  (*f_val) += barrier_term_;
117  }
118 
119 void NLPBarrier::calc_Gf(const Vector& x, bool newx) const
120  {
122 
123  nlp_->calc_Gf(x, newx);
124  grad_objective_term_ = nlp_->get_Gf()->clone();
125 
126  //std::cout << "grad_objective_term=\n";
127  //grad_objective_term_->output(std::cout);
128 
131 
132  if (!grad_barrier_term_.get())
134 
136  *grad_barrier_term_ = 0.0;
137 
139  //std::cout << "mu*invXU=\n";
140  //grad_barrier_term_->output(std::cout);
141 
143  //std::cout << "mu*invXL=\n";
144  //grad_barrier_term_temp_->output(std::cout);
145 
147 
148  nlp_->get_Gf()->axpy(1.0, *grad_barrier_term_);
149 
150  //std::cout << "grad_objective_term with barrier=\n";
151  //nlp_->get_Gf()->output(std::cout);
152  }
153 
155  const Vector& x,
156  bool newx,
157  const ZeroOrderInfo& zero_order_info
158  ) const
159  {
160  TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
161  }
162 
164  const Vector& x,
165  bool newx,
166  const ZeroOrderInfo& zero_order_info
167  ) const
168  {
169  TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
170  }
171 
173  const Vector& x,
174  bool newx,
175  const ZeroOrderInfo& zero_order_info_breve
176  ) const
177  {
178  TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
179  }
180 
182  const Vector& x,
183  bool newx,
184  const ZeroOrderInfo& zero_order_info_breve
185  ) const
186  {
187  TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
188  }
189 
191  const Vector& x,
192  bool newx,
193  const ObjGradInfo& obj_grad_info
194  ) const
195  {
196  TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
197  }
198 
199 
201  {
204 // std::cerr << "NLPBarrier::CalculateBarrierTerm(x) : (1) barrier_term_ = " << barrier_term_ << std::endl;
205  barrier_term_ *= -mu_;
206 // std::cerr << "NLPBarrier::CalculateBarrierTerm(x) : (2) barrier_term_ = " << barrier_term_ << std::endl;
207  return barrier_term_;
208  }
209 
210 } // end namespace NLPInterfacePack
NLP interface class that adds gradient information for the objective function {abstract}.
value_type barrier_term() const
Get the barrier term. Must be called after calc_f().
Struct for gradient (objective), objective and constriants (pointers)
virtual const VectorSpace & space() const =0
Return the vector space that this vector belongs to.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
void imp_calc_c(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
void calc_f(const Vector &x, bool newx=true) const
Overloaded to include barrier term.
void inv_of_difference(const value_type alpha, const Vector &v0, const Vector &v1, VectorMutable *z)
Computes the inverse of the difference between two vectors.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void InitializeFromNLP(Teuchos::RCP< NLP > original_nlp)
T * get() const
const Teuchos::RCP< Vector > grad_objective_term() const
Get the value of the gradient of the true objective term. Must be called after calc_Gf().
void imp_calc_c_breve(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info_breve) const
void mu(const value_type mu)
Set the barrier parameter.
Teuchos::RCP< VectorMutable > grad_objective_term_
Teuchos::RCP< VectorMutable > grad_barrier_term_temp_
Teuchos::RCP< VectorMutable > grad_barrier_term_
virtual void axpy(value_type alpha, const Vector &x)
Adds a linear combination of another vector to this vector object.
value_type CalculateBarrierTerm(const Vector &x) const
Struct for objective and constriants (pointer).
void imp_calc_h_breve(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info_breve) const
value_type objective_term() const
Get the true objective term value. Must be called after calc_f().
void imp_calc_Gf(const Vector &x, bool newx, const ObjGradInfo &obj_grad_info) const
value_type log_bound_barrier(const Vector &x, const Vector &xl, const Vector &xu)
Computes the log barrier term:
AbstractLinAlgPack::value_type value_type
const Teuchos::RCP< Vector > grad_barrier_term() const
Get the value of the gradient of the barrier term. Must be called after calc_Gf() ...
void imp_calc_f(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void calc_Gf(const Vector &x, bool newx=true) const
Overloaded to include barrier term.