MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConstrainedOptPack_MeritFuncNLPL1.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 
48 #include "Teuchos_Assert.hpp"
49 #include "Teuchos_dyn_cast.hpp"
50 
51 namespace ConstrainedOptPack {
52 
54  : deriv_(0.0), mu_(0.0)
55 {}
56 
57 // Overridden from MeritFuncNLP
58 
60 {
61  using Teuchos::dyn_cast;
62  const MeritFuncNLPL1 &merit_func_l1 = dyn_cast<const MeritFuncNLPL1>(merit_func);
63  if(this == &merit_func_l1)
64  return *this; // assignment to self
65  this->deriv_ = merit_func_l1.deriv_;
66  this->mu_ = merit_func_l1.mu_;
67  return *this;
68 }
69 
71  value_type f
72  ,const Vector *c
73  ,const Vector *h
74  ,const Vector *hl
75  ,const Vector *hu
76  ) const
77 {
78  value_type phi_val_h = 0.0;
79  if(h) {
80  size_type max_viol_i;
81  value_type max_viol, h_i, hlu_i;
82  int bnd_type;
83  AbstractLinAlgPack::max_inequ_viol(*h,*hl,*hu,&max_viol_i,&max_viol,&h_i,&bnd_type,&hlu_i);
84  if(max_viol_i) phi_val_h += mu_ * fabs(h_i - hlu_i);
85  }
86  return f + ( c ? mu_ * c->norm_1() : 0.0) + phi_val_h;
87 }
88 
90 {
91  return deriv_;
92 }
93 
95  , const std::string& L ) const
96 {
97  out
98  << L << "*** Define L1 merit funciton (assumes Gc_k'*d_k + c_k = 0):\n"
99  << L << "phi(f,c) = f + mu_k*( norm(c,1) + max_viol( hl <= h <= hu ) )\n"
100  << L << "Dphi(x_k,d_k) = Gf_k' * d_k - mu*( norm(c_k,1) + max_viol( hl <= h_k <= hu ) )\n";
101 }
102 
103 // Overridden from MeritFuncNLPDirecDeriv
104 
106  const Vector &Gf_k
107  ,const Vector *c_k
108  ,const Vector *h_k
109  ,const Vector *hl
110  ,const Vector *hu
111  ,const Vector &d_k
112  )
113 {
116  h_k || hl || hu, std::logic_error
117  ,"MeritFuncNLPL1::value(...) : Error! general inequalities are not supported yet" );
118  return deriv_ = dot( Gf_k, d_k ) - ( c_k ? mu_ * c_k->norm_1() : 0.0 );
119 }
120 
121 // Overridden from MeritFuncPenaltyParam
122 
124 {
125  mu_ = mu;
126 }
127 
129 {
130  return mu_;
131 }
132 
133 } // end namespace ConstrainedOptPack
AbstractLinAlgPack::size_type size_type
Base class for all merit functions for NonLinear Programs (NLP) {abstract}.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
value_type value(value_type f, const Vector *c, const Vector *h, const Vector *hl, const Vector *hu) const
void print_merit_func(std::ostream &out, const std::string &leading_str) const
T_To & dyn_cast(T_From &from)
MeritFuncNLPL1()
Initializes deriv() = 0 and mu() = 0.
std::ostream * out
value_type calc_deriv(const Vector &Gf_k, const Vector *c_k, const Vector *h_k, const Vector *hl, const Vector *hu, const Vector &d_k)
bool max_inequ_viol(const AbstractLinAlgPack::Vector &v, const AbstractLinAlgPack::Vector &vL, const AbstractLinAlgPack::Vector &vU, AbstractLinAlgPack::size_type *max_viol_i, AbstractLinAlgPack::value_type *max_viol, AbstractLinAlgPack::value_type *v_i, int *bnd_type, AbstractLinAlgPack::value_type *vLU_i)
Compute the maximum violation from a set of inequality constraints vL <= v <= vU. ...
MeritFuncNLP & operator=(const MeritFuncNLP &)
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
AbstractLinAlgPack::value_type value_type