1 // @HEADER
2 // ************************************************************************
3 //
4 //               Rapid Optimization Library (ROL) Package
5 //                 Copyright (2014) 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 lead developers:
38 //              Drew Kouri   (dpkouri@sandia.gov) and
39 //              Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_INACTIVE_SET_VECTOR_HPP
45 #define ROL_INACTIVE_SET_VECTOR_HPP
46 
47 #include "ROL_ScaledVector.hpp"
48 #include "ROL_BoundConstraint.hpp"
49 
50 /** @ingroup la_group
51     \class ROL::InactiveSet_PrimalVector
52     \brief Defines the a Vector which has a diagonally scaled dot
53            product that neglects active set elements
54            Used to simplify Semi-smooth Newton method implementation
55 
56     \class ROL::InactiveSet_DualVector
57     \brief Defines the a Vector which has a diagonally scaled dot
58            product that neglects active set elements
59            Used to simplify Semi-smooth Newton method implementation
60 */
61 
62 namespace ROL {
63 
64 template<typename Real> class InactiveSet_PrimalVector;
65 template<typename Real> class InactiveSet_DualVector;
66 
67 
68 template<typename Real>
69 class InactiveSet_PrimalVector : public PrimalScaledVector<Real> {
70 
71   using V      = Vector<Real>;
72   using Primal = InactiveSet_PrimalVector<Real>;
73   using Dual   = InactiveSet_DualVector<Real>;
74   using Bnd    = BoundConstraint<Real>;
75 
76 private:
77 
78   mutable Ptr<V>  x_;            // Current optimization iterate
79   Ptr<Bnd>        bnd_;
80 
81 public:
82 
InactiveSet_PrimalVector(const Ptr<V> & vec,const Ptr<V> & scaling_vec,const Ptr<V> & x,const Ptr<Bnd> & bnd)83   InactiveSet_PrimalVector( const Ptr<V>& vec,
84                             const Ptr<V>& scaling_vec,
85                             const Ptr<V>& x,
86                             const Ptr<Bnd>& bnd ) :
87     PrimalScaledVector<Real>(vec,scaling_vec_), x_(x), bnd_(bnd) {}
88 
~InactiveSet_PrimalVector()89   virtual ~InactiveSet_PrimalVector() {}
90 
91 
dot(const V & x) const92   Real dot( const V& x ) const override {
93 
94     auto& w = this->getWorkspace();
95     auto y  = w.copy(x);
96 
97     this->multiply_scaling( *y );
98 
99     // Set elements of y corresponsing the the active set of X to zero
100     bnd_->pruneActive( *y, *x_ );
101 
102     return y->dot( *this->getVector() );
103   }
104 
clone() const105   Ptr<V> clone() const override {
106     return makePtr<Primal>( this->getVector()->clone(),
107                             this->getScalingVector(),
108                             x_, bnd_ );
109   }
110 
basis(const int i) const111   Ptr<V> basis( const int i ) const override {
112     return makePtr<Primal>( this->getVector()->basis(i),
113                             this->getScalingVector(),
114                             x_, bnd_ );
115   }
116 
dual() const117   void const V& dual() const override {
118     auto& w = this->getWorkspace();
119     auto dual_vec = w.copy( this->getVector() );
120     this->multiply_scaling( dual_vec );
121     return makePtr<Dual>( dual_vec, this->getScalingVector(), x_, bnd_ );
122   }
123 
setIterateVector(const Ptr<V> & x) const124   void setIterateVector( const Ptr<V>& x ) const { x_->set(x); }
getIterateVector()125   const Ptr<V>& getIterateVector() { return x_; }
getIterateVector() const126   const Ptr<const V>& getIterateVector() const { return x_; }
127 
128 
129 }; // class InactiveSet_PrimalVector
130 
131 
132 template<typename Real>
133 class InactiveSet_DualVector : public DualScaledVector<Real> {
134 
135   using V      = Vector<Real>;
136   using Primal = InactiveSet_PrimalVector<Real>;
137   using Dual   = InactiveSet_DualVector<Real>;
138   using Bnd    = BoundConstraint<Real>;
139 
140 private:
141 
142   mutable Ptr<V>  x_;            // Current optimization iterate
143   Ptr<Bnd>        bnd_;
144 
145 public:
146 
InactiveSet_DualVector(const Ptr<V> & vec,const Ptr<V> & scaling_vec,const Ptr<V> & x,const Ptr<Bnd> & bnd)147   InactiveSet_DualVector( const Ptr<V>& vec,
148                           const Ptr<V>& scaling_vec,
149                           const Ptr<V>& x,
150                           const Ptr<Bnd>& bnd ) :
151     PrimalScaledVector<Real>(vec,scaling_vec_), x_(x), bnd_(bnd) {}
152 
~InactiveSet_PrimalVector()153   virtual ~InactiveSet_PrimalVector() {}
154 
dot(const V & x) const155   Real dot( const V& x ) const override {
156 
157     auto& w = this->getWorkspace();
158     auto y  = w.copy(x);
159     this->divide_scaling( *y, this->getScalingVector() );
160 
161     // Set elements of y corresponsing the the active set of X to zero
162     bnd_->pruneActive( *y, *x_ );
163 
164     return y->dot( *this->getVector() );
165   }
166 
clone() const167   Ptr<V> clone() const override {
168     return makePtr<Primal>( this->getVector()->clone(),
169                             this->getScalingVector(),
170                             x_, bnd_ );
171   }
172 
basis(const int i) const173   Ptr<V> basis( const int i ) const override {
174     return makePtr<Primal>( this->getVector()->basis(i),
175                             this->getScalingVector(),
176                             x_, bnd_ );
177   }
178 
dual() const179   void const V& dual() const override {
180     auto& w = this->getWorkspace();
181     auto dual_vec = w.copy( this->getVector() );
182     this->multiply( dual_vec );
183     return *( makePtr<Dual>( dual_vec, this->getScalingVector(), x_, bnd_ ) );
184   }
185 
setIterateVector(const Ptr<V> & x) const186   void setIterateVector( const Ptr<V>& x ) const { x_->set(x); }
getIterateVector()187   const Ptr<V>& getIterateVector() { return x_; }
getIterateVector() const188   const Ptr<const V>& getIterateVector() const { return x_; }
189 
190 }; // class InactiveSet_PrimalVector
191 
192 
193 
194 
195 
196 } // namespace ROL
197 
198 
199 
200 #endif // ROL_INACTIVE_SET_VECTOR_HPP
201