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_MeritFuncNLPModL1.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_MeritFuncNLPModL1.hpp"
43 #include "AbstractLinAlgPack_VectorMutable.hpp"
44 #include "AbstractLinAlgPack_VectorStdOps.hpp"
45 #include "Teuchos_Assert.hpp"
46 
47 namespace ConstrainedOptPack {
48 
50  : deriv_(0.0)
51 {}
52 
53 // Overridden from MeritFuncNLP
54 
56  value_type f
57  ,const Vector *c
58  ,const Vector *h
59  ,const Vector *hl
60  ,const Vector *hu
61  ) const
62 {
64  h || hl || hu, std::logic_error
65  ,"MeritFuncNLPModL1::value(...) : Error! general inequalities are not supported!" );
66 /*
67  using DenseLinAlgPack::norm_1;
68  return f + local_constr_term( mu_, c, "calc_deriv" );
69 */
70  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Write a reduction operator for the above operation
71  return 0.0;
72 }
73 
74 value_type MeritFuncNLPModL1::deriv() const
75 {
76  return deriv_;
77 }
78 
80  std::ostream& out, const std::string& L
81  ) const
82 {
83  out
84  << L << "*** Define a modified L1 merit funciton that uses different\n"
85  << L << "*** penalty parameters for each constriant.\n"
86  << L << "*** (assumes Gc_k'*d_k + c_k = 0):\n"
87  << L << "phi(f,c) = f + sum( mu(j) * abs(c(j)), j = 1,...,m )\n"
88  << L << "Dphi(x_k,d_k) = Gf_k' * d_k - sum( mu(j) * abs(c(j)), j = 1,...,m )\n";
89 }
90 
91 // Overridden from MeritFuncNLPDirecDeriv
92 
94  const Vector &Gf_k
95  ,const Vector *c_k
96  ,const Vector *h_k
97  ,const Vector *hl
98  ,const Vector *hu
99  ,const Vector &d_k
100  )
101 {
103  h_k || hl || hu, std::logic_error
104  ,"MeritFuncNLPModL1::value(...) : Error! general inequalities are not supported!" );
105 /*
106  using DenseLinAlgPack::dot; using DenseLinAlgPack::norm_1;
107  return deriv_ = dot( Gf_k, d_k ) - local_constr_term( mu_, c_k, "calc_deriv" );
108 */
109  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Write a reduction operator for the above operation
110  return 0.0;
111 }
112 
113 // Overridden from MeritFuncPenaltyParam
114 
115 void MeritFuncNLPModL1::set_space_c( const VectorSpace::space_ptr_t& space_c )
116 {
117  mu_ = space_c->create_member();
118  *mu_ = 0.0;
119 }
120 
122 {
123  return *mu_;
124 }
125 
126 const Vector& MeritFuncNLPModL1::get_mu() const
127 {
128  return *mu_;
129 }
130 
131 } // end namespace ConstrainedOptPack
132 
133 /* ToDo: Write a reduction operator for the following!
134 
135 namespace {
136 
137 value_type local_constr_term( const DVector& mu, const DVectorSlice& c
138  , const char func_name[] )
139 {
140  if( mu.size() != c.size() ) {
141  std::ostringstream omsg;
142  omsg
143  << "MeritFuncNLPModL1::" << func_name << "(...) : "
144  << "Error, the sizes mu.size() == " << mu.size()
145  << " != c.size() == " << c.size();
146  throw ConstrainedOptPack::MeritFuncNLP::InvalidInitialization(omsg.str());
147  }
148  value_type r = 0.0;
149  DVector::const_iterator
150  mu_itr = mu.begin();
151  DVectorSlice::const_iterator
152  c_itr = c.begin();
153  while( mu_itr != mu.end() )
154  r += *mu_itr++ * ::fabs( *c_itr++ );
155  return r;
156 }
157 
158 } // end namespace
159 
160 */
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void print_merit_func(std::ostream &out, const std::string &leading_str) const
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)
If the value n passed to resize(n) does not equal the size of the vector parameters then an exception...
value_type value(value_type f, const Vector *c, const Vector *h, const Vector *hl, const Vector *hu) const
void set_space_c(const VectorSpace::space_ptr_t &space_c)
MeritFuncNLPModL1()
Initializes deriv() = 0 and mu() = 0.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)