44 #define OPTIMIZATION_PROBLEM_REFACTOR 48 #include "ROL_NonlinearProgram.hpp" 55 #include "HS_ProblemFactory.hpp" 73 Teuchos::RCP<const std::vector<Real> > xp =
76 outStream <<
"Standard Vector" << std::endl;
77 for(
size_t i=0; i<xp->size(); ++i ) {
78 outStream << (*xp)[i] << std::endl;
81 catch(
const std::bad_cast& e ) {
82 outStream <<
"Partitioned Vector" << std::endl;
85 typedef typename PV::size_type size_type;
87 const PV &xpv = Teuchos::dyn_cast<
const PV>(x);
89 for( size_type i=0; i<xpv.numVectors(); ++i ) {
90 outStream <<
"--------------------" << std::endl;
93 outStream <<
"--------------------" << std::endl;
100 std::ostream &outStream ) {
101 typedef typename std::vector<Real>::size_type uint;
104 for( uint i=0; i<dim; ++i ) {
105 for( uint j=0; j<dim; ++j ) {
106 outStream << std::setw(6) << A[j]->dot(*(I[i]));
108 outStream << std::endl;
124 int main(
int argc,
char *argv[]) {
128 typedef Teuchos::ParameterList PL;
136 typedef ROL::NonlinearProgram<RealT> NLP;
145 using Teuchos::RCP;
using Teuchos::rcp;
147 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
149 int iprint = argc - 1;
150 RCP<std::ostream> outStream;
151 Teuchos::oblackholestream bhs;
153 outStream = rcp(&std::cout,
false);
155 outStream = rcp(&bhs,
false);
163 RealT tol = std::sqrt(ROL::ROL_EPSILON<RealT>());
167 PL &iplist = parlist.sublist(
"Step").sublist(
"Primal Dual Interior Point");
168 PL &lblist = iplist.sublist(
"Barrier Objective");
170 lblist.set(
"Use Linear Damping",
true);
171 lblist.set(
"Linear Damping Coefficient",1.e-4);
172 lblist.set(
"Initial Barrier Parameter", mu);
174 PL &krylist = parlist.sublist(
"General").sublist(
"Krylov");
176 krylist.set(
"Absolute Tolerance", 1.e-6);
177 krylist.set(
"Relative Tolerance", 1.e-6);
178 krylist.set(
"Iteration Limit", 50);
181 krylist.set(
"Type",
"Conjugate Gradients");
182 RCP<KRYLOV> cg = ROL::KrylovFactory<RealT>(parlist);
183 HS::ProblemFactory<RealT> problemFactory;
187 RCP<NLP> nlp = problemFactory.getProblem(16);
188 RCP<OPT> opt = nlp->getOptimizationProblem();
190 RCP<V> x = opt->getSolutionVector();
191 RCP<V> l = opt->getMultiplierVector();
192 RCP<V> zl = x->clone();
193 RCP<V> zu = x->clone();
195 RCP<V> scratch = x->clone();
197 RCP<PV> x_pv = Teuchos::rcp_dynamic_cast<PV>(x);
201 std::vector<RCP<V> > I;
202 std::vector<RCP<V> > J;
204 for(
int k=0; k<sol->dimension(); ++k ) {
205 I.push_back(sol->basis(k));
206 J.push_back(sol->clone());
209 RCP<V> u = sol->clone();
210 RCP<V> v = sol->clone();
212 RCP<V> rhs = sol->clone();
213 RCP<V> symrhs = sol->clone();
215 RCP<V> gmres_sol = sol->clone(); gmres_sol->set(*sol);
216 RCP<V> cg_sol = sol->clone(); cg_sol->set(*sol);
223 RCP<OBJ> obj = opt->getObjective();
224 RCP<CON> con = opt->getEqualityConstraint();
225 RCP<BND> bnd = opt->getBoundConstraint();
227 PENALTY penalty(obj,bnd,parlist);
229 RCP<const V> maskL = penalty.getLowerMask();
230 RCP<const V> maskU = penalty.getUpperMask();
245 RCP<CON> res = rcp(
new RESIDUAL(obj,con,bnd,*sol,maskL,maskU,scratch,mu,
false) );
246 RCP<LOP> lop = rcp(
new LOPEC( sol, res ) );
249 res->value(*rhs,*sol,tol);
252 krylist.set(
"Type",
"GMRES");
253 RCP<KRYLOV> gmres = ROL::KrylovFactory<RealT>(parlist);
256 for(
int k=0; k<sol->dimension(); ++k ) {
257 res->applyJacobian(*(J[k]),*(I[k]),*sol,tol);
260 *outStream <<
"Nonsymmetric Jacobian" << std::endl;
264 gmres->run( *gmres_sol, *lop, *rhs, identity, gmres_iter, gmres_flag );
266 errorFlag += gmres_flag;
269 *outStream <<
"GMRES terminated after " << gmres_iter <<
" iterations " 270 <<
"with exit flag " << gmres_flag << std::endl;
281 RCP<V> jv = v->clone();
282 RCP<V> ju = u->clone();
284 iplist.set(
"Symmetrize Primal Dual System",
true);
285 RCP<CON> symres = rcp(
new RESIDUAL(obj,con,bnd,*sol,maskL,maskU,scratch,mu,
true) );
286 RCP<LOP> symlop = rcp(
new LOPEC( sol, res ) );
287 symres->value(*symrhs,*sol,tol);
289 symres->applyJacobian(*jv,*v,*sol,tol);
290 symres->applyJacobian(*ju,*u,*sol,tol);
291 *outStream <<
"Symmetry check |u.dot(jv)-v.dot(ju)| = " 292 << std::abs(u->dot(*jv)-v->dot(*ju)) << std::endl;
294 cg->run( *cg_sol, *symlop, *symrhs, identity, cg_iter, cg_flag );
296 *outStream <<
"CG terminated after " << cg_iter <<
" iterations " 297 <<
"with exit flag " << cg_flag << std::endl;
299 *outStream <<
"Check that GMRES solution also is a solution to the symmetrized system" 302 symres->applyJacobian(*ju,*gmres_sol,*sol,tol);
303 ju->axpy(-1.0,*symrhs);
304 RealT mismatch = ju->norm();
308 *outStream <<
"||J_sym*sol_nonsym-rhs_sym|| = " << mismatch << std::endl;
311 catch (std::logic_error err) {
312 *outStream << err.what() << std::endl;
317 std::cout <<
"End Result: TEST FAILED" << std::endl;
319 std::cout <<
"End Result: TEST PASSED" << std::endl;
Provides the interface to evaluate objective functions.
PartitionedVector< Real > PV
void printMatrix(const std::vector< Teuchos::RCP< ROL::Vector< Real > > > &A, const std::vector< Teuchos::RCP< ROL::Vector< Real > > > &I, std::ostream &outStream)
Defines the linear algebra of vector space on a generic partitioned vector.
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Symmetrized form of the KKT operator for the Type-EB problem with equality and bound multipliers...
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(const Teuchos::RCP< Vector< Real > > &a)
Defines the linear algebra or vector space interface.
void apply(ROL::Vector< Real > &Hv, const ROL::Vector< Real > &v, Real &tol) const
Apply linear operator.
Provides the interface to evaluate the Interior Pointy log barrier penalty function with upper and lo...
Defines the equality constraint operator interface.
void printVector(const ROL::Vector< Real > &x, std::ostream &outStream)
Provides definitions for Krylov solvers.
Provides the interface to apply a linear operator.
Provides the interface to apply upper and lower bound constraints.
virtual void set(const Vector &x)
Set where .
int main(int argc, char *argv[])
A simple wrapper which allows application of constraint Jacobians through the LinearOperator interfac...