ROL
ROL_InteriorPointStep.hpp
Go to the documentation of this file.
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_INTERIORPOINTSTEP_H
45 #define ROL_INTERIORPOINTSTEP_H
46 
47 #include "ROL_CompositeStep.hpp"
48 #include "ROL_InteriorPoint.hpp"
49 #include "ROL_Types.hpp"
50 
51 namespace ROL {
52 
53 template <class Real>
54 class InteriorPointStep : public Step<Real> {
55 
58 
59 private:
60 
61  Teuchos::RCP<Vector<Real> > xvec_;
62  Teuchos::RCP<Vector<Real> > gvec_;
63  Teuchos::RCP<Vector<Real> > lvec_;
64  Teuchos::RCP<Vector<Real> > cvec_;
65 
66  Teuchos::RCP<StatusTest<Real> > status_;
67  Teuchos::RCP<Step<Real> > step_;
68  Teuchos::RCP<DefaultAlgorithm<Real> > algo_;
69  Teuchos::RCP<Teuchos::ParameterList> parlist_;
70 
71  Real mu_; // Barrier parameter
72  Real eps_; // Minimal value of barrier parameter
73  Real rho_; // Barrier parameter reduction factor
74  int maxit_; // Maximum number of interior point subproblem solves
75 
76  // For the subproblem
77  Real gtol_; // Status test gradient tolerance
78  Real ctol_; // Status test constraint tolerance
79  Real stol_; // Status test step tolerance
80  int subproblemIter_; // Status test maximum number of iterations
81 
82 public:
83 
85 
86  InteriorPointStep(Teuchos::ParameterList &parlist) :
87  Step<Real>(), step_(Teuchos::null), status_(Teuchos::null) {
88 
89  using Teuchos::ParameterList;
90 
91  ParameterList& iplist = parlist.sublist("Step").sublist("Interior Point");
92  ParameterList& stlist = parlist.sublist("Status Test");
93  ParameterList& cslist = parlist.sublist("Step").sublist("Composite Step");
94 
95 
96  // Interior Point parameters
97  mu_ = iplist.get("Initial Barrier Penalty",1.0);
98  eps_ = iplist.get("Minimum Barrier Penalty",1.e-4);
99  rho_ = iplist.get("Barrier Penalty Reduction Factor",0.5);
100  subproblemIter_ = iplist.get("Subproblem Iteration Limit",10);
101 
102 
103  // Status test parameters
104  gtol_ = stlist.get("Gradient Tolerance", 1.e-8);
105  ctol_ = stlist.get("Constraint Tolerance", 1.e-8);
106  stol_ = stlist.get("Step Tolerance", 1.e-8);
107  maxit_ = stlist.get("Iteration Limit", 100);
108 
109 
110 
111  parlist_ = Teuchos::rcp(&parlist, false);
112 
113  step_ = Teuchos::rcp(new CompositeStep<Real>(cslist) );
114 
115  }
116 
121 
122  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
123  state->descentVec = x.clone();
124  state->gradientVec = g.clone();
125  state->constraintVec = c.clone();
126 
127  // Downcast Objective -> InteriorPointObjective
128  IPOBJ &ipobj = Teuchos::dyn_cast<IPOBJ>(obj);
129  IPCON &ipcon = Teuchos::dyn_cast<IPCON>(con);
130 
131  // Set initial penalty
132  ipobj.updatePenalty(mu_);
133 
134  xvec_ = x.clone();
135  gvec_ = g.clone();
136  lvec_ = l.clone();
137  cvec_ = c.clone();
138 
139  algo_state.nfval = 0;
140  algo_state.ncval = 0;
141  algo_state.ngrad = 0;
142 
143  Real zerotol = 0.0;
144  obj.update(x,true,algo_state.iter);
145  algo_state.value = obj.value(x,zerotol);
146 
147  obj.gradient(g,x,zerotol);
148  algo_state.gnorm = g.norm();
149 
150  con.value(c,x,zerotol);
151  algo_state.cnorm = c.norm();
152 
153  algo_state.nfval += ipobj.getNumberFunctionEvaluations();
154  algo_state.ngval += ipobj.getNumberGradientEvaluations();
155  algo_state.ncval += ipcon.getNumberConstraintEvaluations();
156 
157  }
158 
159  void compute( Vector<Real> &s, const Vector<Real> &x,
161  AlgorithmState<Real> &algo_state ) {
162 
163  // Reset the status test
164  status_ = Teuchos::rcp( new ConstraintStatusTest<Real>(gtol_,ctol_,stol_,maxit_) );
165 
166  // Create the algorithm
167  algo_ = Teuchos::rcp( new DefaultAlgorithm<Real>(step_,status_,false) );
168 
169  xvec_->set(x);
170 
171  // Run the algorithm
172  algo_->run(*xvec_,*gvec_,*lvec_,*cvec_,obj,con,false);
173 
174  s.set(*xvec_); s.axpy(-1.0,x);
175 
176  // Get number of iterations from the subproblem solve
177  subproblemIter_ = (algo_->getState())->iter;
178 
179  }
180 
181  void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj,
182  EqualityConstraint<Real> &con, AlgorithmState<Real> &algo_state ) {
183 
184  Teuchos::RCP<StepState<Real> > state = Step<Real>::getState();
185 
186 
187  x.plus(s);
188  algo_state.iter++;
189 
190  // Downcast Objective -> InteriorPointObjective
191  IPOBJ &ipobj = Teuchos::dyn_cast<IPOBJ>(obj);
192  IPCON &ipcon = Teuchos::dyn_cast<IPCON>(con);
193 
194  algo_state_->nfval += ipobj.getNumberFunctionEvaluations();
195  algo_state_->ngval += ipobj.getNumberGradientEvaluations();
196  algo_state_->ncval += ipcon.getNumberConstraintEvaluations();
197 
198 
199  // If we can reduce the barrier parameter, do so
200  if(mu_ > eps_) {
201  mu_ *= rho_;
202  ipobj.updatePenalty(mu_);
203  }
204 
205 
206 
207  }
208 
209 
210 
216  AlgorithmState<Real> &algo_state ) {}
217 
223  AlgorithmState<Real> &algo_state ) {}
224 
225 
226 
229  std::string printHeader( void ) const {
230  std::stringstream hist;
231  hist << " ";
232  hist << std::setw(6) << std::left << "iter";
233  hist << std::setw(15) << std::left << "fval";
234  hist << std::setw(15) << std::left << "cnorm";
235  hist << std::setw(15) << std::left << "gnorm";
236  hist << std::setw(15) << std::left << "snorm";
237  hist << std::setw(15) << std::left << "penalty";
238  hist << std::setw(8) << std::left << "#fval";
239  hist << std::setw(8) << std::left << "#grad";
240  hist << std::setw(8) << std::left << "#cval";
241  hist << std::setw(8) << std::left << "subIter";
242  hist << "\n";
243  return hist.str();
244  }
245 
248  std::string printName( void ) const {
249  std::stringstream hist;
250  hist << "\n" << " Interior Point solver\n";
251  return hist.str();
252  }
253 
256  std::string print( AlgorithmState<Real> &algo_state, bool printHeader = false ) const {
257  std::stringstream hist;
258  hist << std::scientific << std::setprecision(6);
259  if ( algo_state.iter == 0 ) {
260  hist << " ";
261  hist << std::setw(6) << std::left << algo_state.iter;
262  hist << std::setw(15) << std::left << algo_state.value;
263  hist << std::setw(15) << std::left << algo_state.cnorm;
264  hist << std::setw(15) << std::left << algo_state.gnorm;
265  hist << std::setw(15) << std::left << algo_state.snorm;
266  hist << std::setw(15) << std::left << mu_;
267  hist << std::setw(8) << std::left << algo_state.nfval;
268  hist << std::setw(8) << std::left << algo_state.ngrad;
269  hist << std::setw(8) << std::left << algo_state.ncval;
270  hist << std::setw(8) << std::left << subproblemIter_;
271  hist << "\n";
272  }
273  if ( print_header ) {
274  hist << printHeader();
275  }
276  return hist.str();
277  }
278 
279 
280 
281 
282 
283 }; // class InteriorPointStep
284 
285 } // namespace ROL
286 
287 #endif // ROL_INTERIORPOINTSTEP_H
Provides the interface to evaluate objective functions.
Teuchos::RCP< Vector< Real > > lvec_
Teuchos::RCP< Teuchos::ParameterList > parlist_
virtual void plus(const Vector &x)=0
Compute , where .
void initialize(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, EqualityConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with equality constraint.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:143
Has both inequality and equality constraints. Treat inequality constraint as equality with slack vari...
Teuchos::RCP< Vector< Real > > cvec_
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:67
Teuchos::RCP< Vector< Real > > gvec_
Teuchos::RCP< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:72
Contains definitions of custom data types in ROL.
Teuchos::RCP< Step< Real > > step_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, EqualityConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, EqualityConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Provides an interface to check status of optimization algorithms for problems with equality constrain...
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:77
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Teuchos::RCP< DefaultAlgorithm< Real > > algo_
Defines the equality constraint operator interface.
InteriorPointEqualityConstraint< Real > IPCON
Teuchos::RCP< Vector< Real > > xvec_
void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step for bound constraints; here only to satisfy the interface requirements, does nothing, needs refactoring.
Implements the computation of optimization steps with composite-step trust-region methods...
Adds barrier term to generic objective.
Provides the interface to apply upper and lower bound constraints.
std::string printName(void) const
Print step name.
InteriorPointObjective< Real > IPOBJ
std::string printHeader(void) const
Print iterate header.
std::string print(AlgorithmState< Real > &algo_state, bool printHeader=false) const
Print iterate status.
void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, for bound constraints; here only to satisfy the interface requirements, does nothing, needs refactoring.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:196
virtual Real norm() const =0
Returns where .
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
Teuchos::RCP< StatusTest< Real > > status_
InteriorPointStep(Teuchos::ParameterList &parlist)