ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ConstrainedOptPack_VariableBoundsTester.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 "ConstrainedOptPack_VariableBoundsTester.hpp"
43 #include "AbstractLinAlgPack_VectorSpace.hpp"
44 #include "AbstractLinAlgPack_VectorMutable.hpp"
45 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
46 
47 namespace ConstrainedOptPack {
48 
49 // public
50 
52  value_type warning_tol
53  ,value_type error_tol
54  )
55  :warning_tol_(warning_tol)
56  ,error_tol_(error_tol)
57 {}
58 
60  std::ostream* out, bool print_all_warnings, bool print_vectors
61  ,const Vector& xL, const char xL_name[]
62  ,const Vector& xU, const char xU_name[]
63  ,const Vector& x, const char x_name[]
64  )
65 {
67 
68  if(out)
69  *out
70  << "\n*** Checking that variables are in bounds\n";
71 
72  VectorSpace::vec_mut_ptr_t zero = x.space().create_member(0.0);
73  std::pair<value_type,value_type>
74  u = max_near_feas_step( x, *zero, xL, xU, warning_tol() );
75  if(u.first < 0.0) {
76  if(out)
77  *out << "\nWarning! the variables " << xL_name << " <= " << x_name << " <= " << xU_name
78  << " are out of bounds by more than warning_tol = " << warning_tol() << "\n";
79  u = max_near_feas_step( x, *zero, xL, xU, error_tol() );
80  if(u.first < 0.0) {
81  if(out)
82  *out << "\nError! the variables " << xL_name << " <= " << x_name << " <= " << xU_name
83  << " are out of bounds by more than error_tol = " << error_tol() << "\n";
84  return false;
85  }
86  }
87  return true;
88 }
89 
90 } // end namespace ConstrainedOptPack
VariableBoundsTester(value_type warning_tol=1e-10, value_type error_tol=1e-5)
virtual bool check_in_bounds(std::ostream *out, bool print_all_warnings, bool print_vectors, const Vector &xL, const char xL_name[], const Vector &xU, const char xU_name[], const Vector &x, const char x_name[])
Check that the variables are within bounds.
std::pair< value_type, value_type > max_near_feas_step(const Vector &x, const Vector &d, const Vector &xl, const Vector &xu, value_type max_bnd_viol)