ROL
ROL_OptimizationSolver.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_OPTIMIZATIONSOLVER_HPP
45 #define ROL_OPTIMIZATIONSOLVER_HPP
46 
47 #define OPTIMIZATION_PROBLEM_REFACTOR
48 
49 #include "ROL_Algorithm.hpp"
51 
52 #include "Teuchos_oblackholestream.hpp"
53 
59 namespace ROL {
60 
61 template<class Real>
63 
64  typedef Vector<Real> V;
68 
69 private:
70 
71  Teuchos::RCP<Algorithm<Real> > algo_;
72  Teuchos::RCP<Step<Real> > step_;
73  Teuchos::RCP<StatusTest<Real> > status_;
74  Teuchos::RCP<AlgorithmState<Real> > state_;
75 
76  Teuchos::RCP<V> x_;
77  Teuchos::RCP<V> g_;
78  Teuchos::RCP<V> l_;
79  Teuchos::RCP<V> c_;
80 
81  Teuchos::RCP<OBJ> obj_;
82  Teuchos::RCP<BND> bnd_;
83  Teuchos::RCP<EQCON> eqcon_;
84 
85  std::vector<std::string> output_;
86 
88 
89 public:
90 
92  Teuchos::ParameterList &parlist ) {
93 
94  using Teuchos::RCP; using Teuchos::rcp;
95 
96  std::string stepname = parlist.sublist("Step").get("Type","Last Type (Dummy)");
97 
98  EStep stepType = StringToEStep(stepname);
99 
100  problemType_ = opt.getProblemType();
101 
102  TEUCHOS_TEST_FOR_EXCEPTION( !isValidStep(stepType), std::invalid_argument,
103  "Invalid step name in OptimizationSolver constructor!" );
104 
105  TEUCHOS_TEST_FOR_EXCEPTION( !isCompatibleStep(problemType_, stepType), std::logic_error,
106  "Error in OptimizationSolver constructor: Step type " << stepname << " does not support "
107  << EProblemToString(problemType_) << " problems" << std::endl );
108 
110  StatusTestFactory<Real> statusTestFactory;
111 
112  step_ = stepFactory.getStep(stepname,parlist);
113  status_ = statusTestFactory.getStatusTest(stepname,parlist);
114  state_ = rcp( new AlgorithmState<Real> );
115 
116  algo_ = rcp( new Algorithm<Real>( step_, status_, state_ ) );
117 
118  x_ = opt.getSolutionVector();
119  g_ = x_->dual().clone();
120 
121  // If there is an equality constraint, get the multiplier and create a constraint vector
122  if( problemType_ == TYPE_E || problemType_ == TYPE_EB ) {
123  l_ = opt.getMultiplierVector();
124  c_ = l_->dual().clone();
125  }
126 
127  // Create modified objectives if needed
128  if( stepType == STEP_AUGMENTEDLAGRANGIAN ) {
129  RCP<OBJ> raw_obj = opt.getObjective();
130  eqcon_ = opt.getEqualityConstraint();
131 
132  // TODO: Provide access to change initial penalty
133  obj_ = rcp( new AugmentedLagrangian<Real>(raw_obj,eqcon_,*l_,1.0,*x_,*c_,parlist) );
134  bnd_ = opt.getBoundConstraint();
135  }
136  else if( stepType == STEP_MOREAUYOSIDAPENALTY ) {
137  RCP<OBJ> raw_obj = opt.getObjective();
138  bnd_ = opt.getBoundConstraint();
139  eqcon_ = opt.getEqualityConstraint();
140 
141  // TODO: Provide access to change initial penalty
142  obj_ = rcp( new MoreauYosidaPenalty<Real>(raw_obj,bnd_,*x_,parlist) );
143  }
144  else {
145  obj_ = opt.getObjective();
146  bnd_ = opt.getBoundConstraint();
147  eqcon_ = opt.getEqualityConstraint();
148  }
149  }
150 
151  virtual std::vector<std::string> getOutput() {
152  return output_;
153  }
154 
155  virtual int solve() {
156  Teuchos::oblackholestream bhs;
157  return solve(bhs);
158  }
159 
160  virtual int solve( std::ostream &outStream ) {
161 
162  switch(problemType_) {
163  case TYPE_U:
164  output_ = algo_->run(*x_,*g_,*obj_,true,outStream);
165  break;
166  case TYPE_B:
167  output_ = algo_->run(*x_,*g_,*obj_,*bnd_,true,outStream);
168  break;
169  case TYPE_E:
170  output_ = algo_->run(*x_,*g_,*l_,*c_,*obj_,*eqcon_,true,outStream);
171  break;
172  case TYPE_EB:
173  output_ = algo_->run(*x_,*g_,*l_,*c_,*obj_,*eqcon_,*bnd_,true,outStream);
174  break;
175  case TYPE_LAST:
176  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
177  "Error in OptimizationSolver::solve() : Unsupported problem type");
178  break;
179  }
180 
181  // TODO: Interrogate AlgorithmState and StatusTest to generate a return code
182  // that indicates why the solver has stopped
183 
184 
185  // Return an integer code
186  return 0;
187  }
188 
189  Teuchos::RCP<const AlgorithmState<Real> > getAlgorithmState() {
190  return state_;
191  }
192 
193 
194 
195 }; // class OptimizationSolver
196 
197 } // namespace ROL
198 
199 #endif // ROL_OPTIMIZATIONSOLVER_HPP
200 
201 
Provides the interface to evaluate objective functions.
Provides the interface to evaluate the augmented Lagrangian.
Teuchos::RCP< AlgorithmState< Real > > state_
EStep StringToEStep(std::string s)
Definition: ROL_Types.hpp:307
Teuchos::RCP< Algorithm< Real > > algo_
Teuchos::RCP< StatusTest< Real > > status_
BoundConstraint< Real > BND
void stepFactory(Teuchos::ParameterList &parlist, Teuchos::RCP< ROL::Step< Real > > &step)
A minimalist step factory which specializes the Step Type depending on whether a Trust-Region or Line...
Teuchos::RCP< Step< Real > > getStep(const std::string &type, Teuchos::ParameterList &parlist) const
std::vector< std::string > output_
Teuchos::RCP< EQCON > eqcon_
virtual std::vector< std::string > getOutput()
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
Teuchos::RCP< BoundConstraint< Real > > getBoundConstraint(void)
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:91
Teuchos::RCP< Step< Real > > step_
Defines the equality constraint operator interface.
Provides an interface to run optimization algorithms.
Provides the interface to evaluate the Moreau-Yosida penalty function.
virtual int solve(std::ostream &outStream)
std::string EProblemToString(EProblem p)
Definition: ROL_Types.hpp:257
Teuchos::RCP< Vector< Real > > getMultiplierVector(void)
Provides the interface to apply upper and lower bound constraints.
OptimizationSolver(OptimizationProblem< Real > &opt, Teuchos::ParameterList &parlist)
Provides a simplified interface for solving a wide range of optimization problems.
int isValidStep(EStep ls)
Verifies validity of a TrustRegion enum.
Definition: ROL_Types.hpp:276
int isCompatibleStep(EProblem p, EStep s)
Definition: ROL_Types.hpp:230
Teuchos::RCP< EqualityConstraint< Real > > getEqualityConstraint(void)
Teuchos::RCP< const AlgorithmState< Real > > getAlgorithmState()
Teuchos::RCP< Vector< Real > > getSolutionVector(void)
Teuchos::RCP< StatusTest< Real > > getStatusTest(const std::string step, Teuchos::ParameterList &parlist)
EStep
Enumeration of step types.
Definition: ROL_Types.hpp:201
EqualityConstraint< Real > EQCON
EProblem
Definition: ROL_Types.hpp:182
Teuchos::RCP< Objective< Real > > getObjective(void)